Fix ALL the license headers!
[quassel.git] / src / common / quassel.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2012 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         uint commitDate;
51         QString buildDate;
52         bool isSourceDirty;
53         uint protocolVersion;
54         uint clientNeedsProtocol;
55         uint coreNeedsProtocol;
56
57         QString applicationName;
58         QString coreApplicationName;
59         QString clientApplicationName;
60         QString organizationName;
61         QString organizationDomain;
62     };
63
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.
68      *
69      *  This list should be cleaned up after every protocol break, as we can assume them to be present then.
70      */
71     enum Feature {
72         SynchronizedMarkerLine = 0x0001,
73         SaslAuthentication = 0x0002,
74
75         NumFeatures = 0x0002
76     };
77     Q_DECLARE_FLAGS(Features, Feature);
78
79     //! The features the current version of Quassel supports (\sa Feature)
80     /** \return An ORed list of all enum values in Feature
81      */
82     static Features features();
83
84     virtual ~Quassel();
85
86     static void setupBuildInfo(const QString &generated);
87     static inline const BuildInfo &buildInfo();
88     static inline RunMode runMode();
89
90     static QString configDirPath();
91
92     //! Returns a list of data directory paths
93     /** There are several locations for applications to install their data files in. On Unix,
94     *  a common location is /usr/share; others include $PREFIX/share and additional directories
95     *  specified in the env variable XDG_DATA_DIRS.
96     *  \return A list of directory paths to look for data files in
97     */
98     static QStringList dataDirPaths();
99
100     //! Searches for a data file in the possible data directories
101     /** Data files can reside in $DATA_DIR/apps/quassel, where $DATA_DIR is one of the directories
102     *  returned by \sa dataDirPaths().
103     *  \Note With KDE integration enabled, files are searched (only) in KDE's appdata dirs.
104     *  \return The full path to the data file if found; a null QString else
105     */
106     static QString findDataFilePath(const QString &filename);
107
108     static QString translationDirPath();
109
110     //! Returns a list of directories we look for scripts in
111     /** We look for a subdirectory named "scripts" in the configdir and in all datadir paths.
112     *   \return A list of directory paths containing executable scripts for /exec
113     */
114     static QStringList scriptDirPaths();
115
116     static void loadTranslation(const QLocale &locale);
117
118     static inline void setCliParser(AbstractCliParser *cliParser);
119     static inline AbstractCliParser *cliParser();
120     static inline QString optionValue(const QString &option);
121     static inline bool isOptionSet(const QString &option);
122
123     static const QString &coreDumpFileName();
124
125     static bool DEBUG;
126
127     enum LogLevel {
128         DebugLevel,
129         InfoLevel,
130         WarningLevel,
131         ErrorLevel
132     };
133
134     static inline LogLevel logLevel();
135     static inline QFile *logFile();
136     static inline bool logToSyslog();
137
138     static void logFatalMessage(const char *msg);
139
140 protected:
141     Quassel();
142     virtual bool init();
143     virtual void quit();
144
145     inline void setRunMode(RunMode mode);
146     inline void setDataDirPaths(const QStringList &paths);
147     QStringList findDataDirPaths() const;
148     inline void disableCrashhandler();
149
150 private:
151     void registerMetaTypes();
152
153     static void handleSignal(int signal);
154     static void logBacktrace(const QString &filename);
155
156     static Quassel *_instance;
157     static BuildInfo _buildInfo;
158     static AbstractCliParser *_cliParser;
159     static RunMode _runMode;
160     static bool _initialized;
161     static bool _handleCrashes;
162
163     static QString _coreDumpFileName;
164     static QString _configDirPath;
165     static QStringList _dataDirPaths;
166     static QString _translationDirPath;
167
168     static LogLevel _logLevel;
169     static QFile *_logFile;
170     static bool _logToSyslog;
171 };
172
173
174 Q_DECLARE_OPERATORS_FOR_FLAGS(Quassel::Features);
175
176 const Quassel::BuildInfo &Quassel::buildInfo() { return _buildInfo; }
177 Quassel::RunMode Quassel::runMode() { return _runMode; }
178 void Quassel::setRunMode(Quassel::RunMode mode) { _runMode = mode; }
179 void Quassel::setDataDirPaths(const QStringList &paths) { _dataDirPaths = paths; }
180 void Quassel::disableCrashhandler() { _handleCrashes = false; }
181
182 void Quassel::setCliParser(AbstractCliParser *parser) { _cliParser = parser; }
183 AbstractCliParser *Quassel::cliParser() { return _cliParser; }
184 QString Quassel::optionValue(const QString &key) { return cliParser()->value(key); }
185 bool Quassel::isOptionSet(const QString &key) { return cliParser()->isSet(key); }
186
187 Quassel::LogLevel Quassel::logLevel() { return _logLevel; }
188 QFile *Quassel::logFile() { return _logFile; }
189 bool Quassel::logToSyslog() { return _logToSyslog; }
190
191 #endif