Don't actually build miniz if we have zlib
[quassel.git] / src / common / networkevent.cpp
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 #include "networkevent.h"
22
23 Event *NetworkEvent::create(EventManager::EventType type, QVariantMap &map, Network *network)
24 {
25     switch (type) {
26     case EventManager::NetworkIncoming:
27         return new NetworkDataEvent(type, map, network);
28
29     case EventManager::NetworkConnecting:
30     case EventManager::NetworkInitializing:
31     case EventManager::NetworkInitialized:
32     case EventManager::NetworkReconnecting:
33     case EventManager::NetworkDisconnecting:
34     case EventManager::NetworkDisconnected:
35         return new NetworkConnectionEvent(type, map, network);
36
37     case EventManager::NetworkSplitJoin:
38     case EventManager::NetworkSplitQuit:
39         return new NetworkSplitEvent(type, map, network);
40
41     default:
42         return 0;
43     }
44 }
45
46
47 NetworkEvent::NetworkEvent(EventManager::EventType type, QVariantMap &map, Network *network)
48     : Event(type, map)
49     , _network(network)
50 {
51 }
52
53
54 void NetworkEvent::toVariantMap(QVariantMap &map) const
55 {
56     Event::toVariantMap(map);
57     map["network"] = networkId().toInt();
58 }
59
60
61 NetworkDataEvent::NetworkDataEvent(EventManager::EventType type, QVariantMap &map, Network *network)
62     : NetworkEvent(type, map, network)
63 {
64     _data = map.take("data").toByteArray();
65 }
66
67
68 void NetworkDataEvent::toVariantMap(QVariantMap &map) const
69 {
70     NetworkEvent::toVariantMap(map);
71     map["data"] = data();
72 }
73
74
75 NetworkConnectionEvent::NetworkConnectionEvent(EventManager::EventType type, QVariantMap &map, Network *network)
76     : NetworkEvent(type, map, network)
77 {
78     _state = static_cast<Network::ConnectionState>(map.take("state").toInt()); // FIXME: check enum plausibility
79 }
80
81
82 void NetworkConnectionEvent::toVariantMap(QVariantMap &map) const
83 {
84     NetworkEvent::toVariantMap(map);
85     map["state"] = connectionState();
86 }
87
88
89 NetworkSplitEvent::NetworkSplitEvent(EventManager::EventType type, QVariantMap &map, Network *network)
90     : NetworkEvent(type, map, network)
91 {
92     _channel = map.take("channel").toString();
93     _users = map.take("users").toStringList();
94     _quitMsg = map.take("quitMessage").toString();
95 }
96
97
98 void NetworkSplitEvent::toVariantMap(QVariantMap &map) const
99 {
100     NetworkEvent::toVariantMap(map);
101     map["channel"] = channel();
102     map["users"] = users();
103     map["quitMessage"] = quitMessage();
104 }