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 ***************************************************************************/
24 #include <QAbstractSocket>
29 #include "bufferinfo.h"
34 class AbstractMessageProcessor;
45 class BufferViewOverlay;
46 class ClientBacklogManager;
47 class ClientBufferViewManager;
48 class ClientIrcListHelper;
50 class ClientUserInputHandler;
56 class Client : public QObject {
65 static Client *instance();
66 static void destroy();
67 static void init(AbstractUi *);
68 static AbstractUi *mainUi();
70 static QList<NetworkId> networkIds();
71 static const Network * network(NetworkId);
73 static QList<IdentityId> identityIds();
74 static const Identity *identity(IdentityId);
76 //! Request creation of an identity with the given data.
77 /** The request will be sent to the core, and will be propagated back to all the clients
78 * with a new valid IdentityId.
79 * \param identity The identity template for the new identity. It does not need to have a valid ID.
81 static void createIdentity(const CertIdentity &identity);
83 //! Request update 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 * \param id The identity to be updated.
86 * \param serializedData The identity's content (cf. SyncableObject::toVariantMap())
88 static void updateIdentity(IdentityId id, const QVariantMap &serializedData);
90 //! Request removal of the identity with the given ID from the core (and all the clients, of course).
91 /** \param id The ID of the identity to be removed.
93 static void removeIdentity(IdentityId id);
95 static void createNetwork(const NetworkInfo &info, const QStringList &persistentChannels = QStringList());
96 static void updateNetwork(const NetworkInfo &info);
97 static void removeNetwork(NetworkId id);
99 static inline NetworkModel *networkModel() { return instance()->_networkModel; }
100 static inline BufferModel *bufferModel() { return instance()->_bufferModel; }
101 static inline MessageModel *messageModel() { return instance()->_messageModel; }
102 static inline AbstractMessageProcessor *messageProcessor() { return instance()->_messageProcessor; }
103 static inline SignalProxy *signalProxy() { return instance()->_signalProxy; }
105 static inline ClientBacklogManager *backlogManager() { return instance()->_backlogManager; }
106 static inline ClientIrcListHelper *ircListHelper() { return instance()->_ircListHelper; }
107 static inline ClientBufferViewManager *bufferViewManager() { return instance()->_bufferViewManager; }
108 static inline BufferViewOverlay *bufferViewOverlay() { return instance()->_bufferViewOverlay; }
109 static inline ClientUserInputHandler *inputHandler() { return instance()->_inputHandler; }
111 static AccountId currentCoreAccount();
113 static bool isConnected();
114 static bool isSynced();
115 static inline bool internalCore() { return instance()->_internalCore; }
117 static void userInput(const BufferInfo &bufferInfo, const QString &message);
119 static void setBufferLastSeenMsg(BufferId id, const MsgId &msgId); // this is synced to core and other clients
120 static void removeBuffer(BufferId id);
121 static void renameBuffer(BufferId bufferId, const QString &newName);
122 static void mergeBuffersPermanently(BufferId bufferId1, BufferId bufferId2);
123 static void purgeKnownBufferIds();
125 static void logMessage(QtMsgType type, const char *msg);
126 static inline const QString &debugLog() { return instance()->_debugLogBuffer; }
128 static inline void registerClientSyncer(ClientSyncer *syncer) { emit instance()->newClientSyncer(syncer); }
131 void requestNetworkStates();
133 void showConfigWizard(const QVariantMap &coredata);
137 void coreConnectionStateChanged(bool);
139 //! The identity with the given ID has been newly created in core and client.
140 /** \param id The ID of the newly created identity.
142 void identityCreated(IdentityId id);
144 //! The identity with the given ID has been removed.
145 /** Upon emitting this signal, the identity is already gone from the core, and it will
146 * be deleted from the client immediately afterwards, so connected slots need to clean
148 * \param id The ID of the identity about to be removed.
150 void identityRemoved(IdentityId id);
152 //! Sent to the core when an identity shall be created. Should not be used elsewhere.
153 void requestCreateIdentity(const Identity &, const QVariantMap &);
154 //! Sent to the core when an identity shall be removed. Should not be used elsewhere.
155 void requestRemoveIdentity(IdentityId);
157 void networkCreated(NetworkId id);
158 void networkRemoved(NetworkId id);
160 void requestCreateNetwork(const NetworkInfo &info, const QStringList &persistentChannels = QStringList());
161 void requestRemoveNetwork(NetworkId);
163 void newClientSyncer(ClientSyncer *);
165 void logUpdated(const QString &msg);
168 void disconnectFromCore();
170 void bufferRemoved(BufferId bufferId);
171 void bufferRenamed(BufferId bufferId, const QString &newName);
172 void buffersPermanentlyMerged(BufferId bufferId1, BufferId bufferId2);
175 void disconnectedFromCore();
177 void recvMessage(const Message &message);
178 void recvStatusMsg(QString network, QString message);
180 void networkDestroyed();
181 void coreIdentityCreated(const Identity &);
182 void coreIdentityRemoved(IdentityId);
183 void coreNetworkCreated(NetworkId);
184 void coreNetworkRemoved(NetworkId);
186 void setConnectedToCore(AccountId id, QIODevice *socket = 0);
187 void setSyncedToCore();
188 void requestInitialBacklog();
189 void createDefaultBufferView();
192 Client(QObject *parent = 0);
196 static void addNetwork(Network *);
197 static void setCurrentCoreAccount(AccountId);
198 static inline BufferSyncer *bufferSyncer() { return instance()->_bufferSyncer; }
200 static QPointer<Client> instanceptr;
202 SignalProxy * _signalProxy;
203 AbstractUi * _mainUi;
204 NetworkModel * _networkModel;
205 BufferModel * _bufferModel;
206 BufferSyncer * _bufferSyncer;
207 ClientBacklogManager *_backlogManager;
208 ClientBufferViewManager *_bufferViewManager;
209 BufferViewOverlay *_bufferViewOverlay;
210 ClientIrcListHelper *_ircListHelper;
211 ClientUserInputHandler *_inputHandler;
213 MessageModel *_messageModel;
214 AbstractMessageProcessor *_messageProcessor;
216 ClientMode clientMode;
218 bool _connectedToCore, _syncedToCore;
221 QHash<NetworkId, Network *> _networks;
222 QHash<IdentityId, Identity *> _identities;
224 static AccountId _currentCoreAccount;
226 QString _debugLogBuffer;
227 QTextStream _debugLog;
229 friend class ClientSyncer;