1 /***************************************************************************
2 * Copyright (C) 2005-09 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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 {
69 static bool instanceExists();
70 static Client *instance();
71 static void destroy();
72 static void init(AbstractUi *);
73 static AbstractUi *mainUi();
75 static QList<NetworkId> networkIds();
76 static const Network * network(NetworkId);
78 static QList<IdentityId> identityIds();
79 static const Identity *identity(IdentityId);
81 //! Request creation of an identity with the given data.
82 /** The request will be sent to the core, and will be propagated back to all the clients
83 * with a new valid IdentityId.
84 * \param identity The identity template for the new identity. It does not need to have a valid ID.
86 static void createIdentity(const CertIdentity &identity);
88 //! Request update 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 * \param id The identity to be updated.
91 * \param serializedData The identity's content (cf. SyncableObject::toVariantMap())
93 static void updateIdentity(IdentityId id, const QVariantMap &serializedData);
95 //! Request removal of the identity with the given ID from the core (and all the clients, of course).
96 /** \param id The ID of the identity to be removed.
98 static void removeIdentity(IdentityId id);
100 static void createNetwork(const NetworkInfo &info, const QStringList &persistentChannels = QStringList());
101 static void updateNetwork(const NetworkInfo &info);
102 static void removeNetwork(NetworkId id);
104 static inline NetworkModel *networkModel() { return instance()->_networkModel; }
105 static inline BufferModel *bufferModel() { return instance()->_bufferModel; }
106 static inline MessageModel *messageModel() { return instance()->_messageModel; }
107 static inline AbstractMessageProcessor *messageProcessor() { return instance()->_messageProcessor; }
108 static inline SignalProxy *signalProxy() { return instance()->_signalProxy; }
110 static inline ClientAliasManager *aliasManager() { return instance()->_aliasManager; }
111 static inline ClientBacklogManager *backlogManager() { return instance()->_backlogManager; }
112 static inline ClientIrcListHelper *ircListHelper() { return instance()->_ircListHelper; }
113 static inline ClientBufferViewManager *bufferViewManager() { return instance()->_bufferViewManager; }
114 static inline BufferViewOverlay *bufferViewOverlay() { return instance()->_bufferViewOverlay; }
115 static inline ClientUserInputHandler *inputHandler() { return instance()->_inputHandler; }
116 static inline NetworkConfig *networkConfig() { return instance()->_networkConfig; }
117 static inline ClientIgnoreListManager *ignoreListManager() { return instance()->_ignoreListManager; }
119 static inline CoreAccountModel *coreAccountModel() { return instance()->_coreAccountModel; }
120 static inline CoreConnection *coreConnection() { return instance()->_coreConnection; }
121 static inline CoreAccount currentCoreAccount() { return coreConnection()->currentAccount(); }
122 static inline Quassel::Features coreFeatures() { return _coreFeatures; }
124 static bool isConnected();
125 static bool internalCore();
127 static void userInput(const BufferInfo &bufferInfo, const QString &message);
129 static void setBufferLastSeenMsg(BufferId id, const MsgId &msgId); // this is synced to core and other clients
130 static void setMarkerLine(BufferId id, const MsgId &msgId); // this is synced to core and other clients
131 static MsgId markerLine(BufferId id);
133 static void removeBuffer(BufferId id);
134 static void renameBuffer(BufferId bufferId, const QString &newName);
135 static void mergeBuffersPermanently(BufferId bufferId1, BufferId bufferId2);
136 static void purgeKnownBufferIds();
138 static void logMessage(QtMsgType type, const char *msg);
139 static inline const QString &debugLog() { return instance()->_debugLogBuffer; }
142 void requestNetworkStates();
144 void showConfigWizard(const QVariantMap &coredata);
148 void coreConnectionStateChanged(bool);
150 //! The identity with the given ID has been newly created in core and client.
151 /** \param id The ID of the newly created identity.
153 void identityCreated(IdentityId id);
155 //! The identity with the given ID has been removed.
156 /** Upon emitting this signal, the identity is already gone from the core, and it will
157 * be deleted from the client immediately afterwards, so connected slots need to clean
159 * \param id The ID of the identity about to be removed.
161 void identityRemoved(IdentityId id);
163 //! Sent to the core when an identity shall be created. Should not be used elsewhere.
164 void requestCreateIdentity(const Identity &, const QVariantMap &);
165 //! Sent to the core when an identity shall be removed. Should not be used elsewhere.
166 void requestRemoveIdentity(IdentityId);
168 void networkCreated(NetworkId id);
169 void networkRemoved(NetworkId id);
171 void requestCreateNetwork(const NetworkInfo &info, const QStringList &persistentChannels = QStringList());
172 void requestRemoveNetwork(NetworkId);
174 void logUpdated(const QString &msg);
176 //! Emitted when a buffer has been marked as read
177 /** This is currently triggered by setting lastSeenMsg, either local or remote,
178 * or by bringing the window to front.
179 * \param id The buffer that has been marked as read
181 void bufferMarkedAsRead(BufferId id);
184 void disconnectFromCore();
186 void bufferRemoved(BufferId bufferId);
187 void bufferRenamed(BufferId bufferId, const QString &newName);
188 void buffersPermanentlyMerged(BufferId bufferId1, BufferId bufferId2);
190 void markBufferAsRead(BufferId id);
193 void setSyncedToCore();
194 void setDisconnectedFromCore();
195 void connectionStateChanged(CoreConnection::ConnectionState);
197 void recvMessage(const Message &message);
198 void recvStatusMsg(QString network, QString message);
200 void networkDestroyed();
201 void coreIdentityCreated(const Identity &);
202 void coreIdentityRemoved(IdentityId);
203 void coreNetworkCreated(NetworkId);
204 void coreNetworkRemoved(NetworkId);
206 void requestInitialBacklog();
208 void sendBufferedUserInput();
211 Client(QObject *parent = 0);
215 static void addNetwork(Network *);
216 static void setCoreFeatures(Quassel::Features);
217 static inline BufferSyncer *bufferSyncer() { return instance()->_bufferSyncer; }
219 static QPointer<Client> instanceptr;
221 SignalProxy * _signalProxy;
222 AbstractUi * _mainUi;
223 NetworkModel * _networkModel;
224 BufferModel * _bufferModel;
225 BufferSyncer * _bufferSyncer;
226 ClientAliasManager *_aliasManager;
227 ClientBacklogManager *_backlogManager;
228 ClientBufferViewManager *_bufferViewManager;
229 BufferViewOverlay *_bufferViewOverlay;
230 ClientIrcListHelper *_ircListHelper;
231 ClientUserInputHandler *_inputHandler;
232 NetworkConfig *_networkConfig;
233 ClientIgnoreListManager *_ignoreListManager;
235 MessageModel *_messageModel;
236 AbstractMessageProcessor *_messageProcessor;
238 CoreAccountModel *_coreAccountModel;
239 CoreConnection *_coreConnection;
241 ClientMode clientMode;
243 QHash<NetworkId, Network *> _networks;
244 QHash<IdentityId, Identity *> _identities;
247 static Quassel::Features _coreFeatures;
249 QString _debugLogBuffer;
250 QTextStream _debugLog;
252 QList<QPair<BufferInfo, QString> > _userInputBuffer;
254 friend class CoreConnection;