cmake: avoid de-duplication of user's CXXFLAGS
[quassel.git] / src / common / ircevent.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2022 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 #pragma once
22
23 #include "common-export.h"
24
25 #include <utility>
26
27 #include "irctag.h"
28 #include "networkevent.h"
29 #include "util.h"
30
31 class COMMON_EXPORT IrcEvent : public NetworkEvent
32 {
33 public:
34     explicit IrcEvent(
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))
40     {}
41
42     inline QString prefix() const { return _prefix; }
43     inline void setPrefix(const QString& prefix) { _prefix = prefix; }
44
45     inline QHash<IrcTagKey, QString> tags() const { return _tags; }
46     inline void setTags(const QHash<IrcTagKey, QString>& tags) { _tags = tags; }
47
48     inline QString nick() const { return nickFromMask(prefix()); }
49
50     inline QStringList params() const { return _params; }
51     inline void setParams(const QStringList& params) { _params = params; }
52
53     static Event* create(EventManager::EventType type, QVariantMap& map, Network* network);
54
55 protected:
56     explicit IrcEvent(EventManager::EventType type, QVariantMap& map, Network* network);
57     void toVariantMap(QVariantMap& map) const override;
58
59     inline QString className() const override { return "IrcEvent"; }
60     inline void debugInfo(QDebug& dbg) const override
61     {
62         NetworkEvent::debugInfo(dbg);
63         dbg << ", prefix = " << qPrintable(prefix()) << ", params = " << params();
64     }
65
66 private:
67     QHash<IrcTagKey, QString> _tags;
68     QString _prefix;
69     QStringList _params;
70 };
71
72 class COMMON_EXPORT IrcEventNumeric : public IrcEvent
73 {
74 public:
75     explicit IrcEventNumeric(uint number,
76                              Network* network,
77                              QHash<IrcTagKey, QString> tags,
78                              QString prefix,
79                              QString target,
80                              QStringList params = {})
81         : IrcEvent(EventManager::IrcEventNumeric, network, std::move(tags), std::move(prefix), std::move(params))
82         , _number(number)
83         , _target(std::move(target))
84     {}
85
86     inline uint number() const { return _number; }
87
88     inline QString target() const { return _target; }
89     inline void setTarget(const QString& target) { _target = target; }
90
91 protected:
92     explicit IrcEventNumeric(EventManager::EventType type, QVariantMap& map, Network* network);
93     void toVariantMap(QVariantMap& map) const override;
94
95     inline QString className() const override { return "IrcEventNumeric"; }
96     inline void debugInfo(QDebug& dbg) const override
97     {
98         dbg << ", num = " << number();
99         NetworkEvent::debugInfo(dbg);
100         dbg << ", target = " << qPrintable(target())
101             << ", prefix = " << qPrintable(prefix())
102             << ", params = " << params();
103     }
104
105 private:
106     uint _number;
107     QString _target;
108
109     friend class IrcEvent;
110 };
111
112 class COMMON_EXPORT IrcEventRawMessage : public IrcEvent
113 {
114 public:
115     explicit IrcEventRawMessage(EventManager::EventType type,
116                                 Network* network,
117                                 QHash<IrcTagKey, QString> tags,
118                                 QByteArray rawMessage,
119                                 QString prefix,
120                                 QString target,
121                                 const QDateTime& timestamp = QDateTime())
122         : IrcEvent(type, network, std::move(tags), std::move(prefix), QStringList() << target)
123         , _rawMessage(std::move(rawMessage))
124     {
125         setTimestamp(timestamp);
126     }
127
128     inline QString target() const { return params().at(0); }
129     inline void setTarget(const QString& target) { setParams(QStringList() << target); }
130
131     inline QByteArray rawMessage() const { return _rawMessage; }
132     inline void setRawMessage(const QByteArray& rawMessage) { _rawMessage = rawMessage; }
133
134 protected:
135     explicit IrcEventRawMessage(EventManager::EventType type, QVariantMap& map, Network* network);
136     void toVariantMap(QVariantMap& map) const override;
137
138     inline QString className() const override { return "IrcEventRawMessage"; }
139     inline void debugInfo(QDebug& dbg) const override
140     {
141         NetworkEvent::debugInfo(dbg);
142         dbg << ", target = " << qPrintable(target())
143             << ", prefix = " << qPrintable(prefix())
144             << ", msg = " << rawMessage();
145     }
146
147 private:
148     QByteArray _rawMessage;
149
150     friend class IrcEvent;
151 };