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 ClientIrcListHelper;
48 class BufferViewManager;
54 class Client : public QObject {
63 static Client *instance();
64 static void destroy();
65 static void init(AbstractUi *);
66 static AbstractUi *mainUi();
68 static QList<NetworkId> networkIds();
69 static const Network * network(NetworkId);
71 static QList<IdentityId> identityIds();
72 static const Identity *identity(IdentityId);
74 //! Request creation of an identity with the given data.
75 /** The request will be sent to the core, and will be propagated back to all the clients
76 * with a new valid IdentityId.
77 * \param identity The identity template for the new identity. It does not need to have a valid ID.
79 static void createIdentity(const CertIdentity &identity);
81 //! Request update 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 * \param id The identity to be updated.
84 * \param serializedData The identity's content (cf. SyncableObject::toVariantMap())
86 static void updateIdentity(IdentityId id, const QVariantMap &serializedData);
88 //! Request removal of the identity with the given ID from the core (and all the clients, of course).
89 /** \param id The ID of the identity to be removed.
91 static void removeIdentity(IdentityId id);
93 static void createNetwork(const NetworkInfo &info, const QStringList &persistentChannels = QStringList());
94 static void updateNetwork(const NetworkInfo &info);
95 static void removeNetwork(NetworkId id);
97 static inline NetworkModel *networkModel() { return instance()->_networkModel; }
98 static inline BufferModel *bufferModel() { return instance()->_bufferModel; }
99 static inline MessageModel *messageModel() { return instance()->_messageModel; }
100 static inline AbstractMessageProcessor *messageProcessor() { return instance()->_messageProcessor; }
101 static inline SignalProxy *signalProxy() { return instance()->_signalProxy; }
103 static inline ClientBacklogManager *backlogManager() { return instance()->_backlogManager; }
104 static inline ClientIrcListHelper *ircListHelper() { return instance()->_ircListHelper; }
105 static inline BufferViewManager *bufferViewManager() { return instance()->_bufferViewManager; }
107 static AccountId currentCoreAccount();
109 static bool isConnected();
110 static bool isSynced();
111 static inline bool internalCore() { return instance()->_internalCore; }
113 static void userInput(BufferInfo bufferInfo, QString message);
115 static void setBufferLastSeenMsg(BufferId id, const MsgId &msgId); // this is synced to core and other clients
116 static void removeBuffer(BufferId id);
117 static void renameBuffer(BufferId bufferId, const QString &newName);
118 static void mergeBuffersPermanently(BufferId bufferId1, BufferId bufferId2);
120 static void logMessage(QtMsgType type, const char *msg);
121 static inline const QString &debugLog() { return instance()->_debugLogBuffer; }
123 static inline void registerClientSyncer(ClientSyncer *syncer) { emit instance()->newClientSyncer(syncer); }
126 void sendInput(BufferInfo, QString message);
127 void requestNetworkStates();
129 void showConfigWizard(const QVariantMap &coredata);
133 void coreConnectionStateChanged(bool);
135 //! The identity with the given ID has been newly created in core and client.
136 /** \param id The ID of the newly created identity.
138 void identityCreated(IdentityId id);
140 //! The identity with the given ID has been removed.
141 /** Upon emitting this signal, the identity is already gone from the core, and it will
142 * be deleted from the client immediately afterwards, so connected slots need to clean
144 * \param id The ID of the identity about to be removed.
146 void identityRemoved(IdentityId id);
148 //! Sent to the core when an identity shall be created. Should not be used elsewhere.
149 void requestCreateIdentity(const Identity &, const QVariantMap &);
150 //! Sent to the core when an identity shall be removed. Should not be used elsewhere.
151 void requestRemoveIdentity(IdentityId);
153 void networkCreated(NetworkId id);
154 void networkRemoved(NetworkId id);
156 void requestCreateNetwork(const NetworkInfo &info, const QStringList &persistentChannels = QStringList());
157 void requestRemoveNetwork(NetworkId);
159 void newClientSyncer(ClientSyncer *);
161 void logUpdated(const QString &msg);
164 //void selectBuffer(Buffer *);
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();
188 void createDefaultIdentity();
189 void createDefaultNetworks();
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 BufferViewManager *_bufferViewManager;
209 ClientIrcListHelper *_ircListHelper;
211 MessageModel *_messageModel;
212 AbstractMessageProcessor *_messageProcessor;
214 ClientMode clientMode;
216 bool _connectedToCore, _syncedToCore;
219 QHash<NetworkId, Network *> _networks;
220 QHash<IdentityId, Identity *> _identities;
222 static AccountId _currentCoreAccount;
224 QString _debugLogBuffer;
225 QTextStream _debugLog;
227 friend class ClientSyncer;