From: Manuel Nickschas Date: Fri, 28 Sep 2018 19:41:31 +0000 (+0200) Subject: common: Use the Singleton mixin for the Quassel instance X-Git-Tag: 0.13-rc2~15 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=493043890c74e4679bb3fdaf512a0e1e52c426d3 common: Use the Singleton mixin for the Quassel instance Make use of the newly added Singleton mixon to remove the custom handling of Quassel's instance pointer. Clearly define Quassel's lifetime by making it a local instance in main(), rather than relying on someone to call Quassel::instance() at the right time. Now it is also clear that the instance is deleted after main() returns (which was the case before, however there still was a no-op Quassel::destroy() method too, which has now been removed). This is fine, because Quassel does not own resources that should be deleted before exiting the event loop. --- diff --git a/src/common/main.cpp b/src/common/main.cpp index eb7a140c..234891c7 100644 --- a/src/common/main.cpp +++ b/src/common/main.cpp @@ -80,7 +80,7 @@ int main(int argc, char **argv) #endif // Instantiate early, so log messages are handled - Quassel::instance(); + Quassel quassel; #if QT_VERSION < 0x050000 // All our source files are in UTF-8, and Qt5 even requires that diff --git a/src/common/quassel.cpp b/src/common/quassel.cpp index 5ceddb10..9a922a6a 100644 --- a/src/common/quassel.cpp +++ b/src/common/quassel.cpp @@ -54,15 +54,9 @@ #include "../../version.h" -Quassel *Quassel::instance() -{ - static Quassel instance; - return &instance; -} - - Quassel::Quassel() - : _logger{new Logger{this}} + : Singleton{this} + , _logger{new Logger{this}} { } @@ -129,11 +123,6 @@ bool Quassel::init() } -void Quassel::destroy() -{ -} - - Logger *Quassel::logger() const { return _logger; diff --git a/src/common/quassel.h b/src/common/quassel.h index 85660afc..17e252c1 100644 --- a/src/common/quassel.h +++ b/src/common/quassel.h @@ -32,12 +32,13 @@ #include #include "abstractcliparser.h" +#include "singleton.h" class QFile; class Logger; -class Quassel : public QObject +class Quassel : public QObject, public Singleton { // TODO Qt5: Use Q_GADGET Q_OBJECT @@ -146,7 +147,7 @@ public: class Features; - static Quassel *instance(); + Quassel(); /** * Provides access to the Logger instance. @@ -206,7 +207,6 @@ signals: protected: static bool init(); - static void destroy(); static void setRunMode(Quassel::RunMode runMode); @@ -219,7 +219,6 @@ protected: friend class MonolithicApplication; private: - Quassel(); void setupEnvironment(); void registerMetaTypes(); diff --git a/src/core/coreapplication.cpp b/src/core/coreapplication.cpp index e73a09fb..90f39055 100644 --- a/src/core/coreapplication.cpp +++ b/src/core/coreapplication.cpp @@ -36,7 +36,6 @@ CoreApplication::CoreApplication(int &argc, char **argv) CoreApplication::~CoreApplication() { _core.reset(); - Quassel::destroy(); } diff --git a/src/qtui/monoapplication.cpp b/src/qtui/monoapplication.cpp index e92afcc6..f6e75a24 100644 --- a/src/qtui/monoapplication.cpp +++ b/src/qtui/monoapplication.cpp @@ -59,7 +59,6 @@ MonolithicApplication::~MonolithicApplication() Client::destroy(); _coreThread.quit(); _coreThread.wait(); - Quassel::destroy(); } diff --git a/src/qtui/qtuiapplication.cpp b/src/qtui/qtuiapplication.cpp index b59899e3..47e3a140 100644 --- a/src/qtui/qtuiapplication.cpp +++ b/src/qtui/qtuiapplication.cpp @@ -125,7 +125,6 @@ void QtUiApplication::init() QtUiApplication::~QtUiApplication() { Client::destroy(); - Quassel::destroy(); }