Still working on the authentification stuff. Technically, now even in the monolithic...
[quassel.git] / src / 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     static QVariant connectLocalClient(QString user, QString passwd);
47     static QVariant disconnectLocalClient();
48
49   private slots:
50     void recvProxySignal(CoreSignal, QVariant, QVariant, QVariant);
51     bool startListening(uint port = 4242);
52     void stopListening();
53     void incomingConnection();
54     void clientHasData();
55     void clientDisconnected();
56     void updateGlobalData(UserId, QString);
57
58   private:
59     Core();
60     ~Core();
61     void init();
62     static Core *instanceptr;
63
64     //! Initiate a session for the user with the given credentials if one does not already exist.
65     /** This function is called during the init process for a new client. If there is no session for the
66      *  given user, one is created.
67      * \param userId The user
68      * \return A QVariant containing the session data, e.g. global data and buffers
69      */
70     QVariant initSession(UserId userId);
71     void processClientInit(QTcpSocket *socket, const QVariant &v);
72     void processClientUpdate(QTcpSocket *socket, QString key, const QVariant &data);
73
74     UserId guiUser;
75     QHash<UserId, CoreSession *> sessions;
76     Storage *storage;
77
78     QTcpServer server; // TODO: implement SSL
79     QHash<QTcpSocket *, UserId> validClients;
80     QHash<QTcpSocket *, quint32> blockSizes;
81 };
82
83 class CoreSession : public QObject {
84   Q_OBJECT
85
86   public:
87     CoreSession(UserId, Storage *);
88     ~CoreSession();
89
90     QList<BufferId> buffers() const;
91     inline UserId userId();
92     QVariant sessionState();
93     CoreProxy *proxy();
94
95   public slots:
96     void connectToIrc(QStringList);
97     void processSignal(ClientSignal, QVariant, QVariant, QVariant);
98     void sendBacklog(BufferId, QVariant, QVariant);
99     void msgFromGui(BufferId, QString message);
100     void sendServerStates();
101
102   signals:
103     void proxySignal(CoreSignal, QVariant arg1 = QVariant(), QVariant arg2 = QVariant(), QVariant arg3 = QVariant());
104
105     void msgFromGui(QString net, QString buf, QString message);
106     void displayMsg(Message message);
107     void displayStatusMsg(QString, QString);
108
109     void connectToIrc(QString net);
110     void disconnectFromIrc(QString net);
111     void serverStateRequested();
112
113     void backlogData(BufferId, QList<QVariant>, bool done);
114
115     void bufferIdUpdated(BufferId);
116
117   private slots:
118     //void recvProxySignal(CoreSignal, QVariant arg1 = QVariant(), QVariant arg2 = QVariant(), QVariant arg3 = QVariant());
119     void globalDataUpdated(UserId, QString);
120     void recvStatusMsgFromServer(QString msg);
121     void recvMessageFromServer(Message::Type, QString target, QString text, QString sender = "", quint8 flags = Message::None);
122     void serverConnected(QString net);
123     void serverDisconnected(QString net);
124
125   private:
126     CoreProxy *coreProxy;
127     Storage *storage;
128     QHash<QString, Server *> servers;
129     UserId user;
130
131 };
132
133 /*
134 class Core : public QObject {
135   Q_OBJECT
136
137   public:
138
139     Core();
140     ~Core();
141     QList<BufferId> getBuffers();
142
143   public slots:
144     void connectToIrc(QStringList);
145     void sendBacklog(BufferId, QVariant, QVariant);
146     void msgFromGUI(BufferId, QString message);
147
148   signals:
149     void msgFromGUI(QString net, QString buf, QString message);
150     void displayMsg(Message message);
151     void displayStatusMsg(QString, QString);
152
153     void connectToIrc(QString net);
154     void disconnectFromIrc(QString net);
155     void serverStateRequested();
156
157     void backlogData(BufferId, QList<QVariant>, bool done);
158
159     void bufferIdUpdated(BufferId);
160
161   private slots:
162     void globalDataUpdated(QString);
163     void recvStatusMsgFromServer(QString msg);
164     void recvMessageFromServer(Message::Type, QString target, QString text, QString sender = "", quint8 flags = Message::None);
165     void serverDisconnected(QString net);
166
167   private:
168     Storage *storage;
169     QHash<QString, Server *> servers;
170     UserId user;
171
172 };
173
174 */
175 //extern Core *core;
176
177
178 #endif