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 setBufferMarkerLine(BufferId id, const MsgId &msgId); // this is synced to core and other clients
131 static void removeBuffer(BufferId id);
132 static void renameBuffer(BufferId bufferId, const QString &newName);
133 static void mergeBuffersPermanently(BufferId bufferId1, BufferId bufferId2);
134 static void purgeKnownBufferIds();
136 static void logMessage(QtMsgType type, const char *msg);
137 static inline const QString &debugLog() { return instance()->_debugLogBuffer; }
140 void requestNetworkStates();
142 void showConfigWizard(const QVariantMap &coredata);
146 void coreConnectionStateChanged(bool);
148 //! The identity with the given ID has been newly created in core and client.
149 /** \param id The ID of the newly created identity.
151 void identityCreated(IdentityId id);
153 //! The identity with the given ID has been removed.
154 /** Upon emitting this signal, the identity is already gone from the core, and it will
155 * be deleted from the client immediately afterwards, so connected slots need to clean
157 * \param id The ID of the identity about to be removed.
159 void identityRemoved(IdentityId id);
161 //! Sent to the core when an identity shall be created. Should not be used elsewhere.
162 void requestCreateIdentity(const Identity &, const QVariantMap &);
163 //! Sent to the core when an identity shall be removed. Should not be used elsewhere.
164 void requestRemoveIdentity(IdentityId);
166 void networkCreated(NetworkId id);
167 void networkRemoved(NetworkId id);
169 void requestCreateNetwork(const NetworkInfo &info, const QStringList &persistentChannels = QStringList());
170 void requestRemoveNetwork(NetworkId);
172 void logUpdated(const QString &msg);
174 //! Emitted when a buffer has been marked as read
175 /** This is currently triggered by setting lastSeenMsg, either local or remote,
176 * or by bringing the window to front.
177 * \param id The buffer that has been marked as read
179 void bufferMarkedAsRead(BufferId id);
182 void disconnectFromCore();
184 void bufferRemoved(BufferId bufferId);
185 void bufferRenamed(BufferId bufferId, const QString &newName);
186 void buffersPermanentlyMerged(BufferId bufferId1, BufferId bufferId2);
188 void markBufferAsRead(BufferId id);
191 void setSyncedToCore();
192 void setDisconnectedFromCore();
193 void connectionStateChanged(CoreConnection::ConnectionState);
195 void recvMessage(const Message &message);
196 void recvStatusMsg(QString network, QString message);
198 void networkDestroyed();
199 void coreIdentityCreated(const Identity &);
200 void coreIdentityRemoved(IdentityId);
201 void coreNetworkCreated(NetworkId);
202 void coreNetworkRemoved(NetworkId);
204 void requestInitialBacklog();
205 void createDefaultBufferView();
207 void sendBufferedUserInput();
210 Client(QObject *parent = 0);
214 static void addNetwork(Network *);
215 static void setCoreFeatures(Quassel::Features);
216 static inline BufferSyncer *bufferSyncer() { return instance()->_bufferSyncer; }
218 static QPointer<Client> instanceptr;
220 SignalProxy * _signalProxy;
221 AbstractUi * _mainUi;
222 NetworkModel * _networkModel;
223 BufferModel * _bufferModel;
224 BufferSyncer * _bufferSyncer;
225 ClientAliasManager *_aliasManager;
226 ClientBacklogManager *_backlogManager;
227 ClientBufferViewManager *_bufferViewManager;
228 BufferViewOverlay *_bufferViewOverlay;
229 ClientIrcListHelper *_ircListHelper;
230 ClientUserInputHandler *_inputHandler;
231 NetworkConfig *_networkConfig;
232 ClientIgnoreListManager *_ignoreListManager;
234 MessageModel *_messageModel;
235 AbstractMessageProcessor *_messageProcessor;
237 CoreAccountModel *_coreAccountModel;
238 CoreConnection *_coreConnection;
240 ClientMode clientMode;
242 QHash<NetworkId, Network *> _networks;
243 QHash<IdentityId, Identity *> _identities;
246 static Quassel::Features _coreFeatures;
248 QString _debugLogBuffer;
249 QTextStream _debugLog;
251 QList<QPair<BufferInfo, QString> > _userInputBuffer;
253 friend class CoreConnection;