400c21eb9aada6736c714c659cbf2ded8704fc74
[quassel.git] / core / core.h
1 /***************************************************************************
2  *   Copyright (C) 2005/06 by The Quassel Team                             *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21 #ifndef _CORE_H_
22 #define _CORE_H_
23
24 #include <QString>
25 #include <QVariant>
26 #include <QSqlDatabase>
27
28 #include "server.h"
29 #include "storage.h"
30 #include "global.h"
31 #include "coreproxy.h"
32
33 class CoreSession;
34
35 class Core : public QObject {
36   Q_OBJECT
37
38   public:
39     static Core * instance();
40     static void destroy();
41
42     static CoreSession * session(UserId);
43     static CoreSession * guiSession();
44     static CoreSession * createSession(UserId);
45
46   private slots:
47     void recvProxySignal(CoreSignal, QVariant, QVariant, QVariant);
48     bool startListening(uint port = 4242);
49     void stopListening();
50     void incomingConnection();
51     void clientHasData();
52     void clientDisconnected();
53     void updateGlobalData(UserId, QString);
54
55   private:
56     Core();
57     ~Core();
58     void init();
59     static Core *instanceptr;
60
61     void processClientInit(QTcpSocket *socket, const QVariant &v);
62     void processClientUpdate(QTcpSocket *socket, QString key, const QVariant &data);
63
64     UserId guiUser;
65     QHash<UserId, CoreSession *> sessions;
66     Storage *storage;
67
68     QTcpServer server; // TODO: implement SSL
69     QHash<QTcpSocket *, UserId> validClients;
70     QHash<QTcpSocket *, quint32> blockSizes;
71 };
72
73 class CoreSession : public QObject {
74   Q_OBJECT
75
76   public:
77     CoreSession(UserId, Storage *);
78     ~CoreSession();
79
80     QList<BufferId> buffers() const;
81     inline UserId userId();
82     QVariant sessionState();
83     CoreProxy *proxy();
84
85   public slots:
86     void connectToIrc(QStringList);
87     void processSignal(GUISignal, QVariant, QVariant, QVariant);
88     void sendBacklog(BufferId, QVariant, QVariant);
89     void msgFromGui(BufferId, QString message);
90     void sendServerStates();
91
92   signals:
93     void proxySignal(CoreSignal, QVariant arg1 = QVariant(), QVariant arg2 = QVariant(), QVariant arg3 = QVariant());
94
95     void msgFromGui(QString net, QString buf, QString message);
96     void displayMsg(Message message);
97     void displayStatusMsg(QString, QString);
98
99     void connectToIrc(QString net);
100     void disconnectFromIrc(QString net);
101     void serverStateRequested();
102
103     void backlogData(BufferId, QList<QVariant>, bool done);
104
105     void bufferIdUpdated(BufferId);
106
107   private slots:
108     //void recvProxySignal(CoreSignal, QVariant arg1 = QVariant(), QVariant arg2 = QVariant(), QVariant arg3 = QVariant());
109     void globalDataUpdated(UserId, QString);
110     void recvStatusMsgFromServer(QString msg);
111     void recvMessageFromServer(Message::Type, QString target, QString text, QString sender = "", quint8 flags = Message::None);
112     void serverDisconnected(QString net);
113
114   private:
115     CoreProxy *coreProxy;
116     Storage *storage;
117     QHash<QString, Server *> servers;
118     UserId user;
119
120 };
121
122 /*
123 class Core : public QObject {
124   Q_OBJECT
125
126   public:
127
128     Core();
129     ~Core();
130     QList<BufferId> getBuffers();
131
132   public slots:
133     void connectToIrc(QStringList);
134     void sendBacklog(BufferId, QVariant, QVariant);
135     void msgFromGUI(BufferId, QString message);
136
137   signals:
138     void msgFromGUI(QString net, QString buf, QString message);
139     void displayMsg(Message message);
140     void displayStatusMsg(QString, QString);
141
142     void connectToIrc(QString net);
143     void disconnectFromIrc(QString net);
144     void serverStateRequested();
145
146     void backlogData(BufferId, QList<QVariant>, bool done);
147
148     void bufferIdUpdated(BufferId);
149
150   private slots:
151     void globalDataUpdated(QString);
152     void recvStatusMsgFromServer(QString msg);
153     void recvMessageFromServer(Message::Type, QString target, QString text, QString sender = "", quint8 flags = Message::None);
154     void serverDisconnected(QString net);
155
156   private:
157     Storage *storage;
158     QHash<QString, Server *> servers;
159     UserId user;
160
161 };
162
163 */
164 //extern Core *core;
165
166
167 #endif