diff --git a/shell/openprojectdialog.h b/shell/openprojectdialog.h --- a/shell/openprojectdialog.h +++ b/shell/openprojectdialog.h @@ -33,7 +33,17 @@ public: OpenProjectDialog( bool fetch, const QUrl& startUrl, QWidget* parent = 0 ); + + /** + * Return a QUrl pointing to the project's .kdev file. + */ QUrl projectFileUrl(); + /** + * Return a QUrl pointing to the file, that was selected by the user. + * Unlike projectFileUrl(), this can be a .kdev file, as well + * as build system file (e.g. CMakeLists.txt). + */ + QUrl selectedUrl() const; QString projectName(); QString projectManager(); @@ -48,6 +58,7 @@ private: void validateProjectInfo(); QUrl m_url; + QUrl m_selected; QString m_projectName; QString m_projectManager; KPageWidgetItem* sourcePage; diff --git a/shell/openprojectdialog.cpp b/shell/openprojectdialog.cpp --- a/shell/openprojectdialog.cpp +++ b/shell/openprojectdialog.cpp @@ -123,6 +123,8 @@ return; } + m_selected = url; + if( isDir || extension != ShellExtension::getInstance()->projectFileExtension() ) { setAppropriate( projectInfoPage, true ); @@ -212,6 +214,11 @@ return m_url; } +QUrl OpenProjectDialog::selectedUrl() const +{ + return m_selected; +} + QString OpenProjectDialog::projectName() { return m_projectName; diff --git a/shell/projectcontroller.cpp b/shell/projectcontroller.cpp --- a/shell/projectcontroller.cpp +++ b/shell/projectcontroller.cpp @@ -328,28 +328,29 @@ ProjectDialogProvider::~ProjectDialogProvider() {} -bool writeNewProjectFile( const QString& localConfigFile, const QString& name, const QString& manager ) +bool writeNewProjectFile( const QString& localConfigFile, const QString& name, const QString& createdFrom, const QString& manager ) { KSharedConfigPtr cfg = KSharedConfig::openConfig( localConfigFile, KConfig::SimpleConfig ); if (!cfg->isConfigWritable(true)) { qCDebug(SHELL) << "can't write to configfile"; return false; } KConfigGroup grp = cfg->group( "Project" ); grp.writeEntry( "Name", name ); + grp.writeEntry( "CreatedFrom", createdFrom ); grp.writeEntry( "Manager", manager ); cfg->sync(); return true; } -bool writeProjectSettingsToConfigFile(const QUrl& projectFileUrl, const QString& projectName, const QString& projectManager) +bool writeProjectSettingsToConfigFile(const QUrl& projectFileUrl, OpenProjectDialog* dlg) { if ( !projectFileUrl.isLocalFile() ) { QTemporaryFile tmp; if ( !tmp.open() ) { return false; } - if ( !writeNewProjectFile( tmp.fileName(), projectName, projectManager ) ) { + if ( !writeNewProjectFile( tmp.fileName(), dlg->projectName(), dlg->selectedUrl().fileName(), dlg->projectManager() ) ) { return false; } // explicitly close file before uploading it, see also: https://bugs.kde.org/show_bug.cgi?id=254519 @@ -359,7 +360,9 @@ KJobWidgets::setWindow(uploadJob, Core::self()->uiControllerInternal()->defaultMainWindow()); return uploadJob->exec(); } - return writeNewProjectFile( projectFileUrl.toLocalFile(),projectName, projectManager ); + // Here and above we take .filename() part of the selectedUrl() to make it relative to the project root, + // thus making .kdev file relocatable + return writeNewProjectFile( projectFileUrl.toLocalFile(), dlg->projectName(), dlg->selectedUrl().fileName(), dlg->projectManager() ); } @@ -401,18 +404,21 @@ { // check whether config is equal bool shouldAsk = true; - if( projectFileUrl.isLocalFile() ) + if( projectFileUrl == dlg.selectedUrl() ) { - shouldAsk = !equalProjectFile( projectFileUrl.toLocalFile(), &dlg ); - } else { - shouldAsk = false; - - QTemporaryFile tmpFile; - if (tmpFile.open()) { - auto downloadJob = KIO::file_copy(projectFileUrl, QUrl::fromLocalFile(tmpFile.fileName())); - KJobWidgets::setWindow(downloadJob, qApp->activeWindow()); - if (downloadJob->exec()) { - shouldAsk = !equalProjectFile(tmpFile.fileName(), &dlg); + if( projectFileUrl.isLocalFile() ) + { + shouldAsk = !equalProjectFile( projectFileUrl.toLocalFile(), &dlg ); + } else { + shouldAsk = false; + + QTemporaryFile tmpFile; + if (tmpFile.open()) { + auto downloadJob = KIO::file_copy(projectFileUrl, QUrl::fromLocalFile(tmpFile.fileName())); + KJobWidgets::setWindow(downloadJob, qApp->activeWindow()); + if (downloadJob->exec()) { + shouldAsk = !equalProjectFile(tmpFile.fileName(), &dlg); + } } } } @@ -446,7 +452,7 @@ } if (writeProjectConfigToFile) { - if (!writeProjectSettingsToConfigFile(projectFileUrl, dlg.projectName(), dlg.projectManager())) { + if (!writeProjectSettingsToConfigFile(projectFileUrl, &dlg)) { KMessageBox::error(d->m_core->uiControllerInternal()->defaultMainWindow(), i18n("Unable to create configuration file %1", projectFileUrl.url())); return QUrl();