From 1adc69e39a92d25a2b5192c5cc9efe420075c717 Mon Sep 17 00:00:00 2001 From: Kurt Hindenburg Date: Sat, 23 Dec 2017 11:20:15 -0500 Subject: [PATCH] Popup dialog if changes are made to read-only profiles Add dialog to explain how to change a ro profile. patch by ahmadsamir Differential Revision: https://phabricator.kde.org/D9350 --- src/EditProfileDialog.cpp | 25 ++++++++++++++++++++++--- src/EditProfileDialog.h | 7 +++++-- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/EditProfileDialog.cpp b/src/EditProfileDialog.cpp index 6496958e..52b94c2b 100644 --- a/src/EditProfileDialog.cpp +++ b/src/EditProfileDialog.cpp @@ -143,10 +143,15 @@ void EditProfileDialog::reject() void EditProfileDialog::accept() { - if (!isValidProfileName()) { - return; + // if the Apply button is disabled then no settings were changed + // or the changes have already been saved by apply() + if (mButtonBox->button(QDialogButtonBox::Apply)->isEnabled()) { + if (!isValidProfileName()) { + return; + } + save(); } - save(); + unpreviewAll(); QDialog::accept(); } @@ -164,6 +169,20 @@ bool EditProfileDialog::isValidProfileName() Q_ASSERT(_profile); Q_ASSERT(_tempProfile); + // check whether the user has enough permissions to save the profile + QFileInfo fileInfo(_profile->path()); + if (fileInfo.exists() && !fileInfo.isWritable()) { + if (!_tempProfile->isPropertySet(Profile::Name) + || (_tempProfile->isPropertySet(Profile::Name) && _tempProfile->name() == _profile->name())) { + KMessageBox::sorry(this, + i18n("

Konsole does not have permission to save this profile to:
\"%1\"

" + "

To be able to save settings you can either change the permissions " + "of the profile configuration file or change the profile name to save " + "the settings to a new profile.

", _profile->path())); + return false; + } + } + const QList existingProfiles = ProfileManager::instance()->allProfiles(); QStringList otherExistingProfileNames; diff --git a/src/EditProfileDialog.h b/src/EditProfileDialog.h index 5f05cd2a..1c844599 100644 --- a/src/EditProfileDialog.h +++ b/src/EditProfileDialog.h @@ -242,8 +242,11 @@ private: }; void setupCheckBoxes(BooleanOption *options, const Profile::Ptr profile); - // returns false if the profile name is empty or if the name matches - // the name of an already existing profile; otherwise return true. + // returns false if: + // - the profile name is empty + // - the name matches the name of an already existing profile + // - the existing profile config file is read-only + // otherwise returns true. bool isValidProfileName(); Ui::EditProfileDialog *_ui;