Committing a whole bunch of Identity-related stuff that's not actually used yet,
[quassel.git] / src / client / client.h
1 /***************************************************************************
2  *   Copyright (C) 2005-07 by the Quassel IRC 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) 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 NetworkInfo;
35
36
37 class AbstractUi;
38 class AbstractUiMsg;
39 class NetworkModel;
40 class SignalProxy;
41
42 class QTimer;
43
44
45 class Client : public QObject {
46   Q_OBJECT
47
48 public:
49   static Client *instance();
50   static void destroy();
51   static void init(AbstractUi *);
52
53   static QList<NetworkInfo *> networkInfos();
54   static NetworkInfo *networkInfo(uint networkid);
55
56   static QList<BufferInfo> allBufferInfos();
57   static QList<Buffer *> buffers();
58   static Buffer *buffer(uint bufferUid);
59   static Buffer *buffer(BufferInfo);
60   static BufferInfo statusBufferInfo(QString net);
61   static BufferInfo bufferInfo(QString net, QString buf);
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 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 bufferSelected(Buffer *);
104   void bufferUpdated(Buffer *);
105   void bufferActivity(Buffer::ActivityLevel, Buffer *);
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 networkInfoDestroyed();
177   void ircChannelAdded(QString);
178   void coreIdentityCreated(const Identity &);
179   void coreIdentityRemoved(IdentityId);
180
181 private:
182   Client(QObject *parent = 0);
183   virtual ~Client();
184   void init();
185
186   void syncToCore(const QVariant &coreState);
187
188   static QPointer<Client> instanceptr;
189
190   QPointer<QIODevice> socket;
191   QPointer<SignalProxy> _signalProxy;
192   QPointer<AbstractUi> mainUi;
193   QPointer<NetworkModel> _networkModel;
194
195   ClientMode clientMode;
196
197   quint32 blockSize;
198   bool connectedToCore;
199
200   QVariantMap coreConnectionInfo;
201   QHash<BufferId, Buffer *> _buffers;
202   QHash<NetworkId, NetworkInfo *> _networkInfo;
203   QHash<IdentityId, Identity *> _identities;
204
205   QTimer *layoutTimer;
206   QList<Buffer *> layoutQueue;
207
208   QVariantMap sessionData;
209
210
211 };
212
213 #endif