Provide (de)serialization for all event types
[quassel.git] / src / common / ctcpevent.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2012 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  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21 #ifndef CTCPEVENT_H
22 #define CTCPEVENT_H
23
24 #include "ircevent.h"
25
26 #include <QUuid>
27
28 class CtcpEvent : public IrcEvent {
29
30 public:
31   enum CtcpType {
32     Query,
33     Reply
34   };
35
36   explicit CtcpEvent(EventManager::EventType type, Network *network, const QString &prefix, const QString &target,
37                      CtcpType ctcpType, const QString &ctcpCmd, const QString &param,
38                      const QDateTime &timestamp = QDateTime(), const QUuid &uuid = QUuid())
39     : IrcEvent(type, network, prefix),
40     _ctcpType(ctcpType),
41     _ctcpCmd(ctcpCmd),
42     _target(target),
43     _param(param),
44     _uuid(uuid)
45   {
46     setTimestamp(timestamp);
47   }
48
49   inline CtcpType ctcpType() const { return _ctcpType; }
50   inline void setCtcpType(CtcpType type) { _ctcpType = type; }
51
52   inline QString ctcpCmd() const { return _ctcpCmd; }
53   inline void setCtcpCmd(const QString &ctcpCmd) { _ctcpCmd = ctcpCmd; }
54
55   inline QString target() const { return _target; }
56   inline void setTarget(const QString &target) { _target = target; }
57
58   inline QString param() const { return _param; }
59   inline void setParam(const QString &param) { _param = param; }
60
61   inline QString reply() const { return _reply; }
62   inline void setReply(const QString &reply) { _reply = reply; }
63
64   inline QUuid uuid() const { return _uuid; }
65   inline void setUuid(const QUuid &uuid) { _uuid = uuid; }
66
67   static Event *create(EventManager::EventType type, QVariantMap &map, Network *network);
68
69 protected:
70   explicit CtcpEvent(EventManager::EventType type, QVariantMap &map, Network *network);
71   void toVariantMap(QVariantMap &map) const;
72
73   virtual inline QString className() const { return "CtcpEvent"; }
74   virtual inline void debugInfo(QDebug &dbg) const {
75     NetworkEvent::debugInfo(dbg);
76     dbg << ", prefix = " << qPrintable(prefix())
77         << ", target = " << qPrintable(target())
78         << ", ctcptype = " << (ctcpType() == Query? "query" : "reply")
79         << ", cmd = " << qPrintable(ctcpCmd())
80         << ", param = " << qPrintable(param())
81         << ", reply = " << qPrintable(reply());
82   }
83
84 private:
85   CtcpType _ctcpType;
86   QString _ctcpCmd;
87   QString _target, _param, _reply;
88   QUuid _uuid;
89 };
90
91 #endif