Commit 056df09c authored by Daniel Molkentin's avatar Daniel Molkentin Committed by Eike Ziller

WelcomePage: Reintroduce fallback copying.

In case the project file is not user-writable,
assume that the entire project isn't and create
a copy. Useful e.g. for distro packaged examples.

Also, make the additonal files to open work properly.

Change-Id: Iedd590ba7709c0e689adcb3944e75394b6ef0955
Reviewed-on: http://codereview.qt.nokia.com/1097Reviewed-by: default avatarQt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: default avatarEike Ziller <eike.ziller@nokia.com>
parent 8dd37bd5
......@@ -92,7 +92,7 @@ QList<ExampleItem> ExamplesListModel::parseExamples(QXmlStreamReader* reader, co
item.imageUrl = attributes.value(QLatin1String("imagePath")).toString();
item.docUrl = attributes.value(QLatin1String("docUrl")).toString();
} else if (reader->name() == QLatin1String("fileToOpen")) {
item.filesToOpen.append(reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement));
item.filesToOpen.append(projectsOffset + '/' + reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement));
} else if (reader->name() == QLatin1String("description")) {
item.description = reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement);
} else if (reader->name() == QLatin1String("tags")) {
......@@ -132,7 +132,7 @@ QList<ExampleItem> ExamplesListModel::parseDemos(QXmlStreamReader* reader, const
item.imageUrl = attributes.value(QLatin1String("imageUrl")).toString();
item.docUrl = attributes.value(QLatin1String("docUrl")).toString();
} else if (reader->name() == QLatin1String("fileToOpen")) {
item.filesToOpen.append(reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement));
item.filesToOpen.append(projectsOffset + '/' + reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement));
} else if (reader->name() == QLatin1String("description")) {
item.description = reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement);
} else if (reader->name() == QLatin1String("tags")) {
......@@ -171,7 +171,7 @@ QList<ExampleItem> ExamplesListModel::parseTutorials(QXmlStreamReader* reader, c
item.imageUrl = attributes.value(QLatin1String("imageUrl")).toString();
item.docUrl = attributes.value(QLatin1String("docUrl")).toString();
} else if (reader->name() == QLatin1String("fileToOpen")) {
item.filesToOpen.append(reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement));
item.filesToOpen.append(projectsOffset + '/' + reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement));
} else if (reader->name() == QLatin1String("description")) {
item.description = reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement);
} else if (reader->name() == QLatin1String("tags")) {
......@@ -192,7 +192,7 @@ QList<ExampleItem> ExamplesListModel::parseTutorials(QXmlStreamReader* reader, c
return tutorials;
}
void ExamplesListModel::readNewsItems(const QString &examplesPath, const QString &demosPath, const QString & /* sourcePath */)
void ExamplesListModel::readNewsItems(const QString &examplesPath, const QString &demosPath, const QString & sourcePath)
{
clear();
foreach (const QString exampleSource, exampleSources()) {
......@@ -207,9 +207,18 @@ void ExamplesListModel::readNewsItems(const QString &examplesPath, const QString
QDir examplesDir(offsetPath);
QDir demosDir(offsetPath);
if (offsetPath.startsWith(Core::ICore::instance()->resourcePath())) {
// Try to get dir from first Qt Version
examplesDir = examplesPath;
demosDir = demosPath;
// Try to get dir from first Qt Version, based on the Qt source directory
// at first, since examplesPath / demosPath points at the build directory
QString sourceBasedExamplesPath = sourcePath + QLatin1String("/examples");
QString sourceBasedDemosPath = sourcePath + QLatin1String("/demos");
examplesDir = sourceBasedExamplesPath;
demosDir = sourceBasedDemosPath;
// SDK case, folders might be called sth else (e.g. 'Examples' with uppercase E)
// but examplesPath / demosPath is correct
if (!examplesDir.exists() || !demosDir.exists()) {
examplesDir = examplesPath;
demosDir = demosPath;
}
}
QXmlStreamReader reader(&exampleFile);
......@@ -350,7 +359,7 @@ void ExamplesListModel::helpInitialized()
disconnect(this, SLOT(cacheExamplesPath(QString, QString, QString)));
connect(QtVersionManager::instance(), SIGNAL(updateExamples(QString,QString,QString)),
SLOT(readNewsItems(QString,QString,QString)));
readNewsItems(m_cache.examplesPath, m_cache.demosPath, m_cache.examplesPath);
readNewsItems(m_cache.examplesPath, m_cache.demosPath, m_cache.sourcePath);
}
......
......@@ -34,6 +34,9 @@
#include "exampleslistmodel.h"
#include <utils/pathchooser.h>
#include <utils/fileutils.h>
#include <coreplugin/coreplugin.h>
#include <coreplugin/helpmanager.h>
#include <projectexplorer/projectexplorer.h>
......@@ -49,6 +52,8 @@
namespace QtSupport {
namespace Internal {
const char *C_FALLBACK_ROOT = "ProjectsFallbackRoot";
class HelpImageProvider : public QDeclarativeImageProvider
{
public:
......@@ -79,7 +84,7 @@ GettingStartedWelcomePage::GettingStartedWelcomePage()
void GettingStartedWelcomePage::facilitateQml(QDeclarativeEngine *engine)
{
m_engine = engine;
m_engine->addImageProvider("helpimage", new HelpImageProvider);
m_engine->addImageProvider(QLatin1String("helpimage"), new HelpImageProvider);
m_examplesModel = new ExamplesListModel(this);
connect (m_examplesModel, SIGNAL(tagsUpdated()), SLOT(updateTagsModel()));
ExamplesListModelFilter *proxy = new ExamplesListModelFilter(this);
......@@ -89,8 +94,8 @@ void GettingStartedWelcomePage::facilitateQml(QDeclarativeEngine *engine)
proxy->setFilterCaseSensitivity(Qt::CaseInsensitive);
QDeclarativeContext *rootContenxt = m_engine->rootContext();
rootContenxt->setContextProperty("examplesModel", proxy);
rootContenxt->setContextProperty("gettingStarted", this);
rootContenxt->setContextProperty(QLatin1String("examplesModel"), proxy);
rootContenxt->setContextProperty(QLatin1String("gettingStarted"), this);
}
void GettingStartedWelcomePage::openSplitHelp(const QUrl &help)
......@@ -103,19 +108,94 @@ QStringList GettingStartedWelcomePage::tagList() const
return m_examplesModel->tags();
}
QString GettingStartedWelcomePage::copyToAlternativeLocation(const QFileInfo& proFileInfo, QStringList &filesToOpen)
{
const QString projectDir = proFileInfo.canonicalPath();
QDialog d(Core::ICore::instance()->mainWindow());
QGridLayout *lay = new QGridLayout(&d);
QLabel *descrLbl = new QLabel;
d.setWindowTitle(tr("Copy Project to writable Location?"));
descrLbl->setTextFormat(Qt::RichText);
descrLbl->setWordWrap(true);
descrLbl->setText(tr("<p>The project you are about to open is located in the "
"write-protected location:</p><blockquote>%1</blockquote>"
"<p>Please select a writable location below and click \"Copy Project and Open\" "
"to open a modifiable copy of the project or click \"Keep Project and Open\" "
"to open the project in location.</p><p><b>Note:</b> You will not "
"be able to alter or compile your project in the current location.</p>")
.arg(QDir::toNativeSeparators(projectDir)));
lay->addWidget(descrLbl, 0, 0, 1, 2);
QLabel *txt = new QLabel(tr("&Location:"));
Utils::PathChooser *chooser = new Utils::PathChooser;
txt->setBuddy(chooser);
chooser->setExpectedKind(Utils::PathChooser::ExistingDirectory);
QSettings *settings = Core::ICore::instance()->settings();
chooser->setPath(settings->value(
QString::fromLatin1(C_FALLBACK_ROOT), QDir::homePath()).toString());
lay->addWidget(txt, 1, 0);
lay->addWidget(chooser, 1, 1);
QDialogButtonBox *bb = new QDialogButtonBox;
connect(bb, SIGNAL(accepted()), &d, SLOT(accept()));
connect(bb, SIGNAL(rejected()), &d, SLOT(reject()));
QPushButton *copyBtn = bb->addButton(tr("&Copy Project and Open"), QDialogButtonBox::AcceptRole);
copyBtn->setDefault(true);
bb->addButton(tr("&Keep Project and Open"), QDialogButtonBox::RejectRole);
lay->addWidget(bb, 2, 0, 1, 2);
connect(chooser, SIGNAL(validChanged(bool)), copyBtn, SLOT(setEnabled(bool)));
if (d.exec() == QDialog::Accepted) {
QString exampleDirName = proFileInfo.dir().dirName();
QString destBaseDir = chooser->path();
settings->setValue(QString::fromLatin1(C_FALLBACK_ROOT), destBaseDir);
QDir toDirWithExamplesDir(destBaseDir);
if (toDirWithExamplesDir.cd(exampleDirName)) {
toDirWithExamplesDir.cdUp(); // step out, just to not be in the way
QMessageBox::warning(Core::ICore::instance()->mainWindow(), tr("Cannot Use Location"),
tr("The specified location already exists. "
"Please specify a valid location."),
QMessageBox::Ok, QMessageBox::NoButton);
return QString();
} else {
QString error;
QString targetDir = destBaseDir + '/' + exampleDirName;
if (Utils::FileUtils::copyRecursively(projectDir, targetDir, &error)) {
// set vars to new location
QStringList::Iterator it;
for (it = filesToOpen.begin(); it != filesToOpen.end(); ++it)
it->replace(projectDir, targetDir);
return targetDir+ '/' + proFileInfo.fileName();
} else {
QMessageBox::warning(Core::ICore::instance()->mainWindow(), tr("Cannot Copy Project"), error);
}
}
}
return QString();
}
void GettingStartedWelcomePage::openProject(const QString &projectFile, const QStringList &additionalFilesToOpen, const QUrl &help)
{
qDebug() << projectFile << additionalFilesToOpen << help;
QString proFile = projectFile;
if (proFile.isEmpty())
return;
QStringList filesToOpen = additionalFilesToOpen;
QFileInfo proFileInfo(proFile);
// If the Qt is a distro Qt on Linux, it will not be writable, hence compilation will fail
if (!proFileInfo.isWritable())
proFile = copyToAlternativeLocation(proFileInfo, filesToOpen);
// don't try to load help and files if loading the help request is being cancelled
if (ProjectExplorer::ProjectExplorerPlugin::instance()->openProject(projectFile)) {
Core::ICore::instance()->openFiles(additionalFilesToOpen);
if (!proFile.isEmpty() && ProjectExplorer::ProjectExplorerPlugin::instance()->openProject(proFile)) {
Core::ICore::instance()->openFiles(filesToOpen);
Core::ICore::instance()->helpManager()->handleHelpRequest(help.toString()+QLatin1String("?view=split"));
}
}
void GettingStartedWelcomePage::updateTagsModel()
{
m_engine->rootContext()->setContextProperty("tagsList", m_examplesModel->tags());
m_engine->rootContext()->setContextProperty(QLatin1String("tagsList"), m_examplesModel->tags());
emit tagsUpdated();
}
......
......@@ -41,6 +41,7 @@
QT_BEGIN_NAMESPACE
class QDeclarativeEngine;
class QFileInfo;
QT_END_NAMESPACE
namespace QtSupport {
......@@ -71,6 +72,7 @@ public slots:
void updateTagsModel();
private:
QString copyToAlternativeLocation(const QFileInfo &fileInfo, QStringList &filesToOpen);
ExamplesListModel *m_examplesModel;
QDeclarativeEngine *m_engine;
};
......
include(../../plugins/projectexplorer/projectexplorer.pri)
include(../../libs/qmljs/qmljs.pri)
include(../../libs/utils/utils.pri)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment