1 /***************************************************************************
2 * Copyright (C) 2005-07 by the Quassel IRC Team *
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
45 class Client : public QObject {
49 static Client *instance();
50 static void destroy();
51 static void init(AbstractUi *);
53 static QList<NetworkInfo *> networkInfos();
54 static NetworkInfo *networkInfo(uint networkid);
56 static QList<BufferInfo> allBufferInfos();
57 static QList<Buffer *> buffers();
58 static Buffer *buffer(uint bufferUid);
59 static Buffer *buffer(BufferInfo);
60 static BufferInfo statusBufferInfo(QString net);
61 static BufferInfo bufferInfo(QString net, QString buf);
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 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 bufferSelected(Buffer *);
104 void bufferUpdated(Buffer *);
105 void bufferActivity(Buffer::ActivityLevel, Buffer *);
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 networkInfoDestroyed();
177 void ircChannelAdded(QString);
178 void coreIdentityCreated(const Identity &);
179 void coreIdentityRemoved(IdentityId);
182 Client(QObject *parent = 0);
186 void syncToCore(const QVariant &coreState);
188 static QPointer<Client> instanceptr;
190 QPointer<QIODevice> socket;
191 QPointer<SignalProxy> _signalProxy;
192 QPointer<AbstractUi> mainUi;
193 QPointer<NetworkModel> _networkModel;
195 ClientMode clientMode;
198 bool connectedToCore;
200 QVariantMap coreConnectionInfo;
201 QHash<BufferId, Buffer *> _buffers;
202 QHash<NetworkId, NetworkInfo *> _networkInfo;
203 QHash<IdentityId, Identity *> _identities;
206 QList<Buffer *> layoutQueue;
208 QVariantMap sessionData;