X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fquassel.h;h=a30ece70365effcc2f51d847575b67b97fc9562e;hp=85660afc8edfa311165d54e20242934f7fe099d9;hb=HEAD;hpb=37110ceaa070167b4f40ed449ac9ea130503a792 diff --git a/src/common/quassel.h b/src/common/quassel.h index 85660afc..a298e326 100644 --- a/src/common/quassel.h +++ b/src/common/quassel.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2018 by the Quassel Project * + * Copyright (C) 2005-2022 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -20,45 +20,50 @@ #pragma once +#include "common-export.h" + #include -#include #include +#include #include #include -#include #include +#include #include #include -#include "abstractcliparser.h" +#include "abstractsignalwatcher.h" +#include "singleton.h" class QFile; class Logger; -class Quassel : public QObject +class COMMON_EXPORT Quassel : public QObject, public Singleton { // TODO Qt5: Use Q_GADGET Q_OBJECT public: - enum RunMode { + enum RunMode + { Monolithic, ClientOnly, CoreOnly }; - struct BuildInfo { - QString fancyVersionString; // clickable rev - QString plainVersionString; // no tag + struct BuildInfo + { + QString fancyVersionString; // clickable rev + QString plainVersionString; // no tag QString baseVersion; QString generatedVersion; QString commitHash; QString commitDate; - uint protocolVersion; // deprecated + uint protocolVersion; // deprecated QString applicationName; QString coreApplicationName; @@ -80,7 +85,8 @@ public: * * @sa Feature */ - enum class LegacyFeature : quint32 { + enum class LegacyFeature : quint32 + { SynchronizedMarkerLine = 0x0001, SaslAuthentication = 0x0002, SaslExternal = 0x0004, @@ -113,83 +119,81 @@ 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 + enum class Feature : uint32_t + { SynchronizedMarkerLine, SaslAuthentication, SaslExternal, HideInactiveNetworks, - PasswordChange, ///< Remote password change - CapNegotiation, ///< IRCv3 capability negotiation, account tracking - VerifyServerSSL, ///< IRC server SSL validation - CustomRateLimits, ///< IRC server custom message rate limits - AwayFormatTimestamp, ///< Timestamp formatting in away (e.g. %%hh:mm%%) - Authenticators, ///< Whether or not the core supports auth backends - BufferActivitySync, ///< Sync buffer activity status - CoreSideHighlights, ///< Core-Side highlight configuration and matching - SenderPrefixes, ///< Show prefixes for senders in backlog - RemoteDisconnect, ///< Allow this peer to be remotely disconnected - ExtendedFeatures, ///< Extended features - 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 + PasswordChange, ///< Remote password change + CapNegotiation, ///< IRCv3 capability negotiation, account tracking + VerifyServerSSL, ///< IRC server SSL validation + CustomRateLimits, ///< IRC server custom message rate limits + AwayFormatTimestamp, ///< Timestamp formatting in away (e.g. %%hh:mm%%) + Authenticators, ///< Whether or not the core supports auth backends + BufferActivitySync, ///< Sync buffer activity status + CoreSideHighlights, ///< Core-Side highlight configuration and matching + SenderPrefixes, ///< Show prefixes for senders in backlog + RemoteDisconnect, ///< Allow this peer to be remotely disconnected + ExtendedFeatures, ///< Extended features + LongTime, ///< Serialize time as 64-bit values + RichMessages, ///< Real Name and Avatar URL in backlog + BacklogFilterType, ///< BacklogManager supports filtering backlog by MessageType + EcdsaCertfpKeys, ///< ECDSA keys for CertFP in identities + LongMessageId, ///< 64-bit IDs for messages + SyncedCoreInfo, ///< CoreInfo dynamically updated using signals + LoadBacklogForwards, ///< Allow loading backlog in ascending order, old to new + SkipIrcCaps, ///< Control what IRCv3 capabilities are skipped during negotiation }; Q_ENUMS(Feature) class Features; - static Quassel *instance(); + Quassel(); + + void init(RunMode runMode); /** * Provides access to the Logger instance. * * @returns The Logger instance */ - Logger *logger() const; + Logger* logger() const; static void setupBuildInfo(); - static const BuildInfo &buildInfo(); + static const BuildInfo& buildInfo(); static RunMode runMode(); static QString configDirPath(); //! Returns a list of data directory paths /** There are several locations for applications to install their data files in. On Unix, - * a common location is /usr/share; others include $PREFIX/share and additional directories - * specified in the env variable XDG_DATA_DIRS. - * \return A list of directory paths to look for data files in - */ + * a common location is /usr/share; others include $PREFIX/share and additional directories + * specified in the env variable XDG_DATA_DIRS. + * \return A list of directory paths to look for data files in + */ static QStringList dataDirPaths(); //! Searches for a data file in the possible data directories /** Data files can reside in $DATA_DIR/apps/quassel, where $DATA_DIR is one of the directories - * returned by \sa dataDirPaths(). - * \Note With KDE integration enabled, files are searched (only) in KDE's appdata dirs. - * \return The full path to the data file if found; a null QString else - */ - static QString findDataFilePath(const QString &filename); + * returned by \sa dataDirPaths(). + * \Note With KDE integration enabled, files are searched (only) in KDE's appdata dirs. + * \return The full path to the data file if found; a null QString else + */ + static QString findDataFilePath(const QString& filename); static QString translationDirPath(); //! Returns a list of directories we look for scripts in /** We look for a subdirectory named "scripts" in the configdir and in all datadir paths. - * \return A list of directory paths containing executable scripts for /exec - */ + * \return A list of directory paths containing executable scripts for /exec + */ static QStringList scriptDirPaths(); - static void loadTranslation(const QLocale &locale); + static void loadTranslation(const QLocale& locale); - static void setCliParser(std::shared_ptr cliParser); - static QString optionValue(const QString &option); - static bool isOptionSet(const QString &option); + static QString optionValue(const QString& option); + static bool isOptionSet(const QString& option); using ReloadHandler = std::function; @@ -197,31 +201,34 @@ public: 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(); - -signals: - void messageLogged(const QDateTime &timeStamp, const QString &msg); - -protected: - static bool init(); - static void destroy(); + const QString& coreDumpFileName(); - static void setRunMode(Quassel::RunMode runMode); - - static void setDataDirPaths(const QStringList &paths); - static QStringList findDataDirPaths(); - static void disableCrashHandler(); +public slots: + /** + * Requests to quit the application. + * + * Calls any registered quit handlers. If no handlers are registered, calls QCoreApplication::quit(). + */ + void quit(); - friend class CoreApplication; - friend class QtUiApplication; - friend class MonolithicApplication; +signals: + void messageLogged(const QDateTime& timeStamp, const QString& msg); private: - Quassel(); - void setupEnvironment(); void registerMetaTypes(); + void setupSignalHandling(); + void setupEnvironment(); + void setupCliParser(); /** * Requests a reload of relevant runtime configuration. @@ -233,31 +240,25 @@ 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); + 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; - std::shared_ptr _cliParser; + QCommandLineParser _cliParser; - Logger *_logger; + Logger* _logger; + AbstractSignalWatcher* _signalWatcher{nullptr}; std::vector _reloadHandlers; std::vector _quitHandlers; @@ -270,7 +271,7 @@ private: * * @sa Quassel::Feature */ -class Quassel::Features +class COMMON_EXPORT Quassel::Features { public: /** @@ -292,7 +293,7 @@ public: * @param legacyFeatures Holds a bit-wise combination of LegacyFeature flag values, which are each added to the list of * features represented by this Features instance. */ - Features(const QStringList &features, LegacyFeatures legacyFeatures); + Features(const QStringList& features, LegacyFeatures legacyFeatures); /** * Check if a given feature is marked as enabled in this Features instance.