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