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;
65 class Client : public QObject
75 static bool instanceExists();
76 static Client *instance();
77 static void destroy();
78 static void init(AbstractUi *);
79 static AbstractUi *mainUi();
81 static QList<NetworkId> networkIds();
82 static const Network *network(NetworkId);
84 static QList<IdentityId> identityIds();
85 static const Identity *identity(IdentityId);
87 //! Request creation of an identity with the given data.
88 /** The request will be sent to the core, and will be propagated back to all the clients
89 * with a new valid IdentityId.
90 * \param identity The identity template for the new identity. It does not need to have a valid ID.
92 static void createIdentity(const CertIdentity &identity);
94 //! Request update of an identity with the given data.
95 /** The request will be sent to the core, and will be propagated back to all the clients.
96 * \param id The identity to be updated.
97 * \param serializedData The identity's content (cf. SyncableObject::toVariantMap())
99 static void updateIdentity(IdentityId id, const QVariantMap &serializedData);
101 //! Request removal of the identity with the given ID from the core (and all the clients, of course).
102 /** \param id The ID of the identity to be removed.
104 static void removeIdentity(IdentityId id);
106 static void createNetwork(const NetworkInfo &info, const QStringList &persistentChannels = QStringList());
107 static void updateNetwork(const NetworkInfo &info);
108 static void removeNetwork(NetworkId id);
110 static inline NetworkModel *networkModel() { return instance()->_networkModel; }
111 static inline BufferModel *bufferModel() { return instance()->_bufferModel; }
112 static inline MessageModel *messageModel() { return instance()->_messageModel; }
113 static inline AbstractMessageProcessor *messageProcessor() { return instance()->_messageProcessor; }
114 static inline SignalProxy *signalProxy() { return instance()->_signalProxy; }
116 static inline ClientAliasManager *aliasManager() { return instance()->_aliasManager; }
117 static inline ClientBacklogManager *backlogManager() { return instance()->_backlogManager; }
118 static inline DccConfig *dccConfig() { return instance()->_dccConfig; }
119 static inline ClientIrcListHelper *ircListHelper() { return instance()->_ircListHelper; }
120 static inline ClientBufferViewManager *bufferViewManager() { return instance()->_bufferViewManager; }
121 static inline BufferViewOverlay *bufferViewOverlay() { return instance()->_bufferViewOverlay; }
122 static inline ClientUserInputHandler *inputHandler() { return instance()->_inputHandler; }
123 static inline NetworkConfig *networkConfig() { return instance()->_networkConfig; }
124 static inline ClientIgnoreListManager *ignoreListManager() { return instance()->_ignoreListManager; }
125 static inline ClientTransferManager *transferManager() { return instance()->_transferManager; }
126 static inline TransferModel *transferModel() { return instance()->_transferModel; }
128 static inline BufferSyncer *bufferSyncer() { return instance()->_bufferSyncer; }
130 static inline CoreAccountModel *coreAccountModel() { return instance()->_coreAccountModel; }
131 static inline CoreConnection *coreConnection() { return instance()->_coreConnection; }
132 static inline CoreAccount currentCoreAccount() { return coreConnection()->currentAccount(); }
133 static inline Quassel::Features coreFeatures() { return _coreFeatures; }
135 static void setCoreFeatures(Quassel::Features features);
137 static bool isConnected();
138 static bool internalCore();
140 static void userInput(const BufferInfo &bufferInfo, const QString &message);
142 static void setBufferLastSeenMsg(BufferId id, const MsgId &msgId); // this is synced to core and other clients
143 static void setMarkerLine(BufferId id, const MsgId &msgId); // this is synced to core and other clients
144 static MsgId markerLine(BufferId id);
146 static void removeBuffer(BufferId id);
147 static void renameBuffer(BufferId bufferId, const QString &newName);
148 static void mergeBuffersPermanently(BufferId bufferId1, BufferId bufferId2);
149 static void purgeKnownBufferIds();
151 static void changePassword(const QString &oldPassword, const QString &newPassword);
153 #if QT_VERSION < 0x050000
154 static void logMessage(QtMsgType type, const char *msg);
156 static void logMessage(QtMsgType, const QMessageLogContext&, const QString&);
158 static inline const QString &debugLog() { return instance()->_debugLogBuffer; }
161 void requestNetworkStates();
163 void showConfigWizard(const QVariantMap &coredata);
167 void coreConnectionStateChanged(bool);
169 //! The identity with the given ID has been newly created in core and client.
170 /** \param id The ID of the newly created identity.
172 void identityCreated(IdentityId id);
174 //! The identity with the given ID has been removed.
175 /** Upon emitting this signal, the identity is already gone from the core, and it will
176 * be deleted from the client immediately afterwards, so connected slots need to clean
178 * \param id The ID of the identity about to be removed.
180 void identityRemoved(IdentityId id);
182 //! Sent to the core when an identity shall be created. Should not be used elsewhere.
183 void requestCreateIdentity(const Identity &, const QVariantMap &);
184 //! Sent to the core when an identity shall be removed. Should not be used elsewhere.
185 void requestRemoveIdentity(IdentityId);
187 void networkCreated(NetworkId id);
188 void networkRemoved(NetworkId id);
190 void requestCreateNetwork(const NetworkInfo &info, const QStringList &persistentChannels = QStringList());
191 void requestRemoveNetwork(NetworkId);
193 void logUpdated(const QString &msg);
195 //! Emitted when a buffer has been marked as read
196 /** This is currently triggered by setting lastSeenMsg, either local or remote,
197 * or by bringing the window to front.
198 * \param id The buffer that has been marked as read
200 void bufferMarkedAsRead(BufferId id);
202 //! Requests a password change (user name must match the currently logged in user)
203 void requestPasswordChange(PeerPtr peer, const QString &userName, const QString &oldPassword, const QString &newPassword);
204 void passwordChanged(bool success);
207 void disconnectFromCore();
209 void bufferRemoved(BufferId bufferId);
210 void bufferRenamed(BufferId bufferId, const QString &newName);
211 void buffersPermanentlyMerged(BufferId bufferId1, BufferId bufferId2);
213 void markBufferAsRead(BufferId id);
216 void setSyncedToCore();
217 void setDisconnectedFromCore();
218 void connectionStateChanged(CoreConnection::ConnectionState);
220 void recvMessage(const Message &message);
221 void recvStatusMsg(QString network, QString message);
223 void networkDestroyed();
224 void coreIdentityCreated(const Identity &);
225 void coreIdentityRemoved(IdentityId);
226 void coreNetworkCreated(NetworkId);
227 void coreNetworkRemoved(NetworkId);
229 void corePasswordChanged(PeerPtr, bool success);
231 void finishConnectionInitialization();
233 void sendBufferedUserInput();
236 Client(QObject *parent = 0);
240 void requestInitialBacklog();
242 static void addNetwork(Network *);
244 static QPointer<Client> instanceptr;
246 SignalProxy *_signalProxy;
248 NetworkModel *_networkModel;
249 BufferModel *_bufferModel;
250 BufferSyncer *_bufferSyncer;
251 ClientAliasManager *_aliasManager;
252 ClientBacklogManager *_backlogManager;
253 ClientBufferViewManager *_bufferViewManager;
254 BufferViewOverlay *_bufferViewOverlay;
255 DccConfig *_dccConfig;
256 ClientIrcListHelper *_ircListHelper;
257 ClientUserInputHandler *_inputHandler;
258 NetworkConfig *_networkConfig;
259 ClientIgnoreListManager *_ignoreListManager;
260 ClientTransferManager *_transferManager;
261 TransferModel *_transferModel;
263 MessageModel *_messageModel;
264 AbstractMessageProcessor *_messageProcessor;
266 CoreAccountModel *_coreAccountModel;
267 CoreConnection *_coreConnection;
269 ClientMode clientMode;
271 QHash<NetworkId, Network *> _networks;
272 QHash<IdentityId, Identity *> _identities;
275 static Quassel::Features _coreFeatures;
277 QString _debugLogBuffer;
278 QTextStream _debugLog;
280 QList<QPair<BufferInfo, QString> > _userInputBuffer;
282 friend class CoreConnection;