452bed07f7d91adf80fbb4b2c4caf160470ef409
[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   signals:
59     void sendInput(BufferId, QString message);
60     void showBuffer(Buffer *);
61     void bufferSelected(Buffer *);
62     void bufferUpdated(Buffer *);
63     void bufferActivity(Buffer::ActivityLevel, Buffer *);
64     void bufferDestroyed(Buffer *);
65     void backlogReceived(Buffer *, QList<Message>);
66     void requestBacklog(BufferId, QVariant, QVariant);
67     void requestNetworkStates();
68
69     void recvPartialItem(quint32 avail, quint32 size);
70     void coreConnectionError(QString errorMsg);
71
72     void connected();
73     void disconnected();
74
75   public slots:
76     //void selectBuffer(Buffer *);
77     //void connectToLocalCore();
78     void connectToCore(const VarMap &);
79     void disconnectFromCore();
80
81   private slots:
82     void updateCoreData(UserId, QString);
83     void updateLocalData(QString, QVariant);
84     void recvProxySignal(ClientSignal sig, QVariant arg1, QVariant arg2, QVariant arg3);
85
86     void serverError(QAbstractSocket::SocketError);
87     void serverHasData();
88     void coreConnected();
89     void coreDisconnected();
90
91     void userInput(BufferId, QString);
92     void networkConnected(QString);
93     void networkDisconnected(QString);
94     void recvNetworkState(QString, QVariant);
95     void recvMessage(const Message &message);
96     void recvStatusMsg(QString network, QString message);
97     void setTopic(QString net, QString buf, QString);
98     void addNick(QString net, QString nick, VarMap props);
99     void removeNick(QString net, QString nick);
100     void renameNick(QString net, QString oldnick, QString newnick);
101     void updateNick(QString net, QString nick, VarMap props);
102     void setOwnNick(QString net, QString nick);
103     void recvBacklogData(BufferId, const QList<QVariant> &, bool);
104     void updateBufferId(BufferId);
105
106     void layoutMsg();
107
108   private:
109     Client();
110     ~Client();
111     void init();
112     static Client *instanceptr;
113
114     void syncToCore();
115     QVariant connectToLocalCore(QString user, QString passwd);  // defined in main.cpp
116     void disconnectFromLocalCore();                             // defined in main.cpp
117
118     enum ClientMode { LocalCore, RemoteCore };
119     static ClientMode clientMode;
120
121     AbstractUi *mainUi;
122     ClientProxy *clientProxy;
123     BufferTreeModel *_bufferModel;
124
125     QTcpSocket socket;
126     quint32 blockSize;
127
128     static bool connectedToCore;
129     static QHash<BufferId, Buffer *> buffers;
130     static QHash<uint, BufferId> bufferIds;
131     static QHash<QString, QHash<QString, VarMap> > nicks;
132     static QHash<QString, bool> netConnected;
133     static QHash<QString, QString> ownNick;
134
135     QTimer *layoutTimer;
136     QList<Buffer *> layoutQueue;
137 };
138
139 #endif