Made the Nicklist Pretty again
[quassel.git] / src / client / client.h
1 /***************************************************************************
2  *   Copyright (C) 2005-08 by the Quassel Project                          *
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) version 3.                                           *
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" // needed for activity lvl
30 class BufferInfo;
31 class Message;
32
33 class Identity;
34 class Network;
35
36
37 class AbstractUi;
38 class AbstractUiMsg;
39 class NetworkModel;
40 class BufferModel;
41 class NickModel;
42 class SignalProxy;
43
44 class QTimer;
45
46
47 class Client : public QObject {
48   Q_OBJECT
49
50 public:
51   static Client *instance();
52   static void destroy();
53   static void init(AbstractUi *);
54
55   static QList<Network *> networks();
56   static Network *network(uint networkid);
57
58   static QList<BufferInfo> allBufferInfos();
59   static QList<Buffer *> buffers();
60   static Buffer *buffer(uint bufferUid);
61   static Buffer *buffer(BufferInfo);
62
63   static QList<IdentityId> identityIds();
64   static const Identity * identity(IdentityId);
65
66   //! Request creation of an identity with the given data.
67   /** The request will be sent to the core, and will be propagated back to all the clients
68    *  with a new valid IdentityId.
69    *  \param identity The identity template for the new identity. It does not need to have a valid ID.
70    */
71   static void createIdentity(const Identity &identity);
72
73   //! Request update of an identity with the given data.
74   /** The request will be sent to the core, and will be propagated back to all the clients.
75    *  \param identity The identity to be updated.
76    */
77   static void updateIdentity(const Identity &identity);
78
79   //! Request removal of the identity with the given ID from the core (and all the clients, of course).
80   /** \param id The ID of the identity to be removed.
81    */
82   static void removeIdentity(IdentityId id);
83
84   static NetworkModel *networkModel();
85   static BufferModel *bufferModel();
86   static NickModel *nickModel();
87   static SignalProxy *signalProxy();
88
89   static AbstractUiMsg *layoutMsg(const Message &);
90
91   static bool isConnected();
92
93   static void fakeInput(uint bufferUid, QString message);
94   static void fakeInput(BufferInfo bufferInfo, QString message);
95
96   static void storeSessionData(const QString &key, const QVariant &data);
97   static QVariant retrieveSessionData(const QString &key, const QVariant &def = QVariant());
98   static QStringList sessionDataKeys();
99
100   enum ClientMode { LocalCore, RemoteCore };
101
102 signals:
103   void sendInput(BufferInfo, QString message);
104   void showBuffer(Buffer *);
105   void bufferUpdated(BufferInfo bufferInfo);
106   void backlogReceived(Buffer *, QList<Message>);
107   void requestBacklog(BufferInfo, QVariant, QVariant);
108   void requestNetworkStates();
109
110   void recvPartialItem(uint avail, uint size);
111   void coreConnectionError(QString errorMsg);
112   void coreConnectionMsg(const QString &msg);
113   void coreConnectionProgress(uint part, uint total);
114
115   void showConfigWizard(const QVariantMap &coredata);
116
117   void connected();
118   void disconnected();
119   void coreConnectionStateChanged(bool);
120
121   void sessionDataChanged(const QString &key);
122   void sessionDataChanged(const QString &key, const QVariant &data);
123   void sendSessionData(const QString &key, const QVariant &data);
124
125   //! The identity with the given ID has been newly created in core and client.
126   /** \param id The ID of the newly created identity.
127    */
128   void identityCreated(IdentityId id);
129
130   //! The identity with the given ID has been removed.
131   /** Upon emitting this signal, the identity is already gone from the core, and it will
132    *  be deleted from the client immediately afterwards, so connected slots need to clean
133    *  up their stuff.
134    *  \param id The ID of the identity about to be removed.
135    */
136   void identityRemoved(IdentityId id);
137
138   //! Sent to the core when an identity shall be created. Should not be used elsewhere.
139   void requestCreateIdentity(const Identity &);
140   //! Sent to the core when an identity shall be updated. Should not be used elsewhere.
141   void requestUpdateIdentity(const Identity &);
142   //! Sent to the core when an identity shall be removed. Should not be used elsewhere.
143   void requestRemoveIdentity(IdentityId);
144
145 public slots:
146   //void selectBuffer(Buffer *);
147   //void connectToLocalCore();
148   void connectToCore(const QVariantMap &);
149   void disconnectFromCore();
150
151   void setCoreConfiguration(const QVariantMap &settings);
152
153 private slots:
154   void recvCoreState(const QVariant &state);
155   void recvSessionData(const QString &key, const QVariant &data);
156
157   void coreSocketError(QAbstractSocket::SocketError);
158   void coreHasData();
159   void coreSocketConnected();
160   void coreSocketDisconnected();
161
162   void userInput(BufferInfo, QString);
163
164   void networkConnected(uint);
165   void networkDisconnected(uint);
166
167   void updateCoreConnectionProgress();
168   void recvMessage(const Message &message);
169   void recvStatusMsg(QString network, QString message);
170   void recvBacklogData(BufferInfo, QVariantList, bool);
171   void updateBufferInfo(BufferInfo);
172
173   void layoutMsg();
174
175   void bufferDestroyed();
176   void networkDestroyed();
177   void coreIdentityCreated(const Identity &);
178   void coreIdentityRemoved(IdentityId);
179
180 private:
181   Client(QObject *parent = 0);
182   virtual ~Client();
183   void init();
184
185   void syncToCore(const QVariant &coreState);
186
187   static QPointer<Client> instanceptr;
188
189   QPointer<QIODevice> socket;
190   QPointer<SignalProxy> _signalProxy;
191   QPointer<AbstractUi> mainUi;
192   QPointer<NetworkModel> _networkModel;
193   QPointer<BufferModel> _bufferModel;
194   QPointer<NickModel> _nickModel;
195
196   ClientMode clientMode;
197
198   quint32 blockSize;
199   bool connectedToCore;
200
201   QVariantMap coreConnectionInfo;
202   QHash<BufferId, Buffer *> _buffers;
203   QHash<NetworkId, Network *> _network;
204   QHash<IdentityId, Identity *> _identities;
205
206   QTimer *layoutTimer;
207   QList<Buffer *> layoutQueue;
208
209   QVariantMap sessionData;
210
211
212 };
213
214 #endif