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