eee57fd5c11ea8288d70d40be05f50fc0b87f971
[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 <QtCore>
25 #include <QtNetwork>
26
27 #include "quasselui.h"
28 #include "buffer.h"
29 #include "message.h"
30 #include "proxy_common.h"
31
32 class ClientProxy;
33 class BufferTreeModel;
34
35 class Client : public QObject {
36   Q_OBJECT
37
38   public:
39     static Client *instance();
40     static void init(AbstractUi *);
41     static void destroy();
42
43     static Buffer *buffer(BufferId);
44     static BufferId statusBufferId(QString net);
45     static BufferId bufferId(QString net, QString buf);
46
47     static BufferTreeModel *bufferModel();
48
49     static AbstractUiMsg *layoutMsg(const Message &);
50
51   signals:
52     void sendInput(BufferId, QString message);
53     void showBuffer(Buffer *);
54     void bufferSelected(Buffer *);
55     void bufferUpdated(Buffer *);
56     void bufferActivity(Buffer::ActivityLevel, Buffer *);
57     void bufferDestroyed(Buffer *);
58     void backlogReceived(Buffer *, QList<Message>);
59     void requestBacklog(BufferId, QVariant, QVariant);
60
61     void recvPartialItem(quint32 avail, quint32 size);
62     void coreConnectionError(QString errorMsg);
63
64   public slots:
65     //void selectBuffer(Buffer *);
66     void connectToCore(QString host, quint16 port);
67     void disconnectFromCore();
68
69   private slots:
70     void updateCoreData(UserId, QString);
71     void updateLocalData(QString, QVariant);
72     void recvProxySignal(ClientSignal sig, QVariant arg1, QVariant arg2, QVariant arg3);
73
74     void serverError(QAbstractSocket::SocketError);
75     void serverHasData();
76     void coreConnected();
77     void coreDisconnected();
78
79     void userInput(BufferId, QString);
80     void networkConnected(QString);
81     void networkDisconnected(QString);
82     void recvNetworkState(QString, QVariant);
83     void recvMessage(const Message &message);
84     void recvStatusMsg(QString network, QString message);
85     void setTopic(QString net, QString buf, QString);
86     void addNick(QString net, QString nick, VarMap props);
87     void removeNick(QString net, QString nick);
88     void renameNick(QString net, QString oldnick, QString newnick);
89     void updateNick(QString net, QString nick, VarMap props);
90     void setOwnNick(QString net, QString nick);
91     void recvBacklogData(BufferId, const QList<QVariant> &, bool);
92     void updateBufferId(BufferId);
93
94     void layoutMsg();
95
96   private:
97     Client();
98     ~Client();
99     void init();
100     static Client *instanceptr;
101
102     void syncToCore();
103
104     enum ClientMode { LocalCore, RemoteCore };
105     static ClientMode clientMode;
106
107     AbstractUi *mainUi;
108     ClientProxy *clientProxy;
109     BufferTreeModel *_bufferModel;
110
111     QTcpSocket socket;
112     quint32 blockSize;
113
114     static QHash<BufferId, Buffer *> buffers;
115     static QHash<uint, BufferId> bufferIds;
116     static QHash<QString, QHash<QString, VarMap> > nicks;
117     static QHash<QString, bool> connected;
118     static QHash<QString, QString> ownNick;
119     static QList<BufferId> coreBuffers;
120
121     QTimer *layoutTimer;
122     QList<Buffer *> layoutQueue;
123 };
124
125 #endif