a6c5462dbab6f1e44d40933217152db5b0f901e2
[quassel.git] / src / common / ctcpevent.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2019 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 <QUuid>
28
29 #include "ircevent.h"
30
31 class COMMON_EXPORT CtcpEvent : public IrcEvent
32 {
33 public:
34     enum CtcpType
35     {
36         Query,
37         Reply
38     };
39
40     explicit CtcpEvent(EventManager::EventType type,
41                        Network* network,
42                        const QString& prefix,
43                        QString target,
44                        CtcpType ctcpType,
45                        QString ctcpCmd,
46                        QString param,
47                        const QDateTime& timestamp = QDateTime(),
48                        const QUuid& uuid = QUuid())
49         : IrcEvent(type, network, prefix)
50         , _ctcpType(ctcpType)
51         , _ctcpCmd(std::move(ctcpCmd))
52         , _target(std::move(target))
53         , _param(std::move(param))
54         , _uuid(uuid)
55     {
56         setTimestamp(timestamp);
57     }
58
59     inline CtcpType ctcpType() const { return _ctcpType; }
60     inline void setCtcpType(CtcpType type) { _ctcpType = type; }
61
62     inline QString ctcpCmd() const { return _ctcpCmd; }
63     inline void setCtcpCmd(const QString& ctcpCmd) { _ctcpCmd = ctcpCmd; }
64
65     inline QString target() const { return _target; }
66     inline void setTarget(const QString& target) { _target = target; }
67
68     inline QString param() const { return _param; }
69     inline void setParam(const QString& param) { _param = param; }
70
71     inline QString reply() const { return _reply; }
72     inline void setReply(const QString& reply) { _reply = reply; }
73
74     inline QUuid uuid() const { return _uuid; }
75     inline void setUuid(const QUuid& uuid) { _uuid = uuid; }
76
77     static Event* create(EventManager::EventType type, QVariantMap& map, Network* network);
78
79 protected:
80     explicit CtcpEvent(EventManager::EventType type, QVariantMap& map, Network* network);
81     void toVariantMap(QVariantMap& map) const override;
82
83     inline QString className() const override { return "CtcpEvent"; }
84     inline void debugInfo(QDebug& dbg) const override
85     {
86         NetworkEvent::debugInfo(dbg);
87         dbg << ", prefix = " << qPrintable(prefix()) << ", target = " << qPrintable(target())
88             << ", ctcptype = " << (ctcpType() == Query ? "query" : "reply") << ", cmd = " << qPrintable(ctcpCmd())
89             << ", param = " << qPrintable(param()) << ", reply = " << qPrintable(reply());
90     }
91
92 private:
93     CtcpType _ctcpType;
94     QString _ctcpCmd;
95     QString _target, _param, _reply;
96     QUuid _uuid;
97 };