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);
61 static Buffer *monitorBuffer();
63 static QList<NetworkId> networkIds();
64 static const Network * network(NetworkId);
66 static QList<IdentityId> identityIds();
67 static const Identity * identity(IdentityId);
69 //! Request creation of an identity with the given data.
70 /** The request will be sent to the core, and will be propagated back to all the clients
71 * with a new valid IdentityId.
72 * \param identity The identity template for the new identity. It does not need to have a valid ID.
74 static void createIdentity(const Identity &identity);
76 //! Request update of an identity with the given data.
77 /** The request will be sent to the core, and will be propagated back to all the clients.
78 * \param identity The identity to be updated.
80 static void updateIdentity(const Identity &identity);
82 //! Request removal of the identity with the given ID from the core (and all the clients, of course).
83 /** \param id The ID of the identity to be removed.
85 static void removeIdentity(IdentityId id);
87 static void createNetwork(const NetworkInfo &info);
88 static void updateNetwork(const NetworkInfo &info);
89 static void removeNetwork(NetworkId id);
91 static NetworkModel *networkModel();
92 static BufferModel *bufferModel();
93 static SignalProxy *signalProxy();
95 static AbstractUiMsg *layoutMsg(const Message &);
97 static bool isConnected();
98 static bool isSynced();
100 static void userInput(BufferInfo bufferInfo, QString message);
102 enum ClientMode { LocalCore, RemoteCore };
105 void sendInput(BufferInfo, QString message);
106 void showBuffer(Buffer *);
107 void bufferUpdated(BufferInfo bufferInfo);
108 void backlogReceived(Buffer *, QList<Message>);
109 void requestBacklog(BufferInfo, QVariant, QVariant);
110 void requestNetworkStates();
112 void showConfigWizard(const QVariantMap &coredata);
116 void coreConnectionStateChanged(bool);
118 //! The identity with the given ID has been newly created in core and client.
119 /** \param id The ID of the newly created identity.
121 void identityCreated(IdentityId id);
123 //! The identity with the given ID has been removed.
124 /** Upon emitting this signal, the identity is already gone from the core, and it will
125 * be deleted from the client immediately afterwards, so connected slots need to clean
127 * \param id The ID of the identity about to be removed.
129 void identityRemoved(IdentityId id);
131 //! Sent to the core when an identity shall be created. Should not be used elsewhere.
132 void requestCreateIdentity(const Identity &);
133 //! Sent to the core when an identity shall be updated. Should not be used elsewhere.
134 void requestUpdateIdentity(const Identity &);
135 //! Sent to the core when an identity shall be removed. Should not be used elsewhere.
136 void requestRemoveIdentity(IdentityId);
138 void networkCreated(NetworkId id);
139 void networkRemoved(NetworkId id);
141 void requestCreateNetwork(const NetworkInfo &info);
142 void requestUpdateNetwork(const NetworkInfo &info);
143 void requestRemoveNetwork(NetworkId);
146 //void selectBuffer(Buffer *);
148 void setConnectedToCore(QIODevice *socket);
149 void setSyncedToCore();
150 void disconnectFromCore();
152 void setCoreConfiguration(const QVariantMap &settings);
155 //void coreSocketError(QAbstractSocket::SocketError);
157 //void networkConnected(NetworkId);
158 //void networkDisconnected(NetworkId);
160 void recvMessage(const Message &message);
161 void recvStatusMsg(QString network, QString message);
162 void recvBacklogData(BufferInfo, QVariantList, bool);
163 void updateBufferInfo(BufferInfo);
167 void bufferDestroyed();
168 void networkDestroyed();
169 void coreIdentityCreated(const Identity &);
170 void coreIdentityRemoved(IdentityId);
171 void coreNetworkCreated(NetworkId);
172 void coreNetworkRemoved(NetworkId);
175 Client(QObject *parent = 0);
179 static void addNetwork(Network *);
181 static QPointer<Client> instanceptr;
183 QPointer<QIODevice> socket;
184 QPointer<SignalProxy> _signalProxy;
185 QPointer<AbstractUi> mainUi;
186 QPointer<NetworkModel> _networkModel;
187 QPointer<BufferModel> _bufferModel;
189 ClientMode clientMode;
191 bool _connectedToCore, _syncedToCore;
193 QHash<BufferId, Buffer *> _buffers;
194 QHash<NetworkId, Network *> _networks;
195 QHash<IdentityId, Identity *> _identities;
197 Buffer *_monitorBuffer;
200 QList<Buffer *> layoutQueue;
202 friend class ClientSyncer;