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