1 /***************************************************************************
2 * Copyright (C) 2005/06 by The Quassel Team *
3 * devel@quassel-irc.org *
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. *
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. *
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 ***************************************************************************/
26 #include <QSqlDatabase>
31 #include "coreproxy.h"
35 class Core : public QObject {
39 static Core * instance();
40 static void destroy();
42 static CoreSession * session(UserId);
43 static CoreSession * localSession();
44 static CoreSession * createSession(UserId);
46 static QVariant connectLocalClient(QString user, QString passwd);
47 static QVariant disconnectLocalClient();
50 void recvProxySignal(CoreSignal, QVariant, QVariant, QVariant);
51 bool startListening(uint port = 4242);
53 void incomingConnection();
55 void clientDisconnected();
56 void updateGlobalData(UserId, QString);
62 static Core *instanceptr;
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
70 QVariant initSession(UserId userId);
71 void processClientInit(QTcpSocket *socket, const QVariant &v);
72 void processClientUpdate(QTcpSocket *socket, QString key, const QVariant &data);
75 QHash<UserId, CoreSession *> sessions;
78 QTcpServer server; // TODO: implement SSL
79 QHash<QTcpSocket *, UserId> validClients;
80 QHash<QTcpSocket *, quint32> blockSizes;
83 class CoreSession : public QObject {
87 CoreSession(UserId, Storage *);
90 QList<BufferId> buffers() const;
91 inline UserId userId();
92 QVariant sessionState();
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();
103 void proxySignal(CoreSignal, QVariant arg1 = QVariant(), QVariant arg2 = QVariant(), QVariant arg3 = QVariant());
105 void msgFromGui(QString net, QString buf, QString message);
106 void displayMsg(Message message);
107 void displayStatusMsg(QString, QString);
109 void connectToIrc(QString net);
110 void disconnectFromIrc(QString net);
111 void serverStateRequested();
113 void backlogData(BufferId, QList<QVariant>, bool done);
115 void bufferIdUpdated(BufferId);
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);
126 CoreProxy *coreProxy;
128 QHash<QString, Server *> servers;
134 class Core : public QObject {
141 QList<BufferId> getBuffers();
144 void connectToIrc(QStringList);
145 void sendBacklog(BufferId, QVariant, QVariant);
146 void msgFromGUI(BufferId, QString message);
149 void msgFromGUI(QString net, QString buf, QString message);
150 void displayMsg(Message message);
151 void displayStatusMsg(QString, QString);
153 void connectToIrc(QString net);
154 void disconnectFromIrc(QString net);
155 void serverStateRequested();
157 void backlogData(BufferId, QList<QVariant>, bool done);
159 void bufferIdUpdated(BufferId);
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);
169 QHash<QString, Server *> servers;