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 ClientBacklogManager;
46 class ClientBufferViewManager;
47 class ClientIrcListHelper;
49 class ClientUserInputHandler;
55 class Client : public QObject {
64 static Client *instance();
65 static void destroy();
66 static void init(AbstractUi *);
67 static AbstractUi *mainUi();
69 static QList<NetworkId> networkIds();
70 static const Network * network(NetworkId);
72 static QList<IdentityId> identityIds();
73 static const Identity *identity(IdentityId);
75 //! Request creation of an identity with the given data.
76 /** The request will be sent to the core, and will be propagated back to all the clients
77 * with a new valid IdentityId.
78 * \param identity The identity template for the new identity. It does not need to have a valid ID.
80 static void createIdentity(const CertIdentity &identity);
82 //! Request update 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 * \param id The identity to be updated.
85 * \param serializedData The identity's content (cf. SyncableObject::toVariantMap())
87 static void updateIdentity(IdentityId id, const QVariantMap &serializedData);
89 //! Request removal of the identity with the given ID from the core (and all the clients, of course).
90 /** \param id The ID of the identity to be removed.
92 static void removeIdentity(IdentityId id);
94 static void createNetwork(const NetworkInfo &info, const QStringList &persistentChannels = QStringList());
95 static void updateNetwork(const NetworkInfo &info);
96 static void removeNetwork(NetworkId id);
98 static inline NetworkModel *networkModel() { return instance()->_networkModel; }
99 static inline BufferModel *bufferModel() { return instance()->_bufferModel; }
100 static inline MessageModel *messageModel() { return instance()->_messageModel; }
101 static inline AbstractMessageProcessor *messageProcessor() { return instance()->_messageProcessor; }
102 static inline SignalProxy *signalProxy() { return instance()->_signalProxy; }
104 static inline ClientBacklogManager *backlogManager() { return instance()->_backlogManager; }
105 static inline ClientIrcListHelper *ircListHelper() { return instance()->_ircListHelper; }
106 static inline ClientBufferViewManager *bufferViewManager() { return instance()->_bufferViewManager; }
107 static inline ClientUserInputHandler *inputHandler() { return instance()->_inputHandler; }
109 static AccountId currentCoreAccount();
111 static bool isConnected();
112 static bool isSynced();
113 static inline bool internalCore() { return instance()->_internalCore; }
115 static void userInput(const BufferInfo &bufferInfo, const QString &message);
117 static void setBufferLastSeenMsg(BufferId id, const MsgId &msgId); // this is synced to core and other clients
118 static void removeBuffer(BufferId id);
119 static void renameBuffer(BufferId bufferId, const QString &newName);
120 static void mergeBuffersPermanently(BufferId bufferId1, BufferId bufferId2);
121 static void purgeKnownBufferIds();
123 static void logMessage(QtMsgType type, const char *msg);
124 static inline const QString &debugLog() { return instance()->_debugLogBuffer; }
126 static inline void registerClientSyncer(ClientSyncer *syncer) { emit instance()->newClientSyncer(syncer); }
129 void requestNetworkStates();
131 void showConfigWizard(const QVariantMap &coredata);
135 void coreConnectionStateChanged(bool);
137 //! The identity with the given ID has been newly created in core and client.
138 /** \param id The ID of the newly created identity.
140 void identityCreated(IdentityId id);
142 //! The identity with the given ID has been removed.
143 /** Upon emitting this signal, the identity is already gone from the core, and it will
144 * be deleted from the client immediately afterwards, so connected slots need to clean
146 * \param id The ID of the identity about to be removed.
148 void identityRemoved(IdentityId id);
150 //! Sent to the core when an identity shall be created. Should not be used elsewhere.
151 void requestCreateIdentity(const Identity &, const QVariantMap &);
152 //! Sent to the core when an identity shall be removed. Should not be used elsewhere.
153 void requestRemoveIdentity(IdentityId);
155 void networkCreated(NetworkId id);
156 void networkRemoved(NetworkId id);
158 void requestCreateNetwork(const NetworkInfo &info, const QStringList &persistentChannels = QStringList());
159 void requestRemoveNetwork(NetworkId);
161 void newClientSyncer(ClientSyncer *);
163 void logUpdated(const QString &msg);
166 void disconnectFromCore();
168 void bufferRemoved(BufferId bufferId);
169 void bufferRenamed(BufferId bufferId, const QString &newName);
170 void buffersPermanentlyMerged(BufferId bufferId1, BufferId bufferId2);
173 void disconnectedFromCore();
175 void recvMessage(const Message &message);
176 void recvStatusMsg(QString network, QString message);
178 void networkDestroyed();
179 void coreIdentityCreated(const Identity &);
180 void coreIdentityRemoved(IdentityId);
181 void coreNetworkCreated(NetworkId);
182 void coreNetworkRemoved(NetworkId);
184 void setConnectedToCore(AccountId id, QIODevice *socket = 0);
185 void setSyncedToCore();
186 void requestInitialBacklog();
187 void createDefaultBufferView();
190 Client(QObject *parent = 0);
194 static void addNetwork(Network *);
195 static void setCurrentCoreAccount(AccountId);
196 static inline BufferSyncer *bufferSyncer() { return instance()->_bufferSyncer; }
198 static QPointer<Client> instanceptr;
200 SignalProxy * _signalProxy;
201 AbstractUi * _mainUi;
202 NetworkModel * _networkModel;
203 BufferModel * _bufferModel;
204 BufferSyncer * _bufferSyncer;
205 ClientBacklogManager *_backlogManager;
206 ClientBufferViewManager *_bufferViewManager;
207 ClientIrcListHelper *_ircListHelper;
208 ClientUserInputHandler *_inputHandler;
210 MessageModel *_messageModel;
211 AbstractMessageProcessor *_messageProcessor;
213 ClientMode clientMode;
215 bool _connectedToCore, _syncedToCore;
218 QHash<NetworkId, Network *> _networks;
219 QHash<IdentityId, Identity *> _identities;
221 static AccountId _currentCoreAccount;
223 QString _debugLogBuffer;
224 QTextStream _debugLog;
226 friend class ClientSyncer;