X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fcommon%2Fquassel.h;h=b658677d30cd15f41ae512b9fbd31fe305e25357;hb=ab7ef4d24f62b5848b628482b7762ebfc0b53e1a;hp=952f8fa8513e7381a86b1a7031f9d6c966c5f7a0;hpb=e375f7a6a6de045735a897ef05bf6dcc82770ff5;p=quassel.git diff --git a/src/common/quassel.h b/src/common/quassel.h index 952f8fa8..b658677d 100644 --- a/src/common/quassel.h +++ b/src/common/quassel.h @@ -32,10 +32,14 @@ #include #include "abstractcliparser.h" +#include "abstractsignalwatcher.h" +#include "singleton.h" class QFile; -class Quassel : public QObject +class Logger; + +class Quassel : public QObject, public Singleton { // TODO Qt5: Use Q_GADGET Q_OBJECT @@ -111,11 +115,7 @@ public: * * This list should be cleaned up after every protocol break, as we can assume them to be present then. */ - #if QT_VERSION >= 0x050000 enum class Feature : uint32_t { - #else - enum Feature { - #endif SynchronizedMarkerLine, SaslAuthentication, SaslExternal, @@ -134,9 +134,7 @@ public: LongTime, ///< Serialize time as 64-bit values RichMessages, ///< Real Name and Avatar URL in backlog BacklogFilterType, ///< BacklogManager supports filtering backlog by MessageType -#if QT_VERSION >= 0x050500 EcdsaCertfpKeys, ///< ECDSA keys for CertFP in identities -#endif LongMessageId, ///< 64-bit IDs for messages SyncedCoreInfo, ///< CoreInfo dynamically updated using signals }; @@ -144,7 +142,14 @@ public: class Features; - static Quassel *instance(); + Quassel(); + + /** + * Provides access to the Logger instance. + * + * @returns The Logger instance + */ + Logger *logger() const; static void setupBuildInfo(); static const BuildInfo &buildInfo(); @@ -182,48 +187,51 @@ public: static QString optionValue(const QString &option); static bool isOptionSet(const QString &option); - enum LogLevel { - DebugLevel, - InfoLevel, - WarningLevel, - ErrorLevel - }; - - static LogLevel logLevel(); - static void setLogLevel(LogLevel logLevel); - static QFile *logFile(); - static bool logToSyslog(); - - static void logFatalMessage(const char *msg); - using ReloadHandler = std::function; static void registerReloadHandler(ReloadHandler handler); using QuitHandler = std::function; + /** + * 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(); - - const QString &coreDumpFileName(); + void setupSignalHandling(); /** * Requests a reload of relevant runtime configuration. @@ -235,34 +243,27 @@ 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; QStringList _dataDirPaths; QString _translationDirPath; - LogLevel _logLevel{InfoLevel}; - bool _logToSyslog{false}; - std::unique_ptr _logFile; - std::shared_ptr _cliParser; + Logger *_logger; + AbstractSignalWatcher *_signalWatcher{nullptr}; + std::vector _reloadHandlers; std::vector _quitHandlers; };