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