1 /***************************************************************************
2 * Copyright (C) 2005-2018 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 ***************************************************************************/
28 #include "bufferinfo.h"
30 #include "coreaccount.h"
31 #include "coreconnection.h"
32 #include "highlightrulemanager.h"
34 #include "singleton.h"
39 class AbstractMessageProcessor;
50 class BufferViewOverlay;
51 class ClientAliasManager;
52 class ClientBacklogManager;
53 class ClientBufferViewManager;
54 class ClientIgnoreListManager;
55 class ClientIrcListHelper;
56 class ClientTransferManager;
57 class ClientUserInputHandler;
58 class CoreAccountModel;
69 class Client : public QObject, public Singleton<Client>
79 Client(std::unique_ptr<AbstractUi>, QObject *parent = nullptr);
82 static AbstractUi *mainUi();
84 static QList<NetworkId> networkIds();
85 static const Network *network(NetworkId);
87 static QList<IdentityId> identityIds();
88 static const Identity *identity(IdentityId);
90 //! Request creation of an identity with the given data.
91 /** The request will be sent to the core, and will be propagated back to all the clients
92 * with a new valid IdentityId.
93 * \param identity The identity template for the new identity. It does not need to have a valid ID.
95 static void createIdentity(const CertIdentity &identity);
97 //! Request update of an identity with the given data.
98 /** The request will be sent to the core, and will be propagated back to all the clients.
99 * \param id The identity to be updated.
100 * \param serializedData The identity's content (cf. SyncableObject::toVariantMap())
102 static void updateIdentity(IdentityId id, const QVariantMap &serializedData);
104 //! Request removal of the identity with the given ID from the core (and all the clients, of course).
105 /** \param id The ID of the identity to be removed.
107 static void removeIdentity(IdentityId id);
109 static void createNetwork(const NetworkInfo &info, const QStringList &persistentChannels = QStringList());
110 static void updateNetwork(const NetworkInfo &info);
111 static void removeNetwork(NetworkId id);
113 static inline NetworkModel *networkModel() { return instance()->_networkModel; }
114 static inline BufferModel *bufferModel() { return instance()->_bufferModel; }
115 static inline MessageModel *messageModel() { return instance()->_messageModel; }
116 static inline AbstractMessageProcessor *messageProcessor() { return instance()->_messageProcessor; }
117 static inline SignalProxy *signalProxy() { return instance()->_signalProxy; }
119 static inline ClientAliasManager *aliasManager() { return instance()->_aliasManager; }
120 static inline ClientBacklogManager *backlogManager() { return instance()->_backlogManager; }
121 static inline CoreInfo *coreInfo() { return instance()->_coreInfo; }
122 static inline DccConfig *dccConfig() { return instance()->_dccConfig; }
123 static inline ClientIrcListHelper *ircListHelper() { return instance()->_ircListHelper; }
124 static inline ClientBufferViewManager *bufferViewManager() { return instance()->_bufferViewManager; }
125 static inline BufferViewOverlay *bufferViewOverlay() { return instance()->_bufferViewOverlay; }
126 static inline ClientUserInputHandler *inputHandler() { return instance()->_inputHandler; }
127 static inline NetworkConfig *networkConfig() { return instance()->_networkConfig; }
128 static inline ClientIgnoreListManager *ignoreListManager() { return instance()->_ignoreListManager; }
129 static inline HighlightRuleManager *highlightRuleManager() { return instance()->_highlightRuleManager; }
130 static inline ClientTransferManager *transferManager() { return instance()->_transferManager; }
131 static inline TransferModel *transferModel() { return instance()->_transferModel; }
133 static inline BufferSyncer *bufferSyncer() { return instance()->_bufferSyncer; }
135 static inline CoreAccountModel *coreAccountModel() { return instance()->_coreAccountModel; }
136 static inline CoreConnection *coreConnection() { return instance()->_coreConnection; }
137 static inline CoreAccount currentCoreAccount() { return coreConnection()->currentAccount(); }
138 static bool isCoreFeatureEnabled(Quassel::Feature feature);
140 static bool isConnected();
141 static bool internalCore();
143 static void userInput(const BufferInfo &bufferInfo, const QString &message);
145 static void setBufferLastSeenMsg(BufferId id, const MsgId &msgId); // this is synced to core and other clients
146 static void setMarkerLine(BufferId id, const MsgId &msgId); // this is synced to core and other clients
147 static MsgId markerLine(BufferId id);
149 static void removeBuffer(BufferId id);
150 static void renameBuffer(BufferId bufferId, const QString &newName);
151 static void mergeBuffersPermanently(BufferId bufferId1, BufferId bufferId2);
152 static void purgeKnownBufferIds();
155 * Requests client to resynchronize the CoreInfo object for legacy (pre-0.13) cores
157 * This provides compatibility with updating core information for legacy cores, and can be
158 * removed after protocol break.
160 * NOTE: On legacy (pre-0.13) cores, any existing connected signals will be destroyed and must
161 * be re-added after calling this, in addition to checking for existing data in coreInfo().
163 static void refreshLegacyCoreInfo();
165 static void changePassword(const QString &oldPassword, const QString &newPassword);
166 static void kickClient(int peerId);
168 void displayIgnoreList(QString ignoreRule) {
169 emit showIgnoreList(ignoreRule);
173 * Request to show the channel list dialog for the network, optionally searching by channel name
175 * @see Client::showChannelList()
177 * @param networkId Network ID for associated network
178 * @param channelFilters Partial channel name to search for, or empty to show all
179 * @param listImmediately If true, immediately list channels, otherwise just show dialog
181 void displayChannelList(NetworkId networkId, const QString &channelFilters = {},
182 bool listImmediately = false)
184 emit showChannelList(networkId, channelFilters, listImmediately);
188 void requestNetworkStates();
190 void showConfigWizard(const QVariantMap &coredata);
193 * Request to show the channel list dialog for the network, optionally searching by channel name
195 * @see MainWin::showChannelList()
197 * @param networkId Network ID for associated network
198 * @param channelFilters Partial channel name to search for, or empty to show all
199 * @param listImmediately If true, immediately list channels, otherwise just show dialog
201 void showChannelList(NetworkId networkId, const QString &channelFilters = {},
202 bool listImmediately = false);
204 void showIgnoreList(QString ignoreRule);
208 void coreConnectionStateChanged(bool);
211 * Signals that core information has been resynchronized, removing existing signal handlers
213 * Whenever this is emitted, one should re-add any handlers for CoreInfo::coreDataChanged() and
214 * apply any existing information in the coreInfo() object.
216 * Only emitted on legacy (pre-0.13) cores. Generally, one should use the
217 * CoreInfo::coreDataChanged() signal too.
219 void coreInfoResynchronized();
221 //! The identity with the given ID has been newly created in core and client.
222 /** \param id The ID of the newly created identity.
224 void identityCreated(IdentityId id);
226 //! The identity with the given ID has been removed.
227 /** Upon emitting this signal, the identity is already gone from the core, and it will
228 * be deleted from the client immediately afterwards, so connected slots need to clean
230 * \param id The ID of the identity about to be removed.
232 void identityRemoved(IdentityId id);
234 //! Sent to the core when an identity shall be created. Should not be used elsewhere.
235 void requestCreateIdentity(const Identity &, const QVariantMap &);
236 //! Sent to the core when an identity shall be removed. Should not be used elsewhere.
237 void requestRemoveIdentity(IdentityId);
239 void networkCreated(NetworkId id);
240 void networkRemoved(NetworkId id);
242 void requestCreateNetwork(const NetworkInfo &info, const QStringList &persistentChannels = QStringList());
243 void requestRemoveNetwork(NetworkId);
245 //! Emitted when a buffer has been marked as read
246 /** This is currently triggered by setting lastSeenMsg, either local or remote,
247 * or by bringing the window to front.
248 * \param id The buffer that has been marked as read
250 void bufferMarkedAsRead(BufferId id);
252 //! Requests a password change (user name must match the currently logged in user)
253 void requestPasswordChange(PeerPtr peer, const QString &userName, const QString &oldPassword, const QString &newPassword);
255 void requestKickClient(int peerId);
256 void passwordChanged(bool success);
258 //! Emitted when database schema upgrade starts or ends (only mono client)
259 void dbUpgradeInProgress(bool inProgress);
261 //! Emitted before an exit request is handled
262 void exitRequested(const QString &reason);
265 void disconnectFromCore();
267 void bufferRemoved(BufferId bufferId);
268 void bufferRenamed(BufferId bufferId, const QString &newName);
269 void buffersPermanentlyMerged(BufferId bufferId1, BufferId bufferId2);
271 void markBufferAsRead(BufferId id);
273 void onDbUpgradeInProgress(bool inProgress);
274 void onExitRequested(int exitCode, const QString &reason);
277 void setSyncedToCore();
278 void setDisconnectedFromCore();
279 void connectionStateChanged(CoreConnection::ConnectionState);
281 void recvMessage(const Message &message);
282 void recvStatusMsg(QString network, QString message);
284 void networkDestroyed();
285 void coreIdentityCreated(const Identity &);
286 void coreIdentityRemoved(IdentityId);
287 void coreNetworkCreated(NetworkId);
288 void coreNetworkRemoved(NetworkId);
290 void corePasswordChanged(PeerPtr, bool success);
292 void finishConnectionInitialization();
294 void sendBufferedUserInput();
297 void requestInitialBacklog();
300 * Deletes and resynchronizes the CoreInfo object for legacy (pre-0.13) cores
302 * This provides compatibility with updating core information for legacy cores, and can be
303 * removed after protocol break.
305 * NOTE: On legacy (pre-0.13) cores, any existing connected signals will be destroyed and must
306 * be re-added after calling this, in addition to checking for existing data in coreInfo().
308 void requestLegacyCoreInfo();
310 static void addNetwork(Network *);
312 SignalProxy *_signalProxy;
313 std::unique_ptr<AbstractUi> _mainUi;
314 NetworkModel *_networkModel;
315 BufferModel *_bufferModel;
316 BufferSyncer *_bufferSyncer;
317 ClientAliasManager *_aliasManager;
318 ClientBacklogManager *_backlogManager;
319 ClientBufferViewManager *_bufferViewManager;
320 BufferViewOverlay *_bufferViewOverlay;
322 DccConfig *_dccConfig;
323 ClientIrcListHelper *_ircListHelper;
324 ClientUserInputHandler *_inputHandler;
325 NetworkConfig *_networkConfig;
326 ClientIgnoreListManager *_ignoreListManager;
327 HighlightRuleManager *_highlightRuleManager;
328 ClientTransferManager *_transferManager;
329 TransferModel *_transferModel;
331 MessageModel *_messageModel;
332 AbstractMessageProcessor *_messageProcessor;
334 CoreAccountModel *_coreAccountModel;
335 CoreConnection *_coreConnection;
337 ClientMode clientMode;
339 QHash<NetworkId, Network *> _networks;
340 QHash<IdentityId, Identity *> _identities;
344 QList<QPair<BufferInfo, QString> > _userInputBuffer;
346 friend class CoreConnection;