Deuglify channel state icons
[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   virtual ~Quassel();
62
63   static void setupBuildInfo(const QString &generated);
64   static inline const BuildInfo & buildInfo();
65   static inline RunMode runMode();
66
67   static QString configDirPath();
68
69   //! Returns a list of data directory paths
70   /** There are several locations for applications to install their data files in. On Unix,
71   *  a common location is /usr/share; others include $PREFIX/share and additional directories
72   *  specified in the env variable XDG_DATA_DIRS.
73   *  \return A list of directory paths to look for data files in
74   */
75   static QStringList dataDirPaths();
76
77   //! Searches for a data file in the possible data directories
78   /** Data files can reside in $DATA_DIR/apps/quassel, where $DATA_DIR is one of the directories
79   *  returned by \sa dataDirPaths().
80   *  \Note With KDE integration enabled, files are searched (only) in KDE's appdata dirs.
81   *  \return The full path to the data file if found; a null QString else
82   */
83   static QString findDataFilePath(const QString &filename);
84
85   static QString translationDirPath();
86
87   static void loadTranslation(const QLocale &locale);
88
89   static inline void setCliParser(AbstractCliParser *cliParser);
90   static inline AbstractCliParser *cliParser();
91   static inline QString optionValue(const QString &option);
92   static inline bool isOptionSet(const QString &option);
93
94   static const QString &coreDumpFileName();
95
96   static bool DEBUG;
97
98   static void logFatalMessage(const char *msg);
99
100 protected:
101   Quassel();
102   virtual bool init();
103
104   inline void setRunMode(RunMode mode);
105   inline void setDataDirPaths(const QStringList &paths);
106   QStringList findDataDirPaths() const;
107
108 private:
109   void registerMetaTypes();
110
111   static void handleSignal(int signal);
112   static void logBacktrace(const QString &filename);
113
114   static BuildInfo _buildInfo;
115   static AbstractCliParser *_cliParser;
116   static RunMode _runMode;
117   static bool _initialized;
118
119   static QString _coreDumpFileName;
120   static QString _configDirPath;
121   static QStringList _dataDirPaths;
122   static QString _translationDirPath;
123 };
124
125 const Quassel::BuildInfo & Quassel::buildInfo() { return _buildInfo; }
126 Quassel::RunMode Quassel::runMode() { return _runMode; }
127 void Quassel::setRunMode(Quassel::RunMode mode) { _runMode = mode; }
128 void Quassel::setDataDirPaths(const QStringList &paths) { _dataDirPaths = paths; }
129
130 void Quassel::setCliParser(AbstractCliParser *parser) { _cliParser = parser; }
131 AbstractCliParser *Quassel::cliParser() { return _cliParser; }
132 QString Quassel::optionValue(const QString &key) { return cliParser()->value(key); }
133 bool Quassel::isOptionSet(const QString &key) { return cliParser()->isSet(key); }
134
135 #endif