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