Provide (de)serialization for all event types
[quassel.git] / src / common / networkevent.h
index dfa492d..7e46984 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2005-2010 by the Quassel Project                        *
+ *   Copyright (C) 2005-2012 by the Quassel Project                        *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
@@ -38,10 +38,21 @@ public:
   inline NetworkId networkId() const { return network()? network()->networkId() : NetworkId(); }
   inline Network *network() const { return _network; }
 
+  static Event *create(EventManager::EventType type, QVariantMap &map, Network *network);
+
+protected:
+  explicit NetworkEvent(EventManager::EventType type, QVariantMap &map, Network *network);
+  void toVariantMap(QVariantMap &map) const;
+
+  virtual inline QString className() const { return "NetworkEvent"; }
+  virtual inline void debugInfo(QDebug &dbg) const { dbg.nospace() << ", net = " << qPrintable(_network->networkName()); }
+
 private:
   Network *_network;
 };
 
+/*****************************************************************************/
+
 class NetworkConnectionEvent : public NetworkEvent {
 
 public:
@@ -53,8 +64,20 @@ public:
   inline Network::ConnectionState connectionState() const { return _state; }
   inline void setConnectionState(Network::ConnectionState state) { _state = state; }
 
+protected:
+  explicit NetworkConnectionEvent(EventManager::EventType type, QVariantMap &map, Network *network);
+  void toVariantMap(QVariantMap &map) const;
+
+  virtual inline QString className() const { return "NetworkConnectionEvent"; }
+  virtual inline void debugInfo(QDebug &dbg) const {
+    NetworkEvent::debugInfo(dbg);
+    dbg.nospace() << ", state = " << qPrintable(QString::number(_state));
+  }
+
 private:
   Network::ConnectionState _state;
+
+  friend class NetworkEvent;
 };
 
 class NetworkDataEvent : public NetworkEvent {
@@ -68,8 +91,59 @@ public:
   inline QByteArray data() const { return _data; }
   inline void setData(const QByteArray &data) { _data = data; }
 
+protected:
+  explicit NetworkDataEvent(EventManager::EventType type, QVariantMap &map, Network *network);
+  void toVariantMap(QVariantMap &map) const;
+
+  virtual inline QString className() const { return "NetworkDataEvent"; }
+  virtual inline void debugInfo(QDebug &dbg) const {
+    NetworkEvent::debugInfo(dbg);
+    dbg.nospace() << ", data = " << data();
+  }
+
 private:
   QByteArray _data;
+
+  friend class NetworkEvent;
 };
 
+class NetworkSplitEvent : public NetworkEvent {
+
+public:
+  explicit NetworkSplitEvent(EventManager::EventType type,
+                             Network *network,
+                             const QString &channel,
+                             const QStringList &users,
+                             const QString &quitMsg)
+    : NetworkEvent(type, network),
+      _channel(channel),
+      _users(users),
+      _quitMsg(quitMsg)
+  {}
+
+  inline QString channel() const { return _channel; }
+  inline QStringList users() const { return _users; }
+  inline QString quitMessage() const { return _quitMsg; }
+
+protected:
+  explicit NetworkSplitEvent(EventManager::EventType type, QVariantMap &map, Network *network);
+  void toVariantMap(QVariantMap &map) const;
+
+  virtual inline QString className() const { return "NetworkSplitEvent"; }
+  virtual inline void debugInfo(QDebug &dbg) const {
+    NetworkEvent::debugInfo(dbg);
+    dbg.nospace() << ", channel = " << qPrintable(channel())
+                  << ", users = " << users()
+                  << ", quitmsg = " << quitMessage();
+  }
+
+private:
+  QString _channel;
+  QStringList _users;
+  QString _quitMsg;
+
+  friend class NetworkEvent;
+};
+
+
 #endif