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 ***************************************************************************/
24 #include <QCoreApplication>
28 #include "abstractcliparser.h"
34 Q_DECLARE_TR_FUNCTIONS(Quassel)
44 QString fancyVersionString; // clickable rev
45 QString plainVersionString; // no <a> tag
48 QString generatedVersion;
52 uint protocolVersion; // deprecated
54 QString applicationName;
55 QString coreApplicationName;
56 QString clientApplicationName;
57 QString organizationName;
58 QString organizationDomain;
61 //! A list of features that are optional in core and/or client, but need runtime checking
62 /** Some features require an uptodate counterpart, but don't justify a protocol break.
63 * This is what we use this enum for. Add such features to it and check at runtime on the other
64 * side for their existence.
66 * This list should be cleaned up after every protocol break, as we can assume them to be present then.
69 SynchronizedMarkerLine = 0x0001,
70 SaslAuthentication = 0x0002,
71 SaslExternal = 0x0004,
72 HideInactiveNetworks = 0x0008,
73 PasswordChange = 0x0010,
74 CapNegotiation = 0x0020, /// IRCv3 capability negotiation, account tracking
75 VerifyServerSSL = 0x0040, /// IRC server SSL validation
76 CustomRateLimits = 0x0080, /// IRC server custom message rate limits
77 DccFileTransfer = 0x0100,
78 AwayFormatTimestamp = 0x0200, /// Timestamp formatting in away (e.g. %%hh:mm%%)
79 Authenticators = 0x0400, /// Whether or not the core supports auth backends.
80 BufferActivitySync = 0x0800, /// Sync buffer activity status
81 CoreSideHighlights = 0x1000, /// Core-Side highlight configuration and matching
82 SenderPrefixes = 0x2000, /// Show prefixes for senders in backlog
83 RemoteDisconnect = 0x4000, /// Allow this peer to be remotely disconnected
87 Q_DECLARE_FLAGS(Features, Feature)
89 //! The features the current version of Quassel supports (\sa Feature)
90 /** \return An ORed list of all enum values in Feature
92 static Features features();
96 static void setupBuildInfo();
97 static inline const BuildInfo &buildInfo();
98 static inline RunMode runMode();
100 static QString configDirPath();
102 //! Returns a list of data directory paths
103 /** There are several locations for applications to install their data files in. On Unix,
104 * a common location is /usr/share; others include $PREFIX/share and additional directories
105 * specified in the env variable XDG_DATA_DIRS.
106 * \return A list of directory paths to look for data files in
108 static QStringList dataDirPaths();
110 //! Searches for a data file in the possible data directories
111 /** Data files can reside in $DATA_DIR/apps/quassel, where $DATA_DIR is one of the directories
112 * returned by \sa dataDirPaths().
113 * \Note With KDE integration enabled, files are searched (only) in KDE's appdata dirs.
114 * \return The full path to the data file if found; a null QString else
116 static QString findDataFilePath(const QString &filename);
118 static QString translationDirPath();
120 //! Returns a list of directories we look for scripts in
121 /** We look for a subdirectory named "scripts" in the configdir and in all datadir paths.
122 * \return A list of directory paths containing executable scripts for /exec
124 static QStringList scriptDirPaths();
126 static void loadTranslation(const QLocale &locale);
128 static inline void setCliParser(AbstractCliParser *cliParser);
129 static inline AbstractCliParser *cliParser();
130 static inline QString optionValue(const QString &option);
131 static inline bool isOptionSet(const QString &option);
133 static const QString &coreDumpFileName();
144 static inline LogLevel logLevel();
145 static inline QFile *logFile();
146 static inline bool logToSyslog();
148 static void logFatalMessage(const char *msg);
156 * Requests a reload of relevant runtime configuration.
158 * Does not reload all configuration, but could catch things such as SSL certificates. Unless
159 * overridden, simply does nothing.
161 * @return True if configuration reload successful, otherwise false
163 virtual bool reloadConfig() { return true; }
165 inline void setRunMode(RunMode mode);
166 inline void setDataDirPaths(const QStringList &paths);
167 QStringList findDataDirPaths() const;
168 inline void disableCrashhandler();
171 void setupEnvironment();
172 void registerMetaTypes();
174 static void handleSignal(int signal);
175 static void logBacktrace(const QString &filename);
177 static Quassel *_instance;
178 static BuildInfo _buildInfo;
179 static AbstractCliParser *_cliParser;
180 static RunMode _runMode;
181 static bool _initialized;
182 static bool _handleCrashes;
184 static QString _coreDumpFileName;
185 static QString _configDirPath;
186 static QStringList _dataDirPaths;
187 static QString _translationDirPath;
189 static LogLevel _logLevel;
190 static QFile *_logFile;
191 static bool _logToSyslog;
195 Q_DECLARE_OPERATORS_FOR_FLAGS(Quassel::Features);
197 const Quassel::BuildInfo &Quassel::buildInfo() { return _buildInfo; }
198 Quassel::RunMode Quassel::runMode() { return _runMode; }
199 void Quassel::setRunMode(Quassel::RunMode mode) { _runMode = mode; }
200 void Quassel::setDataDirPaths(const QStringList &paths) { _dataDirPaths = paths; }
201 void Quassel::disableCrashhandler() { _handleCrashes = false; }
203 void Quassel::setCliParser(AbstractCliParser *parser) { _cliParser = parser; }
204 AbstractCliParser *Quassel::cliParser() { return _cliParser; }
205 QString Quassel::optionValue(const QString &key) { return cliParser()->value(key); }
206 bool Quassel::isOptionSet(const QString &key) { return cliParser()->isSet(key); }
208 Quassel::LogLevel Quassel::logLevel() { return _logLevel; }
209 QFile *Quassel::logFile() { return _logFile; }
210 bool Quassel::logToSyslog() { return _logToSyslog; }