Big update this time - Core has been redesigned to be multi-user capable. At least...
[quassel.git] / main / global.h
index ad4cb1d..fa961f2 100644 (file)
 #define _GLOBAL_H_
 
 /** The protocol version we use fo the communication between core and GUI */
-#define GUI_PROTOCOL 1
+#define GUI_PROTOCOL 2
+
+#define BACKLOG_FORMAT 2
+#define BACKLOG_STRING "QuasselIRC Backlog File"
 
 class Global;
 
@@ -31,7 +34,9 @@ class Global;
 
 /* Some global stuff */
 typedef QMap<QString, QVariant> VarMap;
-extern Global *global;
+
+typedef uint UserId;
+typedef uint MsgId;
 
 /**
  * This class is mostly a globally synchronized data store, meant for storing systemwide settings such
@@ -47,40 +52,52 @@ class Global : public QObject {
   Q_OBJECT
 
   public:
-    Global();
     //static Logger *getLogger();
     //static void setLogger(Logger *);
 
 //    static QIcon *getIcon(QString symbol);
 
-    QVariant getData(QString key, QVariant defaultValue = QVariant());
-    QStringList getKeys();
+    static Global *instance();
+    static void destroy();
+    static void setGuiUser(UserId);
+
+    static QVariant data(QString key, QVariant defaultValue = QVariant());
+    static QVariant data(UserId, QString key, QVariant defaultValue = QVariant());
+    static QStringList keys();
+    static QStringList keys(UserId);
+
+    static void putData(QString key, QVariant data);      ///< Store data changed locally, will be propagated to all other clients and the core
+    static void putData(UserId, QString key, QVariant data);
 
-  public slots:
-    void putData(QString key, QVariant data);      ///< Store data changed locally, will be propagated to all other clients and the core
-    void updateData(QString key, QVariant data);   ///< Update stored data if requested by the core or other clients
+    static void updateData(QString key, QVariant data);   ///< Update stored data if requested by the core or other clients
+    static void updateData(UserId, QString key, QVariant data);
 
   signals:
-    void dataPutLocally(QString key);
-    void dataUpdatedRemotely(QString key);  // sent by remote update only!
+    void dataPutLocally(UserId, QString key);
+    void dataUpdatedRemotely(UserId, QString key);  // sent by remote update only!
 
   public:
-    enum RunMode { Monolithic, GUIOnly, CoreOnly };
+    enum RunMode { Monolithic, GuiOnly, CoreOnly };
     static RunMode runMode;
+    static QString quasselDir;
 
   private:
-    static void initIconMap();
+    Global();
+    ~Global();
+    static Global *instanceptr;
+
+    static UserId guiUser;
+    //static void initIconMap();
 
     //static Logger *logger;
 
 //    static QString iconPath;
-    QHash<QString, QString> iconMap;
-    QMutex mutex;
-    QHash<QString, QVariant> data;
+    //QHash<QString, QString> iconMap;
+    static QMutex mutex;
+    QHash<UserId, QHash<QString, QVariant> > datastore;
 };
 
-class Exception {
-  public:
+struct Exception {
     Exception(QString msg = "Unknown Exception") : _msg(msg) {};
     virtual inline QString msg() { return _msg; }
 
@@ -89,4 +106,35 @@ class Exception {
 
 };
 
+class BufferId {
+  public:
+    BufferId() { id = gid = 0; } // FIXME
+    BufferId(uint uid, QString net, QString buf, uint gid = 0);
+
+    inline uint uid() { return id; }
+    inline uint groupId() { return gid; }
+    inline QString network() { return net; }
+    QString buffer(); // nickfrommask?
+
+    void setGroupId(uint _gid) { gid = _gid; }
+
+    inline bool operator==(const BufferId &other) const { return id == other.id; }
+  private:
+    uint id;
+    uint gid;
+    QString net;
+    QString buf;
+
+    friend uint qHash(const BufferId &);
+    friend QDataStream &operator<<(QDataStream &out, const BufferId &bufferId);
+    friend QDataStream &operator>>(QDataStream &in, BufferId &bufferId);
+};
+
+QDataStream &operator<<(QDataStream &out, const BufferId &bufferId);
+QDataStream &operator>>(QDataStream &in, BufferId &bufferId);
+
+Q_DECLARE_METATYPE(BufferId);
+
+uint qHash(const BufferId &);
+
 #endif