Big update this time - Core has been redesigned to be multi-user capable. At least...
[quassel.git] / main / global.cpp
index 3317cfd..3c82e81 100644 (file)
@@ -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  *
 
 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>("Message");
   qRegisterMetaTypeStreamOperators<Message>("Message");
   qRegisterMetaType<BufferId>("BufferId");
   qRegisterMetaTypeStreamOperators<BufferId>("BufferId");
 
-  //initIconMap();
+  guiUser = 0;
 }
 
-/*
-void Global::setLogger(Logger *) {
+Global::~Global() {
 
 
-};
-*/
+}
+
+void Global::setGuiUser(UserId uid) {
+  guiUser = uid;
+}
+
+QVariant Global::data(QString key, QVariant defval) {
+  return data(guiUser, key, defval);
+}
 
-QVariant Global::getData(QString key, QVariant 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("<<key<<"): " << d;
   return d;
 }
 
-QStringList Global::getKeys() {
+QStringList Global::keys() {
+  return keys(guiUser);
+}
+
+QStringList Global::keys(UserId uid) {
   QStringList k;
   mutex.lock();
-  k = data.keys();
+  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();
-  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)) {
@@ -95,8 +124,8 @@ void Global::initIconMap() {
     file.close();
 
   }
-*/
 }
+*/
 
 /**************************************************************************************/
 
@@ -141,6 +170,7 @@ uint qHash(const BufferId &bid) {
 //  return 0;
 //}
 
-Global *global = 0;
+QMutex Global::mutex;
 Global::RunMode Global::runMode;
+UserId Global::guiUser;
 QString Global::quasselDir;