Optimise saving profile shortcuts

- Call ProfileSettings::slotAccepted() when the parent ConfigurationDialog
  is accepted, so that ProfileManager::saveSettings() is called
- don't delete the ProfileSettings dialog on accept, it'll be destroyed when
  the parent ConfigurationDialog is destroyed
- save the profiles' shorcuts if they were actually changed

With this commit and the previous one, there is no need for ~Part() or
~Application() to call saveSettings(), shorcuts settings are saved when
the ProfileSettings dialog is accepted and saving the default profile is
done in setDefaultProfile(). This fixes an issue where changing e.g. the
default profile is only saved to the konsolerc file when the main window is
closed.
wilder
Ahmad Samir 4 years ago committed by Kurt Hindenburg
parent 4a64904a89
commit c24a0876f7
  1. 1
      src/Application.cpp
  2. 4
      src/MainWindow.cpp
  3. 5
      src/Part.cpp
  4. 22
      src/profile/ProfileManager.cpp
  5. 6
      src/profile/ProfileManager.h
  6. 1
      src/settings/ProfileSettings.cpp
  7. 3
      src/settings/ProfileSettings.h

@ -109,7 +109,6 @@ QStringList Application::getCustomCommand(QStringList &args)
Application::~Application()
{
SessionManager::instance()->closeAllSessions();
ProfileManager::instance()->saveSettings();
}
MainWindow *Application::newMainWindow()

@ -766,9 +766,11 @@ void MainWindow::showSettingsDialog(const bool showProfilePage)
generalPage->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
confDialog->addPage(generalPage, true);
auto *profilePage = new KPageWidgetItem(new ProfileSettings(confDialog), profilePageName);
auto *profileSettings = new ProfileSettings(confDialog);
auto *profilePage = new KPageWidgetItem(profileSettings, profilePageName);
profilePage->setIcon(QIcon::fromTheme(QStringLiteral("preferences-system-profiles")));
confDialog->addPage(profilePage, true);
connect(confDialog, &QDialog::accepted, profileSettings, &ProfileSettings::slotAccepted);
const QString tabBarPageName = i18nc("@title Preferences page name", "Tab Bar / Splitters");
auto tabBarPage = new KPageWidgetItem(new TabBarSettings(confDialog), tabBarPageName);

@ -67,10 +67,7 @@ Part::Part(QWidget *parentWidget, QObject *parent, const QVariantList &)
createSession();
}
Part::~Part()
{
ProfileManager::instance()->saveSettings();
}
Part::~Part() = default;
bool Part::openFile()
{

@ -215,12 +215,7 @@ void ProfileManager::loadAllProfiles(const QString &defaultProfileFileName)
void ProfileManager::saveSettings()
{
// save shortcuts
saveShortcuts();
// ensure default/shortcuts settings are synced into disk
KSharedConfigPtr appConfig = KSharedConfig::openConfig();
appConfig->sync();
}
void ProfileManager::sortProfiles()
@ -467,17 +462,24 @@ void ProfileManager::loadShortcuts()
void ProfileManager::saveShortcuts()
{
KSharedConfigPtr appConfig = KSharedConfig::openConfig();
KConfigGroup shortcutGroup = appConfig->group("Profile Shortcuts");
shortcutGroup.deleteGroup();
if (_profileShortcutsChanged) {
_profileShortcutsChanged = false;
KSharedConfigPtr appConfig = KSharedConfig::openConfig();
KConfigGroup shortcutGroup = appConfig->group("Profile Shortcuts");
shortcutGroup.deleteGroup();
for (const auto &[profile, keySeq] : _shortcuts) {
shortcutGroup.writeEntry(keySeq.toString(), profile->name());
}
for (const auto &[profile, keySeq] : _shortcuts) {
shortcutGroup.writeEntry(keySeq.toString(), profile->name());
appConfig->sync();
}
}
void ProfileManager::setShortcut(Profile::Ptr profile, const QKeySequence &keySequence)
{
_profileShortcutsChanged = true;
QKeySequence existingShortcut = shortcut(profile);
auto profileIt = std::find_if(_shortcuts.begin(), _shortcuts.end(), [&profile](const ShortcutData &data) {

@ -181,7 +181,7 @@ Q_SIGNALS:
void shortcutChanged(const Profile::Ptr &profile, const QKeySequence &newShortcut);
public Q_SLOTS:
/** Saves settings (shortcuts, default profile etc.) to disk. */
/** Saves settings (shortcuts) to disk. */
void saveSettings();
protected Q_SLOTS:
@ -233,6 +233,10 @@ private:
QKeySequence keySeq;
};
std::vector<ShortcutData> _shortcuts;
// Set to true when setShortcut() is called so that when the ProfileSettings
// dialog is accepted the profiles shorcut changes are saved
bool _profileShortcutsChanged = false;
};
}

@ -57,7 +57,6 @@ ProfileSettings::~ProfileSettings() = default;
void ProfileSettings::slotAccepted()
{
ProfileManager::instance()->saveSettings();
deleteLater();
}
void ProfileSettings::doubleClicked(const QModelIndex &idx)

@ -54,9 +54,10 @@ public:
*/
void setShortcutEditorVisible(bool visible);
protected:
private Q_SLOTS:
friend class MainWindow;
void slotAccepted();
void deleteSelected();
void setSelectedAsDefault();
void createProfile();

Loading…
Cancel
Save