Make authenticator changes to protocol backwards-compatible
[quassel.git] / src / common / quassel.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2016 by the Quassel Project                        *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
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.                                           *
9  *                                                                         *
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.                          *
14  *                                                                         *
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  ***************************************************************************/
20
21 #ifndef QUASSEL_H_
22 #define QUASSEL_H_
23
24 #include <QCoreApplication>
25 #include <QLocale>
26 #include <QString>
27
28 #include "abstractcliparser.h"
29
30 class QFile;
31
32 class Quassel
33 {
34     Q_DECLARE_TR_FUNCTIONS(Quassel)
35
36 public:
37     enum RunMode {
38         Monolithic,
39         ClientOnly,
40         CoreOnly
41     };
42
43     struct BuildInfo {
44         QString fancyVersionString; // clickable rev
45         QString plainVersionString; // no <a> tag
46
47         QString baseVersion;
48         QString generatedVersion;
49         QString commitHash;
50         QString commitDate;
51
52         uint protocolVersion; // deprecated
53
54         QString applicationName;
55         QString coreApplicationName;
56         QString clientApplicationName;
57         QString organizationName;
58         QString organizationDomain;
59     };
60
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.
65      *
66      *  This list should be cleaned up after every protocol break, as we can assume them to be present then.
67      */
68     enum Feature {
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         // Whether or not the core supports auth backends.
80         AuthBackends = 0x0400,
81
82         NumFeatures = 0x0400
83     };
84     Q_DECLARE_FLAGS(Features, Feature)
85
86     //! The features the current version of Quassel supports (\sa Feature)
87     /** \return An ORed list of all enum values in Feature
88      */
89     static Features features();
90
91     virtual ~Quassel();
92
93     static void setupBuildInfo();
94     static inline const BuildInfo &buildInfo();
95     static inline RunMode runMode();
96
97     static QString configDirPath();
98
99     //! Returns a list of data directory paths
100     /** There are several locations for applications to install their data files in. On Unix,
101     *  a common location is /usr/share; others include $PREFIX/share and additional directories
102     *  specified in the env variable XDG_DATA_DIRS.
103     *  \return A list of directory paths to look for data files in
104     */
105     static QStringList dataDirPaths();
106
107     //! Searches for a data file in the possible data directories
108     /** Data files can reside in $DATA_DIR/apps/quassel, where $DATA_DIR is one of the directories
109     *  returned by \sa dataDirPaths().
110     *  \Note With KDE integration enabled, files are searched (only) in KDE's appdata dirs.
111     *  \return The full path to the data file if found; a null QString else
112     */
113     static QString findDataFilePath(const QString &filename);
114
115     static QString translationDirPath();
116
117     //! Returns a list of directories we look for scripts in
118     /** We look for a subdirectory named "scripts" in the configdir and in all datadir paths.
119     *   \return A list of directory paths containing executable scripts for /exec
120     */
121     static QStringList scriptDirPaths();
122
123     static void loadTranslation(const QLocale &locale);
124
125     static inline void setCliParser(AbstractCliParser *cliParser);
126     static inline AbstractCliParser *cliParser();
127     static inline QString optionValue(const QString &option);
128     static inline bool isOptionSet(const QString &option);
129
130     static const QString &coreDumpFileName();
131
132     static bool DEBUG;
133
134     enum LogLevel {
135         DebugLevel,
136         InfoLevel,
137         WarningLevel,
138         ErrorLevel
139     };
140
141     static inline LogLevel logLevel();
142     static inline QFile *logFile();
143     static inline bool logToSyslog();
144
145     static void logFatalMessage(const char *msg);
146
147 protected:
148     Quassel();
149     virtual bool init();
150     virtual void quit();
151
152     /**
153      * Requests a reload of relevant runtime configuration.
154      *
155      * Does not reload all configuration, but could catch things such as SSL certificates.  Unless
156      * overridden, simply does nothing.
157      *
158      * @return True if configuration reload successful, otherwise false
159      */
160     virtual bool reloadConfig() { return true; }
161
162     inline void setRunMode(RunMode mode);
163     inline void setDataDirPaths(const QStringList &paths);
164     QStringList findDataDirPaths() const;
165     inline void disableCrashhandler();
166
167 private:
168     void setupEnvironment();
169     void registerMetaTypes();
170
171     static void handleSignal(int signal);
172     static void logBacktrace(const QString &filename);
173
174     static Quassel *_instance;
175     static BuildInfo _buildInfo;
176     static AbstractCliParser *_cliParser;
177     static RunMode _runMode;
178     static bool _initialized;
179     static bool _handleCrashes;
180
181     static QString _coreDumpFileName;
182     static QString _configDirPath;
183     static QStringList _dataDirPaths;
184     static QString _translationDirPath;
185
186     static LogLevel _logLevel;
187     static QFile *_logFile;
188     static bool _logToSyslog;
189 };
190
191
192 Q_DECLARE_OPERATORS_FOR_FLAGS(Quassel::Features);
193
194 const Quassel::BuildInfo &Quassel::buildInfo() { return _buildInfo; }
195 Quassel::RunMode Quassel::runMode() { return _runMode; }
196 void Quassel::setRunMode(Quassel::RunMode mode) { _runMode = mode; }
197 void Quassel::setDataDirPaths(const QStringList &paths) { _dataDirPaths = paths; }
198 void Quassel::disableCrashhandler() { _handleCrashes = false; }
199
200 void Quassel::setCliParser(AbstractCliParser *parser) { _cliParser = parser; }
201 AbstractCliParser *Quassel::cliParser() { return _cliParser; }
202 QString Quassel::optionValue(const QString &key) { return cliParser()->value(key); }
203 bool Quassel::isOptionSet(const QString &key) { return cliParser()->isSet(key); }
204
205 Quassel::LogLevel Quassel::logLevel() { return _logLevel; }
206 QFile *Quassel::logFile() { return _logFile; }
207 bool Quassel::logToSyslog() { return _logToSyslog; }
208
209 #endif