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 "bufferinfo.h"
34 class AbstractMessageProcessor;
44 class ClientBacklogManager;
45 class ClientIrcListHelper;
47 class BufferViewManager;
53 class Client : public QObject {
62 static Client *instance();
63 static void destroy();
64 static void init(AbstractUi *);
66 static QList<NetworkId> networkIds();
67 static const Network * network(NetworkId);
69 static QList<IdentityId> identityIds();
70 static const Identity * identity(IdentityId);
72 //! Request creation of an identity with the given data.
73 /** The request will be sent to the core, and will be propagated back to all the clients
74 * with a new valid IdentityId.
75 * \param identity The identity template for the new identity. It does not need to have a valid ID.
77 static void createIdentity(const Identity &identity);
79 //! Request update of an identity with the given data.
80 /** The request will be sent to the core, and will be propagated back to all the clients.
81 * \param id The identity to be updated.
82 * \param serializedData The identity's content (cf. SyncableObject::toVariantMap())
84 static void updateIdentity(IdentityId id, const QVariantMap &serializedData);
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 AbstractMessageProcessor *messageProcessor() { return instance()->_messageProcessor; }
99 static inline SignalProxy *signalProxy() { return instance()->_signalProxy; }
101 static inline ClientBacklogManager *backlogManager() { return instance()->_backlogManager; }
102 static inline ClientIrcListHelper *ircListHelper() { return instance()->_ircListHelper; }
103 static inline BufferViewManager *bufferViewManager() { return instance()->_bufferViewManager; }
105 static AccountId currentCoreAccount();
107 static bool isConnected();
108 static bool isSynced();
110 static void userInput(BufferInfo bufferInfo, QString message);
112 static void setBufferLastSeenMsg(BufferId id, const MsgId &msgId); // this is synced to core and other clients
113 static void removeBuffer(BufferId id);
115 static void logMessage(QtMsgType type, const char *msg);
116 static inline const QString &debugLog() { return instance()->_debugLogBuffer; }
119 void sendInput(BufferInfo, QString message);
120 void requestNetworkStates();
122 void showConfigWizard(const QVariantMap &coredata);
125 void securedConnection();
127 void coreConnectionStateChanged(bool);
129 //! The identity with the given ID has been newly created in core and client.
130 /** \param id The ID of the newly created identity.
132 void identityCreated(IdentityId id);
134 //! The identity with the given ID has been removed.
135 /** Upon emitting this signal, the identity is already gone from the core, and it will
136 * be deleted from the client immediately afterwards, so connected slots need to clean
138 * \param id The ID of the identity about to be removed.
140 void identityRemoved(IdentityId id);
142 //! Sent to the core when an identity shall be created. Should not be used elsewhere.
143 void requestCreateIdentity(const Identity &);
144 //! Sent to the core when an identity shall be removed. Should not be used elsewhere.
145 void requestRemoveIdentity(IdentityId);
147 void networkCreated(NetworkId id);
148 void networkRemoved(NetworkId id);
150 void requestCreateNetwork(const NetworkInfo &info);
151 void requestRemoveNetwork(NetworkId);
153 void newClientSyncer(ClientSyncer *);
155 void logUpdated(const QString &msg);
158 //void selectBuffer(Buffer *);
160 void disconnectFromCore();
162 void bufferRemoved(BufferId bufferId);
163 void bufferRenamed(BufferId bufferId, const QString &newName);
166 void disconnectedFromCore();
168 void recvMessage(const Message &message);
169 void recvStatusMsg(QString network, QString message);
171 void networkDestroyed();
172 void coreIdentityCreated(const Identity &);
173 void coreIdentityRemoved(IdentityId);
174 void coreNetworkCreated(NetworkId);
175 void coreNetworkRemoved(NetworkId);
177 void setConnectedToCore(AccountId id, QIODevice *socket = 0);
178 void setSyncedToCore();
179 void setSecuredConnection();
183 Client(QObject *parent = 0);
187 static void addNetwork(Network *);
188 static void setCurrentCoreAccount(AccountId);
189 static inline BufferSyncer *bufferSyncer() { return instance()->_bufferSyncer; }
191 static QPointer<Client> instanceptr;
193 SignalProxy * _signalProxy;
195 NetworkModel * _networkModel;
196 BufferModel * _bufferModel;
197 BufferSyncer * _bufferSyncer;
198 ClientBacklogManager *_backlogManager;
199 BufferViewManager *_bufferViewManager;
200 ClientIrcListHelper *_ircListHelper;
202 MessageModel *_messageModel;
203 AbstractMessageProcessor *_messageProcessor;
205 ClientMode clientMode;
207 bool _connectedToCore, _syncedToCore;
209 QHash<NetworkId, Network *> _networks;
210 QHash<IdentityId, Identity *> _identities;
212 static AccountId _currentCoreAccount;
214 QString _debugLogBuffer;
215 QTextStream _debugLog;
217 friend class ClientSyncer;