Setting status buffer active on connection (by creating a BufferId for it in Core
[quassel.git] / core / core.h
index 6b7a0ae..c4a6646 100644 (file)
 #ifndef _CORE_H_
 #define _CORE_H_
 
-#include <QMap>
 #include <QString>
 #include <QVariant>
+#include <QSqlDatabase>
 
 #include "server.h"
+#include "storage.h"
+#include "global.h"
+#include "coreproxy.h"
 
+class CoreSession;
+
+class Core : public QObject {
+  Q_OBJECT
+
+  public:
+    static Core * instance();
+    static void destroy();
+
+    static CoreSession * session(UserId);
+    static CoreSession * guiSession();
+    static CoreSession * createSession(UserId);
+
+  private slots:
+    void recvProxySignal(CoreSignal, QVariant, QVariant, QVariant);
+    bool startListening(uint port = 4242);
+    void stopListening();
+    void incomingConnection();
+    void clientHasData();
+    void clientDisconnected();
+    void updateGlobalData(UserId, QString);
+
+  private:
+    Core();
+    ~Core();
+    void init();
+    static Core *instanceptr;
+
+    void processClientInit(QTcpSocket *socket, const QVariant &v);
+    void processClientUpdate(QTcpSocket *socket, QString key, const QVariant &data);
+
+    UserId guiUser;
+    QHash<UserId, CoreSession *> sessions;
+    Storage *storage;
+
+    QTcpServer server; // TODO: implement SSL
+    QHash<QTcpSocket *, UserId> validClients;
+    QHash<QTcpSocket *, quint32> blockSizes;
+};
+
+class CoreSession : public QObject {
+  Q_OBJECT
+
+  public:
+    CoreSession(UserId, Storage *);
+    ~CoreSession();
+
+    QList<BufferId> buffers() const;
+    inline UserId userId();
+    QVariant sessionState();
+    CoreProxy *proxy();
+
+  public slots:
+    void connectToIrc(QStringList);
+    void processSignal(GUISignal, QVariant, QVariant, QVariant);
+    void sendBacklog(BufferId, QVariant, QVariant);
+    void msgFromGui(BufferId, QString message);
+    void sendServerStates();
+
+  signals:
+    void proxySignal(CoreSignal, QVariant arg1 = QVariant(), QVariant arg2 = QVariant(), QVariant arg3 = QVariant());
+
+    void msgFromGui(QString net, QString buf, QString message);
+    void displayMsg(Message message);
+    void displayStatusMsg(QString, QString);
+
+    void connectToIrc(QString net);
+    void disconnectFromIrc(QString net);
+    void serverStateRequested();
+
+    void backlogData(BufferId, QList<QVariant>, bool done);
+
+    void bufferIdUpdated(BufferId);
+
+  private slots:
+    //void recvProxySignal(CoreSignal, QVariant arg1 = QVariant(), QVariant arg2 = QVariant(), QVariant arg3 = QVariant());
+    void globalDataUpdated(UserId, QString);
+    void recvStatusMsgFromServer(QString msg);
+    void recvMessageFromServer(Message::Type, QString target, QString text, QString sender = "", quint8 flags = Message::None);
+    void serverConnected(QString net);
+    void serverDisconnected(QString net);
+
+  private:
+    CoreProxy *coreProxy;
+    Storage *storage;
+    QHash<QString, Server *> servers;
+    UserId user;
+
+};
+
+/*
 class Core : public QObject {
   Q_OBJECT
 
   public:
 
     Core();
-    //~Core();
+    ~Core();
+    QList<BufferId> getBuffers();
 
   public slots:
     void connectToIrc(QStringList);
+    void sendBacklog(BufferId, QVariant, QVariant);
+    void msgFromGUI(BufferId, QString message);
 
   signals:
-    void msgFromGUI(QString network, QString channel, QString message);
-    void displayMsg(QString network, QString channel, Message message);
+    void msgFromGUI(QString net, QString buf, QString message);
+    void displayMsg(Message message);
     void displayStatusMsg(QString, QString);
 
     void connectToIrc(QString net);
     void disconnectFromIrc(QString net);
+    void serverStateRequested();
+
+    void backlogData(BufferId, QList<QVariant>, bool done);
+
+    void bufferIdUpdated(BufferId);
 
   private slots:
     void globalDataUpdated(QString);
     void recvStatusMsgFromServer(QString msg);
-    void recvMessageFromServer(QString buffer, Message msg);
+    void recvMessageFromServer(Message::Type, QString target, QString text, QString sender = "", quint8 flags = Message::None);
+    void serverDisconnected(QString net);
 
   private:
+    Storage *storage;
     QHash<QString, Server *> servers;
+    UserId user;
 
 };
 
-extern Core *core;
+*/
+//extern Core *core;
+
 
 #endif