9d7df3ee2a3ac22147ccdba35f99b2002a2f52d7
[quassel.git] / src / client / client.h
1 /***************************************************************************
2  *   Copyright (C) 2005-07 by The Quassel IRC Development 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 _CLIENT_H_
22 #define _CLIENT_H_
23
24 #include <QAbstractSocket>
25 #include <QTcpSocket>
26 #include <QList>
27 #include <QPointer>
28
29 #include "buffer.h"
30 #include "message.h"
31 #include "proxy_common.h"
32
33 class AbstractUi;
34 class ClientProxy;
35 class BufferTreeModel;
36 class QtGui;
37 class SignalProxy;
38
39 class QTimer;
40
41 class Client : public QObject {
42   Q_OBJECT
43
44   public:
45     static Client *instance();
46     static void init(AbstractUi *);
47     static void destroy();
48
49     static QList<BufferId> allBufferIds();
50     static Buffer *buffer(BufferId);
51     static BufferId statusBufferId(QString net);
52     static BufferId bufferId(QString net, QString buf);
53
54     static BufferTreeModel *bufferModel();
55     static SignalProxy *signalProxy();
56
57     static AbstractUiMsg *layoutMsg(const Message &);
58
59     static bool isConnected();
60
61     static void storeSessionData(const QString &key, const QVariant &data);
62     static QVariant retrieveSessionData(const QString &key, const QVariant &def = QVariant());
63     static QStringList sessionDataKeys();
64
65     enum ClientMode { LocalCore, RemoteCore };
66     static ClientMode clientMode;
67
68   signals:
69     void sendInput(BufferId, QString message);
70     void showBuffer(Buffer *);
71     void bufferSelected(Buffer *);
72     void bufferUpdated(Buffer *);
73     void bufferActivity(Buffer::ActivityLevel, Buffer *);
74     void bufferDestroyed(Buffer *);
75     void backlogReceived(Buffer *, QList<Message>);
76     void requestBacklog(BufferId, QVariant, QVariant);
77     void requestNetworkStates();
78
79     void recvPartialItem(uint avail, uint size);
80     void coreConnectionError(QString errorMsg);
81     void coreConnectionMsg(const QString &msg);
82     void coreConnectionProgress(uint part, uint total);
83
84     void connected();
85     void disconnected();
86
87     void sessionDataChanged(const QString &key);
88     void sessionDataChanged(const QString &key, const QVariant &data);
89     void sendSessionData(const QString &key, const QVariant &data);
90
91   public slots:
92     //void selectBuffer(Buffer *);
93     //void connectToLocalCore();
94     void connectToCore(const QVariantMap &);
95     void disconnectFromCore();
96
97   private slots:
98     void recvCoreState(const QVariant &state);
99     void recvSessionData(const QString &key, const QVariant &data);
100     void recvProxySignal(ClientSignal sig, QVariant arg1, QVariant arg2, QVariant arg3);
101
102     void coreSocketError(QAbstractSocket::SocketError);
103     void coreHasData();
104     void coreSocketConnected();
105     void coreSocketDisconnected();
106     void coreSocketStateChanged(QAbstractSocket::SocketState);
107
108     void userInput(BufferId, QString);
109     void networkConnected(QString);
110     void networkDisconnected(QString);
111     void recvNetworkState(QString, QVariant);
112     void recvMessage(const Message &message);
113     void recvStatusMsg(QString network, QString message);
114     void setTopic(QString net, QString buf, QString);
115     void addNick(QString net, QString nick, QVariantMap props);
116     void removeNick(QString net, QString nick);
117     void renameNick(QString net, QString oldnick, QString newnick);
118     void updateNick(QString net, QString nick, QVariantMap props);
119     void setOwnNick(QString net, QString nick);
120     void recvBacklogData(BufferId, QVariantList, bool);
121     void updateBufferId(BufferId);
122
123     void removeBuffer(Buffer *);
124
125     void layoutMsg();
126
127   private:
128     Client();
129     ~Client();
130     void init();
131     static Client *instanceptr;
132
133     void syncToCore(const QVariant &coreState);
134     QVariant connectToLocalCore(QString user, QString passwd);  // defined in main.cpp
135     void disconnectFromLocalCore();                             // defined in main.cpp
136
137     AbstractUi *mainUi;
138     //ClientProxy *clientProxy;
139     SignalProxy *_signalProxy;
140     BufferTreeModel *_bufferModel;
141
142     QPointer<QIODevice> socket;
143     quint32 blockSize;
144
145     static bool connectedToCore;
146     static QVariantMap coreConnectionInfo;
147     static QHash<BufferId, Buffer *> buffers;
148     static QHash<uint, BufferId> bufferIds;
149     static QHash<QString, QHash<QString, QVariantMap> > nicks;
150     static QHash<QString, bool> netConnected;
151     static QStringList netsAwaitingInit;
152     static QHash<QString, QString> ownNick;
153
154     QTimer *layoutTimer;
155     QList<Buffer *> layoutQueue;
156
157     QVariantMap sessionData;
158 };
159
160 #endif