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