Provide (de)serialization for all event types
[quassel.git] / src / common / ircevent.cpp
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 #include "ircevent.h"
22
23 Event *IrcEvent::create(EventManager::EventType type, QVariantMap &map, Network *network) {
24   if((type & EventManager::IrcEventNumericMask) == EventManager::IrcEventNumeric)
25     return new IrcEventNumeric(type, map, network);
26
27   if((type & EventManager::EventGroupMask) != EventManager::IrcEvent)
28     return 0;
29
30   switch(type) {
31   case EventManager::IrcEventRawPrivmsg:
32   case EventManager::IrcEventRawNotice:
33     return new IrcEventRawMessage(type, map, network);
34
35   default:
36     return new IrcEvent(type, map, network);
37   }
38 }
39
40
41 IrcEvent::IrcEvent(EventManager::EventType type, QVariantMap &map, Network *network)
42   : NetworkEvent(type, map, network)
43 {
44   _prefix = map.take("prefix").toString();
45   _params = map.take("params").toStringList();
46 }
47
48
49 void IrcEvent::toVariantMap(QVariantMap &map) const {
50   NetworkEvent::toVariantMap(map);
51   map["prefix"] = prefix();
52   map["params"] = params();
53 }
54
55
56 IrcEventNumeric::IrcEventNumeric(EventManager::EventType type, QVariantMap &map, Network *network)
57   : IrcEvent(type, map, network)
58 {
59   _number = map.take("number").toUInt();
60   _target = map.take("target").toString();
61 }
62
63
64 void IrcEventNumeric::toVariantMap(QVariantMap &map) const {
65   IrcEvent::toVariantMap(map);
66   map["number"] = number();
67   map["target"] = target();
68 }
69
70
71 IrcEventRawMessage::IrcEventRawMessage(EventManager::EventType type, QVariantMap &map, Network *network)
72   : IrcEvent(type, map, network)
73 {
74   _rawMessage = map.take("rawMessage").toByteArray();
75 }
76
77
78 void IrcEventRawMessage::toVariantMap(QVariantMap &map) const {
79   IrcEvent::toVariantMap(map);
80   map["rawMessage"] = rawMessage();
81 }