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 ClientAliasManager;
46 class ClientBacklogManager;
47 class ClientBufferViewManager;
48 class ClientIrcListHelper;
50 class ClientUserInputHandler;
56 class Client : public QObject {
65 static bool instanceExists();
66 static Client *instance();
67 static void destroy();
68 static void init(AbstractUi *);
69 static AbstractUi *mainUi();
71 static QList<NetworkId> networkIds();
72 static const Network * network(NetworkId);
74 static QList<IdentityId> identityIds();
75 static const Identity *identity(IdentityId);
77 //! Request creation of an identity with the given data.
78 /** The request will be sent to the core, and will be propagated back to all the clients
79 * with a new valid IdentityId.
80 * \param identity The identity template for the new identity. It does not need to have a valid ID.
82 static void createIdentity(const CertIdentity &identity);
84 //! Request update of an identity with the given data.
85 /** The request will be sent to the core, and will be propagated back to all the clients.
86 * \param id The identity to be updated.
87 * \param serializedData The identity's content (cf. SyncableObject::toVariantMap())
89 static void updateIdentity(IdentityId id, const QVariantMap &serializedData);
91 //! Request removal of the identity with the given ID from the core (and all the clients, of course).
92 /** \param id The ID of the identity to be removed.
94 static void removeIdentity(IdentityId id);
96 static void createNetwork(const NetworkInfo &info, const QStringList &persistentChannels = QStringList());
97 static void updateNetwork(const NetworkInfo &info);
98 static void removeNetwork(NetworkId id);
100 static inline NetworkModel *networkModel() { return instance()->_networkModel; }
101 static inline BufferModel *bufferModel() { return instance()->_bufferModel; }
102 static inline MessageModel *messageModel() { return instance()->_messageModel; }
103 static inline AbstractMessageProcessor *messageProcessor() { return instance()->_messageProcessor; }
104 static inline SignalProxy *signalProxy() { return instance()->_signalProxy; }
106 static inline ClientAliasManager *aliasManager() { return instance()->_aliasManager; }
107 static inline ClientBacklogManager *backlogManager() { return instance()->_backlogManager; }
108 static inline ClientIrcListHelper *ircListHelper() { return instance()->_ircListHelper; }
109 static inline ClientBufferViewManager *bufferViewManager() { return instance()->_bufferViewManager; }
110 static inline ClientUserInputHandler *inputHandler() { return instance()->_inputHandler; }
112 static AccountId currentCoreAccount();
114 static bool isConnected();
115 static bool isSynced();
116 static inline bool internalCore() { return instance()->_internalCore; }
118 static void userInput(const BufferInfo &bufferInfo, const QString &message);
120 static void setBufferLastSeenMsg(BufferId id, const MsgId &msgId); // this is synced to core and other clients
121 static void removeBuffer(BufferId id);
122 static void renameBuffer(BufferId bufferId, const QString &newName);
123 static void mergeBuffersPermanently(BufferId bufferId1, BufferId bufferId2);
124 static void purgeKnownBufferIds();
126 static void logMessage(QtMsgType type, const char *msg);
127 static inline const QString &debugLog() { return instance()->_debugLogBuffer; }
129 static inline void registerClientSyncer(ClientSyncer *syncer) { emit instance()->newClientSyncer(syncer); }
132 void requestNetworkStates();
134 void showConfigWizard(const QVariantMap &coredata);
138 void coreConnectionStateChanged(bool);
140 //! The identity with the given ID has been newly created in core and client.
141 /** \param id The ID of the newly created identity.
143 void identityCreated(IdentityId id);
145 //! The identity with the given ID has been removed.
146 /** Upon emitting this signal, the identity is already gone from the core, and it will
147 * be deleted from the client immediately afterwards, so connected slots need to clean
149 * \param id The ID of the identity about to be removed.
151 void identityRemoved(IdentityId id);
153 //! Sent to the core when an identity shall be created. Should not be used elsewhere.
154 void requestCreateIdentity(const Identity &, const QVariantMap &);
155 //! Sent to the core when an identity shall be removed. Should not be used elsewhere.
156 void requestRemoveIdentity(IdentityId);
158 void networkCreated(NetworkId id);
159 void networkRemoved(NetworkId id);
161 void requestCreateNetwork(const NetworkInfo &info, const QStringList &persistentChannels = QStringList());
162 void requestRemoveNetwork(NetworkId);
164 void newClientSyncer(ClientSyncer *);
166 void logUpdated(const QString &msg);
169 void disconnectFromCore();
171 void bufferRemoved(BufferId bufferId);
172 void bufferRenamed(BufferId bufferId, const QString &newName);
173 void buffersPermanentlyMerged(BufferId bufferId1, BufferId bufferId2);
176 void disconnectedFromCore();
178 void recvMessage(const Message &message);
179 void recvStatusMsg(QString network, QString message);
181 void networkDestroyed();
182 void coreIdentityCreated(const Identity &);
183 void coreIdentityRemoved(IdentityId);
184 void coreNetworkCreated(NetworkId);
185 void coreNetworkRemoved(NetworkId);
187 void setConnectedToCore(AccountId id, QIODevice *socket = 0);
188 void setSyncedToCore();
189 void requestInitialBacklog();
190 void createDefaultBufferView();
192 void sendBufferedUserInput();
195 Client(QObject *parent = 0);
199 static void addNetwork(Network *);
200 static void setCurrentCoreAccount(AccountId);
201 static inline BufferSyncer *bufferSyncer() { return instance()->_bufferSyncer; }
203 static QPointer<Client> instanceptr;
205 SignalProxy * _signalProxy;
206 AbstractUi * _mainUi;
207 NetworkModel * _networkModel;
208 BufferModel * _bufferModel;
209 BufferSyncer * _bufferSyncer;
210 ClientAliasManager *_aliasManager;
211 ClientBacklogManager *_backlogManager;
212 ClientBufferViewManager *_bufferViewManager;
213 ClientIrcListHelper *_ircListHelper;
214 ClientUserInputHandler *_inputHandler;
216 MessageModel *_messageModel;
217 AbstractMessageProcessor *_messageProcessor;
219 ClientMode clientMode;
221 bool _connectedToCore, _syncedToCore;
224 QHash<NetworkId, Network *> _networks;
225 QHash<IdentityId, Identity *> _identities;
227 static AccountId _currentCoreAccount;
229 QString _debugLogBuffer;
230 QTextStream _debugLog;
232 QList<QPair<BufferInfo, QString> > _userInputBuffer;
234 friend class ClientSyncer;