From kde-commits Sat Mar 19 16:50:54 2016 From: Yichao Yu Date: Sat, 19 Mar 2016 16:50:54 +0000 To: kde-commits Subject: [qtcurve] qt5/style: [qt5] properly clean up registered callbacks Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=145840629131210 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 =3D getenv(QTCURVE_PREVIEW_CONFIG); if (env && strcmp(env, QTCURVE_PREVIEW_CONFIG) =3D=3D 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, in= t))); - QDBusConnection::sessionBus().connect( - "org.kde.kwin", "/KWin", "org.kde.KWin", "compositingToggl= ed", - this, SLOT(compositingToggled())); - - if (!qApp || qApp->arguments()[0] !=3D "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 =3D true; + auto bus =3D QDBusConnection::sessionBus(); + bus.connect(QString(), "/KGlobalSettings", "org.kde.KGlobalSettings", + "notifyChange", this, SLOT(kdeGlobalSettingsChange(int, in= t))); + bus.connect("org.kde.kwin", "/KWin", "org.kde.KWin", "compositingToggl= ed", + this, SLOT(compositingToggled())); + + if (!qApp || qApp->arguments()[0] !=3D "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 =3D false; + auto bus =3D QDBusConnection::sessionBus(); + bus.disconnect(QString(), "/KGlobalSettings", "org.kde.KGlobalSettings= ", + "notifyChange", + this, SLOT(kdeGlobalSettingsChange(int, int))); + bus.disconnect("org.kde.kwin", "/KWin", "org.kde.KWin", "compositingTo= ggled", + this, SLOT(compositingToggled())); + + if (!qApp || qApp->arguments()[0] !=3D "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 &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 = -#include - namespace QtCurve { = __attribute__((hot)) static void @@ -120,11 +118,16 @@ StylePlugin::create(const QString &key) return key.toLower() =3D=3D "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 +#include = namespace QtCurve { class StylePlugin: public QStylePlugin { @@ -30,8 +31,10 @@ class StylePlugin: public QStylePlugin { Q_PLUGIN_METADATA(IID QStyleFactoryInterface_iid FILE "qtcurvestyle.js= on") public: QStyle *create(const QString &key) override; + ~StylePlugin(); private: void init(); + std::once_flag m_ref_flag; }; } =20