1 /***************************************************************************
2  *   Copyright (C) 2005-2020 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                        QHash<IrcTagKey, QString> tags,
43                        QString prefix,
44                        QString target,
45                        CtcpType ctcpType,
46                        QString ctcpCmd,
47                        QString param,
48                        const QDateTime& timestamp = QDateTime(),
49                        const QUuid& uuid = QUuid())
IrcEvent(type,network,std::move (tags),std::move (prefix))50         : IrcEvent(type, network, std::move(tags), std::move(prefix))
51         , _ctcpType(ctcpType)
52         , _ctcpCmd(std::move(ctcpCmd))
53         , _target(std::move(target))
54         , _param(std::move(param))
55         , _uuid(uuid)
56     {
57         setTimestamp(timestamp);
58     }
59 
ctcpType()60     inline CtcpType ctcpType() const { return _ctcpType; }
setCtcpType(CtcpType type)61     inline void setCtcpType(CtcpType type) { _ctcpType = type; }
62 
ctcpCmd()63     inline QString ctcpCmd() const { return _ctcpCmd; }
setCtcpCmd(const QString & ctcpCmd)64     inline void setCtcpCmd(const QString& ctcpCmd) { _ctcpCmd = ctcpCmd; }
65 
target()66     inline QString target() const { return _target; }
setTarget(const QString & target)67     inline void setTarget(const QString& target) { _target = target; }
68 
param()69     inline QString param() const { return _param; }
setParam(const QString & param)70     inline void setParam(const QString& param) { _param = param; }
71 
reply()72     inline QString reply() const { return _reply; }
setReply(const QString & reply)73     inline void setReply(const QString& reply) { _reply = reply; }
74 
uuid()75     inline QUuid uuid() const { return _uuid; }
setUuid(const QUuid & uuid)76     inline void setUuid(const QUuid& uuid) { _uuid = uuid; }
77 
78     static Event* create(EventManager::EventType type, QVariantMap& map, Network* network);
79 
80 protected:
81     explicit CtcpEvent(EventManager::EventType type, QVariantMap& map, Network* network);
82     void toVariantMap(QVariantMap& map) const override;
83 
className()84     inline QString className() const override { return "CtcpEvent"; }
debugInfo(QDebug & dbg)85     inline void debugInfo(QDebug& dbg) const override
86     {
87         NetworkEvent::debugInfo(dbg);
88         dbg << ", prefix = " << qPrintable(prefix())
89             << ", target = " << qPrintable(target())
90             << ", ctcptype = " << (ctcpType() == Query ? "query" : "reply")
91             << ", cmd = " << qPrintable(ctcpCmd())
92             << ", param = " << qPrintable(param())
93             << ", reply = " << qPrintable(reply());
94     }
95 
96 private:
97     CtcpType _ctcpType;
98     QString _ctcpCmd;
99     QString _target, _param, _reply;
100     QUuid _uuid;
101 };
102