X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=main%2Fglobal.cpp;h=3c82e815daa8a55cdf00b1c69711ed0592dcd49a;hp=4121806f5410664cefa18f11e17cbf41db332bed;hb=7ec4585cecc74ce8d9a94b0e52f00a96d105e79e;hpb=117a8a4d7ced61a3e374f20c74bea1834386a1d7 diff --git a/main/global.cpp b/main/global.cpp index 4121806f..3c82e815 100644 --- a/main/global.cpp +++ b/main/global.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005 by The Quassel Team * + * Copyright (C) 2005-07 by The Quassel IRC Development Team * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -22,63 +22,96 @@ #include "logger.h" #include "core.h" #include "message.h" +#include "util.h" #include #include 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() { - if(global) qFatal("Trying to instantiate more than one Global object!"); qInstallMsgHandler(messageHandler); qRegisterMetaType("Message"); qRegisterMetaTypeStreamOperators("Message"); - //initIconMap(); + qRegisterMetaType("BufferId"); + qRegisterMetaTypeStreamOperators("BufferId"); + + guiUser = 0; } -/* -void Global::setLogger(Logger *) { +Global::~Global() { -}; -*/ +} -QVariant Global::getData(QString key, QVariant defval) { +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(data.contains(key)) d = data[key]; + if(instance()->datastore[uid].contains(key)) d = instance()->datastore[uid][key]; else d = defval; mutex.unlock(); //qDebug() << "getData("<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(); - data[key] = d; + instance()->datastore[uid][key] = d; mutex.unlock(); - emit dataPutLocally(key); + 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(); - data[key] = d; + instance()->datastore[uid][key] = d; mutex.unlock(); - emit dataUpdatedRemotely(key); + emit instance()->dataUpdatedRemotely(uid, key); } /* not done yet */ +/* void Global::initIconMap() { // Do not depend on GUI in core! -/* QDomDocument doc("IconMap"); QFile file("images/iconmap.xml"); if(!file.open(QIODevice::ReadOnly)) { @@ -91,9 +124,38 @@ void Global::initIconMap() { file.close(); } +} */ + +/**************************************************************************************/ + + + +BufferId::BufferId(uint _id, QString _net, QString _buf, uint _gid) : id(_id), gid(_gid), net(_net), buf(_buf) { + + +} + +QString BufferId::buffer() { + if(isChannelName(buf)) return buf; + else return nickFromMask(buf); +} + +QDataStream &operator<<(QDataStream &out, const BufferId &bufferId) { + out << bufferId.id << bufferId.gid << bufferId.net.toUtf8() << bufferId.buf.toUtf8(); +} + +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); } +uint qHash(const BufferId &bid) { + return qHash(bid.id); +} /** * Retrieves an icon determined by its symbolic name. The mapping shall later @@ -108,6 +170,7 @@ void Global::initIconMap() { // return 0; //} -Global *global = 0; +QMutex Global::mutex; Global::RunMode Global::runMode; +UserId Global::guiUser; QString Global::quasselDir;