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