From b62ed2954e8c8aa82956e7d1940386837fa32635 Mon Sep 17 00:00:00 2001 From: Palo Kisa Date: Mon, 14 Mar 2022 11:44:30 +0100 Subject: [PATCH 1/3] panel/plugin: Fix settings storing/restoring - Add emitting settingsChanged() into PluginSettings::loadFromCache() to notify plugin/users, that settings were updated. Previously the signal was probably emitted by the underlying object detecting the settings file changed, but this is not the case any more (probably enhancement in the underlying Qt's QSettings optimization). - Add PlutingSettings::storeToCache() for the plugin configure dialog to be able to store to cache on closing the dialog -> after re-showing or showing freshly created one, we expect to be able to reset to the values shown initialy in this dialog. - Delete plugin's config dialog before deleting the plugin object itself, as the config dialog can rely/use other plugin objects and deleting/closing the dialog late after plugin object destroyed can cause problems (invalid memory access). --- panel/lxqtpanelpluginconfigdialog.cpp | 9 +++++++++ panel/lxqtpanelpluginconfigdialog.h | 4 ++++ panel/plugin.cpp | 3 ++- panel/pluginsettings.cpp | 9 +++++++++ panel/pluginsettings.h | 1 + 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/panel/lxqtpanelpluginconfigdialog.cpp b/panel/lxqtpanelpluginconfigdialog.cpp index 0978f13a6..a92d46c81 100644 --- a/panel/lxqtpanelpluginconfigdialog.cpp +++ b/panel/lxqtpanelpluginconfigdialog.cpp @@ -58,6 +58,15 @@ PluginSettings& LXQtPanelPluginConfigDialog::settings() const } +/************************************************ + + ************************************************/ +void LXQtPanelPluginConfigDialog::closeEvent(QCloseEvent *event) +{ + mSettings.storeToCache(); + return QDialog::closeEvent(event); +} + /************************************************ diff --git a/panel/lxqtpanelpluginconfigdialog.h b/panel/lxqtpanelpluginconfigdialog.h index 93bd4e0d5..8fdb14e7b 100644 --- a/panel/lxqtpanelpluginconfigdialog.h +++ b/panel/lxqtpanelpluginconfigdialog.h @@ -35,6 +35,7 @@ #include "pluginsettings.h" class QComboBox; +class QCloseEvent; class LXQT_PANEL_API LXQtPanelPluginConfigDialog : public QDialog { @@ -46,6 +47,9 @@ class LXQT_PANEL_API LXQtPanelPluginConfigDialog : public QDialog PluginSettings &settings() const; +protected: + virtual void closeEvent(QCloseEvent *event) override; + protected slots: /* Saves settings in conf file. diff --git a/panel/plugin.cpp b/panel/plugin.cpp index c4d3c440d..25903a100 100644 --- a/panel/plugin.cpp +++ b/panel/plugin.cpp @@ -188,6 +188,8 @@ Plugin::Plugin(const LXQt::PluginInfo &desktopFile, LXQt::Settings *settings, co ************************************************/ Plugin::~Plugin() { + if (mConfigDialog) + delete mConfigDialog.data(); delete mPlugin; delete mPluginLoader; delete mSettings; @@ -515,7 +517,6 @@ void Plugin::showConfigureDialog() if (!mConfigDialog) return; - connect(this, &Plugin::destroyed, mConfigDialog.data(), &QWidget::close); mPanel->willShowWindow(mConfigDialog); mConfigDialog->show(); mConfigDialog->raise(); diff --git a/panel/pluginsettings.cpp b/panel/pluginsettings.cpp index d5a2be958..925db67b1 100644 --- a/panel/pluginsettings.cpp +++ b/panel/pluginsettings.cpp @@ -207,6 +207,15 @@ void PluginSettings::loadFromCache() d->mSettings->beginGroup(d->mGroup); d->mOldSettings.loadToSettings(); d->mSettings->endGroup(); + emit settingsChanged(); +} + +void PluginSettings::storeToCache() +{ + Q_D(PluginSettings); + d->mSettings->beginGroup(d->mGroup); + d->mOldSettings.loadFromSettings(); + d->mSettings->endGroup(); } PluginSettings* PluginSettingsFactory::create(LXQt::Settings *settings, const QString &group, QObject *parent/* = nullptr*/) diff --git a/panel/pluginsettings.h b/panel/pluginsettings.h index 19e5f5f7b..d9b01d554 100644 --- a/panel/pluginsettings.h +++ b/panel/pluginsettings.h @@ -81,6 +81,7 @@ class LXQT_PANEL_API PluginSettings : public QObject void endGroup(); void loadFromCache(); + void storeToCache(); signals: void settingsChanged(); From 51b3132b5d0c991a2d9c621dcfca0802ee64faba Mon Sep 17 00:00:00 2001 From: Palo Kisa Date: Mon, 14 Mar 2022 14:21:39 +0100 Subject: [PATCH 2/3] pluginsettings: Fix cache all keys handling Without calling the beginGroup() on parent settings object, we got the cache object constructed with all keys in the parent object (not only those belonging to our group). Then doing loadFromCache() flushed all keys from config and messed the configuration file. --- panel/pluginsettings.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/panel/pluginsettings.cpp b/panel/pluginsettings.cpp index 925db67b1..3f6c86459 100644 --- a/panel/pluginsettings.cpp +++ b/panel/pluginsettings.cpp @@ -28,15 +28,18 @@ #include "pluginsettings.h" #include "pluginsettings_p.h" #include +#include class PluginSettingsPrivate { public: PluginSettingsPrivate(LXQt::Settings* settings, const QString &group) : mSettings(settings) - , mOldSettings(settings) , mGroup(group) { + mSettings->beginGroup(mGroup); + mOldSettings = std::make_unique(mSettings); + mSettings->endGroup(); } QString prefix() const; @@ -46,7 +49,7 @@ class PluginSettingsPrivate } LXQt::Settings *mSettings; - LXQt::SettingsCache mOldSettings; + std::unique_ptr mOldSettings; QString mGroup; QStringList mSubGroups; }; @@ -163,10 +166,8 @@ void PluginSettings::clear() void PluginSettings::sync() { Q_D(PluginSettings); - d->mSettings->beginGroup(d->mGroup); d->mSettings->sync(); - d->mOldSettings.loadFromSettings(); - d->mSettings->endGroup(); + storeToCache(); emit settingsChanged(); } @@ -205,7 +206,8 @@ void PluginSettings::loadFromCache() { Q_D(PluginSettings); d->mSettings->beginGroup(d->mGroup); - d->mOldSettings.loadToSettings(); + d->mSettings->remove(QString{}); + d->mOldSettings->loadToSettings(); d->mSettings->endGroup(); emit settingsChanged(); } @@ -214,7 +216,7 @@ void PluginSettings::storeToCache() { Q_D(PluginSettings); d->mSettings->beginGroup(d->mGroup); - d->mOldSettings.loadFromSettings(); + d->mOldSettings = std::make_unique(d->mSettings); d->mSettings->endGroup(); } From 56efcad21fd4649160aa125e2a5e098b1e06fbec Mon Sep 17 00:00:00 2001 From: Palo Kisa Date: Mon, 14 Mar 2022 16:06:44 +0100 Subject: [PATCH 3/3] taskbar: Use "static" last resort default values --- plugin-taskbar/lxqttaskbar.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin-taskbar/lxqttaskbar.cpp b/plugin-taskbar/lxqttaskbar.cpp index aa4abe580..e6e4866ae 100644 --- a/plugin-taskbar/lxqttaskbar.cpp +++ b/plugin-taskbar/lxqttaskbar.cpp @@ -485,10 +485,10 @@ void LXQtTaskBar::settingsChanged() else setButtonStyle(Qt::ToolButtonTextBesideIcon); - mShowOnlyOneDesktopTasks = mPlugin->settings()->value(QStringLiteral("showOnlyOneDesktopTasks"), mShowOnlyOneDesktopTasks).toBool(); - mShowDesktopNum = mPlugin->settings()->value(QStringLiteral("showDesktopNum"), mShowDesktopNum).toInt(); - mShowOnlyCurrentScreenTasks = mPlugin->settings()->value(QStringLiteral("showOnlyCurrentScreenTasks"), mShowOnlyCurrentScreenTasks).toBool(); - mShowOnlyMinimizedTasks = mPlugin->settings()->value(QStringLiteral("showOnlyMinimizedTasks"), mShowOnlyMinimizedTasks).toBool(); + mShowOnlyOneDesktopTasks = mPlugin->settings()->value(QStringLiteral("showOnlyOneDesktopTasks"), false).toBool(); + mShowDesktopNum = mPlugin->settings()->value(QStringLiteral("showDesktopNum"), 0).toInt(); + mShowOnlyCurrentScreenTasks = mPlugin->settings()->value(QStringLiteral("showOnlyCurrentScreenTasks"), false).toBool(); + mShowOnlyMinimizedTasks = mPlugin->settings()->value(QStringLiteral("showOnlyMinimizedTasks"), false).toBool(); mAutoRotate = mPlugin->settings()->value(QStringLiteral("autoRotate"), true).toBool(); mCloseOnMiddleClick = mPlugin->settings()->value(QStringLiteral("closeOnMiddleClick"), true).toBool(); mRaiseOnCurrentDesktop = mPlugin->settings()->value(QStringLiteral("raiseOnCurrentDesktop"), false).toBool();