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 "coreconnection.h"
34 class AbstractMessageProcessor;
45 class BufferViewOverlay;
46 class ClientAliasManager;
47 class ClientBacklogManager;
48 class ClientBufferViewManager;
49 class ClientIgnoreListManager;
50 class ClientIrcListHelper;
51 class ClientUserInputHandler;
52 class CoreAccountModel;
60 class Client : public QObject
70 static bool instanceExists();
71 static Client *instance();
72 static void destroy();
73 static void init(AbstractUi *);
74 static AbstractUi *mainUi();
76 static QList<NetworkId> networkIds();
77 static const Network *network(NetworkId);
79 static QList<IdentityId> identityIds();
80 static const Identity *identity(IdentityId);
82 //! Request creation of an identity with the given data.
83 /** The request will be sent to the core, and will be propagated back to all the clients
84 * with a new valid IdentityId.
85 * \param identity The identity template for the new identity. It does not need to have a valid ID.
87 static void createIdentity(const CertIdentity &identity);
89 //! Request update of an identity with the given data.
90 /** The request will be sent to the core, and will be propagated back to all the clients.
91 * \param id The identity to be updated.
92 * \param serializedData The identity's content (cf. SyncableObject::toVariantMap())
94 static void updateIdentity(IdentityId id, const QVariantMap &serializedData);
96 //! Request removal of the identity with the given ID from the core (and all the clients, of course).
97 /** \param id The ID of the identity to be removed.
99 static void removeIdentity(IdentityId id);
101 static void createNetwork(const NetworkInfo &info, const QStringList &persistentChannels = QStringList());
102 static void updateNetwork(const NetworkInfo &info);
103 static void removeNetwork(NetworkId id);
105 static inline NetworkModel *networkModel() { return instance()->_networkModel; }
106 static inline BufferModel *bufferModel() { return instance()->_bufferModel; }
107 static inline MessageModel *messageModel() { return instance()->_messageModel; }
108 static inline AbstractMessageProcessor *messageProcessor() { return instance()->_messageProcessor; }
109 static inline SignalProxy *signalProxy() { return instance()->_signalProxy; }
111 static inline ClientAliasManager *aliasManager() { return instance()->_aliasManager; }
112 static inline ClientBacklogManager *backlogManager() { return instance()->_backlogManager; }
113 static inline ClientIrcListHelper *ircListHelper() { return instance()->_ircListHelper; }
114 static inline ClientBufferViewManager *bufferViewManager() { return instance()->_bufferViewManager; }
115 static inline BufferViewOverlay *bufferViewOverlay() { return instance()->_bufferViewOverlay; }
116 static inline ClientUserInputHandler *inputHandler() { return instance()->_inputHandler; }
117 static inline NetworkConfig *networkConfig() { return instance()->_networkConfig; }
118 static inline ClientIgnoreListManager *ignoreListManager() { return instance()->_ignoreListManager; }
120 static inline CoreAccountModel *coreAccountModel() { return instance()->_coreAccountModel; }
121 static inline CoreConnection *coreConnection() { return instance()->_coreConnection; }
122 static inline CoreAccount currentCoreAccount() { return coreConnection()->currentAccount(); }
123 static inline Quassel::Features coreFeatures() { return _coreFeatures; }
125 static bool isConnected();
126 static bool internalCore();
128 static void userInput(const BufferInfo &bufferInfo, const QString &message);
130 static void setBufferLastSeenMsg(BufferId id, const MsgId &msgId); // this is synced to core and other clients
131 static void setMarkerLine(BufferId id, const MsgId &msgId); // this is synced to core and other clients
132 static MsgId markerLine(BufferId id);
134 static void removeBuffer(BufferId id);
135 static void renameBuffer(BufferId bufferId, const QString &newName);
136 static void mergeBuffersPermanently(BufferId bufferId1, BufferId bufferId2);
137 static void purgeKnownBufferIds();
139 static void logMessage(QtMsgType type, const char *msg);
140 static inline const QString &debugLog() { return instance()->_debugLogBuffer; }
143 void requestNetworkStates();
145 void showConfigWizard(const QVariantMap &coredata);
149 void coreConnectionStateChanged(bool);
151 //! The identity with the given ID has been newly created in core and client.
152 /** \param id The ID of the newly created identity.
154 void identityCreated(IdentityId id);
156 //! The identity with the given ID has been removed.
157 /** Upon emitting this signal, the identity is already gone from the core, and it will
158 * be deleted from the client immediately afterwards, so connected slots need to clean
160 * \param id The ID of the identity about to be removed.
162 void identityRemoved(IdentityId id);
164 //! Sent to the core when an identity shall be created. Should not be used elsewhere.
165 void requestCreateIdentity(const Identity &, const QVariantMap &);
166 //! Sent to the core when an identity shall be removed. Should not be used elsewhere.
167 void requestRemoveIdentity(IdentityId);
169 void networkCreated(NetworkId id);
170 void networkRemoved(NetworkId id);
172 void requestCreateNetwork(const NetworkInfo &info, const QStringList &persistentChannels = QStringList());
173 void requestRemoveNetwork(NetworkId);
175 void logUpdated(const QString &msg);
177 //! Emitted when a buffer has been marked as read
178 /** This is currently triggered by setting lastSeenMsg, either local or remote,
179 * or by bringing the window to front.
180 * \param id The buffer that has been marked as read
182 void bufferMarkedAsRead(BufferId id);
185 void disconnectFromCore();
187 void bufferRemoved(BufferId bufferId);
188 void bufferRenamed(BufferId bufferId, const QString &newName);
189 void buffersPermanentlyMerged(BufferId bufferId1, BufferId bufferId2);
191 void markBufferAsRead(BufferId id);
194 void setSyncedToCore();
195 void setDisconnectedFromCore();
196 void connectionStateChanged(CoreConnection::ConnectionState);
198 void recvMessage(const Message &message);
199 void recvStatusMsg(QString network, QString message);
201 void networkDestroyed();
202 void coreIdentityCreated(const Identity &);
203 void coreIdentityRemoved(IdentityId);
204 void coreNetworkCreated(NetworkId);
205 void coreNetworkRemoved(NetworkId);
207 void requestInitialBacklog();
209 void sendBufferedUserInput();
212 Client(QObject *parent = 0);
216 static void addNetwork(Network *);
217 static void setCoreFeatures(Quassel::Features);
218 static inline BufferSyncer *bufferSyncer() { return instance()->_bufferSyncer; }
220 static QPointer<Client> instanceptr;
222 SignalProxy *_signalProxy;
224 NetworkModel *_networkModel;
225 BufferModel *_bufferModel;
226 BufferSyncer *_bufferSyncer;
227 ClientAliasManager *_aliasManager;
228 ClientBacklogManager *_backlogManager;
229 ClientBufferViewManager *_bufferViewManager;
230 BufferViewOverlay *_bufferViewOverlay;
231 ClientIrcListHelper *_ircListHelper;
232 ClientUserInputHandler *_inputHandler;
233 NetworkConfig *_networkConfig;
234 ClientIgnoreListManager *_ignoreListManager;
236 MessageModel *_messageModel;
237 AbstractMessageProcessor *_messageProcessor;
239 CoreAccountModel *_coreAccountModel;
240 CoreConnection *_coreConnection;
242 ClientMode clientMode;
244 QHash<NetworkId, Network *> _networks;
245 QHash<IdentityId, Identity *> _identities;
248 static Quassel::Features _coreFeatures;
250 QString _debugLogBuffer;
251 QTextStream _debugLog;
253 QList<QPair<BufferInfo, QString> > _userInputBuffer;
255 friend class CoreConnection;