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
49 class Client : public QObject {
53 static Client *instance();
54 static void destroy();
55 static void init(AbstractUi *);
57 static QList<BufferInfo> allBufferInfos();
58 static QList<Buffer *> buffers();
59 static Buffer *buffer(BufferId bufferUid);
60 static Buffer *buffer(BufferInfo);
62 static QList<NetworkId> networkIds();
63 static const Network * network(NetworkId);
65 static QList<IdentityId> identityIds();
66 static const Identity * identity(IdentityId);
68 //! Request creation of an identity with the given data.
69 /** The request will be sent to the core, and will be propagated back to all the clients
70 * with a new valid IdentityId.
71 * \param identity The identity template for the new identity. It does not need to have a valid ID.
73 static void createIdentity(const Identity &identity);
75 //! Request update of an identity with the given data.
76 /** The request will be sent to the core, and will be propagated back to all the clients.
77 * \param identity The identity to be updated.
79 static void updateIdentity(const Identity &identity);
81 //! Request removal of the identity with the given ID from the core (and all the clients, of course).
82 /** \param id The ID of the identity to be removed.
84 static void removeIdentity(IdentityId id);
86 static void addNetwork(NetworkId id);
87 static void addNetwork(Network *);
90 static NetworkModel *networkModel();
91 static BufferModel *bufferModel();
92 static NickModel *nickModel();
93 static SignalProxy *signalProxy();
95 static AbstractUiMsg *layoutMsg(const Message &);
97 static bool isConnected();
98 static bool isSynced();
100 static void fakeInput(BufferId bufferUid, QString message);
101 static void fakeInput(BufferInfo bufferInfo, QString message);
103 static void storeSessionData(const QString &key, const QVariant &data);
104 static QVariant retrieveSessionData(const QString &key, const QVariant &def = QVariant());
105 static QStringList sessionDataKeys();
107 enum ClientMode { LocalCore, RemoteCore };
110 void sendInput(BufferInfo, QString message);
111 void showBuffer(Buffer *);
112 void bufferUpdated(BufferInfo bufferInfo);
113 void backlogReceived(Buffer *, QList<Message>);
114 void requestBacklog(BufferInfo, QVariant, QVariant);
115 void requestNetworkStates();
117 void showConfigWizard(const QVariantMap &coredata);
121 void coreConnectionStateChanged(bool);
123 void sessionDataChanged(const QString &key);
124 void sessionDataChanged(const QString &key, const QVariant &data);
125 void sendSessionData(const QString &key, const QVariant &data);
127 //! The identity with the given ID has been newly created in core and client.
128 /** \param id The ID of the newly created identity.
130 void identityCreated(IdentityId id);
132 //! The identity with the given ID has been removed.
133 /** Upon emitting this signal, the identity is already gone from the core, and it will
134 * be deleted from the client immediately afterwards, so connected slots need to clean
136 * \param id The ID of the identity about to be removed.
138 void identityRemoved(IdentityId id);
140 //! Sent to the core when an identity shall be created. Should not be used elsewhere.
141 void requestCreateIdentity(const Identity &);
142 //! Sent to the core when an identity shall be updated. Should not be used elsewhere.
143 void requestUpdateIdentity(const Identity &);
144 //! Sent to the core when an identity shall be removed. Should not be used elsewhere.
145 void requestRemoveIdentity(IdentityId);
147 void networkAdded(NetworkId id);
150 //void selectBuffer(Buffer *);
152 void setConnectedToCore(QIODevice *socket);
153 void setSyncedToCore();
154 void disconnectFromCore();
156 void setCoreConfiguration(const QVariantMap &settings);
160 void recvSessionData(const QString &key, const QVariant &data);
162 //void coreSocketError(QAbstractSocket::SocketError);
164 void userInput(BufferInfo, QString);
166 //void networkConnected(NetworkId);
167 //void networkDisconnected(NetworkId);
169 void recvMessage(const Message &message);
170 void recvStatusMsg(QString network, QString message);
171 void recvBacklogData(BufferInfo, QVariantList, bool);
172 void updateBufferInfo(BufferInfo);
176 void bufferDestroyed();
177 void networkDestroyed();
178 void coreIdentityCreated(const Identity &);
179 void coreIdentityRemoved(IdentityId);
182 Client(QObject *parent = 0);
186 void syncToCore(const QVariantMap &sessionState);
188 static QPointer<Client> instanceptr;
190 QPointer<QIODevice> socket;
191 QPointer<SignalProxy> _signalProxy;
192 QPointer<AbstractUi> mainUi;
193 QPointer<NetworkModel> _networkModel;
194 QPointer<BufferModel> _bufferModel;
195 QPointer<NickModel> _nickModel;
197 ClientMode clientMode;
199 bool _connectedToCore, _syncedToCore;
201 QHash<BufferId, Buffer *> _buffers;
202 QHash<NetworkId, Network *> _networks;
203 QHash<IdentityId, Identity *> _identities;
206 QList<Buffer *> layoutQueue;
208 QVariantMap sessionData;
210 friend class ClientSyncer;