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