1 /***************************************************************************
2 * Copyright (C) 2005-2018 by the Quassel Project *
3 * devel@quassel-irc.org *
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. *
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. *
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 ***************************************************************************/
21 #include "networkevent.h"
23 Event *NetworkEvent::create(EventManager::EventType type, QVariantMap &map, Network *network)
26 case EventManager::NetworkIncoming:
27 return new NetworkDataEvent(type, map, network);
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);
37 case EventManager::NetworkSplitJoin:
38 case EventManager::NetworkSplitQuit:
39 return new NetworkSplitEvent(type, map, network);
47 NetworkEvent::NetworkEvent(EventManager::EventType type, QVariantMap &map, Network *network)
54 void NetworkEvent::toVariantMap(QVariantMap &map) const
56 Event::toVariantMap(map);
57 map["network"] = networkId().toInt();
61 NetworkDataEvent::NetworkDataEvent(EventManager::EventType type, QVariantMap &map, Network *network)
62 : NetworkEvent(type, map, network)
64 _data = map.take("data").toByteArray();
68 void NetworkDataEvent::toVariantMap(QVariantMap &map) const
70 NetworkEvent::toVariantMap(map);
75 NetworkConnectionEvent::NetworkConnectionEvent(EventManager::EventType type, QVariantMap &map, Network *network)
76 : NetworkEvent(type, map, network)
78 _state = static_cast<Network::ConnectionState>(map.take("state").toInt()); // FIXME: check enum plausibility
82 void NetworkConnectionEvent::toVariantMap(QVariantMap &map) const
84 NetworkEvent::toVariantMap(map);
85 map["state"] = connectionState();
89 NetworkSplitEvent::NetworkSplitEvent(EventManager::EventType type, QVariantMap &map, Network *network)
90 : NetworkEvent(type, map, network)
92 _channel = map.take("channel").toString();
93 _users = map.take("users").toStringList();
94 _quitMsg = map.take("quitMessage").toString();
98 void NetworkSplitEvent::toVariantMap(QVariantMap &map) const
100 NetworkEvent::toVariantMap(map);
101 map["channel"] = channel();
102 map["users"] = users();
103 map["quitMessage"] = quitMessage();