40e2e12f738d1eb459b6be3258e34783d77391cc
[quassel.git] / src / common / quassel.h
1 /***************************************************************************
2  *   Copyright (C) 2005-08 by the Quassel IRC Team                         *
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 "cliparser.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 version;
41       QString baseVersion;
42       QString generatedVersion;
43       QString buildDate;
44       QString buildTime;
45       QString commitHash;
46       uint archiveDate;
47       uint protocolVersion;
48       uint clientNeedsProtocol;
49       uint coreNeedsProtocol;
50
51       QString applicationName;
52       QString coreApplicationName;
53       QString clientApplicationName;
54       QString organizationName;
55       QString organizationDomain;
56     };
57
58     virtual ~Quassel();
59
60     static inline const BuildInfo & buildInfo();
61     static inline RunMode runMode();
62
63     static inline CliParser *cliParser();
64     static inline QString optionValue(const QString &option);
65     static inline bool isOptionSet(const QString &option);
66
67     static bool DEBUG;
68
69   protected:
70     Quassel();
71     virtual bool init();
72
73     inline void setRunMode(RunMode mode);
74
75
76   private:
77     void setupBuildInfo();
78     void setupTranslations();
79     void registerMetaTypes();
80
81     static void handleSignal(int signal);
82     static void handleCrash();
83
84     static BuildInfo _buildInfo;
85     static CliParser *_cliParser;
86     static RunMode _runMode;
87     static bool _initialized;
88 };
89
90 // FIXME temporary
91 namespace Global {
92   extern QString quasselVersion;
93   extern QString quasselBaseVersion;
94   extern QString quasselBuildDate;
95   extern QString quasselBuildTime;
96   extern QString quasselCommit;
97   extern uint quasselArchiveDate;
98   extern uint protocolVersion;
99
100   extern uint clientNeedsProtocol;  //< Minimum protocol version the client needs
101   extern uint coreNeedsProtocol;    //< Minimum protocol version the core needs
102
103   extern QString quasselGeneratedVersion;  //< This is possibly set in version.gen
104
105   void setupVersion();
106 };
107
108 const Quassel::BuildInfo & Quassel::buildInfo() { return _buildInfo; }
109 Quassel::RunMode Quassel::runMode() { return _runMode; }
110 void Quassel::setRunMode(Quassel::RunMode mode) { _runMode = mode; }
111
112 CliParser *Quassel::cliParser() { return _cliParser; }
113 QString Quassel::optionValue(const QString &key) { return cliParser()->value(key); }
114 bool Quassel::isOptionSet(const QString &key) { return cliParser()->isSet(key); }
115
116 #endif