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;
53 class Client : public QObject {
57 static Client *instance();
58 static void destroy();
59 static void init(AbstractUi *);
61 static QList<BufferInfo> allBufferInfos();
62 static QList<Buffer *> buffers();
63 static Buffer *buffer(BufferId bufferUid);
64 static Buffer *buffer(BufferInfo);
65 static inline Buffer *monitorBuffer() { return instance()->_monitorBuffer; }
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 MessageModel *messageModel() { return instance()->_messageModel; }
98 static inline SignalProxy *signalProxy() { return instance()->_signalProxy; }
100 static inline ClientBacklogManager *backlogManager() { return instance()->_backlogManager; }
101 static inline ClientIrcListHelper *ircListHelper() { return instance()->_ircListHelper; }
102 static inline BufferViewManager *bufferViewManager() { return instance()->_bufferViewManager; }
104 static AccountId currentCoreAccount();
106 static AbstractUiMsg *layoutMsg(const Message &);
108 static bool isConnected();
109 static bool isSynced();
111 static void userInput(BufferInfo bufferInfo, QString message);
113 enum ClientMode { LocalCore, RemoteCore };
115 static void checkForHighlight(Message &msg);
116 static void setBufferLastSeenMsg(BufferId id, const MsgId &msgId); // this is synced to core and other clients
117 static void removeBuffer(BufferId id);
120 void sendInput(BufferInfo, QString message);
121 void showBuffer(Buffer *);
122 void bufferUpdated(BufferInfo bufferInfo);
123 void backlogReceived(Buffer *, QList<Message>);
124 void requestBacklog(BufferInfo, QVariant, QVariant);
125 void requestNetworkStates();
126 void messageReceived(const Message &msg);
128 void showConfigWizard(const QVariantMap &coredata);
131 void securedConnection();
133 void coreConnectionStateChanged(bool);
135 //! The identity with the given ID has been newly created in core and client.
136 /** \param id The ID of the newly created identity.
138 void identityCreated(IdentityId id);
140 //! The identity with the given ID has been removed.
141 /** Upon emitting this signal, the identity is already gone from the core, and it will
142 * be deleted from the client immediately afterwards, so connected slots need to clean
144 * \param id The ID of the identity about to be removed.
146 void identityRemoved(IdentityId id);
148 //! Sent to the core when an identity shall be created. Should not be used elsewhere.
149 void requestCreateIdentity(const Identity &);
150 //! Sent to the core when an identity shall be updated. Should not be used elsewhere.
151 void requestUpdateIdentity(const Identity &);
152 //! Sent to the core when an identity shall be removed. Should not be used elsewhere.
153 void requestRemoveIdentity(IdentityId);
155 void networkCreated(NetworkId id);
156 void networkRemoved(NetworkId id);
158 void requestCreateNetwork(const NetworkInfo &info);
159 void requestUpdateNetwork(const NetworkInfo &info);
160 void requestRemoveNetwork(NetworkId);
163 //void selectBuffer(Buffer *);
165 void disconnectFromCore();
167 void setCoreConfiguration(const QVariantMap &settings);
169 void bufferRemoved(BufferId bufferId);
170 void bufferRenamed(BufferId bufferId, const QString &newName);
173 //void coreSocketError(QAbstractSocket::SocketError);
175 //void networkConnected(NetworkId);
176 //void networkDisconnected(NetworkId);
178 void recvMessage(const Message &message);
179 void recvStatusMsg(QString network, QString message);
180 void receiveBacklog(BufferId bufferId, const QVariantList &msgs);
181 void updateBufferInfo(BufferInfo);
182 void updateLastSeenMsg(BufferId id, const MsgId &msgId);
186 void bufferDestroyed();
187 void networkDestroyed();
188 void coreIdentityCreated(const Identity &);
189 void coreIdentityRemoved(IdentityId);
190 void coreNetworkCreated(NetworkId);
191 void coreNetworkRemoved(NetworkId);
193 void setConnectedToCore(QIODevice *socket, AccountId id);
194 void setSyncedToCore();
195 void setSecuredConnection();
199 Client(QObject *parent = 0);
203 static void addNetwork(Network *);
204 static void setCurrentCoreAccount(AccountId);
205 static inline BufferSyncer *bufferSyncer() { return instance()->_bufferSyncer; }
207 Buffer *statusBuffer(const NetworkId &networkid) const;
209 static QPointer<Client> instanceptr;
211 QPointer<QIODevice> socket;
213 SignalProxy * _signalProxy;
215 NetworkModel * _networkModel;
216 BufferModel * _bufferModel;
217 BufferSyncer * _bufferSyncer;
218 ClientBacklogManager *_backlogManager;
219 BufferViewManager *_bufferViewManager;
220 ClientIrcListHelper *_ircListHelper;
222 MessageModel *_messageModel;
224 ClientMode clientMode;
226 bool _connectedToCore, _syncedToCore;
228 QHash<BufferId, Buffer *> _buffers;
229 QHash<NetworkId, Buffer *> _statusBuffers; // fast lookup
230 QHash<NetworkId, Network *> _networks;
231 QHash<IdentityId, Identity *> _identities;
233 Buffer *_monitorBuffer;
236 QLinkedList<Buffer *> layoutQueue;
238 static AccountId _currentCoreAccount;
240 friend class ClientSyncer;