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 "buffer.h" // needed for activity lvl
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<BufferInfo> allBufferInfos();
66 static QList<Buffer *> buffers();
67 // static Buffer *buffer(BufferId bufferUid);
68 static Buffer *buffer(BufferInfo);
70 static QList<NetworkId> networkIds();
71 static const Network * network(NetworkId);
73 static QList<IdentityId> identityIds();
74 static const Identity * identity(IdentityId);
76 //! Request creation of an identity with the given data.
77 /** The request will be sent to the core, and will be propagated back to all the clients
78 * with a new valid IdentityId.
79 * \param identity The identity template for the new identity. It does not need to have a valid ID.
81 static void createIdentity(const Identity &identity);
83 //! Request update of an identity with the given data.
84 /** The request will be sent to the core, and will be propagated back to all the clients.
85 * \param id The identity to be updated.
86 * \param serializedData The identity's content (cf. SyncableObject::toVariantMap())
88 static void updateIdentity(IdentityId id, const QVariantMap &serializedData);
90 //! Request removal of the identity with the given ID from the core (and all the clients, of course).
91 /** \param id The ID of the identity to be removed.
93 static void removeIdentity(IdentityId id);
95 static void createNetwork(const NetworkInfo &info);
96 static void updateNetwork(const NetworkInfo &info);
97 static void removeNetwork(NetworkId id);
99 static inline NetworkModel *networkModel() { return instance()->_networkModel; }
100 static inline BufferModel *bufferModel() { return instance()->_bufferModel; }
101 static inline MessageModel *messageModel() { return instance()->_messageModel; }
102 static inline AbstractMessageProcessor *messageProcessor() { return instance()->_messageProcessor; }
103 static inline SignalProxy *signalProxy() { return instance()->_signalProxy; }
105 static inline ClientBacklogManager *backlogManager() { return instance()->_backlogManager; }
106 static inline ClientIrcListHelper *ircListHelper() { return instance()->_ircListHelper; }
107 static inline BufferViewManager *bufferViewManager() { return instance()->_bufferViewManager; }
109 static AccountId currentCoreAccount();
111 static bool isConnected();
112 static bool isSynced();
114 static void userInput(BufferInfo bufferInfo, QString message);
116 static void setBufferLastSeenMsg(BufferId id, const MsgId &msgId); // this is synced to core and other clients
117 static void removeBuffer(BufferId id);
120 void sendInput(BufferInfo, QString message);
121 void showBuffer(Buffer *);
122 void bufferUpdated(BufferInfo bufferInfo);
123 void backlogReceived(Buffer *, QList<Message>);
124 void requestBacklog(BufferInfo, QVariant, QVariant);
125 void requestNetworkStates();
127 void showConfigWizard(const QVariantMap &coredata);
130 void securedConnection();
132 void coreConnectionStateChanged(bool);
134 //! The identity with the given ID has been newly created in core and client.
135 /** \param id The ID of the newly created identity.
137 void identityCreated(IdentityId id);
139 //! The identity with the given ID has been removed.
140 /** Upon emitting this signal, the identity is already gone from the core, and it will
141 * be deleted from the client immediately afterwards, so connected slots need to clean
143 * \param id The ID of the identity about to be removed.
145 void identityRemoved(IdentityId id);
147 //! Sent to the core when an identity shall be created. Should not be used elsewhere.
148 void requestCreateIdentity(const Identity &);
149 //! Sent to the core when an identity shall be removed. Should not be used elsewhere.
150 void requestRemoveIdentity(IdentityId);
152 void networkCreated(NetworkId id);
153 void networkRemoved(NetworkId id);
155 void requestCreateNetwork(const NetworkInfo &info);
156 void requestUpdateNetwork(const NetworkInfo &info);
157 void requestRemoveNetwork(NetworkId);
160 //void selectBuffer(Buffer *);
162 void disconnectFromCore();
164 void setCoreConfiguration(const QVariantMap &settings);
166 void bufferRemoved(BufferId bufferId);
167 void bufferRenamed(BufferId bufferId, const QString &newName);
170 //void coreSocketError(QAbstractSocket::SocketError);
172 //void networkConnected(NetworkId);
173 //void networkDisconnected(NetworkId);
175 void recvMessage(const Message &message);
176 void recvStatusMsg(QString network, QString message);
177 void receiveBacklog(BufferId bufferId, const QVariantList &msgs);
178 void updateBufferInfo(BufferInfo);
180 void bufferDestroyed();
181 void networkDestroyed();
182 void coreIdentityCreated(const Identity &);
183 void coreIdentityRemoved(IdentityId);
184 void coreNetworkCreated(NetworkId);
185 void coreNetworkRemoved(NetworkId);
187 void setConnectedToCore(QIODevice *socket, AccountId id);
188 void setSyncedToCore();
189 void setSecuredConnection();
193 Client(QObject *parent = 0);
197 static void addNetwork(Network *);
198 static void setCurrentCoreAccount(AccountId);
199 static inline BufferSyncer *bufferSyncer() { return instance()->_bufferSyncer; }
201 Buffer *statusBuffer(const NetworkId &networkid) const;
203 static QPointer<Client> instanceptr;
205 QPointer<QIODevice> socket;
207 SignalProxy * _signalProxy;
209 NetworkModel * _networkModel;
210 BufferModel * _bufferModel;
211 BufferSyncer * _bufferSyncer;
212 ClientBacklogManager *_backlogManager;
213 BufferViewManager *_bufferViewManager;
214 ClientIrcListHelper *_ircListHelper;
216 MessageModel *_messageModel;
217 AbstractMessageProcessor *_messageProcessor;
219 ClientMode clientMode;
221 bool _connectedToCore, _syncedToCore;
223 QHash<BufferId, Buffer *> _buffers;
224 QHash<NetworkId, Buffer *> _statusBuffers; // fast lookup
225 QHash<NetworkId, Network *> _networks;
226 QHash<IdentityId, Identity *> _identities;
228 static AccountId _currentCoreAccount;
230 friend class ClientSyncer;