Skip to content

Commit

Permalink
panel/plugin: Fix settings storing/restoring
Browse files Browse the repository at this point in the history
- 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).
  • Loading branch information
palinek committed Mar 14, 2022
1 parent e3ab2ee commit 5a669b1
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
9 changes: 9 additions & 0 deletions panel/lxqtpanelpluginconfigdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ PluginSettings& LXQtPanelPluginConfigDialog::settings() const
}


/************************************************
************************************************/
void LXQtPanelPluginConfigDialog::closeEvent(QCloseEvent *event)
{
mSettings.storeToCache();
return QDialog::closeEvent(event);
}


/************************************************
Expand Down
4 changes: 4 additions & 0 deletions panel/lxqtpanelpluginconfigdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "pluginsettings.h"

class QComboBox;
class QCloseEvent;

class LXQT_PANEL_API LXQtPanelPluginConfigDialog : public QDialog
{
Expand All @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion panel/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 8 additions & 0 deletions panel/pluginsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,14 @@ void PluginSettings::loadFromCache()
d->mSettings->endGroup();
}

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*/)
{
return new PluginSettings{settings, group, parent};
Expand Down
1 change: 1 addition & 0 deletions panel/pluginsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class LXQT_PANEL_API PluginSettings : public QObject
void endGroup();

void loadFromCache();
void storeToCache();

signals:
void settingsChanged();
Expand Down

0 comments on commit 5a669b1

Please sign in to comment.