Event backend porting
[quassel.git] / src / common / networkevent.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2010 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 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 protected:
42   virtual inline QString className() const { return "NetworkEvent"; }
43   virtual inline void debugInfo(QDebug &dbg) const { dbg.nospace() << ", net = " << qPrintable(_network->networkName()); }
44
45 private:
46   Network *_network;
47 };
48
49 class NetworkConnectionEvent : public NetworkEvent {
50
51 public:
52   explicit NetworkConnectionEvent(EventManager::EventType type, Network *network, Network::ConnectionState state)
53     : NetworkEvent(type, network),
54       _state(state)
55   {}
56
57   inline Network::ConnectionState connectionState() const { return _state; }
58   inline void setConnectionState(Network::ConnectionState state) { _state = state; }
59
60 protected:
61   virtual inline QString className() const { return "NetworkConnectionEvent"; }
62   virtual inline void debugInfo(QDebug &dbg) const {
63     NetworkEvent::debugInfo(dbg);
64     dbg.nospace() << ", state = " << qPrintable(QString::number(_state));
65   }
66
67 private:
68   Network::ConnectionState _state;
69 };
70
71 class NetworkDataEvent : public NetworkEvent {
72
73 public:
74   explicit NetworkDataEvent(EventManager::EventType type, Network *network, const QByteArray &data)
75     : NetworkEvent(type, network),
76       _data(data)
77   {}
78
79   inline QByteArray data() const { return _data; }
80   inline void setData(const QByteArray &data) { _data = data; }
81
82 protected:
83   virtual inline QString className() const { return "NetworkDataEvent"; }
84   virtual inline void debugInfo(QDebug &dbg) const {
85     NetworkEvent::debugInfo(dbg);
86     dbg.nospace() << ", data = " << data();
87   }
88
89 private:
90   QByteArray _data;
91 };
92
93 #endif