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);
175 void disconnectFromCore();
177 void bufferRemoved(BufferId bufferId);
178 void bufferRenamed(BufferId bufferId, const QString &newName);
179 void buffersPermanentlyMerged(BufferId bufferId1, BufferId bufferId2);
182 void setSyncedToCore();
183 void setDisconnectedFromCore();
184 void connectionStateChanged(CoreConnection::ConnectionState);
186 void recvMessage(const Message &message);
187 void recvStatusMsg(QString network, QString message);
189 void networkDestroyed();
190 void coreIdentityCreated(const Identity &);
191 void coreIdentityRemoved(IdentityId);
192 void coreNetworkCreated(NetworkId);
193 void coreNetworkRemoved(NetworkId);
195 void requestInitialBacklog();
196 void createDefaultBufferView();
198 void sendBufferedUserInput();
201 Client(QObject *parent = 0);
205 static void addNetwork(Network *);
206 static void setCoreFeatures(Quassel::Features);
207 static inline BufferSyncer *bufferSyncer() { return instance()->_bufferSyncer; }
209 static QPointer<Client> instanceptr;
211 SignalProxy * _signalProxy;
212 AbstractUi * _mainUi;
213 NetworkModel * _networkModel;
214 BufferModel * _bufferModel;
215 BufferSyncer * _bufferSyncer;
216 ClientAliasManager *_aliasManager;
217 ClientBacklogManager *_backlogManager;
218 ClientBufferViewManager *_bufferViewManager;
219 BufferViewOverlay *_bufferViewOverlay;
220 ClientIrcListHelper *_ircListHelper;
221 ClientUserInputHandler *_inputHandler;
222 NetworkConfig *_networkConfig;
223 ClientIgnoreListManager *_ignoreListManager;
225 MessageModel *_messageModel;
226 AbstractMessageProcessor *_messageProcessor;
228 CoreAccountModel *_coreAccountModel;
229 CoreConnection *_coreConnection;
231 ClientMode clientMode;
233 QHash<NetworkId, Network *> _networks;
234 QHash<IdentityId, Identity *> _identities;
237 static Quassel::Features _coreFeatures;
239 QString _debugLogBuffer;
240 QTextStream _debugLog;
242 QList<QPair<BufferInfo, QString> > _userInputBuffer;
244 friend class CoreConnection;