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
43 class ClientBacklogManager;
52 class Client : public QObject {
56 static Client *instance();
57 static void destroy();
58 static void init(AbstractUi *);
60 static QList<BufferInfo> allBufferInfos();
61 static QList<Buffer *> buffers();
62 static Buffer *buffer(BufferId bufferUid);
63 static Buffer *buffer(BufferInfo);
64 static inline Buffer *monitorBuffer() { return instance()->_monitorBuffer; }
66 static QList<NetworkId> networkIds();
67 static const Network * network(NetworkId);
69 static QList<IdentityId> identityIds();
70 static const Identity * identity(IdentityId);
72 //! Request creation of an identity with the given data.
73 /** The request will be sent to the core, and will be propagated back to all the clients
74 * with a new valid IdentityId.
75 * \param identity The identity template for the new identity. It does not need to have a valid ID.
77 static void createIdentity(const Identity &identity);
79 //! Request update of an identity with the given data.
80 /** The request will be sent to the core, and will be propagated back to all the clients.
81 * \param identity The identity to be updated.
83 static void updateIdentity(const Identity &identity);
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 SignalProxy *signalProxy() { return instance()->_signalProxy; }
98 static inline ClientBacklogManager *backlogManager() { return instance()->_backlogManager; }
100 static AccountId currentCoreAccount();
102 static AbstractUiMsg *layoutMsg(const Message &);
104 static bool isConnected();
105 static bool isSynced();
107 static void userInput(BufferInfo bufferInfo, QString message);
109 enum ClientMode { LocalCore, RemoteCore };
111 static void checkForHighlight(Message &msg);
112 static void setBufferLastSeenMsg(BufferId id, const MsgId &msgId); // this is synced to core and other clients
113 static void removeBuffer(BufferId id);
116 void sendInput(BufferInfo, QString message);
117 void showBuffer(Buffer *);
118 void bufferUpdated(BufferInfo bufferInfo);
119 void backlogReceived(Buffer *, QList<Message>);
120 void requestBacklog(BufferInfo, QVariant, QVariant);
121 void requestNetworkStates();
123 void showConfigWizard(const QVariantMap &coredata);
127 void coreConnectionStateChanged(bool);
129 //! The identity with the given ID has been newly created in core and client.
130 /** \param id The ID of the newly created identity.
132 void identityCreated(IdentityId id);
134 //! The identity with the given ID has been removed.
135 /** Upon emitting this signal, the identity is already gone from the core, and it will
136 * be deleted from the client immediately afterwards, so connected slots need to clean
138 * \param id The ID of the identity about to be removed.
140 void identityRemoved(IdentityId id);
142 //! Sent to the core when an identity shall be created. Should not be used elsewhere.
143 void requestCreateIdentity(const Identity &);
144 //! Sent to the core when an identity shall be updated. Should not be used elsewhere.
145 void requestUpdateIdentity(const Identity &);
146 //! Sent to the core when an identity shall be removed. Should not be used elsewhere.
147 void requestRemoveIdentity(IdentityId);
149 void networkCreated(NetworkId id);
150 void networkRemoved(NetworkId id);
152 void requestCreateNetwork(const NetworkInfo &info);
153 void requestUpdateNetwork(const NetworkInfo &info);
154 void requestRemoveNetwork(NetworkId);
157 //void selectBuffer(Buffer *);
159 void disconnectFromCore();
161 void setCoreConfiguration(const QVariantMap &settings);
163 void bufferRemoved(BufferId bufferId);
164 void bufferRenamed(BufferId bufferId, const QString &newName);
167 //void coreSocketError(QAbstractSocket::SocketError);
169 //void networkConnected(NetworkId);
170 //void networkDisconnected(NetworkId);
172 void recvMessage(const Message &message);
173 void recvStatusMsg(QString network, QString message);
174 void receiveBacklog(BufferId bufferId, const QVariantList &msgs);
175 void updateBufferInfo(BufferInfo);
176 void updateLastSeenMsg(BufferId id, const MsgId &msgId);
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();
191 Client(QObject *parent = 0);
195 static void addNetwork(Network *);
196 static void setCurrentCoreAccount(AccountId);
197 static inline BufferSyncer *bufferSyncer() { return instance()->_bufferSyncer; }
199 Buffer *statusBuffer(const NetworkId &networkid) const;
201 static QPointer<Client> instanceptr;
203 QPointer<QIODevice> socket;
205 SignalProxy * _signalProxy;
207 NetworkModel * _networkModel;
208 BufferModel * _bufferModel;
209 BufferSyncer * _bufferSyncer;
210 ClientBacklogManager *_backlogManager;
212 ClientMode clientMode;
214 bool _connectedToCore, _syncedToCore;
216 QHash<BufferId, Buffer *> _buffers;
217 QHash<NetworkId, Buffer *> _statusBuffers; // fast lookup
218 QHash<NetworkId, Network *> _networks;
219 QHash<IdentityId, Identity *> _identities;
221 Buffer *_monitorBuffer;
224 QList<Buffer *> layoutQueue;
226 static AccountId _currentCoreAccount;
228 friend class ClientSyncer;