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);
69 static inline Buffer *monitorBuffer() { return instance()->_monitorBuffer; }
71 static QList<NetworkId> networkIds();
72 static const Network * network(NetworkId);
74 static QList<IdentityId> identityIds();
75 static const Identity * identity(IdentityId);
77 //! Request creation of an identity with the given data.
78 /** The request will be sent to the core, and will be propagated back to all the clients
79 * with a new valid IdentityId.
80 * \param identity The identity template for the new identity. It does not need to have a valid ID.
82 static void createIdentity(const Identity &identity);
84 //! Request update of an identity with the given data.
85 /** The request will be sent to the core, and will be propagated back to all the clients.
86 * \param identity The identity to be updated.
88 static void updateIdentity(const Identity &identity);
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 updated. Should not be used elsewhere.
150 void requestUpdateIdentity(const Identity &);
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 requestUpdateNetwork(const NetworkInfo &info);
159 void requestRemoveNetwork(NetworkId);
162 //void selectBuffer(Buffer *);
164 void disconnectFromCore();
166 void setCoreConfiguration(const QVariantMap &settings);
168 void bufferRemoved(BufferId bufferId);
169 void bufferRenamed(BufferId bufferId, const QString &newName);
172 //void coreSocketError(QAbstractSocket::SocketError);
174 //void networkConnected(NetworkId);
175 //void networkDisconnected(NetworkId);
177 void recvMessage(const Message &message);
178 void recvStatusMsg(QString network, QString message);
179 void receiveBacklog(BufferId bufferId, const QVariantList &msgs);
180 void updateBufferInfo(BufferInfo);
181 void updateLastSeenMsg(BufferId id, const MsgId &msgId);
183 void bufferDestroyed();
184 void networkDestroyed();
185 void coreIdentityCreated(const Identity &);
186 void coreIdentityRemoved(IdentityId);
187 void coreNetworkCreated(NetworkId);
188 void coreNetworkRemoved(NetworkId);
190 void setConnectedToCore(QIODevice *socket, AccountId id);
191 void setSyncedToCore();
192 void setSecuredConnection();
196 Client(QObject *parent = 0);
200 static void addNetwork(Network *);
201 static void setCurrentCoreAccount(AccountId);
202 static inline BufferSyncer *bufferSyncer() { return instance()->_bufferSyncer; }
204 Buffer *statusBuffer(const NetworkId &networkid) const;
206 static QPointer<Client> instanceptr;
208 QPointer<QIODevice> socket;
210 SignalProxy * _signalProxy;
212 NetworkModel * _networkModel;
213 BufferModel * _bufferModel;
214 BufferSyncer * _bufferSyncer;
215 ClientBacklogManager *_backlogManager;
216 BufferViewManager *_bufferViewManager;
217 ClientIrcListHelper *_ircListHelper;
219 MessageModel *_messageModel;
220 AbstractMessageProcessor *_messageProcessor;
222 ClientMode clientMode;
224 bool _connectedToCore, _syncedToCore;
226 QHash<BufferId, Buffer *> _buffers;
227 QHash<NetworkId, Buffer *> _statusBuffers; // fast lookup
228 QHash<NetworkId, Network *> _networks;
229 QHash<IdentityId, Identity *> _identities;
231 Buffer *_monitorBuffer;
233 static AccountId _currentCoreAccount;
235 friend class ClientSyncer;