recreating some indexes that were lost in an upgrade
[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 "bufferinfo.h"
30 #include "types.h"
31
32 class Message;
33 class MessageModel;
34 class AbstractMessageProcessor;
35
36 class Identity;
37 class CertIdentity;
38 class Network;
39
40 class AbstractUi;
41 class AbstractUiMsg;
42 class NetworkModel;
43 class BufferModel;
44 class BufferSyncer;
45 class ClientBacklogManager;
46 class ClientIrcListHelper;
47 class ClientSyncer;
48 class BufferViewManager;
49 class IrcUser;
50 class IrcChannel;
51 class SignalProxy;
52 struct NetworkInfo;
53
54 class Client : public QObject {
55   Q_OBJECT
56
57 public:
58   enum ClientMode {
59     LocalCore,
60     RemoteCore
61   };
62
63   static Client *instance();
64   static void destroy();
65   static void init(AbstractUi *);
66   static AbstractUi *mainUi();
67
68   static QList<NetworkId> networkIds();
69   static const Network * network(NetworkId);
70
71   static QList<IdentityId> identityIds();
72   static const Identity *identity(IdentityId);
73
74   //! Request creation of an identity with the given data.
75   /** The request will be sent to the core, and will be propagated back to all the clients
76    *  with a new valid IdentityId.
77    *  \param identity The identity template for the new identity. It does not need to have a valid ID.
78    */
79   static void createIdentity(const CertIdentity &identity);
80
81   //! Request update of an identity with the given data.
82   /** The request will be sent to the core, and will be propagated back to all the clients.
83    *  \param id The identity to be updated.
84    *  \param serializedData The identity's content (cf. SyncableObject::toVariantMap())
85    */
86   static void updateIdentity(IdentityId id, const QVariantMap &serializedData);
87
88   //! Request removal of the identity with the given ID from the core (and all the clients, of course).
89   /** \param id The ID of the identity to be removed.
90    */
91   static void removeIdentity(IdentityId id);
92
93   static void createNetwork(const NetworkInfo &info);
94   static void updateNetwork(const NetworkInfo &info);
95   static void removeNetwork(NetworkId id);
96
97   static inline NetworkModel *networkModel() { return instance()->_networkModel; }
98   static inline BufferModel *bufferModel() { return instance()->_bufferModel; }
99   static inline MessageModel *messageModel() { return instance()->_messageModel; }
100   static inline AbstractMessageProcessor *messageProcessor() { return instance()->_messageProcessor; }
101   static inline SignalProxy *signalProxy() { return instance()->_signalProxy; }
102
103   static inline ClientBacklogManager *backlogManager() { return instance()->_backlogManager; }
104   static inline ClientIrcListHelper *ircListHelper() { return instance()->_ircListHelper; }
105   static inline BufferViewManager *bufferViewManager() { return instance()->_bufferViewManager; }
106
107   static AccountId currentCoreAccount();
108
109   static bool isConnected();
110   static bool isSynced();
111
112   static void userInput(BufferInfo bufferInfo, QString message);
113
114   static void setBufferLastSeenMsg(BufferId id, const MsgId &msgId); // this is synced to core and other clients
115   static void removeBuffer(BufferId id);
116   static void renameBuffer(BufferId bufferId, const QString &newName);
117
118   static void logMessage(QtMsgType type, const char *msg);
119   static inline const QString &debugLog() { return instance()->_debugLogBuffer; }
120
121 signals:
122   void sendInput(BufferInfo, QString message);
123   void requestNetworkStates();
124
125   void showConfigWizard(const QVariantMap &coredata);
126
127   void connected();
128   void securedConnection();
129   void disconnected();
130   void coreConnectionStateChanged(bool);
131
132   //! The identity with the given ID has been newly created in core and client.
133   /** \param id The ID of the newly created identity.
134    */
135   void identityCreated(IdentityId id);
136
137   //! The identity with the given ID has been removed.
138   /** Upon emitting this signal, the identity is already gone from the core, and it will
139    *  be deleted from the client immediately afterwards, so connected slots need to clean
140    *  up their stuff.
141    *  \param id The ID of the identity about to be removed.
142    */
143   void identityRemoved(IdentityId id);
144
145   //! Sent to the core when an identity shall be created. Should not be used elsewhere.
146   void requestCreateIdentity(const Identity &, const QVariantMap &);
147   //! Sent to the core when an identity shall be removed. Should not be used elsewhere.
148   void requestRemoveIdentity(IdentityId);
149
150   void networkCreated(NetworkId id);
151   void networkRemoved(NetworkId id);
152
153   void requestCreateNetwork(const NetworkInfo &info);
154   void requestRemoveNetwork(NetworkId);
155
156   void newClientSyncer(ClientSyncer *);
157
158   void logUpdated(const QString &msg);
159
160 public slots:
161   //void selectBuffer(Buffer *);
162
163   void disconnectFromCore();
164
165   void bufferRemoved(BufferId bufferId);
166   void bufferRenamed(BufferId bufferId, const QString &newName);
167
168 private slots:
169   void disconnectedFromCore();
170
171   void recvMessage(const Message &message);
172   void recvStatusMsg(QString network, QString message);
173
174   void networkDestroyed();
175   void coreIdentityCreated(const Identity &);
176   void coreIdentityRemoved(IdentityId);
177   void coreNetworkCreated(NetworkId);
178   void coreNetworkRemoved(NetworkId);
179
180   void setConnectedToCore(AccountId id, QIODevice *socket = 0);
181   void setSyncedToCore();
182   void requestInitialBacklog();
183   void setSecuredConnection();
184
185
186 private:
187   Client(QObject *parent = 0);
188   virtual ~Client();
189   void init();
190
191   static void addNetwork(Network *);
192   static void setCurrentCoreAccount(AccountId);
193   static inline BufferSyncer *bufferSyncer() { return instance()->_bufferSyncer; }
194
195   static QPointer<Client> instanceptr;
196
197   SignalProxy * _signalProxy;
198   AbstractUi * _mainUi;
199   NetworkModel * _networkModel;
200   BufferModel * _bufferModel;
201   BufferSyncer * _bufferSyncer;
202   ClientBacklogManager *_backlogManager;
203   BufferViewManager *_bufferViewManager;
204   ClientIrcListHelper *_ircListHelper;
205
206   MessageModel *_messageModel;
207   AbstractMessageProcessor *_messageProcessor;
208
209   ClientMode clientMode;
210
211   bool _connectedToCore, _syncedToCore;
212
213   QHash<NetworkId, Network *> _networks;
214   QHash<IdentityId, Identity *> _identities;
215
216   static AccountId _currentCoreAccount;
217
218   QString _debugLogBuffer;
219   QTextStream _debugLog;
220
221   friend class ClientSyncer;
222 };
223
224 #endif