Implement password changing from client.
[quassel.git] / src / core / coresession.h
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 "protocol.h"
31 #include "message.h"
32 #include "storage.h"
33
34 class CoreBacklogManager;
35 class CoreBufferSyncer;
36 class CoreBufferViewManager;
37 class CoreIdentity;
38 class CoreIrcListHelper;
39 class CoreNetwork;
40 class CoreNetworkConfig;
41 class CoreSessionEventProcessor;
42 class CoreTransferManager;
43 class CtcpParser;
44 class EventManager;
45 class EventStringifier;
46 class InternalPeer;
47 class IrcParser;
48 class Peer;
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; }
68     CoreNetwork *network(NetworkId) const;
69     CoreIdentity *identity(IdentityId) const;
70     inline CoreNetworkConfig *networkConfig() const { return _networkConfig; }
71     NetworkConnection *networkConnection(NetworkId) const;
72
73     Protocol::SessionState sessionState() const;
74
75     inline SignalProxy *signalProxy() const { return _signalProxy; }
76
77     const AliasManager &aliasManager() const { return _aliasManager; }
78     AliasManager &aliasManager() { return _aliasManager; }
79
80     inline EventManager *eventManager() const { return _eventManager; }
81     inline EventStringifier *eventStringifier() const { return _eventStringifier; }
82     inline CoreSessionEventProcessor *sessionEventProcessor() const { return _sessionEventProcessor; }
83     inline CtcpParser *ctcpParser() const { return _ctcpParser; }
84     inline IrcParser *ircParser() const { return _ircParser; }
85
86     inline CoreIrcListHelper *ircListHelper() const { return _ircListHelper; }
87
88     inline CoreIgnoreListManager *ignoreListManager() { return &_ignoreListManager; }
89     inline CoreTransferManager *transferManager() const { return _transferManager; }
90
91 //   void attachNetworkConnection(NetworkConnection *conn);
92
93     //! Return necessary data for restoring the session after restarting the core
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
102     //! Create an identity and propagate the changes to the clients.
103     /** \param identity The identity to be created.
104      */
105     void createIdentity(const Identity &identity, const QVariantMap &additional);
106     void createIdentity(const CoreIdentity &identity);
107
108     //! Remove identity and propagate that fact to the clients.
109     /** \param identity The identity to be removed.
110      */
111     void removeIdentity(IdentityId identity);
112
113     //! Create a network and propagate the changes to the clients.
114     /** \param info The network's settings.
115      */
116     void createNetwork(const NetworkInfo &info, const QStringList &persistentChannels = QStringList());
117
118     //! Remove network and propagate that fact to the clients.
119     /** \param network The id of the network to be removed.
120      */
121     void removeNetwork(NetworkId network);
122
123     //! Rename a Buffer for a given network
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     QHash<QString, QString> persistentChannels(NetworkId) const;
131
132     //! Marks us away (or unaway) on all networks
133     void globalAway(const QString &msg = QString());
134
135     void changePassword(QString password);
136
137 signals:
138     void initialized();
139     void sessionState(const Protocol::SessionState &sessionState);
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
147     //! Identity has been created.
148     /** This signal is propagated to the clients to tell them that the given identity has been created.
149      *  \param identity The new identity.
150      */
151     void identityCreated(const Identity &identity);
152
153     //! Identity has been removed.
154     /** This signal is propagated to the clients to inform them about the removal of the given identity.
155      *  \param identity The identity that has been removed.
156      */
157     void identityRemoved(IdentityId identity);
158
159     void networkCreated(NetworkId);
160     void networkRemoved(NetworkId);
161     void networkDisconnected(NetworkId);
162
163     void passwordChangeRequested(UserId user, QString password);
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
174     void destroyNetwork(NetworkId);
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
191     /// Hook for converting events to the old displayMsg() handlers
192     Q_INVOKABLE void processMessageEvent(MessageEvent *event);
193
194     UserId _user;
195
196     SignalProxy *_signalProxy;
197     CoreAliasManager _aliasManager;
198     // QHash<NetworkId, NetworkConnection *> _connections;
199     QHash<NetworkId, CoreNetwork *> _networks;
200     //  QHash<NetworkId, CoreNetwork *> _networksToRemove;
201     QHash<IdentityId, CoreIdentity *> _identities;
202
203     CoreBufferSyncer *_bufferSyncer;
204     CoreBacklogManager *_backlogManager;
205     CoreBufferViewManager *_bufferViewManager;
206     CoreIrcListHelper *_ircListHelper;
207     CoreNetworkConfig *_networkConfig;
208     CoreCoreInfo _coreInfo;
209     CoreTransferManager *_transferManager;
210
211     EventManager *_eventManager;
212     EventStringifier *_eventStringifier; // should eventually move into client
213     CoreSessionEventProcessor *_sessionEventProcessor;
214     CtcpParser *_ctcpParser;
215     IrcParser *_ircParser;
216
217     QScriptEngine *scriptEngine;
218
219     QList<RawMessage> _messageQueue;
220     bool _processMessages;
221     CoreIgnoreListManager _ignoreListManager;
222 };
223
224
225 struct RawMessage {
226     NetworkId networkId;
227     Message::Type type;
228     BufferInfo::Type bufferType;
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