1 /***************************************************************************
2 * Copyright (C) 2005-2018 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 "corehighlightrulemanager.h"
30 #include "coreignorelistmanager.h"
36 class CoreBacklogManager;
37 class CoreBufferSyncer;
38 class CoreBufferViewManager;
41 class CoreIrcListHelper;
43 class CoreNetworkConfig;
44 class CoreSessionEventProcessor;
45 class CoreTransferManager;
48 class EventStringifier;
52 class NetworkConnection;
60 class CoreSession : public QObject
65 CoreSession(UserId, bool restoreState, QObject *parent = 0);
68 QList<BufferInfo> buffers() const;
69 inline UserId user() const { return _user; }
70 CoreNetwork *network(NetworkId) const;
71 CoreIdentity *identity(IdentityId) const;
72 const QString strictSysident();
73 inline CoreNetworkConfig *networkConfig() const { return _networkConfig; }
74 NetworkConnection *networkConnection(NetworkId) const;
76 Protocol::SessionState sessionState() const;
78 inline SignalProxy *signalProxy() const { return _signalProxy; }
80 const AliasManager &aliasManager() const { return _aliasManager; }
81 AliasManager &aliasManager() { return _aliasManager; }
83 inline EventManager *eventManager() const { return _eventManager; }
84 inline EventStringifier *eventStringifier() const { return _eventStringifier; }
85 inline CoreSessionEventProcessor *sessionEventProcessor() const { return _sessionEventProcessor; }
86 inline CtcpParser *ctcpParser() const { return _ctcpParser; }
87 inline IrcParser *ircParser() const { return _ircParser; }
89 inline CoreIrcListHelper *ircListHelper() const { return _ircListHelper; }
91 inline CoreIgnoreListManager *ignoreListManager() { return &_ignoreListManager; }
92 inline HighlightRuleManager *highlightRuleManager() { return &_highlightRuleManager; }
93 inline CoreTransferManager *transferManager() const { return _transferManager; }
94 inline CoreDccConfig *dccConfig() const { return _dccConfig; }
96 // void attachNetworkConnection(NetworkConnection *conn);
98 //! Return necessary data for restoring the session after restarting the core
99 void restoreSessionState();
102 void addClient(RemotePeer *peer);
103 void addClient(InternalPeer *peer);
105 void msgFromClient(BufferInfo, QString message);
107 //! Create an identity and propagate the changes to the clients.
108 /** \param identity The identity to be created.
110 void createIdentity(const Identity &identity, const QVariantMap &additional);
111 void createIdentity(const CoreIdentity &identity);
113 //! Remove identity and propagate that fact to the clients.
114 /** \param identity The identity to be removed.
116 void removeIdentity(IdentityId identity);
118 //! Create a network and propagate the changes to the clients.
119 /** \param info The network's settings.
121 void createNetwork(const NetworkInfo &info, const QStringList &persistentChannels = QStringList());
123 //! Remove network and propagate that fact to the clients.
124 /** \param network The id of the network to be removed.
126 void removeNetwork(NetworkId network);
128 //! Rename a Buffer for a given network
129 /* \param networkId The id of the network the buffer belongs to
130 * \param newName The new name of the buffer
131 * \param oldName The old name of the buffer
133 void renameBuffer(const NetworkId &networkId, const QString &newName, const QString &oldName);
135 void changePassword(PeerPtr peer, const QString &userName, const QString &oldPassword, const QString &newPassword);
137 void kickClient(int peerId);
139 QHash<QString, QString> persistentChannels(NetworkId) const;
142 * Marks us away (or unaway) on all networks
144 * @param[in] msg Away message, or blank to set unaway
145 * @param[in] skipFormatting If true, skip timestamp formatting codes (e.g. if already done)
147 void globalAway(const QString &msg = QString(), const bool skipFormatting = false);
151 void sessionState(const Protocol::SessionState &sessionState);
153 //void msgFromGui(uint netid, QString buf, QString message);
154 void displayMsg(Message message);
155 void displayStatusMsg(QString, QString);
157 void scriptResult(QString result);
159 //! Identity has been created.
160 /** This signal is propagated to the clients to tell them that the given identity has been created.
161 * \param identity The new identity.
163 void identityCreated(const Identity &identity);
165 //! Identity has been removed.
166 /** This signal is propagated to the clients to inform them about the removal of the given identity.
167 * \param identity The identity that has been removed.
169 void identityRemoved(IdentityId identity);
171 void networkCreated(NetworkId);
172 void networkRemoved(NetworkId);
173 void networkDisconnected(NetworkId);
175 void passwordChanged(PeerPtr peer, bool success);
177 void disconnectFromCore();
180 virtual void customEvent(QEvent *event);
183 void removeClient(Peer *peer);
185 void recvStatusMsgFromServer(QString msg);
186 void recvMessageFromServer(NetworkId networkId, Message::Type, BufferInfo::Type, const QString &target, const QString &text, const QString &sender = "", Message::Flags flags = Message::None);
188 void destroyNetwork(NetworkId);
190 void scriptRequest(QString script);
192 void clientsConnected();
193 void clientsDisconnected();
195 void updateIdentityBySender();
197 void saveSessionState() const;
200 void processMessages();
203 void initScriptEngine();
205 /// Hook for converting events to the old displayMsg() handlers
206 Q_INVOKABLE void processMessageEvent(MessageEvent *event);
210 SignalProxy *_signalProxy;
211 CoreAliasManager _aliasManager;
212 // QHash<NetworkId, NetworkConnection *> _connections;
213 QHash<NetworkId, CoreNetwork *> _networks;
214 // QHash<NetworkId, CoreNetwork *> _networksToRemove;
215 QHash<IdentityId, CoreIdentity *> _identities;
217 CoreBufferSyncer *_bufferSyncer;
218 CoreBacklogManager *_backlogManager;
219 CoreBufferViewManager *_bufferViewManager;
220 CoreDccConfig *_dccConfig;
221 CoreIrcListHelper *_ircListHelper;
222 CoreNetworkConfig *_networkConfig;
223 CoreCoreInfo _coreInfo;
224 CoreTransferManager *_transferManager;
226 EventManager *_eventManager;
227 EventStringifier *_eventStringifier; // should eventually move into client
228 CoreSessionEventProcessor *_sessionEventProcessor;
229 CtcpParser *_ctcpParser;
230 IrcParser *_ircParser;
232 QScriptEngine *scriptEngine;
235 * This method obtains the prefixes of the message's sender within a channel, by looking up their channelmodes, and
236 * processing them to prefixes based on the network's settings.
237 * @param sender The hostmask of the sender
238 * @param bufferInfo The BufferInfo object of the buffer
240 QString senderPrefixes(const QString &sender, const BufferInfo &bufferInfo) const;
241 QList<RawMessage> _messageQueue;
242 bool _processMessages;
243 CoreIgnoreListManager _ignoreListManager;
244 CoreHighlightRuleManager _highlightRuleManager;
251 BufferInfo::Type bufferType;
255 Message::Flags flags;
256 RawMessage(NetworkId networkId, Message::Type type, BufferInfo::Type bufferType, const QString &target, const QString &text, const QString &sender, Message::Flags flags)
257 : networkId(networkId), type(type), bufferType(bufferType), target(target), text(text), sender(sender), flags(flags) {}