/***************************************************************************
- * Copyright (C) 2005-07 by The Quassel IRC Development Team *
+ * Copyright (C) 2005-08 by the Quassel Project *
* devel@quassel-irc.org *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
+ * (at your option) version 3. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
+#include <QObject>
+#include <QMetaType>
#include "global.h"
#include "logger.h"
-#include "core.h"
#include "message.h"
-#include "util.h"
-
-#include <QtCore>
-#include <QDomDocument>
+#include "identity.h"
+#include "network.h"
+#include "bufferinfo.h"
+#include "types.h"
+#include "syncableobject.h"
extern void messageHandler(QtMsgType type, const char *msg);
-Global *Global::instanceptr = 0;
-
-Global * Global::instance() {
- if(instanceptr) return instanceptr;
- return instanceptr = new Global();
-}
-
-void Global::destroy() {
- delete instanceptr;
- instanceptr = 0;
-}
-
-Global::Global() {
- qInstallMsgHandler(messageHandler);
- qRegisterMetaType<Message>("Message");
- qRegisterMetaTypeStreamOperators<Message>("Message");
- qRegisterMetaType<BufferId>("BufferId");
- qRegisterMetaTypeStreamOperators<BufferId>("BufferId");
-
- guiUser = 0;
-}
-
-Global::~Global() {
-
-
-}
-
-void Global::setGuiUser(UserId uid) {
- guiUser = uid;
-}
-
-QVariant Global::data(QString key, QVariant defval) {
- return data(guiUser, key, defval);
-}
-
-QVariant Global::data(UserId uid, QString key, QVariant defval) {
- QVariant d;
- mutex.lock();
- if(instance()->datastore[uid].contains(key)) d = instance()->datastore[uid][key];
- else d = defval;
- mutex.unlock();
- //qDebug() << "getData("<<key<<"): " << d;
- return d;
-}
-
-QStringList Global::keys() {
- return keys(guiUser);
-}
-
-QStringList Global::keys(UserId uid) {
- QStringList k;
- mutex.lock();
- k = instance()->datastore[uid].keys();
- mutex.unlock();
- return k;
-}
-
-void Global::putData(QString key, QVariant d) {
- putData(guiUser, key, d);
-}
-
-void Global::putData(UserId uid, QString key, QVariant d) {
- mutex.lock();
- instance()->datastore[uid][key] = d;
- mutex.unlock();
- emit instance()->dataPutLocally(uid, key);
-}
-
-void Global::updateData(QString key, QVariant d) {
- updateData(guiUser, key, d);
-}
-
-void Global::updateData(UserId uid, QString key, QVariant d) {
- mutex.lock();
- instance()->datastore[uid][key] = d;
- mutex.unlock();
- emit instance()->dataUpdatedRemotely(uid, key);
-}
-
/* not done yet */
/*
void Global::initIconMap() {
}
*/
-/**************************************************************************************/
+/**
+ * Retrieves an icon determined by its symbolic name. The mapping shall later
+ * be performed by a theme manager or something like that.
+ * @param symbol Symbol of requested icon
+ * @return Pointer to a newly created QIcon
+ */
+//
+//QIcon *Global::getIcon(QString /*symbol*/) {
+ //if(symbol == "connect"
+// return 0;
+//}
+//! Register our custom types with Qt's Meta Object System.
+/** This makes them available for QVariant and in signals/slots, among other things.
+ *
+ */
+void Global::registerMetaTypes() {
+ // Complex types
+ qRegisterMetaType<QVariant>("QVariant");
+ qRegisterMetaType<Message>("Message");
+ qRegisterMetaType<BufferInfo>("BufferInfo");
+ qRegisterMetaType<NetworkInfo>("NetworkInfo");
+ qRegisterMetaType<Identity>("Identity");
+ qRegisterMetaType<Network::ConnectionState>("Network::ConnectionState");
-BufferId::BufferId(uint _id, QString _net, QString _buf, uint _gid) : id(_id), gid(_gid), net(_net), buf(_buf) {
+ qRegisterMetaTypeStreamOperators<QVariant>("QVariant");
+ qRegisterMetaTypeStreamOperators<Message>("Message");
+ qRegisterMetaTypeStreamOperators<BufferInfo>("BufferInfo");
+ qRegisterMetaTypeStreamOperators<NetworkInfo>("NetworkInfo");
+ qRegisterMetaTypeStreamOperators<Identity>("Identity");
+ qRegisterMetaTypeStreamOperators<qint8>("Network::ConnectionState");
+ qRegisterMetaType<IdentityId>("IdentityId");
+ qRegisterMetaType<BufferId>("BufferId");
+ qRegisterMetaType<NetworkId>("NetworkId");
+ qRegisterMetaType<UserId>("UserId");
+ qRegisterMetaType<AccountId>("AccountId");
+ qRegisterMetaType<MsgId>("MsgId");
+ qRegisterMetaTypeStreamOperators<IdentityId>("IdentityId");
+ qRegisterMetaTypeStreamOperators<BufferId>("BufferId");
+ qRegisterMetaTypeStreamOperators<NetworkId>("NetworkId");
+ qRegisterMetaTypeStreamOperators<UserId>("UserId");
+ qRegisterMetaTypeStreamOperators<AccountId>("AccountId");
+ qRegisterMetaTypeStreamOperators<MsgId>("MsgId");
}
-QString BufferId::buffer() {
- if(isChannelName(buf)) return buf;
- else return nickFromMask(buf);
-}
+//! This includes version.inc and possibly version.gen and sets up our version numbers.
+void Global::setupVersion() {
-QDataStream &operator<<(QDataStream &out, const BufferId &bufferId) {
- out << bufferId.id << bufferId.gid << bufferId.net.toUtf8() << bufferId.buf.toUtf8();
-}
+# include "version.inc"
+# ifdef HAVE_VERSION_GEN
+# include "version.gen"
+# endif
-QDataStream &operator>>(QDataStream &in, BufferId &bufferId) {
- QByteArray n, b;
- BufferId i;
- in >> bufferId.id >> bufferId.gid >> n >> b;
- bufferId.net = QString::fromUtf8(n);
- bufferId.buf = QString::fromUtf8(b);
-}
+ if(quasselGeneratedVersion.isEmpty()) {
+ quasselVersion = QString("v%1 (unknown rev)").arg(quasselBaseVersion);
+ } else {
+ QStringList parts = quasselGeneratedVersion.split(':');
+ if(parts.count() < 2) parts.append("unknown rev");
+ quasselVersion = QString("v%1 (%2)").arg(parts[0], parts[1]);
+ }
+# ifdef __DATE__
+ quasselBuildDate = __DATE__;
+# endif
-uint qHash(const BufferId &bid) {
- return qHash(bid.id);
}
-/**
- * Retrieves an icon determined by its symbolic name. The mapping shall later
- * be performed by a theme manager or something like that.
- * @param symbol Symbol of requested icon
- * @return Pointer to a newly created QIcon
- */
-//
-//QIcon *Global::getIcon(QString /*symbol*/) {
- //if(symbol == "connect"
+// Static variables
-// return 0;
-//}
+QString Global::quasselVersion;
+QString Global::quasselBaseVersion;
+QString Global::quasselGeneratedVersion;
+QString Global::quasselBuildDate;
+uint Global::protocolVersion;
+uint Global::clientNeedsProtocol;
+uint Global::coreNeedsProtocol;
-QMutex Global::mutex;
Global::RunMode Global::runMode;
-UserId Global::guiUser;
-QString Global::quasselDir;
+uint Global::defaultPort;
+
+bool Global::DEBUG;