Quassel IRC  Pre-Release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
coresession.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 CORESESSION_H
22 #define CORESESSION_H
23 
24 #include <QString>
25 #include <QVariant>
26 
27 #include "corecoreinfo.h"
28 #include "corealiasmanager.h"
29 #include "coreignorelistmanager.h"
30 #include "peer.h"
31 #include "protocol.h"
32 #include "message.h"
33 #include "storage.h"
34 
35 class CoreBacklogManager;
36 class CoreBufferSyncer;
38 class CoreIdentity;
39 class CoreIrcListHelper;
40 class CoreNetwork;
41 class CoreNetworkConfig;
44 class CtcpParser;
45 class EventManager;
46 class EventStringifier;
47 class InternalPeer;
48 class IrcParser;
49 class MessageEvent;
50 class NetworkConnection;
51 class RemotePeer;
52 class SignalProxy;
53 
54 struct NetworkInfo;
55 
56 class QScriptEngine;
57 
58 class CoreSession : public QObject
59 {
60  Q_OBJECT
61 
62 public:
63  CoreSession(UserId, bool restoreState, QObject *parent = 0);
64  ~CoreSession();
65 
66  QList<BufferInfo> buffers() const;
67  inline UserId user() const { return _user; }
70  inline CoreNetworkConfig *networkConfig() const { return _networkConfig; }
71  NetworkConnection *networkConnection(NetworkId) const;
72 
74 
75  inline SignalProxy *signalProxy() const { return _signalProxy; }
76 
77  const AliasManager &aliasManager() const { return _aliasManager; }
79 
80  inline EventManager *eventManager() const { return _eventManager; }
83  inline CtcpParser *ctcpParser() const { return _ctcpParser; }
84  inline IrcParser *ircParser() const { return _ircParser; }
85 
86  inline CoreIrcListHelper *ircListHelper() const { return _ircListHelper; }
87 
90 
91 // void attachNetworkConnection(NetworkConnection *conn);
92 
94  void restoreSessionState();
95 
96 public slots:
97  void addClient(RemotePeer *peer);
98  void addClient(InternalPeer *peer);
99 
100  void msgFromClient(BufferInfo, QString message);
101 
103 
105  void createIdentity(const Identity &identity, const QVariantMap &additional);
106  void createIdentity(const CoreIdentity &identity);
107 
109 
112 
114 
116  void createNetwork(const NetworkInfo &info, const QStringList &persistentChannels = QStringList());
117 
119 
122 
124  /* \param networkId The id of the network the buffer belongs to
125  * \param newName The new name of the buffer
126  * \param oldName The old name of the buffer
127  */
128  void renameBuffer(const NetworkId &networkId, const QString &newName, const QString &oldName);
129 
130  void changePassword(PeerPtr peer, const QString &userName, const QString &oldPassword, const QString &newPassword);
131 
132  QHash<QString, QString> persistentChannels(NetworkId) const;
133 
135  void globalAway(const QString &msg = QString());
136 
137 signals:
138  void initialized();
140 
141  //void msgFromGui(uint netid, QString buf, QString message);
142  void displayMsg(Message message);
143  void displayStatusMsg(QString, QString);
144 
145  void scriptResult(QString result);
146 
148 
151  void identityCreated(const Identity &identity);
152 
154 
158 
162 
163  void passwordChanged(PeerPtr peer, bool success);
164 
165 protected:
166  virtual void customEvent(QEvent *event);
167 
168 private slots:
169  void removeClient(Peer *peer);
170 
171  void recvStatusMsgFromServer(QString msg);
172  void recvMessageFromServer(NetworkId networkId, Message::Type, BufferInfo::Type, const QString &target, const QString &text, const QString &sender = "", Message::Flags flags = Message::None);
173 
175 
176  void scriptRequest(QString script);
177 
178  void clientsConnected();
179  void clientsDisconnected();
180 
181  void updateIdentityBySender();
182 
183  void saveSessionState() const;
184 
185 private:
186  void processMessages();
187 
188  void loadSettings();
189  void initScriptEngine();
190 
192  Q_INVOKABLE void processMessageEvent(MessageEvent *event);
193 
195 
198  // QHash<NetworkId, NetworkConnection *> _connections;
199  QHash<NetworkId, CoreNetwork *> _networks;
200  // QHash<NetworkId, CoreNetwork *> _networksToRemove;
201  QHash<IdentityId, CoreIdentity *> _identities;
202 
210 
212  EventStringifier *_eventStringifier; // should eventually move into client
216 
217  QScriptEngine *scriptEngine;
218 
219  QList<RawMessage> _messageQueue;
222 };
223 
224 
225 struct RawMessage {
229  QString target;
230  QString text;
231  QString sender;
232  Message::Flags flags;
233  RawMessage(NetworkId networkId, Message::Type type, BufferInfo::Type bufferType, const QString &target, const QString &text, const QString &sender, Message::Flags flags)
234  : networkId(networkId), type(type), bufferType(bufferType), target(target), text(text), sender(sender), flags(flags) {}
235 };
236 
237 #endif