1 /***************************************************************************
2 * Copyright (C) 2005-2016 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
27 #include <QCoreApplication>
31 #include "abstractcliparser.h"
37 Q_DECLARE_TR_FUNCTIONS(Quassel)
47 QString fancyVersionString; // clickable rev
48 QString plainVersionString; // no <a> tag
51 QString generatedVersion;
55 uint protocolVersion; // deprecated
57 QString applicationName;
58 QString coreApplicationName;
59 QString clientApplicationName;
60 QString organizationName;
61 QString organizationDomain;
64 //! A list of features that are optional in core and/or client, but need runtime checking
65 /** Some features require an uptodate counterpart, but don't justify a protocol break.
66 * This is what we use this enum for. Add such features to it and check at runtime on the other
67 * side for their existence.
69 * This list should be cleaned up after every protocol break, as we can assume them to be present then.
72 SynchronizedMarkerLine = 0x0001,
73 SaslAuthentication = 0x0002,
74 SaslExternal = 0x0004,
75 HideInactiveNetworks = 0x0008,
76 PasswordChange = 0x0010,
77 CapNegotiation = 0x0020, /// IRCv3 capability negotiation, account tracking
78 VerifyServerSSL = 0x0040, /// IRC server SSL validation
79 CustomRateLimits = 0x0080, /// IRC server custom message rate limits
80 DccFileTransfer = 0x0100, /// DCC file transfer support (forcefully disabled for now)
81 AwayFormatTimestamp = 0x0200, /// Timestamp formatting in away (e.g. %%hh:mm%%)
82 Authenticators = 0x0400, /// Whether or not the core supports auth backends.
83 BufferActivitySync = 0x0800, /// Sync buffer activity status
84 CoreSideHighlights = 0x1000, /// Core-Side highlight configuration and matching
85 SenderPrefixes = 0x2000, /// Show prefixes for senders in backlog
86 RemoteDisconnect = 0x4000, /// Allow this peer to be remotely disconnected
90 Q_DECLARE_FLAGS(Features, Feature)
92 //! The features the current version of Quassel supports (\sa Feature)
93 /** \return An ORed list of all enum values in Feature
95 static Features features();
97 static Quassel *instance();
99 static void setupBuildInfo();
100 static const BuildInfo &buildInfo();
101 static RunMode runMode();
103 static QString configDirPath();
105 //! Returns a list of data directory paths
106 /** There are several locations for applications to install their data files in. On Unix,
107 * a common location is /usr/share; others include $PREFIX/share and additional directories
108 * specified in the env variable XDG_DATA_DIRS.
109 * \return A list of directory paths to look for data files in
111 static QStringList dataDirPaths();
113 //! Searches for a data file in the possible data directories
114 /** Data files can reside in $DATA_DIR/apps/quassel, where $DATA_DIR is one of the directories
115 * returned by \sa dataDirPaths().
116 * \Note With KDE integration enabled, files are searched (only) in KDE's appdata dirs.
117 * \return The full path to the data file if found; a null QString else
119 static QString findDataFilePath(const QString &filename);
121 static QString translationDirPath();
123 //! Returns a list of directories we look for scripts in
124 /** We look for a subdirectory named "scripts" in the configdir and in all datadir paths.
125 * \return A list of directory paths containing executable scripts for /exec
127 static QStringList scriptDirPaths();
129 static void loadTranslation(const QLocale &locale);
131 static void setCliParser(std::shared_ptr<AbstractCliParser> cliParser);
132 static QString optionValue(const QString &option);
133 static bool isOptionSet(const QString &option);
142 static LogLevel logLevel();
143 static void setLogLevel(LogLevel logLevel);
144 static QFile *logFile();
145 static bool logToSyslog();
147 static void logFatalMessage(const char *msg);
149 using ReloadHandler = std::function<bool()>;
151 static void registerReloadHandler(ReloadHandler handler);
153 using QuitHandler = std::function<void()>;
155 static void registerQuitHandler(QuitHandler quitHandler);
159 static void destroy();
161 static void setRunMode(Quassel::RunMode runMode);
163 static void setDataDirPaths(const QStringList &paths);
164 static QStringList findDataDirPaths();
165 static void disableCrashHandler();
167 friend class CoreApplication;
168 friend class QtUiApplication;
169 friend class MonolithicApplication;
173 void setupEnvironment();
174 void registerMetaTypes();
176 const QString &coreDumpFileName();
179 * Requests a reload of relevant runtime configuration.
181 * Calls any registered reload handlers, and returns the cumulative result. If no handlers are registered,
182 * does nothing and returns true.
184 * @returns True if configuration reload successful, otherwise false
189 * Requests to quit the application.
191 * Calls any registered quit handlers. If no handlers are registered, calls QCoreApplication::quit().
195 void logBacktrace(const QString &filename);
197 static void handleSignal(int signal);
200 BuildInfo _buildInfo;
202 bool _initialized{false};
203 bool _handleCrashes{true};
205 QString _coreDumpFileName;
206 QString _configDirPath;
207 QStringList _dataDirPaths;
208 QString _translationDirPath;
210 LogLevel _logLevel{InfoLevel};
211 bool _logToSyslog{false};
212 std::unique_ptr<QFile> _logFile;
214 std::shared_ptr<AbstractCliParser> _cliParser;
216 std::vector<ReloadHandler> _reloadHandlers;
217 std::vector<QuitHandler> _quitHandlers;
221 Q_DECLARE_OPERATORS_FOR_FLAGS(Quassel::Features);