src: Yearly copyright bump
[quassel.git] / src / common / quassel.h
index 85660af..eea7a50 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2005-2018 by the Quassel Project                        *
+ *   Copyright (C) 2005-2019 by the Quassel Project                        *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
 #include <QStringList>
 
 #include "abstractcliparser.h"
+#include "abstractsignalwatcher.h"
+#include "singleton.h"
 
 class QFile;
 
 class Logger;
 
-class Quassel : public QObject
+class Quassel : public QObject, public Singleton<Quassel>
 {
     // TODO Qt5: Use Q_GADGET
     Q_OBJECT
@@ -146,7 +148,7 @@ public:
 
     class Features;
 
-    static Quassel *instance();
+    Quassel();
 
     /**
      * Provides access to the Logger instance.
@@ -197,31 +199,45 @@ public:
 
     using QuitHandler = std::function<void()>;
 
+    /**
+     * Registers a handler that is called when the application is supposed to quit.
+     *
+     * @note If multiple handlers are registered, they are processed in order of registration.
+     * @note If any handler is registered, quit() will not call QCoreApplication::quit(). It relies
+     *       on one of the handlers doing so, instead.
+     * @param quitHandler Handler to register
+     */
     static void registerQuitHandler(QuitHandler quitHandler);
 
     const QString &coreDumpFileName();
 
+public slots:
+    /**
+     * Requests to quit the application.
+     *
+     * Calls any registered quit handlers. If no handlers are registered, calls QCoreApplication::quit().
+     */
+    void quit();
+
 signals:
     void messageLogged(const QDateTime &timeStamp, const QString &msg);
 
 protected:
     static bool init();
-    static void destroy();
 
     static void setRunMode(Quassel::RunMode runMode);
 
     static void setDataDirPaths(const QStringList &paths);
     static QStringList findDataDirPaths();
-    static void disableCrashHandler();
 
     friend class CoreApplication;
     friend class QtUiApplication;
     friend class MonolithicApplication;
 
 private:
-    Quassel();
     void setupEnvironment();
     void registerMetaTypes();
+    void setupSignalHandling();
 
     /**
      * Requests a reload of relevant runtime configuration.
@@ -233,22 +249,16 @@ private:
      */
     bool reloadConfig();
 
-    /**
-     * Requests to quit the application.
-     *
-     * Calls any registered quit handlers. If no handlers are registered, calls QCoreApplication::quit().
-     */
-    void quit();
-
     void logBacktrace(const QString &filename);
 
-    static void handleSignal(int signal);
+private slots:
+    void handleSignal(AbstractSignalWatcher::Action action);
 
 private:
     BuildInfo _buildInfo;
     RunMode _runMode;
     bool _initialized{false};
-    bool _handleCrashes{true};
+    bool _quitting{false};
 
     QString _coreDumpFileName;
     QString _configDirPath;
@@ -258,6 +268,7 @@ private:
     std::shared_ptr<AbstractCliParser> _cliParser;
 
     Logger *_logger;
+    AbstractSignalWatcher *_signalWatcher{nullptr};
 
     std::vector<ReloadHandler> _reloadHandlers;
     std::vector<QuitHandler> _quitHandlers;