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