Index: kdevplatform/shell/openprojectdialog.h =================================================================== --- kdevplatform/shell/openprojectdialog.h +++ kdevplatform/shell/openprojectdialog.h @@ -67,6 +67,7 @@ private: bool execNativeDialog(); void validateProjectInfo(); + QUrl m_projectDirUrl; QUrl m_url; QUrl m_selected; QString m_projectName; Index: kdevplatform/shell/openprojectdialog.cpp =================================================================== --- kdevplatform/shell/openprojectdialog.cpp +++ kdevplatform/shell/openprojectdialog.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -73,6 +74,7 @@ const QUrl& repoUrl, IPlugin* vcsOrProviderPlugin, QWidget* parent) : KAssistantDialog( parent ) + , m_projectDirUrl(QUrl()) , m_urlIsDirectory(false) , sourcePage(nullptr) , openPage(nullptr) @@ -308,7 +310,23 @@ void OpenProjectDialog::validateProjectName( const QString& name ) { - m_projectName = name; + if (name != m_projectName) { + m_projectName = name; + if (m_projectDirUrl.isEmpty()) { + m_projectDirUrl = m_url; + } + QUrl url(m_projectDirUrl.adjusted(QUrl::StripTrailingSlash)); + // construct a version of the project name that's safe for use as a filename: + // TODO: do an additional replace of QDir::separator() with "@"? + QString safeName = m_projectName; + safeName.replace(QRegularExpression(QStringLiteral("[\\\\/]")), QStringLiteral("@")); + safeName = safeName.replace(QChar(':'), QChar('=')); + safeName = safeName.replace(QRegExp("\\s"), QStringLiteral("_")); + safeName += '.' + ShellExtension::getInstance()->projectFileExtension(); + m_url.setPath(url.path() + QLatin1Char('/') + safeName); + m_urlIsDirectory = false; + qCDebug(SHELL) << "project name:" << m_projectName << "file name:" << safeName << "in" << url.path(); + } validateProjectInfo(); } Index: kdevplatform/shell/projectcontroller.cpp =================================================================== --- kdevplatform/shell/projectcontroller.cpp +++ kdevplatform/shell/projectcontroller.cpp @@ -414,6 +414,9 @@ KSharedConfigPtr cfg = KSharedConfig::openConfig( configPath, KConfig::SimpleConfig ); KConfigGroup grp = cfg->group( "Project" ); QString defaultName = dlg->projectFileUrl().adjusted(QUrl::RemoveFilename | QUrl::StripTrailingSlash).fileName(); + qCDebug(SHELL) << "configPath=" << configPath << "defaultName=" << defaultName + << "projName=" << dlg->projectName() << "projectMan=" << dlg->projectManager() + << "grp.Name=" << grp.readEntry( "Name", QString() ) << "grp.Manager=" << grp.readEntry( "Manager", QString() ); return (grp.readEntry( "Name", QString() ) == dlg->projectName() || dlg->projectName() == defaultName) && grp.readEntry( "Manager", QString() ) == dlg->projectManager(); } @@ -429,7 +432,8 @@ } QUrl projectFileUrl = dlg->projectFileUrl(); - qCDebug(SHELL) << "selected project:" << projectFileUrl << dlg->projectName() << dlg->projectManager(); + qCDebug(SHELL) << "selected project:" << projectFileUrl << "selectedUrl=" << dlg->selectedUrl() + << "projectName=" << dlg->projectName() << "projectManager=" << dlg->projectManager(); if ( dlg->projectManager() == QLatin1String("") ) { return projectFileUrl; } @@ -438,10 +442,17 @@ bool writeProjectConfigToFile = true; if( projectFileExists( projectFileUrl ) ) { - // check whether config is equal - bool shouldAsk = true; - if( projectFileUrl == dlg->selectedUrl() ) + // check whether we should question the user about overriding an existing project file or not. + // We don't need to do that when the file we're importing (dlg->selectedUrl) is already an + // existing .kdev4 project file (we just verified that it exists): + bool isKDevProject = QFileInfo(dlg->selectedUrl().url()).suffix() == QStringLiteral("kdev4"); + bool shouldAsk = !isKDevProject; + if( !isKDevProject && projectFileUrl == dlg->selectedUrl() ) { + // We're importing a project from another type of project file, post the + // override dialog if there's a discrepancy between the project file URL + // and the information stored in the dialog and the project settings. + qCWarning(SHELL) << "Importing a foreign project type:" << projectFileUrl.url(); if( projectFileUrl.isLocalFile() ) { shouldAsk = !equalProjectFile( projectFileUrl.toLocalFile(), dlg );