1 /***************************************************************************
2 * Copyright (C) 2005-2013 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 ClientUserInputHandler;
53 class CoreAccountModel;
61 class Client : public QObject
71 static bool instanceExists();
72 static Client *instance();
73 static void destroy();
74 static void init(AbstractUi *);
75 static AbstractUi *mainUi();
77 static QList<NetworkId> networkIds();
78 static const Network *network(NetworkId);
80 static QList<IdentityId> identityIds();
81 static const Identity *identity(IdentityId);
83 //! Request creation of an identity with the given data.
84 /** The request will be sent to the core, and will be propagated back to all the clients
85 * with a new valid IdentityId.
86 * \param identity The identity template for the new identity. It does not need to have a valid ID.
88 static void createIdentity(const CertIdentity &identity);
90 //! Request update 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 * \param id The identity to be updated.
93 * \param serializedData The identity's content (cf. SyncableObject::toVariantMap())
95 static void updateIdentity(IdentityId id, const QVariantMap &serializedData);
97 //! Request removal of the identity with the given ID from the core (and all the clients, of course).
98 /** \param id The ID of the identity to be removed.
100 static void removeIdentity(IdentityId id);
102 static void createNetwork(const NetworkInfo &info, const QStringList &persistentChannels = QStringList());
103 static void updateNetwork(const NetworkInfo &info);
104 static void removeNetwork(NetworkId id);
106 static inline NetworkModel *networkModel() { return instance()->_networkModel; }
107 static inline BufferModel *bufferModel() { return instance()->_bufferModel; }
108 static inline MessageModel *messageModel() { return instance()->_messageModel; }
109 static inline AbstractMessageProcessor *messageProcessor() { return instance()->_messageProcessor; }
110 static inline SignalProxy *signalProxy() { return instance()->_signalProxy; }
112 static inline ClientAliasManager *aliasManager() { return instance()->_aliasManager; }
113 static inline ClientBacklogManager *backlogManager() { return instance()->_backlogManager; }
114 static inline ClientIrcListHelper *ircListHelper() { return instance()->_ircListHelper; }
115 static inline ClientBufferViewManager *bufferViewManager() { return instance()->_bufferViewManager; }
116 static inline BufferViewOverlay *bufferViewOverlay() { return instance()->_bufferViewOverlay; }
117 static inline ClientUserInputHandler *inputHandler() { return instance()->_inputHandler; }
118 static inline NetworkConfig *networkConfig() { return instance()->_networkConfig; }
119 static inline ClientIgnoreListManager *ignoreListManager() { return instance()->_ignoreListManager; }
121 static inline CoreAccountModel *coreAccountModel() { return instance()->_coreAccountModel; }
122 static inline CoreConnection *coreConnection() { return instance()->_coreConnection; }
123 static inline CoreAccount currentCoreAccount() { return coreConnection()->currentAccount(); }
124 static inline Quassel::Features coreFeatures() { return _coreFeatures; }
126 static void setCoreFeatures(Quassel::Features features);
128 static bool isConnected();
129 static bool internalCore();
131 static void userInput(const BufferInfo &bufferInfo, const QString &message);
133 static void setBufferLastSeenMsg(BufferId id, const MsgId &msgId); // this is synced to core and other clients
134 static void setMarkerLine(BufferId id, const MsgId &msgId); // this is synced to core and other clients
135 static MsgId markerLine(BufferId id);
137 static void removeBuffer(BufferId id);
138 static void renameBuffer(BufferId bufferId, const QString &newName);
139 static void mergeBuffersPermanently(BufferId bufferId1, BufferId bufferId2);
140 static void purgeKnownBufferIds();
142 static void logMessage(QtMsgType type, const char *msg);
143 static inline const QString &debugLog() { return instance()->_debugLogBuffer; }
146 void requestNetworkStates();
148 void showConfigWizard(const QVariantMap &coredata);
152 void coreConnectionStateChanged(bool);
154 //! The identity with the given ID has been newly created in core and client.
155 /** \param id The ID of the newly created identity.
157 void identityCreated(IdentityId id);
159 //! The identity with the given ID has been removed.
160 /** Upon emitting this signal, the identity is already gone from the core, and it will
161 * be deleted from the client immediately afterwards, so connected slots need to clean
163 * \param id The ID of the identity about to be removed.
165 void identityRemoved(IdentityId id);
167 //! Sent to the core when an identity shall be created. Should not be used elsewhere.
168 void requestCreateIdentity(const Identity &, const QVariantMap &);
169 //! Sent to the core when an identity shall be removed. Should not be used elsewhere.
170 void requestRemoveIdentity(IdentityId);
172 void networkCreated(NetworkId id);
173 void networkRemoved(NetworkId id);
175 void requestCreateNetwork(const NetworkInfo &info, const QStringList &persistentChannels = QStringList());
176 void requestRemoveNetwork(NetworkId);
178 void logUpdated(const QString &msg);
180 //! Emitted when a buffer has been marked as read
181 /** This is currently triggered by setting lastSeenMsg, either local or remote,
182 * or by bringing the window to front.
183 * \param id The buffer that has been marked as read
185 void bufferMarkedAsRead(BufferId id);
188 void disconnectFromCore();
190 void bufferRemoved(BufferId bufferId);
191 void bufferRenamed(BufferId bufferId, const QString &newName);
192 void buffersPermanentlyMerged(BufferId bufferId1, BufferId bufferId2);
194 void markBufferAsRead(BufferId id);
197 void setSyncedToCore();
198 void setDisconnectedFromCore();
199 void connectionStateChanged(CoreConnection::ConnectionState);
201 void recvMessage(const Message &message);
202 void recvStatusMsg(QString network, QString message);
204 void networkDestroyed();
205 void coreIdentityCreated(const Identity &);
206 void coreIdentityRemoved(IdentityId);
207 void coreNetworkCreated(NetworkId);
208 void coreNetworkRemoved(NetworkId);
210 void requestInitialBacklog();
212 void sendBufferedUserInput();
215 Client(QObject *parent = 0);
219 static void addNetwork(Network *);
220 static inline BufferSyncer *bufferSyncer() { return instance()->_bufferSyncer; }
222 static QPointer<Client> instanceptr;
224 SignalProxy *_signalProxy;
226 NetworkModel *_networkModel;
227 BufferModel *_bufferModel;
228 BufferSyncer *_bufferSyncer;
229 ClientAliasManager *_aliasManager;
230 ClientBacklogManager *_backlogManager;
231 ClientBufferViewManager *_bufferViewManager;
232 BufferViewOverlay *_bufferViewOverlay;
233 ClientIrcListHelper *_ircListHelper;
234 ClientUserInputHandler *_inputHandler;
235 NetworkConfig *_networkConfig;
236 ClientIgnoreListManager *_ignoreListManager;
238 MessageModel *_messageModel;
239 AbstractMessageProcessor *_messageProcessor;
241 CoreAccountModel *_coreAccountModel;
242 CoreConnection *_coreConnection;
244 ClientMode clientMode;
246 QHash<NetworkId, Network *> _networks;
247 QHash<IdentityId, Identity *> _identities;
250 static Quassel::Features _coreFeatures;
252 QString _debugLogBuffer;
253 QTextStream _debugLog;
255 QList<QPair<BufferInfo, QString> > _userInputBuffer;
257 friend class CoreConnection;