Lots of additions again. Working on implementing commands and prettifying the output.
[quassel.git] / core / coreproxy.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 _COREPROXY_H_
22 #define _COREPROXY_H_
23
24 #include "proxy_common.h"
25 #include "message.h"
26 #include "global.h"
27
28 #include <QtCore>
29 #include <QTcpSocket>
30 #include <QTcpServer>
31
32 /** This class is the Core side of the proxy. The Core connects its signals and slots to it,
33  *  and the calls are marshalled and sent to (or received and unmarshalled from) the GUIProxy.
34  *  The connection functions are defined in main/main_core.cpp or main/main_mono.cpp.
35  */
36 class CoreProxy : public QObject {
37   Q_OBJECT
38
39   public:
40     CoreProxy();
41
42   public slots:
43     inline void csUpdateGlobalData(QString key, QVariant data)          { send(CS_UPDATE_GLOBAL_DATA, key, data); }
44     inline void csDisplayMsg(QString net, QString buf, Message msg)     { send(CS_DISPLAY_MSG, net, buf, QVariant::fromValue(msg)); }
45     inline void csDisplayStatusMsg(QString net, QString msg)            { send(CS_DISPLAY_STATUS_MSG, net, msg); }
46     inline void csModeSet(QString net, QString target, QString mode)    { send(CS_MODE_SET, net, target, mode); }
47     inline void csTopicSet(QString net, QString buf, QString topic)     { send(CS_TOPIC_SET, net, buf, topic); }
48     inline void csSetNicks(QString net, QString buf, QStringList nicks) { send(CS_SET_NICKS, net, buf, nicks); }
49     inline void csNickAdded(QString net, QString nick, VarMap props)    { send(CS_NICK_ADDED, net, nick, props); }
50     inline void csNickRemoved(QString net, QString nick)                { send(CS_NICK_REMOVED, net, nick); }
51     inline void csNickUpdated(QString net, QString nick, VarMap props)  { send(CS_NICK_UPDATED, net, nick, props); }
52     inline void csOwnNickSet(QString net, QString nick)                 { send(CS_OWN_NICK_SET, net, nick); }
53
54   signals:
55     void gsPutGlobalData(QString, QVariant);
56     void gsUserInput(QString, QString, QString);
57     void gsRequestConnect(QStringList networks);
58
59   private:
60     void send(CoreSignal, QVariant arg1 = QVariant(), QVariant arg2 = QVariant(), QVariant arg3 = QVariant());
61     void recv(GUISignal, QVariant arg1 = QVariant(), QVariant arg2 = QVariant(), QVariant arg3 = QVariant());
62     void sendToGUI(CoreSignal, QVariant arg1, QVariant arg2, QVariant arg3);
63
64     void processClientInit(QTcpSocket *socket, const QVariant &v);
65     void processClientUpdate(QTcpSocket *, QString key, QVariant data);
66
67   private slots:
68     void incomingConnection();
69     void clientHasData();
70     void clientDisconnected();
71     void updateGlobalData(QString key);
72
73   private:
74     QTcpServer server;
75     QList<QTcpSocket *> clients;
76     QHash<QTcpSocket *, quint32> blockSizes;
77
78   friend class GUIProxy;
79 };
80
81 extern CoreProxy *coreProxy;
82
83
84
85 #endif