Commit 4cab54d2 authored by Ahmad Samir's avatar Ahmad Samir Committed by Kurt Hindenburg
Browse files

Don't connect more slots to EditProfileDialog::accepted() signal

This is similar to commit c413d543, EditProfileDialog's base class
(KPageDialog) already connects OK button clicked signal to accepted() signal;
creating another connection to accepted() in SessionController (which
creates the EditProfileDialog object), means the code will be run twice, not
ideal. Instead put the logic in EditProfileDialog::save() which is called by
the EditProfileDialog::accept() slot.

The same goes when ProfileSettings creates an EditProfileDialog.
parent 414f933f
......@@ -917,11 +917,6 @@ void SessionController::editCurrentProfile()
dialog->setModal(true);
dialog->setProfile(profile, state);
connect(dialog, &QDialog::accepted, this, [profile]() {
ProfileManager::instance()->addProfile(profile);
ProfileManager::instance()->changeProfile(profile, profile->setProperties());
});
dialog->show();
}
......
......@@ -151,11 +151,6 @@ void ProfileSettings::createProfile()
dialog->setProfile(newProfile, EditProfileDialog::NewProfile);
dialog->selectProfileName();
connect(dialog, &QDialog::accepted, this, [newProfile]() {
ProfileManager::instance()->addProfile(newProfile);
ProfileManager::instance()->changeProfile(newProfile, newProfile->setProperties());
});
dialog->show();
}
void ProfileSettings::editSelected()
......
......@@ -231,7 +231,19 @@ EditProfileDialog::~EditProfileDialog()
void EditProfileDialog::save()
{
const bool isNewProfile = _profileState == EditProfileDialog::NewProfile;
if (isNewProfile) {
ProfileManager::instance()->addProfile(_profile);
}
if (_tempProfile->isEmpty()) {
if (isNewProfile) {
// New profile, we need to save it to disk, even if no settings
// were changed and _tempProfile is empty
ProfileManager::instance()->changeProfile(_profile, _profile->setProperties());
}
return;
}
......@@ -342,7 +354,7 @@ QString EditProfileDialog::groupProfileNames(const ProfileGroup::Ptr &group, int
return caption;
}
void EditProfileDialog::updateCaption(const Profile::Ptr &profile, EditProfileDialog::InitialProfileState state)
void EditProfileDialog::updateCaption(const Profile::Ptr &profile)
{
const int MAX_GROUP_CAPTION_LENGTH = 25;
ProfileGroup::Ptr group = profile->asGroup();
......@@ -353,7 +365,7 @@ void EditProfileDialog::updateCaption(const Profile::Ptr &profile, EditProfileDi
group->profiles().count(),
caption));
} else {
if (state == EditProfileDialog::NewProfile) {
if (_profileState == EditProfileDialog::NewProfile) {
setWindowTitle(i18n("Create New Profile"));
} else {
setWindowTitle(i18n("Edit Profile \"%1\"", profile->name()));
......@@ -367,8 +379,10 @@ void EditProfileDialog::setProfile(const Konsole::Profile::Ptr &profile, EditPro
_profile = profile;
_profileState = state;
// update caption
updateCaption(profile, state);
updateCaption(profile);
// mark each page of the dialog as out of date
// and force an update of the currently visible page
......
......@@ -270,7 +270,7 @@ private:
void unpreviewAll();
void enableIfNonEmptySelection(QWidget *widget, QItemSelectionModel *selectionModel);
void updateCaption(const Profile::Ptr &profile, InitialProfileState state = EditProfileDialog::ExistingProfile);
void updateCaption(const Profile::Ptr &profile);
void updateTransparencyWarning();
void updateFontPreview(QFont font);
......@@ -342,6 +342,8 @@ private:
ColorSchemeEditor *_colorDialog;
QDialogButtonBox *_buttonBox;
FontDialog *_fontDialog;
InitialProfileState _profileState = ExistingProfile;
};
}
......
Supports Markdown
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