Provide (de)serialization for all event types
[quassel.git] / src / common / ircevent.h
index 0f4336d..71e4ad2 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  *
@@ -22,6 +22,7 @@
 #define IRCEVENT_H
 
 #include "networkevent.h"
+#include "util.h"
 
 class IrcEvent : public NetworkEvent {
 public:
@@ -34,10 +35,17 @@ public:
   inline QString prefix() const { return _prefix; }
   inline void setPrefix(const QString &prefix) { _prefix = prefix; }
 
+  inline QString nick() const { return nickFromMask(prefix()); }
+
   inline QStringList params() const { return _params; }
   inline void setParams(const QStringList &params) { _params = params; }
 
+  static Event *create(EventManager::EventType type, QVariantMap &map, Network *network);
+
 protected:
+  explicit IrcEvent(EventManager::EventType type, QVariantMap &map, Network *network);
+  void toVariantMap(QVariantMap &map) const;
+
   virtual inline QString className() const { return "IrcEvent"; }
   virtual inline void debugInfo(QDebug &dbg) const {
     NetworkEvent::debugInfo(dbg);
@@ -65,6 +73,9 @@ public:
   inline void setTarget(const QString &target) { _target = target; }
 
 protected:
+  explicit IrcEventNumeric(EventManager::EventType type, QVariantMap &map, Network *network);
+  void toVariantMap(QVariantMap &map) const;
+
   virtual inline QString className() const { return "IrcEventNumeric"; }
   virtual inline void debugInfo(QDebug &dbg) const {
     dbg << ", num = " << number();
@@ -78,14 +89,19 @@ private:
   uint _number;
   QString _target;
 
+  friend class IrcEvent;
 };
 
 class IrcEventRawMessage : public IrcEvent {
 public:
-  explicit IrcEventRawMessage(EventManager::EventType type, Network *network, const QString &prefix, const QString &target, const QByteArray &rawMessage)
+  explicit inline IrcEventRawMessage(EventManager::EventType type, Network *network,
+                                     const QByteArray &rawMessage, const QString &prefix, const QString &target,
+                                     const QDateTime &timestamp = QDateTime())
     : IrcEvent(type, network, prefix, QStringList() << target),
       _rawMessage(rawMessage)
-  {}
+  {
+    setTimestamp(timestamp);
+  }
 
   inline QString target() const { return params().at(0); }
   inline void setTarget(const QString &target) { setParams(QStringList() << target); }
@@ -94,6 +110,9 @@ public:
   inline void setRawMessage(const QByteArray &rawMessage) { _rawMessage = rawMessage; }
 
 protected:
+  explicit IrcEventRawMessage(EventManager::EventType type, QVariantMap &map, Network *network);
+  void toVariantMap(QVariantMap &map) const;
+
   virtual inline QString className() const { return "IrcEventRawMessage"; }
   virtual inline void debugInfo(QDebug &dbg) const {
     NetworkEvent::debugInfo(dbg);
@@ -105,6 +124,8 @@ protected:
 
 private:
   QByteArray _rawMessage;
+
+  friend class IrcEvent;
 };
 
 #endif