1 /***************************************************************************
2 * Copyright (C) 2005-2020 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 ***************************************************************************/
23 #include "common-export.h"
28 #include "networkevent.h"
31 class COMMON_EXPORT IrcEvent : public NetworkEvent
35 EventManager::EventType type, Network* network, QHash<IrcTagKey, QString> tags, QString prefix, QStringList params = {})
36 : NetworkEvent(type, network)
37 , _tags(std::move(tags))
38 , _prefix(std::move(prefix))
39 , _params(std::move(params))
42 inline QString prefix() const { return _prefix; }
43 inline void setPrefix(const QString& prefix) { _prefix = prefix; }
45 inline QHash<IrcTagKey, QString> tags() const { return _tags; }
46 inline void setTags(const QHash<IrcTagKey, QString>& tags) { _tags = tags; }
48 inline QString nick() const { return nickFromMask(prefix()); }
50 inline QStringList params() const { return _params; }
51 inline void setParams(const QStringList& params) { _params = params; }
53 static Event* create(EventManager::EventType type, QVariantMap& map, Network* network);
56 explicit IrcEvent(EventManager::EventType type, QVariantMap& map, Network* network);
57 void toVariantMap(QVariantMap& map) const override;
59 inline QString className() const override { return "IrcEvent"; }
60 inline void debugInfo(QDebug& dbg) const override
62 NetworkEvent::debugInfo(dbg);
63 dbg << ", prefix = " << qPrintable(prefix()) << ", params = " << params();
67 QHash<IrcTagKey, QString> _tags;
72 class COMMON_EXPORT IrcEventNumeric : public IrcEvent
75 explicit IrcEventNumeric(uint number,
77 QHash<IrcTagKey, QString> tags,
80 QStringList params = {})
81 : IrcEvent(EventManager::IrcEventNumeric, network, std::move(tags), std::move(prefix), std::move(params))
83 , _target(std::move(target))
86 inline uint number() const { return _number; }
88 inline QString target() const { return _target; }
89 inline void setTarget(const QString& target) { _target = target; }
92 explicit IrcEventNumeric(EventManager::EventType type, QVariantMap& map, Network* network);
93 void toVariantMap(QVariantMap& map) const override;
95 inline QString className() const override { return "IrcEventNumeric"; }
96 inline void debugInfo(QDebug& dbg) const override
98 dbg << ", num = " << number();
99 NetworkEvent::debugInfo(dbg);
100 dbg << ", target = " << qPrintable(target())
101 << ", prefix = " << qPrintable(prefix())
102 << ", params = " << params();
109 friend class IrcEvent;
112 class COMMON_EXPORT IrcEventRawMessage : public IrcEvent
115 explicit IrcEventRawMessage(EventManager::EventType type,
117 QHash<IrcTagKey, QString> tags,
118 QByteArray rawMessage,
121 const QDateTime& timestamp = QDateTime())
122 : IrcEvent(type, network, std::move(tags), std::move(prefix), QStringList() << target)
123 , _rawMessage(std::move(rawMessage))
125 setTimestamp(timestamp);
128 inline QString target() const { return params().at(0); }
129 inline void setTarget(const QString& target) { setParams(QStringList() << target); }
131 inline QByteArray rawMessage() const { return _rawMessage; }
132 inline void setRawMessage(const QByteArray& rawMessage) { _rawMessage = rawMessage; }
135 explicit IrcEventRawMessage(EventManager::EventType type, QVariantMap& map, Network* network);
136 void toVariantMap(QVariantMap& map) const override;
138 inline QString className() const override { return "IrcEventRawMessage"; }
139 inline void debugInfo(QDebug& dbg) const override
141 NetworkEvent::debugInfo(dbg);
142 dbg << ", target = " << qPrintable(target())
143 << ", prefix = " << qPrintable(prefix())
144 << ", msg = " << rawMessage();
148 QByteArray _rawMessage;
150 friend class IrcEvent;