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