Fix ALL the license headers!
[quassel.git] / src / client / client.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2012 by the Quassel Project                        *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
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.                                           *
9  *                                                                         *
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.                          *
14  *                                                                         *
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  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
19  ***************************************************************************/
20
21 #ifndef CLIENT_H_
22 #define CLIENT_H_
23
24 #include <QList>
25 #include <QPointer>
26
27 #include "bufferinfo.h"
28 #include "coreconnection.h"
29 #include "quassel.h"
30 #include "types.h"
31
32 class Message;
33 class MessageModel;
34 class AbstractMessageProcessor;
35
36 class Identity;
37 class CertIdentity;
38 class Network;
39
40 class AbstractUi;
41 class AbstractUiMsg;
42 class NetworkModel;
43 class BufferModel;
44 class BufferSyncer;
45 class BufferViewOverlay;
46 class ClientAliasManager;
47 class ClientBacklogManager;
48 class ClientBufferViewManager;
49 class ClientIgnoreListManager;
50 class ClientIrcListHelper;
51 class ClientUserInputHandler;
52 class CoreAccountModel;
53 class CoreConnection;
54 class IrcUser;
55 class IrcChannel;
56 class NetworkConfig;
57 class SignalProxy;
58 struct NetworkInfo;
59
60 class Client : public QObject
61 {
62     Q_OBJECT
63
64 public:
65     enum ClientMode {
66         LocalCore,
67         RemoteCore
68     };
69
70     static bool instanceExists();
71     static Client *instance();
72     static void destroy();
73     static void init(AbstractUi *);
74     static AbstractUi *mainUi();
75
76     static QList<NetworkId> networkIds();
77     static const Network *network(NetworkId);
78
79     static QList<IdentityId> identityIds();
80     static const Identity *identity(IdentityId);
81
82     //! Request creation of an identity with the given data.
83     /** The request will be sent to the core, and will be propagated back to all the clients
84      *  with a new valid IdentityId.
85      *  \param identity The identity template for the new identity. It does not need to have a valid ID.
86      */
87     static void createIdentity(const CertIdentity &identity);
88
89     //! Request update of an identity with the given data.
90     /** The request will be sent to the core, and will be propagated back to all the clients.
91      *  \param id The identity to be updated.
92      *  \param serializedData The identity's content (cf. SyncableObject::toVariantMap())
93      */
94     static void updateIdentity(IdentityId id, const QVariantMap &serializedData);
95
96     //! Request removal of the identity with the given ID from the core (and all the clients, of course).
97     /** \param id The ID of the identity to be removed.
98      */
99     static void removeIdentity(IdentityId id);
100
101     static void createNetwork(const NetworkInfo &info, const QStringList &persistentChannels = QStringList());
102     static void updateNetwork(const NetworkInfo &info);
103     static void removeNetwork(NetworkId id);
104
105     static inline NetworkModel *networkModel() { return instance()->_networkModel; }
106     static inline BufferModel *bufferModel() { return instance()->_bufferModel; }
107     static inline MessageModel *messageModel() { return instance()->_messageModel; }
108     static inline AbstractMessageProcessor *messageProcessor() { return instance()->_messageProcessor; }
109     static inline SignalProxy *signalProxy() { return instance()->_signalProxy; }
110
111     static inline ClientAliasManager *aliasManager() { return instance()->_aliasManager; }
112     static inline ClientBacklogManager *backlogManager() { return instance()->_backlogManager; }
113     static inline ClientIrcListHelper *ircListHelper() { return instance()->_ircListHelper; }
114     static inline ClientBufferViewManager *bufferViewManager() { return instance()->_bufferViewManager; }
115     static inline BufferViewOverlay *bufferViewOverlay() { return instance()->_bufferViewOverlay; }
116     static inline ClientUserInputHandler *inputHandler() { return instance()->_inputHandler; }
117     static inline NetworkConfig *networkConfig() { return instance()->_networkConfig; }
118     static inline ClientIgnoreListManager *ignoreListManager() { return instance()->_ignoreListManager; }
119
120     static inline CoreAccountModel *coreAccountModel() { return instance()->_coreAccountModel; }
121     static inline CoreConnection *coreConnection() { return instance()->_coreConnection; }
122     static inline CoreAccount currentCoreAccount() { return coreConnection()->currentAccount(); }
123     static inline Quassel::Features coreFeatures() { return _coreFeatures; }
124
125     static bool isConnected();
126     static bool internalCore();
127
128     static void userInput(const BufferInfo &bufferInfo, const QString &message);
129
130     static void setBufferLastSeenMsg(BufferId id, const MsgId &msgId); // this is synced to core and other clients
131     static void setMarkerLine(BufferId id, const MsgId &msgId); // this is synced to core and other clients
132     static MsgId markerLine(BufferId id);
133
134     static void removeBuffer(BufferId id);
135     static void renameBuffer(BufferId bufferId, const QString &newName);
136     static void mergeBuffersPermanently(BufferId bufferId1, BufferId bufferId2);
137     static void purgeKnownBufferIds();
138
139     static void logMessage(QtMsgType type, const char *msg);
140     static inline const QString &debugLog() { return instance()->_debugLogBuffer; }
141
142 signals:
143     void requestNetworkStates();
144
145     void showConfigWizard(const QVariantMap &coredata);
146
147     void connected();
148     void disconnected();
149     void coreConnectionStateChanged(bool);
150
151     //! The identity with the given ID has been newly created in core and client.
152     /** \param id The ID of the newly created identity.
153      */
154     void identityCreated(IdentityId id);
155
156     //! The identity with the given ID has been removed.
157     /** Upon emitting this signal, the identity is already gone from the core, and it will
158      *  be deleted from the client immediately afterwards, so connected slots need to clean
159      *  up their stuff.
160      *  \param id The ID of the identity about to be removed.
161      */
162     void identityRemoved(IdentityId id);
163
164     //! Sent to the core when an identity shall be created. Should not be used elsewhere.
165     void requestCreateIdentity(const Identity &, const QVariantMap &);
166     //! Sent to the core when an identity shall be removed. Should not be used elsewhere.
167     void requestRemoveIdentity(IdentityId);
168
169     void networkCreated(NetworkId id);
170     void networkRemoved(NetworkId id);
171
172     void requestCreateNetwork(const NetworkInfo &info, const QStringList &persistentChannels = QStringList());
173     void requestRemoveNetwork(NetworkId);
174
175     void logUpdated(const QString &msg);
176
177     //! Emitted when a buffer has been marked as read
178     /** This is currently triggered by setting lastSeenMsg, either local or remote,
179      *  or by bringing the window to front.
180      *  \param id The buffer that has been marked as read
181      */
182     void bufferMarkedAsRead(BufferId id);
183
184 public slots:
185     void disconnectFromCore();
186
187     void bufferRemoved(BufferId bufferId);
188     void bufferRenamed(BufferId bufferId, const QString &newName);
189     void buffersPermanentlyMerged(BufferId bufferId1, BufferId bufferId2);
190
191     void markBufferAsRead(BufferId id);
192
193 private slots:
194     void setSyncedToCore();
195     void setDisconnectedFromCore();
196     void connectionStateChanged(CoreConnection::ConnectionState);
197
198     void recvMessage(const Message &message);
199     void recvStatusMsg(QString network, QString message);
200
201     void networkDestroyed();
202     void coreIdentityCreated(const Identity &);
203     void coreIdentityRemoved(IdentityId);
204     void coreNetworkCreated(NetworkId);
205     void coreNetworkRemoved(NetworkId);
206
207     void requestInitialBacklog();
208
209     void sendBufferedUserInput();
210
211 private:
212     Client(QObject *parent = 0);
213     virtual ~Client();
214     void init();
215
216     static void addNetwork(Network *);
217     static void setCoreFeatures(Quassel::Features);
218     static inline BufferSyncer *bufferSyncer() { return instance()->_bufferSyncer; }
219
220     static QPointer<Client> instanceptr;
221
222     SignalProxy *_signalProxy;
223     AbstractUi *_mainUi;
224     NetworkModel *_networkModel;
225     BufferModel *_bufferModel;
226     BufferSyncer *_bufferSyncer;
227     ClientAliasManager *_aliasManager;
228     ClientBacklogManager *_backlogManager;
229     ClientBufferViewManager *_bufferViewManager;
230     BufferViewOverlay *_bufferViewOverlay;
231     ClientIrcListHelper *_ircListHelper;
232     ClientUserInputHandler *_inputHandler;
233     NetworkConfig *_networkConfig;
234     ClientIgnoreListManager *_ignoreListManager;
235
236     MessageModel *_messageModel;
237     AbstractMessageProcessor *_messageProcessor;
238
239     CoreAccountModel *_coreAccountModel;
240     CoreConnection *_coreConnection;
241
242     ClientMode clientMode;
243
244     QHash<NetworkId, Network *> _networks;
245     QHash<IdentityId, Identity *> _identities;
246
247     bool _connected;
248     static Quassel::Features _coreFeatures;
249
250     QString _debugLogBuffer;
251     QTextStream _debugLog;
252
253     QList<QPair<BufferInfo, QString> > _userInputBuffer;
254
255     friend class CoreConnection;
256 };
257
258
259 #endif