1 /***************************************************************************
2 * Copyright (C) 2005-2016 by the Quassel Project *
3 * devel@quassel-irc.org *
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. *
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. *
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 ***************************************************************************/
27 #include "corecoreinfo.h"
28 #include "corealiasmanager.h"
29 #include "coreignorelistmanager.h"
35 class CoreBacklogManager;
36 class CoreBufferSyncer;
37 class CoreBufferViewManager;
39 class CoreIrcListHelper;
41 class CoreNetworkConfig;
42 class CoreSessionEventProcessor;
43 class CoreTransferManager;
46 class EventStringifier;
50 class NetworkConnection;
58 class CoreSession : public QObject
63 CoreSession(UserId, bool restoreState, QObject *parent = 0);
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;
73 Protocol::SessionState sessionState() const;
75 inline SignalProxy *signalProxy() const { return _signalProxy; }
77 const AliasManager &aliasManager() const { return _aliasManager; }
78 AliasManager &aliasManager() { return _aliasManager; }
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; }
86 inline CoreIrcListHelper *ircListHelper() const { return _ircListHelper; }
88 inline CoreIgnoreListManager *ignoreListManager() { return &_ignoreListManager; }
89 inline CoreTransferManager *transferManager() const { return _transferManager; }
91 // void attachNetworkConnection(NetworkConnection *conn);
93 //! Return necessary data for restoring the session after restarting the core
94 void restoreSessionState();
97 void addClient(RemotePeer *peer);
98 void addClient(InternalPeer *peer);
100 void msgFromClient(BufferInfo, QString message);
102 //! Create an identity and propagate the changes to the clients.
103 /** \param identity The identity to be created.
105 void createIdentity(const Identity &identity, const QVariantMap &additional);
106 void createIdentity(const CoreIdentity &identity);
108 //! Remove identity and propagate that fact to the clients.
109 /** \param identity The identity to be removed.
111 void removeIdentity(IdentityId identity);
113 //! Create a network and propagate the changes to the clients.
114 /** \param info The network's settings.
116 void createNetwork(const NetworkInfo &info, const QStringList &persistentChannels = QStringList());
118 //! Remove network and propagate that fact to the clients.
119 /** \param network The id of the network to be removed.
121 void removeNetwork(NetworkId network);
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
128 void renameBuffer(const NetworkId &networkId, const QString &newName, const QString &oldName);
130 void changePassword(PeerPtr peer, const QString &userName, const QString &oldPassword, const QString &newPassword);
132 QHash<QString, QString> persistentChannels(NetworkId) const;
134 //! Marks us away (or unaway) on all networks
135 void globalAway(const QString &msg = QString());
139 void sessionState(const Protocol::SessionState &sessionState);
141 //void msgFromGui(uint netid, QString buf, QString message);
142 void displayMsg(Message message);
143 void displayStatusMsg(QString, QString);
145 void scriptResult(QString result);
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.
151 void identityCreated(const Identity &identity);
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.
157 void identityRemoved(IdentityId identity);
159 void networkCreated(NetworkId);
160 void networkRemoved(NetworkId);
161 void networkDisconnected(NetworkId);
163 void passwordChanged(PeerPtr peer, bool success);
166 virtual void customEvent(QEvent *event);
169 void removeClient(Peer *peer);
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);
174 void destroyNetwork(NetworkId);
176 void scriptRequest(QString script);
178 void clientsConnected();
179 void clientsDisconnected();
181 void updateIdentityBySender();
183 void saveSessionState() const;
186 void processMessages();
189 void initScriptEngine();
191 /// Hook for converting events to the old displayMsg() handlers
192 Q_INVOKABLE void processMessageEvent(MessageEvent *event);
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;
203 CoreBufferSyncer *_bufferSyncer;
204 CoreBacklogManager *_backlogManager;
205 CoreBufferViewManager *_bufferViewManager;
206 CoreIrcListHelper *_ircListHelper;
207 CoreNetworkConfig *_networkConfig;
208 CoreCoreInfo _coreInfo;
209 CoreTransferManager *_transferManager;
211 EventManager *_eventManager;
212 EventStringifier *_eventStringifier; // should eventually move into client
213 CoreSessionEventProcessor *_sessionEventProcessor;
214 CtcpParser *_ctcpParser;
215 IrcParser *_ircParser;
217 QScriptEngine *scriptEngine;
219 QList<RawMessage> _messageQueue;
220 bool _processMessages;
221 CoreIgnoreListManager _ignoreListManager;
228 BufferInfo::Type bufferType;
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) {}