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