Refactoring the GUI. Work in progress.
[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 * localSession();
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(ClientSignal, 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 serverConnected(QString net);
113     void serverDisconnected(QString net);
114
115   private:
116     CoreProxy *coreProxy;
117     Storage *storage;
118     QHash<QString, Server *> servers;
119     UserId user;
120
121 };
122
123 /*
124 class Core : public QObject {
125   Q_OBJECT
126
127   public:
128
129     Core();
130     ~Core();
131     QList<BufferId> getBuffers();
132
133   public slots:
134     void connectToIrc(QStringList);
135     void sendBacklog(BufferId, QVariant, QVariant);
136     void msgFromGUI(BufferId, QString message);
137
138   signals:
139     void msgFromGUI(QString net, QString buf, QString message);
140     void displayMsg(Message message);
141     void displayStatusMsg(QString, QString);
142
143     void connectToIrc(QString net);
144     void disconnectFromIrc(QString net);
145     void serverStateRequested();
146
147     void backlogData(BufferId, QList<QVariant>, bool done);
148
149     void bufferIdUpdated(BufferId);
150
151   private slots:
152     void globalDataUpdated(QString);
153     void recvStatusMsgFromServer(QString msg);
154     void recvMessageFromServer(Message::Type, QString target, QString text, QString sender = "", quint8 flags = Message::None);
155     void serverDisconnected(QString net);
156
157   private:
158     Storage *storage;
159     QHash<QString, Server *> servers;
160     UserId user;
161
162 };
163
164 */
165 //extern Core *core;
166
167
168 #endif