Add checkParamCount() which stops the event if something's wrong
[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 Quassel {
31   Q_DECLARE_TR_FUNCTIONS(Quassel)
32
33 public:
34   enum RunMode {
35     Monolithic,
36     ClientOnly,
37     CoreOnly
38   };
39
40   struct BuildInfo {
41     QString fancyVersionString; // clickable rev
42     QString plainVersionString; // no <a> tag
43
44     QString baseVersion;
45     QString generatedVersion;
46     QString commitHash;
47     uint commitDate;
48     QString buildDate;
49     bool isSourceDirty;
50     uint protocolVersion;
51     uint clientNeedsProtocol;
52     uint coreNeedsProtocol;
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
72     NumFeatures = 0x0002
73   };
74   Q_DECLARE_FLAGS(Features, Feature);
75
76   //! The features the current version of Quassel supports (\sa Feature)
77   /** \return An ORed list of all enum values in Feature
78    */
79   static Features features();
80
81   virtual ~Quassel();
82
83   static void setupBuildInfo(const QString &generated);
84   static inline const BuildInfo & buildInfo();
85   static inline RunMode runMode();
86
87   static QString configDirPath();
88
89   //! Returns a list of data directory paths
90   /** There are several locations for applications to install their data files in. On Unix,
91   *  a common location is /usr/share; others include $PREFIX/share and additional directories
92   *  specified in the env variable XDG_DATA_DIRS.
93   *  \return A list of directory paths to look for data files in
94   */
95   static QStringList dataDirPaths();
96
97   //! Searches for a data file in the possible data directories
98   /** Data files can reside in $DATA_DIR/apps/quassel, where $DATA_DIR is one of the directories
99   *  returned by \sa dataDirPaths().
100   *  \Note With KDE integration enabled, files are searched (only) in KDE's appdata dirs.
101   *  \return The full path to the data file if found; a null QString else
102   */
103   static QString findDataFilePath(const QString &filename);
104
105   static QString translationDirPath();
106
107   //! Returns a list of directories we look for scripts in
108   /** We look for a subdirectory named "scripts" in the configdir and in all datadir paths.
109   *   \return A list of directory paths containing executable scripts for /exec
110   */
111   static QStringList scriptDirPaths();
112
113   static void loadTranslation(const QLocale &locale);
114
115   static inline void setCliParser(AbstractCliParser *cliParser);
116   static inline AbstractCliParser *cliParser();
117   static inline QString optionValue(const QString &option);
118   static inline bool isOptionSet(const QString &option);
119
120   static const QString &coreDumpFileName();
121
122   static bool DEBUG;
123
124   static void logFatalMessage(const char *msg);
125
126 protected:
127   Quassel();
128   virtual bool init();
129   virtual void quit();
130
131   inline void setRunMode(RunMode mode);
132   inline void setDataDirPaths(const QStringList &paths);
133   QStringList findDataDirPaths() const;
134   inline void disableCrashhandler();
135
136 private:
137   void registerMetaTypes();
138
139   static void handleSignal(int signal);
140   static void logBacktrace(const QString &filename);
141
142   static Quassel *_instance;
143   static BuildInfo _buildInfo;
144   static AbstractCliParser *_cliParser;
145   static RunMode _runMode;
146   static bool _initialized;
147   static bool _handleCrashes;
148
149   static QString _coreDumpFileName;
150   static QString _configDirPath;
151   static QStringList _dataDirPaths;
152   static QString _translationDirPath;
153 };
154
155 Q_DECLARE_OPERATORS_FOR_FLAGS(Quassel::Features);
156
157 const Quassel::BuildInfo & Quassel::buildInfo() { return _buildInfo; }
158 Quassel::RunMode Quassel::runMode() { return _runMode; }
159 void Quassel::setRunMode(Quassel::RunMode mode) { _runMode = mode; }
160 void Quassel::setDataDirPaths(const QStringList &paths) { _dataDirPaths = paths; }
161 void Quassel::disableCrashhandler() { _handleCrashes = false; }
162
163 void Quassel::setCliParser(AbstractCliParser *parser) { _cliParser = parser; }
164 AbstractCliParser *Quassel::cliParser() { return _cliParser; }
165 QString Quassel::optionValue(const QString &key) { return cliParser()->value(key); }
166 bool Quassel::isOptionSet(const QString &key) { return cliParser()->isSet(key); }
167
168 #endif