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
46 class Client : public QObject {
50 static Client *instance();
51 static void destroy();
52 static void init(AbstractUi *);
54 static QList<Network *> networks();
55 static Network *network(uint networkid);
57 static QList<BufferInfo> allBufferInfos();
58 static QList<Buffer *> buffers();
59 static Buffer *buffer(uint bufferUid);
60 static Buffer *buffer(BufferInfo);
62 static QList<IdentityId> identityIds();
63 static const Identity * identity(IdentityId);
65 //! Request creation of an identity with the given data.
66 /** The request will be sent to the core, and will be propagated back to all the clients
67 * with a new valid IdentityId.
68 * \param identity The identity template for the new identity. It does not need to have a valid ID.
70 static void createIdentity(const Identity &identity);
72 //! Request update 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 * \param identity The identity to be updated.
76 static void updateIdentity(const Identity &identity);
78 //! Request removal of the identity with the given ID from the core (and all the clients, of course).
79 /** \param id The ID of the identity to be removed.
81 static void removeIdentity(IdentityId id);
83 static NetworkModel *networkModel();
84 static BufferModel *bufferModel();
85 static SignalProxy *signalProxy();
87 static AbstractUiMsg *layoutMsg(const Message &);
89 static bool isConnected();
91 static void fakeInput(uint bufferUid, QString message);
92 static void fakeInput(BufferInfo bufferInfo, QString message);
94 static void storeSessionData(const QString &key, const QVariant &data);
95 static QVariant retrieveSessionData(const QString &key, const QVariant &def = QVariant());
96 static QStringList sessionDataKeys();
98 enum ClientMode { LocalCore, RemoteCore };
101 void sendInput(BufferInfo, QString message);
102 void showBuffer(Buffer *);
103 void bufferUpdated(BufferInfo bufferInfo);
104 void backlogReceived(Buffer *, QList<Message>);
105 void requestBacklog(BufferInfo, QVariant, QVariant);
106 void requestNetworkStates();
108 void recvPartialItem(uint avail, uint size);
109 void coreConnectionError(QString errorMsg);
110 void coreConnectionMsg(const QString &msg);
111 void coreConnectionProgress(uint part, uint total);
113 void showConfigWizard(const QVariantMap &coredata);
117 void coreConnectionStateChanged(bool);
119 void sessionDataChanged(const QString &key);
120 void sessionDataChanged(const QString &key, const QVariant &data);
121 void sendSessionData(const QString &key, const QVariant &data);
123 //! The identity with the given ID has been newly created in core and client.
124 /** \param id The ID of the newly created identity.
126 void identityCreated(IdentityId id);
128 //! The identity with the given ID has been removed.
129 /** Upon emitting this signal, the identity is already gone from the core, and it will
130 * be deleted from the client immediately afterwards, so connected slots need to clean
132 * \param id The ID of the identity about to be removed.
134 void identityRemoved(IdentityId id);
136 //! Sent to the core when an identity shall be created. Should not be used elsewhere.
137 void requestCreateIdentity(const Identity &);
138 //! Sent to the core when an identity shall be updated. Should not be used elsewhere.
139 void requestUpdateIdentity(const Identity &);
140 //! Sent to the core when an identity shall be removed. Should not be used elsewhere.
141 void requestRemoveIdentity(IdentityId);
144 //void selectBuffer(Buffer *);
145 //void connectToLocalCore();
146 void connectToCore(const QVariantMap &);
147 void disconnectFromCore();
149 void setCoreConfiguration(const QVariantMap &settings);
152 void recvCoreState(const QVariant &state);
153 void recvSessionData(const QString &key, const QVariant &data);
155 void coreSocketError(QAbstractSocket::SocketError);
157 void coreSocketConnected();
158 void coreSocketDisconnected();
160 void userInput(BufferInfo, QString);
162 void networkConnected(uint);
163 void networkDisconnected(uint);
165 void updateCoreConnectionProgress();
166 void recvMessage(const Message &message);
167 void recvStatusMsg(QString network, QString message);
168 void recvBacklogData(BufferInfo, QVariantList, bool);
169 void updateBufferInfo(BufferInfo);
173 void bufferDestroyed();
174 void networkDestroyed();
175 void coreIdentityCreated(const Identity &);
176 void coreIdentityRemoved(IdentityId);
179 Client(QObject *parent = 0);
183 void syncToCore(const QVariant &coreState);
185 static QPointer<Client> instanceptr;
187 QPointer<QIODevice> socket;
188 QPointer<SignalProxy> _signalProxy;
189 QPointer<AbstractUi> mainUi;
190 QPointer<NetworkModel> _networkModel;
191 QPointer<BufferModel> _bufferModel;
193 ClientMode clientMode;
196 bool connectedToCore;
198 QVariantMap coreConnectionInfo;
199 QHash<BufferId, Buffer *> _buffers;
200 QHash<NetworkId, Network *> _network;
201 QHash<IdentityId, Identity *> _identities;
204 QList<Buffer *> layoutQueue;
206 QVariantMap sessionData;