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
51 class Client : public QObject {
55 static Client *instance();
56 static void destroy();
57 static void init(AbstractUi *);
59 static QList<BufferInfo> allBufferInfos();
60 static QList<Buffer *> buffers();
61 static Buffer *buffer(BufferId bufferUid);
62 static Buffer *buffer(BufferInfo);
63 static inline Buffer *monitorBuffer() { return instance()->_monitorBuffer; }
65 Buffer *statusBuffer(const NetworkId &networkid) const;
67 static QList<NetworkId> networkIds();
68 static const Network * network(NetworkId);
70 static QList<IdentityId> identityIds();
71 static const Identity * identity(IdentityId);
73 //! Request creation 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 * with a new valid IdentityId.
76 * \param identity The identity template for the new identity. It does not need to have a valid ID.
78 static void createIdentity(const Identity &identity);
80 //! Request update of an identity with the given data.
81 /** The request will be sent to the core, and will be propagated back to all the clients.
82 * \param identity The identity to be updated.
84 static void updateIdentity(const Identity &identity);
86 //! Request removal of the identity with the given ID from the core (and all the clients, of course).
87 /** \param id The ID of the identity to be removed.
89 static void removeIdentity(IdentityId id);
91 static void createNetwork(const NetworkInfo &info);
92 static void updateNetwork(const NetworkInfo &info);
93 static void removeNetwork(NetworkId id);
95 static inline NetworkModel *networkModel() { return instance()->_networkModel; }
96 static inline BufferModel *bufferModel() { return instance()->_bufferModel; }
97 static inline SignalProxy *signalProxy() { return instance()->_signalProxy; }
99 static AccountId currentCoreAccount();
101 static AbstractUiMsg *layoutMsg(const Message &);
103 static bool isConnected();
104 static bool isSynced();
106 static void userInput(BufferInfo bufferInfo, QString message);
108 enum ClientMode { LocalCore, RemoteCore };
110 static void checkForHighlight(Message &msg);
111 static void setBufferLastSeen(BufferId id, const QDateTime &seen); // this is synced to core and other clients
112 static void removeBuffer(BufferId id);
115 void sendInput(BufferInfo, QString message);
116 void showBuffer(Buffer *);
117 void bufferUpdated(BufferInfo bufferInfo);
118 void backlogReceived(Buffer *, QList<Message>);
119 void requestBacklog(BufferInfo, QVariant, QVariant);
120 void requestNetworkStates();
122 void showConfigWizard(const QVariantMap &coredata);
126 void coreConnectionStateChanged(bool);
128 //! The identity with the given ID has been newly created in core and client.
129 /** \param id The ID of the newly created identity.
131 void identityCreated(IdentityId id);
133 //! The identity with the given ID has been removed.
134 /** Upon emitting this signal, the identity is already gone from the core, and it will
135 * be deleted from the client immediately afterwards, so connected slots need to clean
137 * \param id The ID of the identity about to be removed.
139 void identityRemoved(IdentityId id);
141 //! Sent to the core when an identity shall be created. Should not be used elsewhere.
142 void requestCreateIdentity(const Identity &);
143 //! Sent to the core when an identity shall be updated. Should not be used elsewhere.
144 void requestUpdateIdentity(const Identity &);
145 //! Sent to the core when an identity shall be removed. Should not be used elsewhere.
146 void requestRemoveIdentity(IdentityId);
148 void networkCreated(NetworkId id);
149 void networkRemoved(NetworkId id);
151 void requestCreateNetwork(const NetworkInfo &info);
152 void requestUpdateNetwork(const NetworkInfo &info);
153 void requestRemoveNetwork(NetworkId);
156 //void selectBuffer(Buffer *);
158 void disconnectFromCore();
160 void setCoreConfiguration(const QVariantMap &settings);
162 void bufferRemoved(BufferId bufferId);
163 void bufferRenamed(BufferId bufferId, const QString &newName);
166 //void coreSocketError(QAbstractSocket::SocketError);
168 //void networkConnected(NetworkId);
169 //void networkDisconnected(NetworkId);
171 void recvMessage(const Message &message);
172 void recvStatusMsg(QString network, QString message);
173 void recvBacklogData(BufferInfo, QVariantList, bool);
174 void updateBufferInfo(BufferInfo);
175 void updateLastSeen(BufferId id, const QDateTime &lastSeen);
179 void bufferDestroyed();
180 void networkDestroyed();
181 void coreIdentityCreated(const Identity &);
182 void coreIdentityRemoved(IdentityId);
183 void coreNetworkCreated(NetworkId);
184 void coreNetworkRemoved(NetworkId);
186 void setConnectedToCore(QIODevice *socket, AccountId id);
187 void setSyncedToCore();
190 Client(QObject *parent = 0);
194 static void addNetwork(Network *);
195 static void setCurrentCoreAccount(AccountId);
196 static inline BufferSyncer *bufferSyncer() { return instance()->_bufferSyncer; }
198 static QPointer<Client> instanceptr;
200 QPointer<QIODevice> socket;
202 SignalProxy * _signalProxy;
204 NetworkModel * _networkModel;
205 BufferModel * _bufferModel;
206 BufferSyncer * _bufferSyncer;
208 ClientMode clientMode;
210 bool _connectedToCore, _syncedToCore;
212 QHash<BufferId, Buffer *> _buffers;
213 QHash<NetworkId, Buffer *> _statusBuffers; // fast lookup
214 QHash<NetworkId, Network *> _networks;
215 QHash<IdentityId, Identity *> _identities;
217 Buffer *_monitorBuffer;
220 QList<Buffer *> layoutQueue;
222 static AccountId _currentCoreAccount;
224 friend class ClientSyncer;