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 NETWORKEVENT_H |
22 | #define NETWORKEVENT_H |
23 | |
24 | #include <QStringList> |
25 | #include <QVariantList> |
26 | |
27 | #include "event.h" |
28 | #include "network.h" |
29 | |
30 | class NetworkEvent : public Event |
31 | { |
32 | public: |
33 | explicit NetworkEvent(EventManager::EventType type, Network *network) |
34 | : Event(type), |
35 | _network(network) |
36 | {} |
37 | |
38 | inline NetworkId networkId() const { return network() ? network()->networkId() : NetworkId(); } |
39 | inline Network *network() const { return _network; } |
40 | |
41 | static Event *create(EventManager::EventType type, QVariantMap &map, Network *network); |
42 | |
43 | protected: |
44 | explicit NetworkEvent(EventManager::EventType type, QVariantMap &map, Network *network); |
45 | void toVariantMap(QVariantMap &map) const; |
46 | |
47 | virtual inline QString className() const { return "NetworkEvent" ; } |
48 | virtual inline void debugInfo(QDebug &dbg) const { dbg.nospace() << ", net = " << qPrintable(_network->networkName()); } |
49 | |
50 | private: |
51 | Network *_network; |
52 | }; |
53 | |
54 | |
55 | /*****************************************************************************/ |
56 | |
57 | class NetworkConnectionEvent : public NetworkEvent |
58 | { |
59 | public: |
60 | explicit NetworkConnectionEvent(EventManager::EventType type, Network *network, Network::ConnectionState state) |
61 | : NetworkEvent(type, network), |
62 | _state(state) |
63 | {} |
64 | |
65 | inline Network::ConnectionState connectionState() const { return _state; } |
66 | inline void setConnectionState(Network::ConnectionState state) { _state = state; } |
67 | |
68 | protected: |
69 | explicit NetworkConnectionEvent(EventManager::EventType type, QVariantMap &map, Network *network); |
70 | void toVariantMap(QVariantMap &map) const; |
71 | |
72 | virtual inline QString className() const { return "NetworkConnectionEvent" ; } |
73 | virtual inline void debugInfo(QDebug &dbg) const |
74 | { |
75 | NetworkEvent::debugInfo(dbg); |
76 | dbg.nospace() << ", state = " << qPrintable(QString::number(_state)); |
77 | } |
78 | |
79 | |
80 | private: |
81 | Network::ConnectionState _state; |
82 | |
83 | friend class NetworkEvent; |
84 | }; |
85 | |
86 | |
87 | class NetworkDataEvent : public NetworkEvent |
88 | { |
89 | public: |
90 | explicit NetworkDataEvent(EventManager::EventType type, Network *network, const QByteArray &data) |
91 | : NetworkEvent(type, network), |
92 | _data(data) |
93 | {} |
94 | |
95 | inline QByteArray data() const { return _data; } |
96 | inline void setData(const QByteArray &data) { _data = data; } |
97 | |
98 | protected: |
99 | explicit NetworkDataEvent(EventManager::EventType type, QVariantMap &map, Network *network); |
100 | void toVariantMap(QVariantMap &map) const; |
101 | |
102 | virtual inline QString className() const { return "NetworkDataEvent" ; } |
103 | virtual inline void debugInfo(QDebug &dbg) const |
104 | { |
105 | NetworkEvent::debugInfo(dbg); |
106 | dbg.nospace() << ", data = " << data(); |
107 | } |
108 | |
109 | |
110 | private: |
111 | QByteArray _data; |
112 | |
113 | friend class NetworkEvent; |
114 | }; |
115 | |
116 | |
117 | class NetworkSplitEvent : public NetworkEvent |
118 | { |
119 | public: |
120 | explicit NetworkSplitEvent(EventManager::EventType type, |
121 | Network *network, |
122 | const QString &channel, |
123 | const QStringList &users, |
124 | const QString &quitMsg) |
125 | : NetworkEvent(type, network), |
126 | _channel(channel), |
127 | _users(users), |
128 | _quitMsg(quitMsg) |
129 | {} |
130 | |
131 | inline QString channel() const { return _channel; } |
132 | inline QStringList users() const { return _users; } |
133 | inline QString quitMessage() const { return _quitMsg; } |
134 | |
135 | protected: |
136 | explicit NetworkSplitEvent(EventManager::EventType type, QVariantMap &map, Network *network); |
137 | void toVariantMap(QVariantMap &map) const; |
138 | |
139 | virtual inline QString className() const { return "NetworkSplitEvent" ; } |
140 | virtual inline void debugInfo(QDebug &dbg) const |
141 | { |
142 | NetworkEvent::debugInfo(dbg); |
143 | dbg.nospace() << ", channel = " << qPrintable(channel()) |
144 | << ", users = " << users() |
145 | << ", quitmsg = " << quitMessage(); |
146 | } |
147 | |
148 | |
149 | private: |
150 | QString _channel; |
151 | QStringList _users; |
152 | QString _quitMsg; |
153 | |
154 | friend class NetworkEvent; |
155 | }; |
156 | |
157 | |
158 | #endif |
159 | |