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;
44 class BufferViewManager;
53 class Client : public QObject {
57 static Client *instance();
58 static void destroy();
59 static void init(AbstractUi *);
61 static QList<BufferInfo> allBufferInfos();
62 static QList<Buffer *> buffers();
63 static Buffer *buffer(BufferId bufferUid);
64 static Buffer *buffer(BufferInfo);
65 static inline Buffer *monitorBuffer() { return instance()->_monitorBuffer; }
67 static QList<NetworkId> networkIds();
68 static const Network * network(NetworkId);
70 static QList<IdentityId> identityIds();
71 static const Identity * identity(IdentityId);
73 //! Request creation of an identity with the given data.
74 /** The request will be sent to the core, and will be propagated back to all the clients
75 * with a new valid IdentityId.
76 * \param identity The identity template for the new identity. It does not need to have a valid ID.
78 static void createIdentity(const Identity &identity);
80 //! Request update of an identity with the given data.
81 /** The request will be sent to the core, and will be propagated back to all the clients.
82 * \param identity The identity to be updated.
84 static void updateIdentity(const Identity &identity);
86 //! Request removal of the identity with the given ID from the core (and all the clients, of course).
87 /** \param id The ID of the identity to be removed.
89 static void removeIdentity(IdentityId id);
91 static void createNetwork(const NetworkInfo &info);
92 static void updateNetwork(const NetworkInfo &info);
93 static void removeNetwork(NetworkId id);
95 static inline NetworkModel *networkModel() { return instance()->_networkModel; }
96 static inline BufferModel *bufferModel() { return instance()->_bufferModel; }
97 static inline SignalProxy *signalProxy() { return instance()->_signalProxy; }
99 static inline ClientBacklogManager *backlogManager() { return instance()->_backlogManager; }
100 static inline BufferViewManager *bufferViewManager() { return instance()->_bufferViewManager; }
102 static AccountId currentCoreAccount();
104 static AbstractUiMsg *layoutMsg(const Message &);
106 static bool isConnected();
107 static bool isSynced();
109 static void userInput(BufferInfo bufferInfo, QString message);
111 enum ClientMode { LocalCore, RemoteCore };
113 static void checkForHighlight(Message &msg);
114 static void setBufferLastSeenMsg(BufferId id, const MsgId &msgId); // this is synced to core and other clients
115 static void removeBuffer(BufferId id);
118 void sendInput(BufferInfo, QString message);
119 void showBuffer(Buffer *);
120 void bufferUpdated(BufferInfo bufferInfo);
121 void backlogReceived(Buffer *, QList<Message>);
122 void requestBacklog(BufferInfo, QVariant, QVariant);
123 void requestNetworkStates();
124 void messageReceived(const Message &msg);
126 void showConfigWizard(const QVariantMap &coredata);
130 void coreConnectionStateChanged(bool);
132 //! The identity with the given ID has been newly created in core and client.
133 /** \param id The ID of the newly created identity.
135 void identityCreated(IdentityId id);
137 //! The identity with the given ID has been removed.
138 /** Upon emitting this signal, the identity is already gone from the core, and it will
139 * be deleted from the client immediately afterwards, so connected slots need to clean
141 * \param id The ID of the identity about to be removed.
143 void identityRemoved(IdentityId id);
145 //! Sent to the core when an identity shall be created. Should not be used elsewhere.
146 void requestCreateIdentity(const Identity &);
147 //! Sent to the core when an identity shall be updated. Should not be used elsewhere.
148 void requestUpdateIdentity(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);
179 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();
194 Client(QObject *parent = 0);
198 static void addNetwork(Network *);
199 static void setCurrentCoreAccount(AccountId);
200 static inline BufferSyncer *bufferSyncer() { return instance()->_bufferSyncer; }
202 Buffer *statusBuffer(const NetworkId &networkid) const;
204 static QPointer<Client> instanceptr;
206 QPointer<QIODevice> socket;
208 SignalProxy * _signalProxy;
210 NetworkModel * _networkModel;
211 BufferModel * _bufferModel;
212 BufferSyncer * _bufferSyncer;
213 ClientBacklogManager *_backlogManager;
214 BufferViewManager *_bufferViewManager;
216 ClientMode clientMode;
218 bool _connectedToCore, _syncedToCore;
220 QHash<BufferId, Buffer *> _buffers;
221 QHash<NetworkId, Buffer *> _statusBuffers; // fast lookup
222 QHash<NetworkId, Network *> _networks;
223 QHash<IdentityId, Identity *> _identities;
225 Buffer *_monitorBuffer;
228 QList<Buffer *> layoutQueue;
230 static AccountId _currentCoreAccount;
232 friend class ClientSyncer;