diff --git a/src/EditProfileDialog.h b/src/EditProfileDialog.h --- a/src/EditProfileDialog.h +++ b/src/EditProfileDialog.h @@ -91,6 +91,8 @@ // reimplemented void reject() Q_DECL_OVERRIDE; + void apply(); + protected: bool eventFilter(QObject *watched, QEvent *event) Q_DECL_OVERRIDE; @@ -256,6 +258,13 @@ ColorSchemeEditor *_colorDialog; QDialogButtonBox *mButtonBox; + + // returns false if: + // - the profile config file is in a read-only directory e.g. /usr/share/konsole OR + // - the profile name is empty OR + // - if the name matches the name of an already existing profile. + // otherwise returns true + bool canSaveProfile(); }; /** diff --git a/src/EditProfileDialog.cpp b/src/EditProfileDialog.cpp --- a/src/EditProfileDialog.cpp +++ b/src/EditProfileDialog.cpp @@ -83,7 +83,7 @@ connect(mButtonBox->button(QDialogButtonBox::Apply), &QPushButton::clicked, this, - &Konsole::EditProfileDialog::save); + &Konsole::EditProfileDialog::apply); connect(_delayedPreviewTimer, &QTimer::timeout, this, &Konsole::EditProfileDialog::delayedPreviewActivate); @@ -142,21 +142,70 @@ } void EditProfileDialog::accept() +{ + if (!canSaveProfile()) { + return; + } + save(); + unpreviewAll(); + QDialog::accept(); +} + +void EditProfileDialog::apply() +{ + if (!canSaveProfile()) { + return; + } + save(); +} + +bool EditProfileDialog::canSaveProfile() { Q_ASSERT(_profile); Q_ASSERT(_tempProfile); + QFileInfo fileInfo(_profile->path()); + if (_profile->isPropertySet(Profile::Path) && fileInfo.exists()) { + if (!fileInfo.isWritable()) { + KMessageBox::sorry(this, + i18n("
Could not save settings to the current profile:
") + + QStringLiteral("\"") + _profile->path() + QStringLiteral("\"") + + i18n("The profile configuration file is most likely in a read-only directory.
" + "To be able to save settings, please change the profile name.
")); + return false; + } + } + + Profile::Ptr existingProfile; + QListEach profile must have a name before it can be saved " "into disk.
")); - return; + // revert the name in the dialog + _ui->profileNameEdit->setText(_profile->name()); + selectProfileName(); + return false; + } else if (!_tempProfile->name().isEmpty() && otherExistingProfileNames.contains(_tempProfile->name())) { + KMessageBox::sorry(this, + i18n("A profile with this name already exists.
")); + // revert the name in the dialog + _ui->profileNameEdit->setText(_profile->name()); + selectProfileName(); + return false; + } else { + return true; } - save(); - unpreviewAll(); - QDialog::accept(); } QString EditProfileDialog::groupProfileNames(const ProfileGroup::Ptr group, int maxLength) diff --git a/src/ProfileManager.cpp b/src/ProfileManager.cpp --- a/src/ProfileManager.cpp +++ b/src/ProfileManager.cpp @@ -342,6 +342,8 @@ { Q_ASSERT(profile); + QString origPath = profile->path(); + // never save a profile with empty name into disk! persistent = persistent && !profile->name().isEmpty(); @@ -411,6 +413,26 @@ // it has no file on disk if (persistent && !newProfile->isHidden()) { newProfile->setProperty(Profile::Path, saveProfile(newProfile)); + // if the profile was renamed, after saving the new profile + // delete the the old/redundant profile. + // only do this if origPath is not empty, because it's empty + // when creating a new profile, this works around a bug where + // the newly created profile appears twice in the ProfileSettings + // dialog + if (!origPath.isEmpty() && newProfile->path() != origPath) { + Profile::Ptr oldProfile; + // this is needed to include the old profile too + _loadedAllProfiles = false; + QList