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
43 class ClientBacklogManager;
44 class ClientIrcListHelper;
45 class BufferViewManager;
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 static QList<NetworkId> networkIds();
66 static const Network * network(NetworkId);
68 static QList<IdentityId> identityIds();
69 static const Identity * identity(IdentityId);
71 //! Request creation of an identity with the given data.
72 /** The request will be sent to the core, and will be propagated back to all the clients
73 * with a new valid IdentityId.
74 * \param identity The identity template for the new identity. It does not need to have a valid ID.
76 static void createIdentity(const Identity &identity);
78 //! Request update of an identity with the given data.
79 /** The request will be sent to the core, and will be propagated back to all the clients.
80 * \param identity The identity to be updated.
82 static void updateIdentity(const Identity &identity);
84 //! Request removal of the identity with the given ID from the core (and all the clients, of course).
85 /** \param id The ID of the identity to be removed.
87 static void removeIdentity(IdentityId id);
89 static void createNetwork(const NetworkInfo &info);
90 static void updateNetwork(const NetworkInfo &info);
91 static void removeNetwork(NetworkId id);
93 static inline NetworkModel *networkModel() { return instance()->_networkModel; }
94 static inline BufferModel *bufferModel() { return instance()->_bufferModel; }
95 static inline MessageModel *messageModel() { return instance()->_messageModel; }
96 static inline SignalProxy *signalProxy() { return instance()->_signalProxy; }
98 static inline ClientBacklogManager *backlogManager() { return instance()->_backlogManager; }
99 static inline ClientIrcListHelper *ircListHelper() { return instance()->_ircListHelper; }
100 static inline BufferViewManager *bufferViewManager() { return instance()->_bufferViewManager; }
102 static AccountId currentCoreAccount();
104 static bool isConnected();
105 static bool isSynced();
107 static void userInput(BufferInfo bufferInfo, QString message);
109 enum ClientMode { LocalCore, RemoteCore };
111 static void checkForHighlight(Message &msg);
112 static void setBufferLastSeenMsg(BufferId id, const MsgId &msgId); // this is synced to core and other clients
113 static void removeBuffer(BufferId id);
116 void sendInput(BufferInfo, QString message);
117 void showBuffer(Buffer *);
118 void bufferUpdated(BufferInfo bufferInfo);
119 void backlogReceived(Buffer *, QList<Message>);
120 void requestBacklog(BufferInfo, QVariant, QVariant);
121 void requestNetworkStates();
123 void showConfigWizard(const QVariantMap &coredata);
126 void securedConnection();
128 void coreConnectionStateChanged(bool);
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(NetworkId);
158 //void selectBuffer(Buffer *);
160 void disconnectFromCore();
162 void setCoreConfiguration(const QVariantMap &settings);
164 void bufferRemoved(BufferId bufferId);
165 void bufferRenamed(BufferId bufferId, const QString &newName);
168 //void coreSocketError(QAbstractSocket::SocketError);
170 //void networkConnected(NetworkId);
171 //void networkDisconnected(NetworkId);
173 void recvMessage(const Message &message);
174 void recvStatusMsg(QString network, QString message);
175 void receiveBacklog(BufferId bufferId, const QVariantList &msgs);
176 void updateBufferInfo(BufferInfo);
177 void updateLastSeenMsg(BufferId id, const MsgId &msgId);
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();
188 void setSecuredConnection();
192 Client(QObject *parent = 0);
196 static void addNetwork(Network *);
197 static void setCurrentCoreAccount(AccountId);
198 static inline BufferSyncer *bufferSyncer() { return instance()->_bufferSyncer; }
200 Buffer *statusBuffer(const NetworkId &networkid) const;
202 static QPointer<Client> instanceptr;
204 QPointer<QIODevice> socket;
206 SignalProxy * _signalProxy;
208 NetworkModel * _networkModel;
209 BufferModel * _bufferModel;
210 BufferSyncer * _bufferSyncer;
211 ClientBacklogManager *_backlogManager;
212 BufferViewManager *_bufferViewManager;
213 ClientIrcListHelper *_ircListHelper;
215 MessageModel *_messageModel;
217 ClientMode clientMode;
219 bool _connectedToCore, _syncedToCore;
221 QHash<BufferId, Buffer *> _buffers;
222 QHash<NetworkId, Buffer *> _statusBuffers; // fast lookup
223 QHash<NetworkId, Network *> _networks;
224 QHash<IdentityId, Identity *> _identities;
226 Buffer *_monitorBuffer;
228 static AccountId _currentCoreAccount;
230 friend class ClientSyncer;