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();
112 static void userInput(BufferInfo bufferInfo, QString message);
114 static void setBufferLastSeenMsg(BufferId id, const MsgId &msgId); // this is synced to core and other clients
115 static void removeBuffer(BufferId id);
116 static void renameBuffer(BufferId bufferId, const QString &newName);
117 static void mergeBuffersPermanently(BufferId bufferId1, BufferId bufferId2);
119 static void logMessage(QtMsgType type, const char *msg);
120 static inline const QString &debugLog() { return instance()->_debugLogBuffer; }
123 void sendInput(BufferInfo, QString message);
124 void requestNetworkStates();
126 void showConfigWizard(const QVariantMap &coredata);
129 void securedConnection();
131 void coreConnectionStateChanged(bool);
133 //! The identity with the given ID has been newly created in core and client.
134 /** \param id The ID of the newly created identity.
136 void identityCreated(IdentityId id);
138 //! The identity with the given ID has been removed.
139 /** Upon emitting this signal, the identity is already gone from the core, and it will
140 * be deleted from the client immediately afterwards, so connected slots need to clean
142 * \param id The ID of the identity about to be removed.
144 void identityRemoved(IdentityId id);
146 //! Sent to the core when an identity shall be created. Should not be used elsewhere.
147 void requestCreateIdentity(const Identity &, const QVariantMap &);
148 //! Sent to the core when an identity shall be removed. Should not be used elsewhere.
149 void requestRemoveIdentity(IdentityId);
151 void networkCreated(NetworkId id);
152 void networkRemoved(NetworkId id);
154 void requestCreateNetwork(const NetworkInfo &info);
155 void requestRemoveNetwork(NetworkId);
157 void newClientSyncer(ClientSyncer *);
159 void logUpdated(const QString &msg);
162 //void selectBuffer(Buffer *);
164 void disconnectFromCore();
166 void bufferRemoved(BufferId bufferId);
167 void bufferRenamed(BufferId bufferId, const QString &newName);
168 void buffersPermanentlyMerged(BufferId bufferId1, BufferId bufferId2);
171 void disconnectedFromCore();
173 void recvMessage(const Message &message);
174 void recvStatusMsg(QString network, QString message);
176 void networkDestroyed();
177 void coreIdentityCreated(const Identity &);
178 void coreIdentityRemoved(IdentityId);
179 void coreNetworkCreated(NetworkId);
180 void coreNetworkRemoved(NetworkId);
182 void setConnectedToCore(AccountId id, QIODevice *socket = 0);
183 void setSyncedToCore();
184 void requestInitialBacklog();
185 void setSecuredConnection();
189 Client(QObject *parent = 0);
193 static void addNetwork(Network *);
194 static void setCurrentCoreAccount(AccountId);
195 static inline BufferSyncer *bufferSyncer() { return instance()->_bufferSyncer; }
197 static QPointer<Client> instanceptr;
199 SignalProxy * _signalProxy;
200 AbstractUi * _mainUi;
201 NetworkModel * _networkModel;
202 BufferModel * _bufferModel;
203 BufferSyncer * _bufferSyncer;
204 ClientBacklogManager *_backlogManager;
205 BufferViewManager *_bufferViewManager;
206 ClientIrcListHelper *_ircListHelper;
208 MessageModel *_messageModel;
209 AbstractMessageProcessor *_messageProcessor;
211 ClientMode clientMode;
213 bool _connectedToCore, _syncedToCore;
215 QHash<NetworkId, Network *> _networks;
216 QHash<IdentityId, Identity *> _identities;
218 static AccountId _currentCoreAccount;
220 QString _debugLogBuffer;
221 QTextStream _debugLog;
223 friend class ClientSyncer;