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
47 class Client : public QObject {
51 static Client *instance();
52 static void destroy();
53 static void init(AbstractUi *);
55 static QList<Network *> networks();
56 static Network *network(uint networkid);
58 static QList<BufferInfo> allBufferInfos();
59 static QList<Buffer *> buffers();
60 static Buffer *buffer(uint bufferUid);
61 static Buffer *buffer(BufferInfo);
63 static QList<IdentityId> identityIds();
64 static const Identity * identity(IdentityId);
66 //! Request creation of an identity with the given data.
67 /** The request will be sent to the core, and will be propagated back to all the clients
68 * with a new valid IdentityId.
69 * \param identity The identity template for the new identity. It does not need to have a valid ID.
71 static void createIdentity(const Identity &identity);
73 //! Request update 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 * \param identity The identity to be updated.
77 static void updateIdentity(const Identity &identity);
79 //! Request removal of the identity with the given ID from the core (and all the clients, of course).
80 /** \param id The ID of the identity to be removed.
82 static void removeIdentity(IdentityId id);
84 static NetworkModel *networkModel();
85 static BufferModel *bufferModel();
86 static NickModel *nickModel();
87 static SignalProxy *signalProxy();
89 static AbstractUiMsg *layoutMsg(const Message &);
91 static bool isConnected();
93 static void fakeInput(uint bufferUid, QString message);
94 static void fakeInput(BufferInfo bufferInfo, QString message);
96 static void storeSessionData(const QString &key, const QVariant &data);
97 static QVariant retrieveSessionData(const QString &key, const QVariant &def = QVariant());
98 static QStringList sessionDataKeys();
100 enum ClientMode { LocalCore, RemoteCore };
103 void sendInput(BufferInfo, QString message);
104 void showBuffer(Buffer *);
105 void bufferUpdated(BufferInfo bufferInfo);
106 void backlogReceived(Buffer *, QList<Message>);
107 void requestBacklog(BufferInfo, QVariant, QVariant);
108 void requestNetworkStates();
110 void recvPartialItem(uint avail, uint size);
111 void coreConnectionError(QString errorMsg);
112 void coreConnectionMsg(const QString &msg);
113 void coreConnectionProgress(uint part, uint total);
115 void showConfigWizard(const QVariantMap &coredata);
119 void coreConnectionStateChanged(bool);
121 void sessionDataChanged(const QString &key);
122 void sessionDataChanged(const QString &key, const QVariant &data);
123 void sendSessionData(const QString &key, const QVariant &data);
125 //! The identity with the given ID has been newly created in core and client.
126 /** \param id The ID of the newly created identity.
128 void identityCreated(IdentityId id);
130 //! The identity with the given ID has been removed.
131 /** Upon emitting this signal, the identity is already gone from the core, and it will
132 * be deleted from the client immediately afterwards, so connected slots need to clean
134 * \param id The ID of the identity about to be removed.
136 void identityRemoved(IdentityId id);
138 //! Sent to the core when an identity shall be created. Should not be used elsewhere.
139 void requestCreateIdentity(const Identity &);
140 //! Sent to the core when an identity shall be updated. Should not be used elsewhere.
141 void requestUpdateIdentity(const Identity &);
142 //! Sent to the core when an identity shall be removed. Should not be used elsewhere.
143 void requestRemoveIdentity(IdentityId);
146 //void selectBuffer(Buffer *);
147 //void connectToLocalCore();
148 void connectToCore(const QVariantMap &);
149 void disconnectFromCore();
151 void setCoreConfiguration(const QVariantMap &settings);
154 void recvCoreState(const QVariant &state);
155 void recvSessionData(const QString &key, const QVariant &data);
157 void coreSocketError(QAbstractSocket::SocketError);
159 void coreSocketConnected();
160 void coreSocketDisconnected();
162 void userInput(BufferInfo, QString);
164 void networkConnected(uint);
165 void networkDisconnected(uint);
167 void updateCoreConnectionProgress();
168 void recvMessage(const Message &message);
169 void recvStatusMsg(QString network, QString message);
170 void recvBacklogData(BufferInfo, QVariantList, bool);
171 void updateBufferInfo(BufferInfo);
175 void bufferDestroyed();
176 void networkDestroyed();
177 void coreIdentityCreated(const Identity &);
178 void coreIdentityRemoved(IdentityId);
181 Client(QObject *parent = 0);
185 void syncToCore(const QVariant &coreState);
187 static QPointer<Client> instanceptr;
189 QPointer<QIODevice> socket;
190 QPointer<SignalProxy> _signalProxy;
191 QPointer<AbstractUi> mainUi;
192 QPointer<NetworkModel> _networkModel;
193 QPointer<BufferModel> _bufferModel;
194 QPointer<NickModel> _nickModel;
196 ClientMode clientMode;
199 bool connectedToCore;
201 QVariantMap coreConnectionInfo;
202 QHash<BufferId, Buffer *> _buffers;
203 QHash<NetworkId, Network *> _network;
204 QHash<IdentityId, Identity *> _identities;
207 QList<Buffer *> layoutQueue;
209 QVariantMap sessionData;