Implement UI for core-side highlights
[quassel.git] / src / client / client.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2016 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  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
19  ***************************************************************************/
20
21 #ifndef CLIENT_H_
22 #define CLIENT_H_
23
24 #include <QList>
25 #include <QPointer>
26 #include <highlightrulemanager.h>
27
28 #include "bufferinfo.h"
29 #include "coreaccount.h"
30 #include "coreconnection.h"
31 #include "quassel.h"
32 #include "types.h"
33
34 class Message;
35 class MessageModel;
36 class AbstractMessageProcessor;
37
38 class Identity;
39 class CertIdentity;
40 class Network;
41
42 class AbstractUi;
43 class AbstractUiMsg;
44 class NetworkModel;
45 class BufferModel;
46 class BufferSyncer;
47 class BufferViewOverlay;
48 class ClientAliasManager;
49 class ClientBacklogManager;
50 class ClientBufferViewManager;
51 class ClientIgnoreListManager;
52 class ClientIrcListHelper;
53 class ClientTransferManager;
54 class ClientUserInputHandler;
55 class CoreAccountModel;
56 class CoreConnection;
57 class DccConfig;
58 class IrcUser;
59 class IrcChannel;
60 class NetworkConfig;
61 class SignalProxy;
62 class TransferModel;
63
64 struct NetworkInfo;
65
66 class Client : public QObject
67 {
68     Q_OBJECT
69
70 public:
71     enum ClientMode {
72         LocalCore,
73         RemoteCore
74     };
75
76     static bool instanceExists();
77     static Client *instance();
78     static void destroy();
79     static void init(AbstractUi *);
80     static AbstractUi *mainUi();
81
82     static QList<NetworkId> networkIds();
83     static const Network *network(NetworkId);
84
85     static QList<IdentityId> identityIds();
86     static const Identity *identity(IdentityId);
87
88     //! Request creation of an identity with the given data.
89     /** The request will be sent to the core, and will be propagated back to all the clients
90      *  with a new valid IdentityId.
91      *  \param identity The identity template for the new identity. It does not need to have a valid ID.
92      */
93     static void createIdentity(const CertIdentity &identity);
94
95     //! Request update of an identity with the given data.
96     /** The request will be sent to the core, and will be propagated back to all the clients.
97      *  \param id The identity to be updated.
98      *  \param serializedData The identity's content (cf. SyncableObject::toVariantMap())
99      */
100     static void updateIdentity(IdentityId id, const QVariantMap &serializedData);
101
102     //! Request removal of the identity with the given ID from the core (and all the clients, of course).
103     /** \param id The ID of the identity to be removed.
104      */
105     static void removeIdentity(IdentityId id);
106
107     static void createNetwork(const NetworkInfo &info, const QStringList &persistentChannels = QStringList());
108     static void updateNetwork(const NetworkInfo &info);
109     static void removeNetwork(NetworkId id);
110
111     static inline NetworkModel *networkModel() { return instance()->_networkModel; }
112     static inline BufferModel *bufferModel() { return instance()->_bufferModel; }
113     static inline MessageModel *messageModel() { return instance()->_messageModel; }
114     static inline AbstractMessageProcessor *messageProcessor() { return instance()->_messageProcessor; }
115     static inline SignalProxy *signalProxy() { return instance()->_signalProxy; }
116
117     static inline ClientAliasManager *aliasManager() { return instance()->_aliasManager; }
118     static inline ClientBacklogManager *backlogManager() { return instance()->_backlogManager; }
119     static inline DccConfig *dccConfig() { return instance()->_dccConfig; }
120     static inline ClientIrcListHelper *ircListHelper() { return instance()->_ircListHelper; }
121     static inline ClientBufferViewManager *bufferViewManager() { return instance()->_bufferViewManager; }
122     static inline BufferViewOverlay *bufferViewOverlay() { return instance()->_bufferViewOverlay; }
123     static inline ClientUserInputHandler *inputHandler() { return instance()->_inputHandler; }
124     static inline NetworkConfig *networkConfig() { return instance()->_networkConfig; }
125     static inline ClientIgnoreListManager *ignoreListManager() { return instance()->_ignoreListManager; }
126     static inline HighlightRuleManager *highlightRuleManager() { return instance()->_highlightRuleManager; }
127     static inline ClientTransferManager *transferManager() { return instance()->_transferManager; }
128     static inline TransferModel *transferModel() { return instance()->_transferModel; }
129
130     static inline BufferSyncer *bufferSyncer() { return instance()->_bufferSyncer; }
131
132     static inline CoreAccountModel *coreAccountModel() { return instance()->_coreAccountModel; }
133     static inline CoreConnection *coreConnection() { return instance()->_coreConnection; }
134     static inline CoreAccount currentCoreAccount() { return coreConnection()->currentAccount(); }
135     static inline Quassel::Features coreFeatures() { return _coreFeatures; }
136
137     static void setCoreFeatures(Quassel::Features features);
138
139     static bool isConnected();
140     static bool internalCore();
141
142     static void userInput(const BufferInfo &bufferInfo, const QString &message);
143
144     static void setBufferLastSeenMsg(BufferId id, const MsgId &msgId); // this is synced to core and other clients
145     static void setMarkerLine(BufferId id, const MsgId &msgId); // this is synced to core and other clients
146     static MsgId markerLine(BufferId id);
147
148     static void removeBuffer(BufferId id);
149     static void renameBuffer(BufferId bufferId, const QString &newName);
150     static void mergeBuffersPermanently(BufferId bufferId1, BufferId bufferId2);
151     static void purgeKnownBufferIds();
152
153     static void changePassword(const QString &oldPassword, const QString &newPassword);
154     static void kickClient(int peerId);
155
156 #if QT_VERSION < 0x050000
157     static void logMessage(QtMsgType type, const char *msg);
158 #else
159     static void logMessage(QtMsgType, const QMessageLogContext&, const QString&);
160 #endif
161     static inline const QString &debugLog() { return instance()->_debugLogBuffer; }
162
163 signals:
164     void requestNetworkStates();
165
166     void showConfigWizard(const QVariantMap &coredata);
167
168     void connected();
169     void disconnected();
170     void coreConnectionStateChanged(bool);
171
172     //! The identity with the given ID has been newly created in core and client.
173     /** \param id The ID of the newly created identity.
174      */
175     void identityCreated(IdentityId id);
176
177     //! The identity with the given ID has been removed.
178     /** Upon emitting this signal, the identity is already gone from the core, and it will
179      *  be deleted from the client immediately afterwards, so connected slots need to clean
180      *  up their stuff.
181      *  \param id The ID of the identity about to be removed.
182      */
183     void identityRemoved(IdentityId id);
184
185     //! Sent to the core when an identity shall be created. Should not be used elsewhere.
186     void requestCreateIdentity(const Identity &, const QVariantMap &);
187     //! Sent to the core when an identity shall be removed. Should not be used elsewhere.
188     void requestRemoveIdentity(IdentityId);
189
190     void networkCreated(NetworkId id);
191     void networkRemoved(NetworkId id);
192
193     void requestCreateNetwork(const NetworkInfo &info, const QStringList &persistentChannels = QStringList());
194     void requestRemoveNetwork(NetworkId);
195
196     void logUpdated(const QString &msg);
197
198     //! Emitted when a buffer has been marked as read
199     /** This is currently triggered by setting lastSeenMsg, either local or remote,
200      *  or by bringing the window to front.
201      *  \param id The buffer that has been marked as read
202      */
203     void bufferMarkedAsRead(BufferId id);
204
205     //! Requests a password change (user name must match the currently logged in user)
206     void requestPasswordChange(PeerPtr peer, const QString &userName, const QString &oldPassword, const QString &newPassword);
207
208     void requestKickClient(int peerId);
209     void passwordChanged(bool success);
210
211 public slots:
212     void disconnectFromCore();
213
214     void bufferRemoved(BufferId bufferId);
215     void bufferRenamed(BufferId bufferId, const QString &newName);
216     void buffersPermanentlyMerged(BufferId bufferId1, BufferId bufferId2);
217
218     void markBufferAsRead(BufferId id);
219
220 private slots:
221     void setSyncedToCore();
222     void setDisconnectedFromCore();
223     void connectionStateChanged(CoreConnection::ConnectionState);
224
225     void recvMessage(const Message &message);
226     void recvStatusMsg(QString network, QString message);
227
228     void networkDestroyed();
229     void coreIdentityCreated(const Identity &);
230     void coreIdentityRemoved(IdentityId);
231     void coreNetworkCreated(NetworkId);
232     void coreNetworkRemoved(NetworkId);
233
234     void corePasswordChanged(PeerPtr, bool success);
235
236     void finishConnectionInitialization();
237
238     void sendBufferedUserInput();
239
240 private:
241     Client(QObject *parent = 0);
242     virtual ~Client();
243     void init();
244
245     void requestInitialBacklog();
246
247     static void addNetwork(Network *);
248
249     static QPointer<Client> instanceptr;
250
251     SignalProxy *_signalProxy;
252     AbstractUi *_mainUi;
253     NetworkModel *_networkModel;
254     BufferModel *_bufferModel;
255     BufferSyncer *_bufferSyncer;
256     ClientAliasManager *_aliasManager;
257     ClientBacklogManager *_backlogManager;
258     ClientBufferViewManager *_bufferViewManager;
259     BufferViewOverlay *_bufferViewOverlay;
260     DccConfig *_dccConfig;
261     ClientIrcListHelper *_ircListHelper;
262     ClientUserInputHandler *_inputHandler;
263     NetworkConfig *_networkConfig;
264     ClientIgnoreListManager *_ignoreListManager;
265     HighlightRuleManager *_highlightRuleManager;
266     ClientTransferManager *_transferManager;
267     TransferModel *_transferModel;
268
269     MessageModel *_messageModel;
270     AbstractMessageProcessor *_messageProcessor;
271
272     CoreAccountModel *_coreAccountModel;
273     CoreConnection *_coreConnection;
274
275     ClientMode clientMode;
276
277     QHash<NetworkId, Network *> _networks;
278     QHash<IdentityId, Identity *> _identities;
279
280     bool _connected;
281     static Quassel::Features _coreFeatures;
282
283     QString _debugLogBuffer;
284     QTextStream _debugLog;
285
286     QList<QPair<BufferInfo, QString> > _userInputBuffer;
287
288     friend class CoreConnection;
289 };
290
291
292 #endif