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 ***************************************************************************/
26 #include "bufferinfo.h"
28 #include "coreaccount.h"
29 #include "coreconnection.h"
30 #include "highlightrulemanager.h"
36 class AbstractMessageProcessor;
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;
66 class Client : public QObject
76 static bool instanceExists();
77 static Client *instance();
78 static void destroy();
79 static void init(AbstractUi *);
80 static AbstractUi *mainUi();
82 static QList<NetworkId> networkIds();
83 static const Network *network(NetworkId);
85 static QList<IdentityId> identityIds();
86 static const Identity *identity(IdentityId);
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.
93 static void createIdentity(const CertIdentity &identity);
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())
100 static void updateIdentity(IdentityId id, const QVariantMap &serializedData);
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.
105 static void removeIdentity(IdentityId id);
107 static void createNetwork(const NetworkInfo &info, const QStringList &persistentChannels = QStringList());
108 static void updateNetwork(const NetworkInfo &info);
109 static void removeNetwork(NetworkId id);
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; }
117 static inline ClientAliasManager *aliasManager() { return instance()->_aliasManager; }
118 static inline ClientBacklogManager *backlogManager() { return instance()->_backlogManager; }
119 static inline CoreInfo *coreInfo() { return instance()->_coreInfo; }
120 static inline DccConfig *dccConfig() { return instance()->_dccConfig; }
121 static inline ClientIrcListHelper *ircListHelper() { return instance()->_ircListHelper; }
122 static inline ClientBufferViewManager *bufferViewManager() { return instance()->_bufferViewManager; }
123 static inline BufferViewOverlay *bufferViewOverlay() { return instance()->_bufferViewOverlay; }
124 static inline ClientUserInputHandler *inputHandler() { return instance()->_inputHandler; }
125 static inline NetworkConfig *networkConfig() { return instance()->_networkConfig; }
126 static inline ClientIgnoreListManager *ignoreListManager() { return instance()->_ignoreListManager; }
127 static inline HighlightRuleManager *highlightRuleManager() { return instance()->_highlightRuleManager; }
128 static inline ClientTransferManager *transferManager() { return instance()->_transferManager; }
129 static inline TransferModel *transferModel() { return instance()->_transferModel; }
131 static inline BufferSyncer *bufferSyncer() { return instance()->_bufferSyncer; }
133 static inline CoreAccountModel *coreAccountModel() { return instance()->_coreAccountModel; }
134 static inline CoreConnection *coreConnection() { return instance()->_coreConnection; }
135 static inline CoreAccount currentCoreAccount() { return coreConnection()->currentAccount(); }
136 static bool isCoreFeatureEnabled(Quassel::Feature feature);
138 static bool isConnected();
139 static bool internalCore();
141 static void userInput(const BufferInfo &bufferInfo, const QString &message);
143 static void setBufferLastSeenMsg(BufferId id, const MsgId &msgId); // this is synced to core and other clients
144 static void setMarkerLine(BufferId id, const MsgId &msgId); // this is synced to core and other clients
145 static MsgId markerLine(BufferId id);
147 static void removeBuffer(BufferId id);
148 static void renameBuffer(BufferId bufferId, const QString &newName);
149 static void mergeBuffersPermanently(BufferId bufferId1, BufferId bufferId2);
150 static void purgeKnownBufferIds();
152 static void changePassword(const QString &oldPassword, const QString &newPassword);
153 static void kickClient(int peerId);
155 void displayIgnoreList(QString ignoreRule) {
156 emit showIgnoreList(ignoreRule);
159 #if QT_VERSION < 0x050000
160 static void logMessage(QtMsgType type, const char *msg);
162 static void logMessage(QtMsgType, const QMessageLogContext&, const QString&);
164 static inline const QString &debugLog() { return instance()->_debugLogBuffer; }
166 void displayChannelList(NetworkId networkId) {
167 emit showChannelList(networkId);
171 void requestNetworkStates();
173 void showConfigWizard(const QVariantMap &coredata);
174 void showChannelList(NetworkId networkId);
175 void showIgnoreList(QString ignoreRule);
179 void coreConnectionStateChanged(bool);
181 //! The identity with the given ID has been newly created in core and client.
182 /** \param id The ID of the newly created identity.
184 void identityCreated(IdentityId id);
186 //! The identity with the given ID has been removed.
187 /** Upon emitting this signal, the identity is already gone from the core, and it will
188 * be deleted from the client immediately afterwards, so connected slots need to clean
190 * \param id The ID of the identity about to be removed.
192 void identityRemoved(IdentityId id);
194 //! Sent to the core when an identity shall be created. Should not be used elsewhere.
195 void requestCreateIdentity(const Identity &, const QVariantMap &);
196 //! Sent to the core when an identity shall be removed. Should not be used elsewhere.
197 void requestRemoveIdentity(IdentityId);
199 void networkCreated(NetworkId id);
200 void networkRemoved(NetworkId id);
202 void requestCreateNetwork(const NetworkInfo &info, const QStringList &persistentChannels = QStringList());
203 void requestRemoveNetwork(NetworkId);
205 void logUpdated(const QString &msg);
207 //! Emitted when a buffer has been marked as read
208 /** This is currently triggered by setting lastSeenMsg, either local or remote,
209 * or by bringing the window to front.
210 * \param id The buffer that has been marked as read
212 void bufferMarkedAsRead(BufferId id);
214 //! Requests a password change (user name must match the currently logged in user)
215 void requestPasswordChange(PeerPtr peer, const QString &userName, const QString &oldPassword, const QString &newPassword);
217 void requestKickClient(int peerId);
218 void passwordChanged(bool success);
221 void disconnectFromCore();
223 void bufferRemoved(BufferId bufferId);
224 void bufferRenamed(BufferId bufferId, const QString &newName);
225 void buffersPermanentlyMerged(BufferId bufferId1, BufferId bufferId2);
227 void markBufferAsRead(BufferId id);
230 void setSyncedToCore();
231 void setDisconnectedFromCore();
232 void connectionStateChanged(CoreConnection::ConnectionState);
234 void recvMessage(const Message &message);
235 void recvStatusMsg(QString network, QString message);
237 void networkDestroyed();
238 void coreIdentityCreated(const Identity &);
239 void coreIdentityRemoved(IdentityId);
240 void coreNetworkCreated(NetworkId);
241 void coreNetworkRemoved(NetworkId);
243 void corePasswordChanged(PeerPtr, bool success);
245 void finishConnectionInitialization();
247 void sendBufferedUserInput();
250 Client(QObject *parent = 0);
254 void requestInitialBacklog();
256 static void addNetwork(Network *);
258 static QPointer<Client> instanceptr;
260 SignalProxy *_signalProxy;
262 NetworkModel *_networkModel;
263 BufferModel *_bufferModel;
264 BufferSyncer *_bufferSyncer;
265 ClientAliasManager *_aliasManager;
266 ClientBacklogManager *_backlogManager;
267 ClientBufferViewManager *_bufferViewManager;
268 BufferViewOverlay *_bufferViewOverlay;
270 DccConfig *_dccConfig;
271 ClientIrcListHelper *_ircListHelper;
272 ClientUserInputHandler *_inputHandler;
273 NetworkConfig *_networkConfig;
274 ClientIgnoreListManager *_ignoreListManager;
275 HighlightRuleManager *_highlightRuleManager;
276 ClientTransferManager *_transferManager;
277 TransferModel *_transferModel;
279 MessageModel *_messageModel;
280 AbstractMessageProcessor *_messageProcessor;
282 CoreAccountModel *_coreAccountModel;
283 CoreConnection *_coreConnection;
285 ClientMode clientMode;
287 QHash<NetworkId, Network *> _networks;
288 QHash<IdentityId, Identity *> _identities;
292 QString _debugLogBuffer;
293 QTextStream _debugLog;
295 QList<QPair<BufferInfo, QString> > _userInputBuffer;
297 friend class CoreConnection;