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