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