1 /***************************************************************************
2 * Copyright (C) 2005-2016 by the Quassel Project *
3 * devel@quassel-irc.org *
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. *
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. *
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 ***************************************************************************/
27 #include "bufferinfo.h"
28 #include "coreaccount.h"
29 #include "coreconnection.h"
35 class AbstractMessageProcessor;
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;
64 class Client : public QObject
74 static bool instanceExists();
75 static Client *instance();
76 static void destroy();
77 static void init(AbstractUi *);
78 static AbstractUi *mainUi();
80 static QList<NetworkId> networkIds();
81 static const Network *network(NetworkId);
83 static QList<IdentityId> identityIds();
84 static const Identity *identity(IdentityId);
86 //! Request creation of an identity with the given data.
87 /** The request will be sent to the core, and will be propagated back to all the clients
88 * with a new valid IdentityId.
89 * \param identity The identity template for the new identity. It does not need to have a valid ID.
91 static void createIdentity(const CertIdentity &identity);
93 //! Request update of an identity with the given data.
94 /** The request will be sent to the core, and will be propagated back to all the clients.
95 * \param id The identity to be updated.
96 * \param serializedData The identity's content (cf. SyncableObject::toVariantMap())
98 static void updateIdentity(IdentityId id, const QVariantMap &serializedData);
100 //! Request removal of the identity with the given ID from the core (and all the clients, of course).
101 /** \param id The ID of the identity to be removed.
103 static void removeIdentity(IdentityId id);
105 static void createNetwork(const NetworkInfo &info, const QStringList &persistentChannels = QStringList());
106 static void updateNetwork(const NetworkInfo &info);
107 static void removeNetwork(NetworkId id);
109 static inline NetworkModel *networkModel() { return instance()->_networkModel; }
110 static inline BufferModel *bufferModel() { return instance()->_bufferModel; }
111 static inline MessageModel *messageModel() { return instance()->_messageModel; }
112 static inline AbstractMessageProcessor *messageProcessor() { return instance()->_messageProcessor; }
113 static inline SignalProxy *signalProxy() { return instance()->_signalProxy; }
115 static inline ClientAliasManager *aliasManager() { return instance()->_aliasManager; }
116 static inline ClientBacklogManager *backlogManager() { return instance()->_backlogManager; }
117 static inline ClientIrcListHelper *ircListHelper() { return instance()->_ircListHelper; }
118 static inline ClientBufferViewManager *bufferViewManager() { return instance()->_bufferViewManager; }
119 static inline BufferViewOverlay *bufferViewOverlay() { return instance()->_bufferViewOverlay; }
120 static inline ClientUserInputHandler *inputHandler() { return instance()->_inputHandler; }
121 static inline NetworkConfig *networkConfig() { return instance()->_networkConfig; }
122 static inline ClientIgnoreListManager *ignoreListManager() { return instance()->_ignoreListManager; }
123 static inline ClientTransferManager *transferManager() { return instance()->_transferManager; }
124 static inline TransferModel *transferModel() { return instance()->_transferModel; }
126 static inline CoreAccountModel *coreAccountModel() { return instance()->_coreAccountModel; }
127 static inline CoreConnection *coreConnection() { return instance()->_coreConnection; }
128 static inline CoreAccount currentCoreAccount() { return coreConnection()->currentAccount(); }
129 static inline Quassel::Features coreFeatures() { return _coreFeatures; }
131 static void setCoreFeatures(Quassel::Features features);
133 static bool isConnected();
134 static bool internalCore();
136 static void userInput(const BufferInfo &bufferInfo, const QString &message);
138 static void setBufferLastSeenMsg(BufferId id, const MsgId &msgId); // this is synced to core and other clients
139 static void setMarkerLine(BufferId id, const MsgId &msgId); // this is synced to core and other clients
140 static MsgId markerLine(BufferId id);
142 static void removeBuffer(BufferId id);
143 static void renameBuffer(BufferId bufferId, const QString &newName);
144 static void mergeBuffersPermanently(BufferId bufferId1, BufferId bufferId2);
145 static void purgeKnownBufferIds();
147 static void changePassword(const QString &oldPassword, const QString &newPassword);
149 #if QT_VERSION < 0x050000
150 static void logMessage(QtMsgType type, const char *msg);
152 static void logMessage(QtMsgType, const QMessageLogContext&, const QString&);
154 static inline const QString &debugLog() { return instance()->_debugLogBuffer; }
157 void requestNetworkStates();
159 void showConfigWizard(const QVariantMap &coredata);
163 void coreConnectionStateChanged(bool);
165 //! The identity with the given ID has been newly created in core and client.
166 /** \param id The ID of the newly created identity.
168 void identityCreated(IdentityId id);
170 //! The identity with the given ID has been removed.
171 /** Upon emitting this signal, the identity is already gone from the core, and it will
172 * be deleted from the client immediately afterwards, so connected slots need to clean
174 * \param id The ID of the identity about to be removed.
176 void identityRemoved(IdentityId id);
178 //! Sent to the core when an identity shall be created. Should not be used elsewhere.
179 void requestCreateIdentity(const Identity &, const QVariantMap &);
180 //! Sent to the core when an identity shall be removed. Should not be used elsewhere.
181 void requestRemoveIdentity(IdentityId);
183 void networkCreated(NetworkId id);
184 void networkRemoved(NetworkId id);
186 void requestCreateNetwork(const NetworkInfo &info, const QStringList &persistentChannels = QStringList());
187 void requestRemoveNetwork(NetworkId);
189 void logUpdated(const QString &msg);
191 //! Emitted when a buffer has been marked as read
192 /** This is currently triggered by setting lastSeenMsg, either local or remote,
193 * or by bringing the window to front.
194 * \param id The buffer that has been marked as read
196 void bufferMarkedAsRead(BufferId id);
198 //! Requests a password change (user name must match the currently logged in user)
199 void requestPasswordChange(PeerPtr peer, const QString &userName, const QString &oldPassword, const QString &newPassword);
200 void passwordChanged(bool success);
203 void disconnectFromCore();
205 void bufferRemoved(BufferId bufferId);
206 void bufferRenamed(BufferId bufferId, const QString &newName);
207 void buffersPermanentlyMerged(BufferId bufferId1, BufferId bufferId2);
209 void markBufferAsRead(BufferId id);
212 void setSyncedToCore();
213 void setDisconnectedFromCore();
214 void connectionStateChanged(CoreConnection::ConnectionState);
216 void recvMessage(const Message &message);
217 void recvStatusMsg(QString network, QString message);
219 void networkDestroyed();
220 void coreIdentityCreated(const Identity &);
221 void coreIdentityRemoved(IdentityId);
222 void coreNetworkCreated(NetworkId);
223 void coreNetworkRemoved(NetworkId);
225 void corePasswordChanged(PeerPtr, bool success);
227 void requestInitialBacklog();
229 void sendBufferedUserInput();
232 Client(QObject *parent = 0);
236 static void addNetwork(Network *);
237 static inline BufferSyncer *bufferSyncer() { return instance()->_bufferSyncer; }
239 static QPointer<Client> instanceptr;
241 SignalProxy *_signalProxy;
243 NetworkModel *_networkModel;
244 BufferModel *_bufferModel;
245 BufferSyncer *_bufferSyncer;
246 ClientAliasManager *_aliasManager;
247 ClientBacklogManager *_backlogManager;
248 ClientBufferViewManager *_bufferViewManager;
249 BufferViewOverlay *_bufferViewOverlay;
250 ClientIrcListHelper *_ircListHelper;
251 ClientUserInputHandler *_inputHandler;
252 NetworkConfig *_networkConfig;
253 ClientIgnoreListManager *_ignoreListManager;
254 ClientTransferManager *_transferManager;
255 TransferModel *_transferModel;
257 MessageModel *_messageModel;
258 AbstractMessageProcessor *_messageProcessor;
260 CoreAccountModel *_coreAccountModel;
261 CoreConnection *_coreConnection;
263 ClientMode clientMode;
265 QHash<NetworkId, Network *> _networks;
266 QHash<IdentityId, Identity *> _identities;
269 static Quassel::Features _coreFeatures;
271 QString _debugLogBuffer;
272 QTextStream _debugLog;
274 QList<QPair<BufferInfo, QString> > _userInputBuffer;
276 friend class CoreConnection;