9492ec6b5892f4b8b6848f33af6a627669b688e8
[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 <QString>
26
27 #include "abstractcliparser.h"
28
29 class Quassel {
30   Q_DECLARE_TR_FUNCTIONS(Quassel)
31
32 public:
33   enum RunMode {
34     Monolithic,
35     ClientOnly,
36     CoreOnly
37   };
38
39   struct BuildInfo {
40     QString fancyVersionString; // clickable rev
41     QString plainVersionString; // no <a> tag
42
43     QString baseVersion;
44     QString generatedVersion;
45     QString commitHash;
46     uint commitDate;
47     QString buildDate;
48     bool isSourceDirty;
49     uint protocolVersion;
50     uint clientNeedsProtocol;
51     uint coreNeedsProtocol;
52
53     QString applicationName;
54     QString coreApplicationName;
55     QString clientApplicationName;
56     QString organizationName;
57     QString organizationDomain;
58   };
59
60   virtual ~Quassel();
61
62   static void setupBuildInfo(const QString &generated);
63   static inline const BuildInfo & buildInfo();
64   static inline RunMode runMode();
65
66   static QString configDirPath();
67
68   //! Returns a list of data directory paths
69   /** There are several locations for applications to install their data files in. On Unix,
70   *  a common location is /usr/share; others include $PREFIX/share and additional directories
71   *  specified in the env variable XDG_DATA_DIRS.
72   *  \return A list of directory paths to look for data files in
73   */
74   static QStringList dataDirPaths();
75
76   //! Searches for a data file in the possible data directories
77   /** Data files can reside in $DATA_DIR/apps/quassel, where $DATA_DIR is one of the directories
78   *  returned by \sa dataDirPaths().
79   *  \Note With KDE integration enabled, files are searched (only) in KDE's appdata dirs.
80   *  \return The full path to the data file if found; a null QString else
81   */
82   static QString findDataFilePath(const QString &filename);
83
84   static inline void setCliParser(AbstractCliParser *cliParser);
85   static inline AbstractCliParser *cliParser();
86   static inline QString optionValue(const QString &option);
87   static inline bool isOptionSet(const QString &option);
88
89   static const QString &coreDumpFileName();
90
91   static bool DEBUG;
92
93   static void logFatalMessage(const char *msg);
94
95 protected:
96   Quassel();
97   virtual bool init();
98
99   inline void setRunMode(RunMode mode);
100   inline void setDataDirPaths(const QStringList &paths);
101   QStringList findDataDirPaths() const;
102
103 private:
104   void registerMetaTypes();
105
106   static void handleSignal(int signal);
107   static void logBacktrace(const QString &filename);
108
109   static BuildInfo _buildInfo;
110   static AbstractCliParser *_cliParser;
111   static RunMode _runMode;
112   static bool _initialized;
113
114   static QString _coreDumpFileName;
115   static QString _configDirPath;
116   static QStringList _dataDirPaths;
117 };
118
119 const Quassel::BuildInfo & Quassel::buildInfo() { return _buildInfo; }
120 Quassel::RunMode Quassel::runMode() { return _runMode; }
121 void Quassel::setRunMode(Quassel::RunMode mode) { _runMode = mode; }
122 void Quassel::setDataDirPaths(const QStringList &paths) { _dataDirPaths = paths; }
123
124 void Quassel::setCliParser(AbstractCliParser *parser) { _cliParser = parser; }
125 AbstractCliParser *Quassel::cliParser() { return _cliParser; }
126 QString Quassel::optionValue(const QString &key) { return cliParser()->value(key); }
127 bool Quassel::isOptionSet(const QString &key) { return cliParser()->isSet(key); }
128
129 #endif