Make the EventType meta enum and related accessors static
[quassel.git] / src / common / eventmanager.h
index 54d2721..7ead8ba 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  *
 #ifndef EVENTMANAGER_H
 #define EVENTMANAGER_H
 
-#include <QHash>
-#include <QObject>
+#include <QMetaEnum>
 
 class Event;
 
 class EventManager : public QObject {
   Q_OBJECT
+  Q_FLAGS(EventFlag EventFlags)
   Q_ENUMS(EventType)
 
 public:
@@ -45,6 +45,16 @@ public:
     HighestPriority
   };
 
+  enum EventFlag {
+    Self     = 0x01, ///< Self-generated (user input) event
+    Fake     = 0x08, ///< Ignore this in CoreSessionEventProcessor
+    Netsplit = 0x10, ///< Netsplit join/part, ignore on display
+    Backlog  = 0x20,
+    Silent   = 0x40, ///< Don't generate a MessageEvent
+    Stopped  = 0x80
+  };
+  Q_DECLARE_FLAGS(EventFlags, EventFlag);
+
   /*
 
   */
@@ -64,6 +74,8 @@ public:
     NetworkReconnecting,
     NetworkDisconnecting,
     NetworkDisconnected,
+    NetworkSplitJoin,
+    NetworkSplitQuit,
     NetworkIncoming,
 
     IrcServerEvent              = 0x00020000,
@@ -71,8 +83,8 @@ public:
     IrcServerParseError,
 
     IrcEvent                    = 0x00030000,
+    IrcEventAuthenticate,
     IrcEventCap,
-    IrcEventCapAuthenticate,
     IrcEventInvite,
     IrcEventJoin,
     IrcEventKick,
@@ -85,27 +97,47 @@ public:
     IrcEventPrivmsg,
     IrcEventQuit,
     IrcEventTopic,
+    IrcEventRawPrivmsg, ///< Undecoded privmsg (still needs CTCP parsing)
+    IrcEventRawNotice,  ///< Undecoded notice (still needs CTCP parsing)
+    IrcEventUnknown,    ///< Unknown non-numeric cmd
 
     IrcEventNumeric             = 0x00031000, /* needs 1000 (0x03e8) consecutive free values! */
+    IrcEventNumericMask         = 0x00000fff, /* for checking if an event is numeric */
+
+    MessageEvent                = 0x00040000, ///< Stringified event suitable for converting to Message
+
+    CtcpEvent                   = 0x00050000,
+    CtcpEventFlush,
   };
 
   EventManager(QObject *parent = 0);
-  //virtual ~EventManager();
 
-  QStringList providesEnums();
+  static EventType eventTypeByName(const QString &name);
+  static EventType eventGroupByName(const QString &name);
+  static QString enumName(EventType type);
+  static QString enumName(int type); // for sanity tests
 
 public slots:
-  void registerObject(QObject *object, Priority priority = NormalPriority, const QString &methodPrefix = "handle");
-  void registerEventHandler(EventType event, QObject *object, const char *slot, Priority priority = NormalPriority);
-  void registerEventHandler(QList<EventType> events, QObject *object, const char *slot, Priority priority = NormalPriority);
+  void registerObject(QObject *object, Priority priority = NormalPriority,
+                      const QString &methodPrefix = "process",
+                      const QString &filterPrefix = "filter");
+  void registerEventHandler(EventType event, QObject *object, const char *slot,
+                            Priority priority = NormalPriority, bool isFilter = false);
+  void registerEventHandler(QList<EventType> events, QObject *object, const char *slot,
+                            Priority priority = NormalPriority, bool isFilter = false);
+
+  void registerEventFilter(EventType event, QObject *object, const char *slot);
+  void registerEventFilter(QList<EventType> events, QObject *object, const char *slot);
 
   //! Send an event to the registered handlers
   /**
     The EventManager takes ownership of the event and will delete it once it's processed.
-    NOTE: This method is not threadsafe!
     @param event The event to be dispatched
    */
-  void sendEvent(Event *event);
+  void postEvent(Event *event);
+
+protected:
+  virtual void customEvent(QEvent *event);
 
 private:
   struct Handler {
@@ -125,13 +157,28 @@ private:
   inline const HandlerHash &registeredHandlers() const { return _registeredHandlers; }
   inline HandlerHash &registeredHandlers() { return _registeredHandlers; }
 
+  inline const HandlerHash &registeredFilters() const { return _registeredFilters; }
+  inline HandlerHash &registeredFilters() { return _registeredFilters; }
+
   //! Add handlers to an existing sorted (by priority) handler list
-  void insertHandlers(const QList<Handler> &newHandlers, QList<Handler> &existing);
+  void insertHandlers(const QList<Handler> &newHandlers, QList<Handler> &existing, bool checkDupes = false);
+  //! Add filters to an existing filter hash
+  void insertFilters(const QList<Handler> &newFilters, QHash<QObject *, Handler> &existing);
+
+  int findEventType(const QString &methodSignature, const QString &methodPrefix) const;
 
+  void processEvent(Event *event);
   void dispatchEvent(Event *event);
 
-  HandlerHash _registeredHandlers;
+  //! @return the EventType enum
+  static QMetaEnum eventEnum();
 
+  HandlerHash _registeredHandlers;
+  HandlerHash _registeredFilters;
+  QList<Event *> _eventQueue;
+  static QMetaEnum _enum;
 };
 
+Q_DECLARE_OPERATORS_FOR_FLAGS(EventManager::EventFlags);
+
 #endif