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

Fix crash in ProfileSettings; clone selected profile settings to new profile

- If there is no selection only enable the "New" button, this fixes a
  crash if you select a profile, then Ctrl+Click to unselect it, the set
  as default button would still be enabled and clicking it caused a crash

- If a profile is selected, clone its properties, otherwise the fallback
  profile properties will be used, this more expected
parent 27cedc46
...@@ -90,13 +90,20 @@ void ProfileSettings::populateTable() ...@@ -90,13 +90,20 @@ void ProfileSettings::populateTable()
connect(profilesList->selectionModel(), &QItemSelectionModel::selectionChanged, this, &Konsole::ProfileSettings::tableSelectionChanged); connect(profilesList->selectionModel(), &QItemSelectionModel::selectionChanged, this, &Konsole::ProfileSettings::tableSelectionChanged);
} }
void ProfileSettings::tableSelectionChanged(const QItemSelection&) void ProfileSettings::tableSelectionChanged(const QItemSelection &selected)
{ {
newProfileButton->setEnabled(true);
if (selected.isEmpty()) {
editProfileButton->setEnabled(false);
deleteProfileButton->setEnabled(false);
setAsDefaultButton->setEnabled(false);
return;
}
const auto profile = currentProfile(); const auto profile = currentProfile();
const bool isNotDefault = profile != ProfileManager::instance()->defaultProfile(); const bool isNotDefault = profile != ProfileManager::instance()->defaultProfile();
newProfileButton->setEnabled(true);
// See comment about isProfileWritable(profile) in editSelected() // See comment about isProfileWritable(profile) in editSelected()
editProfileButton->setEnabled(isProfileWritable(profile)); editProfileButton->setEnabled(isProfileWritable(profile));
...@@ -126,14 +133,14 @@ void ProfileSettings::setSelectedAsDefault() ...@@ -126,14 +133,14 @@ void ProfileSettings::setSelectedAsDefault()
void ProfileSettings::createProfile() void ProfileSettings::createProfile()
{ {
// setup a temporary profile which is a clone of the selected profile auto newProfile = Profile::Ptr(new Profile(ProfileManager::instance()->fallbackProfile()));
// or the default if no profile is selected
Profile::Ptr sourceProfile = currentProfile() ? currentProfile() : ProfileManager::instance()->defaultProfile();
Q_ASSERT(sourceProfile); // If a profile is selected, clone its properties, otherwise the
// the fallback profile properties will be used
if (currentProfile()) {
newProfile->clone(currentProfile(), true);
}
auto newProfile = Profile::Ptr(new Profile(ProfileManager::instance()->fallbackProfile()));
newProfile->clone(sourceProfile, true);
const QString uniqueName = ProfileManager::instance()->generateUniqueName(); const QString uniqueName = ProfileManager::instance()->generateUniqueName();
newProfile->setProperty(Profile::Name, uniqueName); newProfile->setProperty(Profile::Name, uniqueName);
newProfile->setProperty(Profile::UntranslatedName, uniqueName); newProfile->setProperty(Profile::UntranslatedName, uniqueName);
...@@ -189,7 +196,7 @@ Profile::Ptr ProfileSettings::currentProfile() const ...@@ -189,7 +196,7 @@ Profile::Ptr ProfileSettings::currentProfile() const
{ {
QItemSelectionModel* selection = profilesList->selectionModel(); QItemSelectionModel* selection = profilesList->selectionModel();
if ((selection == nullptr) || selection->selectedRows().count() != 1) { if ((selection == nullptr) || !selection->hasSelection()) {
return Profile::Ptr(); return Profile::Ptr();
} }
......
Markdown is supported
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