common: Use the Singleton mixin for the Quassel instance
authorManuel Nickschas <sputnick@quassel-irc.org>
Fri, 28 Sep 2018 19:41:31 +0000 (21:41 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Mon, 1 Oct 2018 17:06:49 +0000 (19:06 +0200)
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.

src/common/main.cpp
src/common/quassel.cpp
src/common/quassel.h
src/core/coreapplication.cpp
src/qtui/monoapplication.cpp
src/qtui/qtuiapplication.cpp

index eb7a140..234891c 100644 (file)
@@ -80,7 +80,7 @@ int main(int argc, char **argv)
 #endif
 
     // Instantiate early, so log messages are handled
 #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
 
 #if QT_VERSION < 0x050000
     // All our source files are in UTF-8, and Qt5 even requires that
index 5ceddb1..9a922a6 100644 (file)
 
 #include "../../version.h"
 
 
 #include "../../version.h"
 
-Quassel *Quassel::instance()
-{
-    static Quassel instance;
-    return &instance;
-}
-
-
 Quassel::Quassel()
 Quassel::Quassel()
-    : _logger{new Logger{this}}
+    : Singleton<Quassel>{this}
+    , _logger{new Logger{this}}
 {
 }
 
 {
 }
 
@@ -129,11 +123,6 @@ bool Quassel::init()
 }
 
 
 }
 
 
-void Quassel::destroy()
-{
-}
-
-
 Logger *Quassel::logger() const
 {
     return _logger;
 Logger *Quassel::logger() const
 {
     return _logger;
index 85660af..17e252c 100644 (file)
 #include <QStringList>
 
 #include "abstractcliparser.h"
 #include <QStringList>
 
 #include "abstractcliparser.h"
+#include "singleton.h"
 
 class QFile;
 
 class Logger;
 
 
 class QFile;
 
 class Logger;
 
-class Quassel : public QObject
+class Quassel : public QObject, public Singleton<Quassel>
 {
     // TODO Qt5: Use Q_GADGET
     Q_OBJECT
 {
     // TODO Qt5: Use Q_GADGET
     Q_OBJECT
@@ -146,7 +147,7 @@ public:
 
     class Features;
 
 
     class Features;
 
-    static Quassel *instance();
+    Quassel();
 
     /**
      * Provides access to the Logger instance.
 
     /**
      * Provides access to the Logger instance.
@@ -206,7 +207,6 @@ signals:
 
 protected:
     static bool init();
 
 protected:
     static bool init();
-    static void destroy();
 
     static void setRunMode(Quassel::RunMode runMode);
 
 
     static void setRunMode(Quassel::RunMode runMode);
 
@@ -219,7 +219,6 @@ protected:
     friend class MonolithicApplication;
 
 private:
     friend class MonolithicApplication;
 
 private:
-    Quassel();
     void setupEnvironment();
     void registerMetaTypes();
 
     void setupEnvironment();
     void registerMetaTypes();
 
index e73a09f..90f3905 100644 (file)
@@ -36,7 +36,6 @@ CoreApplication::CoreApplication(int &argc, char **argv)
 CoreApplication::~CoreApplication()
 {
     _core.reset();
 CoreApplication::~CoreApplication()
 {
     _core.reset();
-    Quassel::destroy();
 }
 
 
 }
 
 
index e92afcc..f6e75a2 100644 (file)
@@ -59,7 +59,6 @@ MonolithicApplication::~MonolithicApplication()
     Client::destroy();
     _coreThread.quit();
     _coreThread.wait();
     Client::destroy();
     _coreThread.quit();
     _coreThread.wait();
-    Quassel::destroy();
 }
 
 
 }
 
 
index b59899e..47e3a14 100644 (file)
@@ -125,7 +125,6 @@ void QtUiApplication::init()
 QtUiApplication::~QtUiApplication()
 {
     Client::destroy();
 QtUiApplication::~QtUiApplication()
 {
     Client::destroy();
-    Quassel::destroy();
 }
 
 
 }