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
50 class Client : public QObject {
54 static Client *instance();
55 static void destroy();
56 static void init(AbstractUi *);
58 static QList<BufferInfo> allBufferInfos();
59 static QList<Buffer *> buffers();
60 static Buffer *buffer(BufferId bufferUid);
61 static Buffer *buffer(BufferInfo);
62 static Buffer *monitorBuffer();
64 static QList<NetworkId> networkIds();
65 static const Network * network(NetworkId);
67 static QList<IdentityId> identityIds();
68 static const Identity * identity(IdentityId);
70 //! Request creation of an identity with the given data.
71 /** The request will be sent to the core, and will be propagated back to all the clients
72 * with a new valid IdentityId.
73 * \param identity The identity template for the new identity. It does not need to have a valid ID.
75 static void createIdentity(const Identity &identity);
77 //! Request update of an identity with the given data.
78 /** The request will be sent to the core, and will be propagated back to all the clients.
79 * \param identity The identity to be updated.
81 static void updateIdentity(const Identity &identity);
83 //! Request removal of the identity with the given ID from the core (and all the clients, of course).
84 /** \param id The ID of the identity to be removed.
86 static void removeIdentity(IdentityId id);
88 static void createNetwork(const NetworkInfo &info);
89 static void updateNetwork(const NetworkInfo &info);
90 static void removeNetwork(NetworkId id);
92 static NetworkModel *networkModel();
93 static BufferModel *bufferModel();
94 static NickModel *nickModel();
95 static SignalProxy *signalProxy();
97 static AbstractUiMsg *layoutMsg(const Message &);
99 static bool isConnected();
100 static bool isSynced();
102 static void userInput(BufferInfo bufferInfo, QString message);
104 static void storeSessionData(const QString &key, const QVariant &data);
105 static QVariant retrieveSessionData(const QString &key, const QVariant &def = QVariant());
106 static QStringList sessionDataKeys();
108 static void disconnectFromNetwork(NetworkId);
110 enum ClientMode { LocalCore, RemoteCore };
113 void sendInput(BufferInfo, QString message);
114 void showBuffer(Buffer *);
115 void bufferUpdated(BufferInfo bufferInfo);
116 void backlogReceived(Buffer *, QList<Message>);
117 void requestBacklog(BufferInfo, QVariant, QVariant);
118 void requestNetworkStates();
120 void showConfigWizard(const QVariantMap &coredata);
124 void coreConnectionStateChanged(bool);
126 void sessionDataChanged(const QString &key);
127 void sessionDataChanged(const QString &key, const QVariant &data);
128 void sendSessionData(const QString &key, const QVariant &data);
130 //! The identity with the given ID has been newly created in core and client.
131 /** \param id The ID of the newly created identity.
133 void identityCreated(IdentityId id);
135 //! The identity with the given ID has been removed.
136 /** Upon emitting this signal, the identity is already gone from the core, and it will
137 * be deleted from the client immediately afterwards, so connected slots need to clean
139 * \param id The ID of the identity about to be removed.
141 void identityRemoved(IdentityId id);
143 //! Sent to the core when an identity shall be created. Should not be used elsewhere.
144 void requestCreateIdentity(const Identity &);
145 //! Sent to the core when an identity shall be updated. Should not be used elsewhere.
146 void requestUpdateIdentity(const Identity &);
147 //! Sent to the core when an identity shall be removed. Should not be used elsewhere.
148 void requestRemoveIdentity(IdentityId);
150 void networkCreated(NetworkId id);
151 void networkRemoved(NetworkId id);
153 void requestCreateNetwork(const NetworkInfo &info);
154 void requestUpdateNetwork(const NetworkInfo &info);
155 void requestRemoveNetwork(const NetworkInfo &info);
158 //void selectBuffer(Buffer *);
160 void setConnectedToCore(QIODevice *socket);
161 void setSyncedToCore();
162 void disconnectFromCore();
164 void setCoreConfiguration(const QVariantMap &settings);
167 void recvSessionData(const QString &key, const QVariant &data);
169 //void coreSocketError(QAbstractSocket::SocketError);
171 //void networkConnected(NetworkId);
172 //void networkDisconnected(NetworkId);
174 void recvMessage(const Message &message);
175 void recvStatusMsg(QString network, QString message);
176 void recvBacklogData(BufferInfo, QVariantList, bool);
177 void updateBufferInfo(BufferInfo);
181 void bufferDestroyed();
182 void networkDestroyed();
183 void coreIdentityCreated(const Identity &);
184 void coreIdentityRemoved(IdentityId);
187 Client(QObject *parent = 0);
191 static void addNetwork(Network *);
193 static QPointer<Client> instanceptr;
195 QPointer<QIODevice> socket;
196 QPointer<SignalProxy> _signalProxy;
197 QPointer<AbstractUi> mainUi;
198 QPointer<NetworkModel> _networkModel;
199 QPointer<BufferModel> _bufferModel;
200 QPointer<NickModel> _nickModel;
202 ClientMode clientMode;
204 bool _connectedToCore, _syncedToCore;
206 QHash<BufferId, Buffer *> _buffers;
207 QHash<NetworkId, Network *> _networks;
208 QHash<IdentityId, Identity *> _identities;
210 Buffer *_monitorBuffer;
213 QList<Buffer *> layoutQueue;
215 QVariantMap sessionData;
217 friend class ClientSyncer;