Merge branch 'cmake'
[quassel.git] / src / common / global.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-08 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 #include <QObject>
21 #include <QMetaType>
22
23 #include "global.h"
24 #include "logger.h"
25 #include "message.h"
26 #include "identity.h"
27 #include "network.h"
28 #include "bufferinfo.h"
29 #include "types.h"
30 #include "syncableobject.h"
31
32 extern void messageHandler(QtMsgType type, const char *msg);
33
34 /* not done yet */
35 /*
36 void Global::initIconMap() {
37 // Do not depend on GUI in core!
38   QDomDocument doc("IconMap");
39   QFile file("images/iconmap.xml");
40   if(!file.open(QIODevice::ReadOnly)) {
41     qDebug() << "Error opening iconMap file!";
42     return;
43   } else if(!doc.setContent(&file)) {
44     file.close();
45     qDebug() << "Error parsing iconMap file!";
46   } else {
47     file.close();
48
49   }
50 }
51 */
52
53 /**
54  * Retrieves an icon determined by its symbolic name. The mapping shall later
55  * be performed by a theme manager or something like that.
56  * @param symbol Symbol of requested icon
57  * @return Pointer to a newly created QIcon
58  */
59 //
60 //QIcon *Global::getIcon(QString /*symbol*/) {
61   //if(symbol == "connect"
62
63 //  return 0;
64 //}
65
66 //! Register our custom types with Qt's Meta Object System.
67 /**  This makes them available for QVariant and in signals/slots, among other things.
68  *
69  */
70 void Global::registerMetaTypes() {
71   // Complex types
72   qRegisterMetaType<QVariant>("QVariant");
73   qRegisterMetaType<Message>("Message");
74   qRegisterMetaType<BufferInfo>("BufferInfo");
75   qRegisterMetaType<NetworkInfo>("NetworkInfo");
76   qRegisterMetaType<Identity>("Identity");
77   qRegisterMetaType<Network::ConnectionState>("Network::ConnectionState");
78
79   qRegisterMetaTypeStreamOperators<QVariant>("QVariant");
80   qRegisterMetaTypeStreamOperators<Message>("Message");
81   qRegisterMetaTypeStreamOperators<BufferInfo>("BufferInfo");
82   qRegisterMetaTypeStreamOperators<NetworkInfo>("NetworkInfo");
83   qRegisterMetaTypeStreamOperators<Identity>("Identity");
84   qRegisterMetaTypeStreamOperators<qint8>("Network::ConnectionState");
85
86   qRegisterMetaType<IdentityId>("IdentityId");
87   qRegisterMetaType<BufferId>("BufferId");
88   qRegisterMetaType<NetworkId>("NetworkId");
89   qRegisterMetaType<UserId>("UserId");
90   qRegisterMetaType<AccountId>("AccountId");
91   qRegisterMetaType<MsgId>("MsgId");
92
93   qRegisterMetaTypeStreamOperators<IdentityId>("IdentityId");
94   qRegisterMetaTypeStreamOperators<BufferId>("BufferId");
95   qRegisterMetaTypeStreamOperators<NetworkId>("NetworkId");
96   qRegisterMetaTypeStreamOperators<UserId>("UserId");
97   qRegisterMetaTypeStreamOperators<AccountId>("AccountId");
98   qRegisterMetaTypeStreamOperators<MsgId>("MsgId");
99 }
100
101 //! This includes version.inc and possibly version.gen and sets up our version numbers.
102 void Global::setupVersion() {
103
104 #  include "version.inc"
105 #  ifdef HAVE_VERSION_GEN
106 #    include "version.gen"
107 #  endif
108
109   if(quasselGeneratedVersion.isEmpty()) {
110     quasselVersion = QString("v%1 (unknown rev)").arg(quasselBaseVersion);
111   } else {
112     QStringList parts = quasselGeneratedVersion.split(':');
113     quasselVersion = QString("v%1").arg(parts[0]);
114     if(parts.count() >= 2) quasselVersion.append(QString(" (%1)").arg(parts[1]));
115   }
116   quasselBuildDate = __DATE__;
117   quasselBuildTime = __TIME__;
118 }
119
120 // Static variables
121
122 QString Global::quasselVersion;
123 QString Global::quasselBaseVersion;
124 QString Global::quasselGeneratedVersion;
125 QString Global::quasselBuildDate;
126 QString Global::quasselBuildTime;
127 uint Global::protocolVersion;
128 uint Global::clientNeedsProtocol;
129 uint Global::coreNeedsProtocol;
130
131 Global::RunMode Global::runMode;
132 uint Global::defaultPort;
133
134 bool Global::DEBUG;