1 /***************************************************************************
2 * Copyright (C) 2005-08 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);
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);
132 void securedConnection();
134 void coreConnectionStateChanged(bool);
136 //! The identity with the given ID has been newly created in core and client.
137 /** \param id The ID of the newly created identity.
139 void identityCreated(IdentityId id);
141 //! The identity with the given ID has been removed.
142 /** Upon emitting this signal, the identity is already gone from the core, and it will
143 * be deleted from the client immediately afterwards, so connected slots need to clean
145 * \param id The ID of the identity about to be removed.
147 void identityRemoved(IdentityId id);
149 //! Sent to the core when an identity shall be created. Should not be used elsewhere.
150 void requestCreateIdentity(const Identity &, const QVariantMap &);
151 //! Sent to the core when an identity shall be removed. Should not be used elsewhere.
152 void requestRemoveIdentity(IdentityId);
154 void networkCreated(NetworkId id);
155 void networkRemoved(NetworkId id);
157 void requestCreateNetwork(const NetworkInfo &info);
158 void requestRemoveNetwork(NetworkId);
160 void newClientSyncer(ClientSyncer *);
162 void logUpdated(const QString &msg);
165 //void selectBuffer(Buffer *);
167 void disconnectFromCore();
169 void bufferRemoved(BufferId bufferId);
170 void bufferRenamed(BufferId bufferId, const QString &newName);
171 void buffersPermanentlyMerged(BufferId bufferId1, BufferId bufferId2);
174 void disconnectedFromCore();
176 void recvMessage(const Message &message);
177 void recvStatusMsg(QString network, QString message);
179 void networkDestroyed();
180 void coreIdentityCreated(const Identity &);
181 void coreIdentityRemoved(IdentityId);
182 void coreNetworkCreated(NetworkId);
183 void coreNetworkRemoved(NetworkId);
185 void setConnectedToCore(AccountId id, QIODevice *socket = 0);
186 void setSyncedToCore();
187 void requestInitialBacklog();
188 void createDefautBufferView();
189 void createDefaultIdentity();
190 void setSecuredConnection();
194 Client(QObject *parent = 0);
198 static void addNetwork(Network *);
199 static void setCurrentCoreAccount(AccountId);
200 static inline BufferSyncer *bufferSyncer() { return instance()->_bufferSyncer; }
202 static QPointer<Client> instanceptr;
204 SignalProxy * _signalProxy;
205 AbstractUi * _mainUi;
206 NetworkModel * _networkModel;
207 BufferModel * _bufferModel;
208 BufferSyncer * _bufferSyncer;
209 ClientBacklogManager *_backlogManager;
210 BufferViewManager *_bufferViewManager;
211 ClientIrcListHelper *_ircListHelper;
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;