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
34 class AbstractMessageProcessor;
44 class ClientBacklogManager;
45 class ClientIrcListHelper;
46 class BufferViewManager;
52 class Client : public QObject {
61 static Client *instance();
62 static void destroy();
63 static void init(AbstractUi *);
65 static QList<BufferInfo> allBufferInfos();
66 static QList<Buffer *> buffers();
67 // static Buffer *buffer(BufferId bufferUid);
68 static Buffer *buffer(BufferInfo);
70 static QList<NetworkId> networkIds();
71 static const Network * network(NetworkId);
73 static QList<IdentityId> identityIds();
74 static const Identity * identity(IdentityId);
76 //! Request creation 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 * with a new valid IdentityId.
79 * \param identity The identity template for the new identity. It does not need to have a valid ID.
81 static void createIdentity(const Identity &identity);
83 //! Request update of an identity with the given data.
84 /** The request will be sent to the core, and will be propagated back to all the clients.
85 * \param identity The identity to be updated.
87 static void updateIdentity(const Identity &identity);
89 //! Request removal of the identity with the given ID from the core (and all the clients, of course).
90 /** \param id The ID of the identity to be removed.
92 static void removeIdentity(IdentityId id);
94 static void createNetwork(const NetworkInfo &info);
95 static void updateNetwork(const NetworkInfo &info);
96 static void removeNetwork(NetworkId id);
98 static inline NetworkModel *networkModel() { return instance()->_networkModel; }
99 static inline BufferModel *bufferModel() { return instance()->_bufferModel; }
100 static inline MessageModel *messageModel() { return instance()->_messageModel; }
101 static inline AbstractMessageProcessor *messageProcessor() { return instance()->_messageProcessor; }
102 static inline SignalProxy *signalProxy() { return instance()->_signalProxy; }
104 static inline ClientBacklogManager *backlogManager() { return instance()->_backlogManager; }
105 static inline ClientIrcListHelper *ircListHelper() { return instance()->_ircListHelper; }
106 static inline BufferViewManager *bufferViewManager() { return instance()->_bufferViewManager; }
108 static AccountId currentCoreAccount();
110 static bool isConnected();
111 static bool isSynced();
113 static void userInput(BufferInfo bufferInfo, QString message);
115 static void setBufferLastSeenMsg(BufferId id, const MsgId &msgId); // this is synced to core and other clients
116 static void removeBuffer(BufferId id);
119 void sendInput(BufferInfo, QString message);
120 void showBuffer(Buffer *);
121 void bufferUpdated(BufferInfo bufferInfo);
122 void backlogReceived(Buffer *, QList<Message>);
123 void requestBacklog(BufferInfo, QVariant, QVariant);
124 void requestNetworkStates();
126 void showConfigWizard(const QVariantMap &coredata);
129 void securedConnection();
131 void coreConnectionStateChanged(bool);
133 //! The identity with the given ID has been newly created in core and client.
134 /** \param id The ID of the newly created identity.
136 void identityCreated(IdentityId id);
138 //! The identity with the given ID has been removed.
139 /** Upon emitting this signal, the identity is already gone from the core, and it will
140 * be deleted from the client immediately afterwards, so connected slots need to clean
142 * \param id The ID of the identity about to be removed.
144 void identityRemoved(IdentityId id);
146 //! Sent to the core when an identity shall be created. Should not be used elsewhere.
147 void requestCreateIdentity(const Identity &);
148 //! Sent to the core when an identity shall be updated. Should not be used elsewhere.
149 void requestUpdateIdentity(const Identity &);
150 //! Sent to the core when an identity shall be removed. Should not be used elsewhere.
151 void requestRemoveIdentity(IdentityId);
153 void networkCreated(NetworkId id);
154 void networkRemoved(NetworkId id);
156 void requestCreateNetwork(const NetworkInfo &info);
157 void requestUpdateNetwork(const NetworkInfo &info);
158 void requestRemoveNetwork(NetworkId);
161 //void selectBuffer(Buffer *);
163 void disconnectFromCore();
165 void setCoreConfiguration(const QVariantMap &settings);
167 void bufferRemoved(BufferId bufferId);
168 void bufferRenamed(BufferId bufferId, const QString &newName);
171 //void coreSocketError(QAbstractSocket::SocketError);
173 //void networkConnected(NetworkId);
174 //void networkDisconnected(NetworkId);
176 void recvMessage(const Message &message);
177 void recvStatusMsg(QString network, QString message);
178 void receiveBacklog(BufferId bufferId, const QVariantList &msgs);
179 void updateBufferInfo(BufferInfo);
181 void bufferDestroyed();
182 void networkDestroyed();
183 void coreIdentityCreated(const Identity &);
184 void coreIdentityRemoved(IdentityId);
185 void coreNetworkCreated(NetworkId);
186 void coreNetworkRemoved(NetworkId);
188 void setConnectedToCore(QIODevice *socket, AccountId id);
189 void setSyncedToCore();
190 void setSecuredConnection();
194 Client(QObject *parent = 0);
198 static void addNetwork(Network *);
199 static void setCurrentCoreAccount(AccountId);
200 static inline BufferSyncer *bufferSyncer() { return instance()->_bufferSyncer; }
202 Buffer *statusBuffer(const NetworkId &networkid) const;
204 static QPointer<Client> instanceptr;
206 QPointer<QIODevice> socket;
208 SignalProxy * _signalProxy;
210 NetworkModel * _networkModel;
211 BufferModel * _bufferModel;
212 BufferSyncer * _bufferSyncer;
213 ClientBacklogManager *_backlogManager;
214 BufferViewManager *_bufferViewManager;
215 ClientIrcListHelper *_ircListHelper;
217 MessageModel *_messageModel;
218 AbstractMessageProcessor *_messageProcessor;
220 ClientMode clientMode;
222 bool _connectedToCore, _syncedToCore;
224 QHash<BufferId, Buffer *> _buffers;
225 QHash<NetworkId, Buffer *> _statusBuffers; // fast lookup
226 QHash<NetworkId, Network *> _networks;
227 QHash<IdentityId, Identity *> _identities;
229 static AccountId _currentCoreAccount;
231 friend class ClientSyncer;