5b93d61e7af5ab62d5f93c0205569205a207ac08
[quassel.git] / src / common / ircevent.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 IRCEVENT_H
22 #define IRCEVENT_H
23
24 #include "networkevent.h"
25 #include "util.h"
26
27 class IrcEvent : public NetworkEvent {
28 public:
29   explicit IrcEvent(EventManager::EventType type, Network *network, const QString &prefix, const QStringList &params = QStringList())
30     : NetworkEvent(type, network),
31       _prefix(prefix),
32       _params(params)
33   {}
34
35   inline QString prefix() const { return _prefix; }
36   inline void setPrefix(const QString &prefix) { _prefix = prefix; }
37
38   inline QString nick() const { return nickFromMask(prefix()); }
39
40   inline QStringList params() const { return _params; }
41   inline void setParams(const QStringList &params) { _params = params; }
42
43 protected:
44   virtual inline QString className() const { return "IrcEvent"; }
45   virtual inline void debugInfo(QDebug &dbg) const {
46     NetworkEvent::debugInfo(dbg);
47     dbg << ", prefix = " << qPrintable(prefix())
48         << ", params = " << params();
49   }
50
51 private:
52   QString _prefix;
53   QStringList _params;
54
55 };
56
57 class IrcEventNumeric : public IrcEvent {
58 public:
59   explicit IrcEventNumeric(uint number, Network *network, const QString &prefix, const QString &target, const QStringList &params = QStringList())
60     : IrcEvent(EventManager::IrcEventNumeric, network, prefix, params),
61       _number(number),
62       _target(target)
63   {}
64
65   inline uint number() const { return _number; }
66
67   inline QString target() const { return _target; }
68   inline void setTarget(const QString &target) { _target = target; }
69
70 protected:
71   virtual inline QString className() const { return "IrcEventNumeric"; }
72   virtual inline void debugInfo(QDebug &dbg) const {
73     dbg << ", num = " << number();
74     NetworkEvent::debugInfo(dbg);
75     dbg << ", target = " << qPrintable(target())
76         << ", prefix = " << qPrintable(prefix())
77         << ", params = " << params();
78   }
79
80 private:
81   uint _number;
82   QString _target;
83
84 };
85
86 class IrcEventRawMessage : public IrcEvent {
87 public:
88   explicit inline IrcEventRawMessage(EventManager::EventType type, Network *network,
89                                      const QByteArray &rawMessage, const QString &prefix, const QString &target,
90                                      const QDateTime &timestamp = QDateTime())
91     : IrcEvent(type, network, prefix, QStringList() << target),
92       _rawMessage(rawMessage)
93   {
94     setTimestamp(timestamp);
95   }
96
97   inline QString target() const { return params().at(0); }
98   inline void setTarget(const QString &target) { setParams(QStringList() << target); }
99
100   inline QByteArray rawMessage() const { return _rawMessage; }
101   inline void setRawMessage(const QByteArray &rawMessage) { _rawMessage = rawMessage; }
102
103 protected:
104   virtual inline QString className() const { return "IrcEventRawMessage"; }
105   virtual inline void debugInfo(QDebug &dbg) const {
106     NetworkEvent::debugInfo(dbg);
107     dbg << ", target = " << qPrintable(target())
108         << ", prefix = " << qPrintable(prefix())
109         << ", msg = " << rawMessage();
110   }
111
112
113 private:
114   QByteArray _rawMessage;
115 };
116
117 #endif