[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [qtcurve] qt5/style: [qt5] properly clean up registered callbacks
From: Yichao Yu <yyc1992 () gmail ! com>
Date: 2016-03-19 16:50:54
Message-ID: E1ahK5W-0003rv-8P () scm ! kde ! org
[Download RAW message or body]
Git commit 47cae702616d2aa6095b7dda622a128775e9466a by Yichao Yu.
Committed on 19/03/2016 at 16:50.
Pushed by yuyichao into branch 'master'.
[qt5] properly clean up registered callbacks
M +59 -24 qt5/style/qtcurve.cpp
M +3 -0 qt5/style/qtcurve.h
M +7 -4 qt5/style/qtcurve_plugin.cpp
M +3 -0 qt5/style/qtcurve_plugin.h
http://commits.kde.org/qtcurve/47cae702616d2aa6095b7dda622a128775e9466a
diff --git a/qt5/style/qtcurve.cpp b/qt5/style/qtcurve.cpp
index f2905e4..ca24837 100644
--- a/qt5/style/qtcurve.cpp
+++ b/qt5/style/qtcurve.cpp
@@ -345,7 +345,8 @@ Style::Style() :
m_sViewSBar(0L),
m_windowManager(new WindowManager(this)),
m_blurHelper(new BlurHelper(this)),
- m_shortcutHandler(new ShortcutHandler(this))
+ m_shortcutHandler(new ShortcutHandler(this)),
+ m_dbusConnected(false)
{
const char *env = getenv(QTCURVE_PREVIEW_CONFIG);
if (env && strcmp(env, QTCURVE_PREVIEW_CONFIG) == 0) {
@@ -388,29 +389,7 @@ void Style::init(bool initial)
qtcReadConfig(QString(), &opts);
if (initial) {
- QDBusConnection::sessionBus().connect(
- QString(), "/KGlobalSettings", "org.kde.KGlobalSettings",
- "notifyChange", this, SLOT(kdeGlobalSettingsChange(int, int)));
- QDBusConnection::sessionBus().connect(
- "org.kde.kwin", "/KWin", "org.kde.KWin", "compositingToggled",
- this, SLOT(compositingToggled()));
-
- if (!qApp || qApp->arguments()[0] != "kwin") {
- QDBusConnection::sessionBus().connect(
- "org.kde.kwin", "/QtCurve", "org.kde.QtCurve",
- "borderSizesChanged", this, SLOT(borderSizesChanged()));
- if (opts.menubarHiding & HIDE_KWIN)
- QDBusConnection::sessionBus().connect(
- "org.kde.kwin", "/QtCurve", "org.kde.QtCurve",
- "toggleMenuBar",
- this, SLOT(toggleMenuBar(unsigned int)));
-
- if(opts.statusbarHiding & HIDE_KWIN)
- QDBusConnection::sessionBus().connect(
- "org.kde.kwin", "/QtCurve", "org.kde.QtCurve",
- "toggleStatusBar",
- this, SLOT(toggleStatusBar(unsigned int)));
- }
+ connectDBus();
}
}
@@ -675,8 +654,64 @@ void Style::init(bool initial)
#endif
}
+void Style::connectDBus()
+{
+ if (m_dbusConnected)
+ return;
+ m_dbusConnected = true;
+ auto bus = QDBusConnection::sessionBus();
+ bus.connect(QString(), "/KGlobalSettings", "org.kde.KGlobalSettings",
+ "notifyChange", this, SLOT(kdeGlobalSettingsChange(int, int)));
+ bus.connect("org.kde.kwin", "/KWin", "org.kde.KWin", "compositingToggled",
+ this, SLOT(compositingToggled()));
+
+ if (!qApp || qApp->arguments()[0] != "kwin") {
+ bus.connect("org.kde.kwin", "/QtCurve", "org.kde.QtCurve",
+ "borderSizesChanged", this, SLOT(borderSizesChanged()));
+ if (opts.menubarHiding & HIDE_KWIN)
+ bus.connect("org.kde.kwin", "/QtCurve", "org.kde.QtCurve",
+ "toggleMenuBar",
+ this, SLOT(toggleMenuBar(unsigned int)));
+
+ if (opts.statusbarHiding & HIDE_KWIN) {
+ bus.connect("org.kde.kwin", "/QtCurve", "org.kde.QtCurve",
+ "toggleStatusBar",
+ this, SLOT(toggleStatusBar(unsigned int)));
+ }
+ }
+}
+
+void Style::disconnectDBus()
+{
+ if (!m_dbusConnected)
+ return;
+ m_dbusConnected = false;
+ auto bus = QDBusConnection::sessionBus();
+ bus.disconnect(QString(), "/KGlobalSettings", "org.kde.KGlobalSettings",
+ "notifyChange",
+ this, SLOT(kdeGlobalSettingsChange(int, int)));
+ bus.disconnect("org.kde.kwin", "/KWin", "org.kde.KWin", "compositingToggled",
+ this, SLOT(compositingToggled()));
+
+ if (!qApp || qApp->arguments()[0] != "kwin") {
+ bus.disconnect("org.kde.kwin", "/QtCurve", "org.kde.QtCurve",
+ "borderSizesChanged", this, SLOT(borderSizesChanged()));
+ if (opts.menubarHiding & HIDE_KWIN)
+ bus.disconnect("org.kde.kwin", "/QtCurve", "org.kde.QtCurve",
+ "toggleMenuBar",
+ this, SLOT(toggleMenuBar(unsigned int)));
+
+ if (opts.statusbarHiding & HIDE_KWIN) {
+ bus.disconnect("org.kde.kwin", "/QtCurve", "org.kde.QtCurve",
+ "toggleStatusBar",
+ this, SLOT(toggleStatusBar(unsigned int)));
+ }
+ }
+}
+
Style::~Style()
{
+ disconnectDBus();
freeColors();
if (m_dBus) {
delete m_dBus;
diff --git a/qt5/style/qtcurve.h b/qt5/style/qtcurve.h
index f8166a5..69cf3d7 100644
--- a/qt5/style/qtcurve.h
+++ b/qt5/style/qtcurve.h
@@ -173,6 +173,8 @@ public:
private:
void init(bool initial);
+ void connectDBus();
+ void disconnectDBus();
void freeColor(QSet<QColor*> &freedColors, QColor **cols);
void freeColors();
void polishFormLayout(QFormLayout *layout);
@@ -557,6 +559,7 @@ private:
WindowManager *m_windowManager;
BlurHelper *m_blurHelper;
ShortcutHandler *m_shortcutHandler;
+ bool m_dbusConnected;
};
}
diff --git a/qt5/style/qtcurve_plugin.cpp b/qt5/style/qtcurve_plugin.cpp
index 749a610..500a3ff 100644
--- a/qt5/style/qtcurve_plugin.cpp
+++ b/qt5/style/qtcurve_plugin.cpp
@@ -41,8 +41,6 @@
#endif
#include <QDebug>
-#include <mutex>
-
namespace QtCurve {
__attribute__((hot)) static void
@@ -120,11 +118,16 @@ StylePlugin::create(const QString &key)
return key.toLower() == "qtcurve" ? new Style : nullptr;
}
+StylePlugin::~StylePlugin()
+{
+ QInternal::unregisterCallback(QInternal::EventNotifyCallback,
+ qtcEventCallback);
+}
+
void
StylePlugin::init()
{
- static std::once_flag ref_flag;
- std::call_once(ref_flag, [] {
+ std::call_once(m_ref_flag, [] {
QInternal::registerCallback(QInternal::EventNotifyCallback,
qtcEventCallback);
#ifdef QTC_QT5_ENABLE_QTQUICK2
diff --git a/qt5/style/qtcurve_plugin.h b/qt5/style/qtcurve_plugin.h
index fd4d620..95bbfed 100644
--- a/qt5/style/qtcurve_plugin.h
+++ b/qt5/style/qtcurve_plugin.h
@@ -23,6 +23,7 @@
#define __QTCURVE_PLUTIN_H__
#include <QStylePlugin>
+#include <mutex>
namespace QtCurve {
class StylePlugin: public QStylePlugin {
@@ -30,8 +31,10 @@ class StylePlugin: public QStylePlugin {
Q_PLUGIN_METADATA(IID QStyleFactoryInterface_iid FILE "qtcurvestyle.json")
public:
QStyle *create(const QString &key) override;
+ ~StylePlugin();
private:
void init();
+ std::once_flag m_ref_flag;
};
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic