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