1 /***************************************************************************
2 * Copyright (C) 2005-2015 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;
63 class Client : public QObject
73 static bool instanceExists();
74 static Client *instance();
75 static void destroy();
76 static void init(AbstractUi *);
77 static AbstractUi *mainUi();
79 static QList<NetworkId> networkIds();
80 static const Network *network(NetworkId);
82 static QList<IdentityId> identityIds();
83 static const Identity *identity(IdentityId);
85 //! Request creation of an identity with the given data.
86 /** The request will be sent to the core, and will be propagated back to all the clients
87 * with a new valid IdentityId.
88 * \param identity The identity template for the new identity. It does not need to have a valid ID.
90 static void createIdentity(const CertIdentity &identity);
92 //! Request update 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 * \param id The identity to be updated.
95 * \param serializedData The identity's content (cf. SyncableObject::toVariantMap())
97 static void updateIdentity(IdentityId id, const QVariantMap &serializedData);
99 //! Request removal of the identity with the given ID from the core (and all the clients, of course).
100 /** \param id The ID of the identity to be removed.
102 static void removeIdentity(IdentityId id);
104 static void createNetwork(const NetworkInfo &info, const QStringList &persistentChannels = QStringList());
105 static void updateNetwork(const NetworkInfo &info);
106 static void removeNetwork(NetworkId id);
108 static inline NetworkModel *networkModel() { return instance()->_networkModel; }
109 static inline BufferModel *bufferModel() { return instance()->_bufferModel; }
110 static inline MessageModel *messageModel() { return instance()->_messageModel; }
111 static inline AbstractMessageProcessor *messageProcessor() { return instance()->_messageProcessor; }
112 static inline SignalProxy *signalProxy() { return instance()->_signalProxy; }
114 static inline ClientAliasManager *aliasManager() { return instance()->_aliasManager; }
115 static inline ClientBacklogManager *backlogManager() { return instance()->_backlogManager; }
116 static inline ClientIrcListHelper *ircListHelper() { return instance()->_ircListHelper; }
117 static inline ClientBufferViewManager *bufferViewManager() { return instance()->_bufferViewManager; }
118 static inline BufferViewOverlay *bufferViewOverlay() { return instance()->_bufferViewOverlay; }
119 static inline ClientUserInputHandler *inputHandler() { return instance()->_inputHandler; }
120 static inline NetworkConfig *networkConfig() { return instance()->_networkConfig; }
121 static inline ClientIgnoreListManager *ignoreListManager() { return instance()->_ignoreListManager; }
122 static inline ClientTransferManager *transferManager() { return instance()->_transferManager; }
124 static inline CoreAccountModel *coreAccountModel() { return instance()->_coreAccountModel; }
125 static inline CoreConnection *coreConnection() { return instance()->_coreConnection; }
126 static inline CoreAccount currentCoreAccount() { return coreConnection()->currentAccount(); }
127 static inline Quassel::Features coreFeatures() { return _coreFeatures; }
129 static void setCoreFeatures(Quassel::Features features);
131 static bool isConnected();
132 static bool internalCore();
134 static void userInput(const BufferInfo &bufferInfo, const QString &message);
136 static void setBufferLastSeenMsg(BufferId id, const MsgId &msgId); // this is synced to core and other clients
137 static void setMarkerLine(BufferId id, const MsgId &msgId); // this is synced to core and other clients
138 static MsgId markerLine(BufferId id);
140 static void removeBuffer(BufferId id);
141 static void renameBuffer(BufferId bufferId, const QString &newName);
142 static void mergeBuffersPermanently(BufferId bufferId1, BufferId bufferId2);
143 static void purgeKnownBufferIds();
145 static void changePassword(const QString &oldPassword, const QString &newPassword);
147 #if QT_VERSION < 0x050000
148 static void logMessage(QtMsgType type, const char *msg);
150 static void logMessage(QtMsgType, const QMessageLogContext&, const QString&);
152 static inline const QString &debugLog() { return instance()->_debugLogBuffer; }
155 void requestNetworkStates();
157 void showConfigWizard(const QVariantMap &coredata);
161 void coreConnectionStateChanged(bool);
163 //! The identity with the given ID has been newly created in core and client.
164 /** \param id The ID of the newly created identity.
166 void identityCreated(IdentityId id);
168 //! The identity with the given ID has been removed.
169 /** Upon emitting this signal, the identity is already gone from the core, and it will
170 * be deleted from the client immediately afterwards, so connected slots need to clean
172 * \param id The ID of the identity about to be removed.
174 void identityRemoved(IdentityId id);
176 //! Sent to the core when an identity shall be created. Should not be used elsewhere.
177 void requestCreateIdentity(const Identity &, const QVariantMap &);
178 //! Sent to the core when an identity shall be removed. Should not be used elsewhere.
179 void requestRemoveIdentity(IdentityId);
181 void networkCreated(NetworkId id);
182 void networkRemoved(NetworkId id);
184 void requestCreateNetwork(const NetworkInfo &info, const QStringList &persistentChannels = QStringList());
185 void requestRemoveNetwork(NetworkId);
187 void logUpdated(const QString &msg);
189 //! Emitted when a buffer has been marked as read
190 /** This is currently triggered by setting lastSeenMsg, either local or remote,
191 * or by bringing the window to front.
192 * \param id The buffer that has been marked as read
194 void bufferMarkedAsRead(BufferId id);
196 //! Requests a password change (user name must match the currently logged in user)
197 void requestPasswordChange(PeerPtr peer, const QString &userName, const QString &oldPassword, const QString &newPassword);
198 void passwordChanged(bool success);
201 void disconnectFromCore();
203 void bufferRemoved(BufferId bufferId);
204 void bufferRenamed(BufferId bufferId, const QString &newName);
205 void buffersPermanentlyMerged(BufferId bufferId1, BufferId bufferId2);
207 void markBufferAsRead(BufferId id);
210 void setSyncedToCore();
211 void setDisconnectedFromCore();
212 void connectionStateChanged(CoreConnection::ConnectionState);
214 void recvMessage(const Message &message);
215 void recvStatusMsg(QString network, QString message);
217 void networkDestroyed();
218 void coreIdentityCreated(const Identity &);
219 void coreIdentityRemoved(IdentityId);
220 void coreNetworkCreated(NetworkId);
221 void coreNetworkRemoved(NetworkId);
223 void corePasswordChanged(PeerPtr, bool success);
225 void requestInitialBacklog();
227 void sendBufferedUserInput();
230 Client(QObject *parent = 0);
234 static void addNetwork(Network *);
235 static inline BufferSyncer *bufferSyncer() { return instance()->_bufferSyncer; }
237 static QPointer<Client> instanceptr;
239 SignalProxy *_signalProxy;
241 NetworkModel *_networkModel;
242 BufferModel *_bufferModel;
243 BufferSyncer *_bufferSyncer;
244 ClientAliasManager *_aliasManager;
245 ClientBacklogManager *_backlogManager;
246 ClientBufferViewManager *_bufferViewManager;
247 BufferViewOverlay *_bufferViewOverlay;
248 ClientIrcListHelper *_ircListHelper;
249 ClientUserInputHandler *_inputHandler;
250 NetworkConfig *_networkConfig;
251 ClientIgnoreListManager *_ignoreListManager;
252 ClientTransferManager *_transferManager;
254 MessageModel *_messageModel;
255 AbstractMessageProcessor *_messageProcessor;
257 CoreAccountModel *_coreAccountModel;
258 CoreConnection *_coreConnection;
260 ClientMode clientMode;
262 QHash<NetworkId, Network *> _networks;
263 QHash<IdentityId, Identity *> _identities;
266 static Quassel::Features _coreFeatures;
268 QString _debugLogBuffer;
269 QTextStream _debugLog;
271 QList<QPair<BufferInfo, QString> > _userInputBuffer;
273 friend class CoreConnection;