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;
44 class ClientBacklogManager;
45 class ClientIrcListHelper;
46 class BufferViewManager;
52 class Client : public QObject {
61 static Client *instance();
62 static void destroy();
63 static void init(AbstractUi *);
65 static QList<NetworkId> networkIds();
66 static const Network * network(NetworkId);
68 static QList<IdentityId> identityIds();
69 static const Identity * identity(IdentityId);
71 //! Request creation of an identity with the given data.
72 /** The request will be sent to the core, and will be propagated back to all the clients
73 * with a new valid IdentityId.
74 * \param identity The identity template for the new identity. It does not need to have a valid ID.
76 static void createIdentity(const Identity &identity);
78 //! Request update 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 * \param id The identity to be updated.
81 * \param serializedData The identity's content (cf. SyncableObject::toVariantMap())
83 static void updateIdentity(IdentityId id, const QVariantMap &serializedData);
85 //! Request removal of the identity with the given ID from the core (and all the clients, of course).
86 /** \param id The ID of the identity to be removed.
88 static void removeIdentity(IdentityId id);
90 static void createNetwork(const NetworkInfo &info);
91 static void updateNetwork(const NetworkInfo &info);
92 static void removeNetwork(NetworkId id);
94 static inline NetworkModel *networkModel() { return instance()->_networkModel; }
95 static inline BufferModel *bufferModel() { return instance()->_bufferModel; }
96 static inline MessageModel *messageModel() { return instance()->_messageModel; }
97 static inline AbstractMessageProcessor *messageProcessor() { return instance()->_messageProcessor; }
98 static inline SignalProxy *signalProxy() { return instance()->_signalProxy; }
100 static inline ClientBacklogManager *backlogManager() { return instance()->_backlogManager; }
101 static inline ClientIrcListHelper *ircListHelper() { return instance()->_ircListHelper; }
102 static inline BufferViewManager *bufferViewManager() { return instance()->_bufferViewManager; }
104 static AccountId currentCoreAccount();
106 static bool isConnected();
107 static bool isSynced();
109 static void userInput(BufferInfo bufferInfo, QString message);
111 static void setBufferLastSeenMsg(BufferId id, const MsgId &msgId); // this is synced to core and other clients
112 static void removeBuffer(BufferId id);
115 void sendInput(BufferInfo, QString message);
116 void requestNetworkStates();
118 void showConfigWizard(const QVariantMap &coredata);
121 void securedConnection();
123 void coreConnectionStateChanged(bool);
125 //! The identity with the given ID has been newly created in core and client.
126 /** \param id The ID of the newly created identity.
128 void identityCreated(IdentityId id);
130 //! The identity with the given ID has been removed.
131 /** Upon emitting this signal, the identity is already gone from the core, and it will
132 * be deleted from the client immediately afterwards, so connected slots need to clean
134 * \param id The ID of the identity about to be removed.
136 void identityRemoved(IdentityId id);
138 //! Sent to the core when an identity shall be created. Should not be used elsewhere.
139 void requestCreateIdentity(const Identity &);
140 //! Sent to the core when an identity shall be removed. Should not be used elsewhere.
141 void requestRemoveIdentity(IdentityId);
143 void networkCreated(NetworkId id);
144 void networkRemoved(NetworkId id);
146 void requestCreateNetwork(const NetworkInfo &info);
147 void requestRemoveNetwork(NetworkId);
150 //void selectBuffer(Buffer *);
152 void disconnectFromCore();
154 void setCoreConfiguration(const QVariantMap &settings);
156 void bufferRemoved(BufferId bufferId);
157 void bufferRenamed(BufferId bufferId, const QString &newName);
160 //void coreSocketError(QAbstractSocket::SocketError);
162 //void networkConnected(NetworkId);
163 //void networkDisconnected(NetworkId);
165 void recvMessage(const Message &message);
166 void recvStatusMsg(QString network, QString message);
168 void networkDestroyed();
169 void coreIdentityCreated(const Identity &);
170 void coreIdentityRemoved(IdentityId);
171 void coreNetworkCreated(NetworkId);
172 void coreNetworkRemoved(NetworkId);
174 void setConnectedToCore(QIODevice *socket, AccountId id);
175 void setSyncedToCore();
176 void setSecuredConnection();
180 Client(QObject *parent = 0);
184 static void addNetwork(Network *);
185 static void setCurrentCoreAccount(AccountId);
186 static inline BufferSyncer *bufferSyncer() { return instance()->_bufferSyncer; }
188 static QPointer<Client> instanceptr;
190 QPointer<QIODevice> socket;
192 SignalProxy * _signalProxy;
194 NetworkModel * _networkModel;
195 BufferModel * _bufferModel;
196 BufferSyncer * _bufferSyncer;
197 ClientBacklogManager *_backlogManager;
198 BufferViewManager *_bufferViewManager;
199 ClientIrcListHelper *_ircListHelper;
201 MessageModel *_messageModel;
202 AbstractMessageProcessor *_messageProcessor;
204 ClientMode clientMode;
206 bool _connectedToCore, _syncedToCore;
208 QHash<NetworkId, Network *> _networks;
209 QHash<IdentityId, Identity *> _identities;
211 static AccountId _currentCoreAccount;
213 friend class ClientSyncer;