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