X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fnetworkevent.h;h=07cfc1ca898084593526193784e9ff38793d7d6e;hp=dfa492d7f0247b628bf138e549c7757dd0d1a8e0;hb=cc6e7c08709c4e761e2fd9c2e322751015497003;hpb=85fb228631cfb087ce80f4b778fae5f1c3877008 diff --git a/src/common/networkevent.h b/src/common/networkevent.h index dfa492d7..07cfc1ca 100644 --- a/src/common/networkevent.h +++ b/src/common/networkevent.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2010 by the Quassel Project * + * Copyright (C) 2005-2019 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -15,11 +15,12 @@ * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#ifndef NETWORKEVENT_H -#define NETWORKEVENT_H +#pragma once + +#include #include #include @@ -27,49 +28,117 @@ #include "event.h" #include "network.h" -class NetworkEvent : public Event { - +class COMMON_EXPORT NetworkEvent : public Event +{ public: - explicit NetworkEvent(EventManager::EventType type, Network *network) - : Event(type), - _network(network) - {} + explicit NetworkEvent(EventManager::EventType type, Network* network) + : Event(type) + , _network(network) + {} + + inline NetworkId networkId() const { return network() ? network()->networkId() : NetworkId(); } + inline Network* network() const { return _network; } + + static Event* create(EventManager::EventType type, QVariantMap& map, Network* network); + +protected: + explicit NetworkEvent(EventManager::EventType type, QVariantMap& map, Network* network); + void toVariantMap(QVariantMap& map) const override; - inline NetworkId networkId() const { return network()? network()->networkId() : NetworkId(); } - inline Network *network() const { return _network; } + inline QString className() const override { return "NetworkEvent"; } + inline void debugInfo(QDebug& dbg) const override { dbg.nospace() << ", net = " << qPrintable(_network->networkName()); } private: - Network *_network; + Network* _network; }; -class NetworkConnectionEvent : public NetworkEvent { +/*****************************************************************************/ +class COMMON_EXPORT NetworkConnectionEvent : public NetworkEvent +{ public: - explicit NetworkConnectionEvent(EventManager::EventType type, Network *network, Network::ConnectionState state) - : NetworkEvent(type, network), - _state(state) - {} + explicit NetworkConnectionEvent(EventManager::EventType type, Network* network, Network::ConnectionState state) + : NetworkEvent(type, network) + , _state(state) + {} - inline Network::ConnectionState connectionState() const { return _state; } - inline void setConnectionState(Network::ConnectionState state) { _state = state; } + inline Network::ConnectionState connectionState() const { return _state; } + inline void setConnectionState(Network::ConnectionState state) { _state = state; } + +protected: + explicit NetworkConnectionEvent(EventManager::EventType type, QVariantMap& map, Network* network); + void toVariantMap(QVariantMap& map) const override; + + inline QString className() const override { return "NetworkConnectionEvent"; } + inline void debugInfo(QDebug& dbg) const override + { + NetworkEvent::debugInfo(dbg); + dbg.nospace() << ", state = " << qPrintable(QString::number(_state)); + } private: - Network::ConnectionState _state; -}; + Network::ConnectionState _state; -class NetworkDataEvent : public NetworkEvent { + friend class NetworkEvent; +}; +class COMMON_EXPORT NetworkDataEvent : public NetworkEvent +{ public: - explicit NetworkDataEvent(EventManager::EventType type, Network *network, const QByteArray &data) - : NetworkEvent(type, network), - _data(data) - {} + explicit NetworkDataEvent(EventManager::EventType type, Network* network, QByteArray data) + : NetworkEvent(type, network) + , _data(std::move(data)) + {} - inline QByteArray data() const { return _data; } - inline void setData(const QByteArray &data) { _data = data; } + inline QByteArray data() const { return _data; } + inline void setData(const QByteArray& data) { _data = data; } + +protected: + explicit NetworkDataEvent(EventManager::EventType type, QVariantMap& map, Network* network); + void toVariantMap(QVariantMap& map) const override; + + inline QString className() const override { return "NetworkDataEvent"; } + inline void debugInfo(QDebug& dbg) const override + { + NetworkEvent::debugInfo(dbg); + dbg.nospace() << ", data = " << data(); + } private: - QByteArray _data; + QByteArray _data; + + friend class NetworkEvent; }; -#endif +class COMMON_EXPORT NetworkSplitEvent : public NetworkEvent +{ +public: + explicit NetworkSplitEvent(EventManager::EventType type, Network* network, QString channel, QStringList users, QString quitMsg) + : NetworkEvent(type, network) + , _channel(std::move(channel)) + , _users(std::move(users)) + , _quitMsg(std::move(quitMsg)) + {} + + inline QString channel() const { return _channel; } + inline QStringList users() const { return _users; } + inline QString quitMessage() const { return _quitMsg; } + +protected: + explicit NetworkSplitEvent(EventManager::EventType type, QVariantMap& map, Network* network); + void toVariantMap(QVariantMap& map) const override; + + inline QString className() const override { return "NetworkSplitEvent"; } + inline void debugInfo(QDebug& dbg) const override + { + NetworkEvent::debugInfo(dbg); + dbg.nospace() << ", channel = " << qPrintable(channel()) << ", users = " << users() << ", quitmsg = " << quitMessage(); + } + +private: + QString _channel; + QStringList _users; + QString _quitMsg; + + friend class NetworkEvent; +};