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