Quassel IRC  Pre-Release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
client.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2015 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;
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;
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 {
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 
86 
90  static void createIdentity(const CertIdentity &identity);
91 
93 
97  static void updateIdentity(IdentityId id, const QVariantMap &serializedData);
98 
100 
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; }
112  static inline SignalProxy *signalProxy() { return instance()->_signalProxy; }
113 
114  static inline ClientAliasManager *aliasManager() { return instance()->_aliasManager; }
120  static inline NetworkConfig *networkConfig() { return instance()->_networkConfig; }
123 
125  static inline CoreConnection *coreConnection() { return instance()->_coreConnection; }
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  static void changePassword(const QString &oldPassword, const QString &newPassword);
146 
147 #if QT_VERSION < 0x050000
148  static void logMessage(QtMsgType type, const char *msg);
149 #else
150  static void logMessage(QtMsgType, const QMessageLogContext&, const QString&);
151 #endif
152  static inline const QString &debugLog() { return instance()->_debugLogBuffer; }
153 
154 signals:
155  void requestNetworkStates();
156 
157  void showConfigWizard(const QVariantMap &coredata);
158 
159  void connected();
160  void disconnected();
161  void coreConnectionStateChanged(bool);
162 
164 
166  void identityCreated(IdentityId id);
167 
169 
174  void identityRemoved(IdentityId id);
175 
177  void requestCreateIdentity(const Identity &, const QVariantMap &);
180 
181  void networkCreated(NetworkId id);
182  void networkRemoved(NetworkId id);
183 
184  void requestCreateNetwork(const NetworkInfo &info, const QStringList &persistentChannels = QStringList());
186 
187  void logUpdated(const QString &msg);
188 
190 
194  void bufferMarkedAsRead(BufferId id);
195 
197  void requestPasswordChange(PeerPtr peer, const QString &userName, const QString &oldPassword, const QString &newPassword);
198  void passwordChanged(bool success);
199 
200 public slots:
201  void disconnectFromCore();
202 
203  void bufferRemoved(BufferId bufferId);
204  void bufferRenamed(BufferId bufferId, const QString &newName);
205  void buffersPermanentlyMerged(BufferId bufferId1, BufferId bufferId2);
206 
207  void markBufferAsRead(BufferId id);
208 
209 private slots:
210  void setSyncedToCore();
213 
214  void recvMessage(const Message &message);
215  void recvStatusMsg(QString network, QString message);
216 
217  void networkDestroyed();
218  void coreIdentityCreated(const Identity &);
222 
223  void corePasswordChanged(PeerPtr, bool success);
224 
225  void requestInitialBacklog();
226 
227  void sendBufferedUserInput();
228 
229 private:
230  Client(QObject *parent = 0);
231  virtual ~Client();
232  void init();
233 
234  static void addNetwork(Network *);
235  static inline BufferSyncer *bufferSyncer() { return instance()->_bufferSyncer; }
236 
237  static QPointer<Client> instanceptr;
238 
253 
256 
259 
261 
262  QHash<NetworkId, Network *> _networks;
263  QHash<IdentityId, Identity *> _identities;
264 
266  static Quassel::Features _coreFeatures;
267 
269  QTextStream _debugLog;
270 
271  QList<QPair<BufferInfo, QString> > _userInputBuffer;
272 
273  friend class CoreConnection;
274 };
275 
276 
277 #endif