X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Feventmanager.h;h=cd8056c218bfe9c7bb0d8d1f85bcacacfff32e5c;hp=0a72a70ad8cc3021123a502c75bae1f06f753255;hb=c1cf157116de7fc3da96203aa6f03c38c7ebb650;hpb=30b159cb876a9495de42e9a3e70ca050516f0805 diff --git a/src/common/eventmanager.h b/src/common/eventmanager.h index 0a72a70a..cd8056c2 100644 --- a/src/common/eventmanager.h +++ b/src/common/eventmanager.h @@ -35,14 +35,15 @@ class COMMON_EXPORT EventManager : public QObject Q_FLAGS(EventFlag EventFlags) Q_ENUMS(EventType) -public : - - enum RegistrationMode { +public: + enum RegistrationMode + { Prepend, Append }; - enum Priority { + enum Priority + { VeryLowPriority, LowPriority, NormalPriority, @@ -50,13 +51,14 @@ 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 + 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,15 +66,16 @@ public : */ /* These values make sense! Don't change without knowing what you do! */ - enum EventType { - Invalid = 0xffffffff, - GenericEvent = 0x00000000, + enum EventType + { + Invalid = 0xffffffff, + GenericEvent = 0x00000000, // for event group handlers (handleIrcEvent() will handle all IrcEvent* enums) // event groups are specified by bits 20-24 - EventGroupMask = 0x00ff0000, + EventGroupMask = 0x00ff0000, - NetworkEvent = 0x00010000, + NetworkEvent = 0x00010000, NetworkConnecting, NetworkInitializing, NetworkInitialized, @@ -83,11 +86,11 @@ public : NetworkSplitQuit, NetworkIncoming, - IrcServerEvent = 0x00020000, + IrcServerEvent = 0x00020000, IrcServerIncoming, IrcServerParseError, - IrcEvent = 0x00030000, + IrcEvent = 0x00030000, IrcEventAuthenticate, IrcEventAccount, IrcEventAway, @@ -105,62 +108,63 @@ public : IrcEventPrivmsg, IrcEventQuit, IrcEventTopic, - IrcEventError, /// ERROR message from server + IrcEventError, /// ERROR message from server IrcEventWallops, - IrcEventRawPrivmsg, ///< Undecoded privmsg (still needs CTCP parsing) - IrcEventRawNotice, ///< Undecoded notice (still needs CTCP parsing) - IrcEventUnknown, ///< Unknown non-numeric cmd + 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 */ + 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 + MessageEvent = 0x00040000, ///< Stringified event suitable for converting to Message - CtcpEvent = 0x00050000, + CtcpEvent = 0x00050000, CtcpEventFlush, - KeyEvent = 0x00060000 + KeyEvent = 0x00060000 }; - EventManager(QObject *parent = nullptr); + EventManager(QObject* parent = nullptr); - static EventType eventTypeByName(const QString &name); - static EventType eventGroupByName(const QString &name); + 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 + static QString enumName(int type); // for sanity tests - Event *createEvent(const QVariantMap &map); + Event* createEvent(const QVariantMap& map); public slots: - 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 events, QObject *object, const char *slot, - Priority priority = NormalPriority, bool isFilter = false); + 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 events, QObject* object, const char* slot, Priority priority = NormalPriority, bool isFilter = false); - void registerEventFilter(EventType event, QObject *object, const char *slot); - void registerEventFilter(QList events, QObject *object, const char *slot); + void registerEventFilter(EventType event, QObject* object, const char* slot); + void registerEventFilter(QList 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. @param event The event to be dispatched */ - void postEvent(Event *event); + void postEvent(Event* event); protected: - virtual Network *networkById(NetworkId id) const = 0; - void customEvent(QEvent *event) override; + virtual Network* networkById(NetworkId id) const = 0; + void customEvent(QEvent* event) override; private: - struct Handler { - QObject *object; + struct Handler + { + QObject* object; int methodIndex; Priority priority; - explicit Handler(QObject *obj = nullptr, int method = 0, Priority prio = NormalPriority) + explicit Handler(QObject* obj = nullptr, int method = 0, Priority prio = NormalPriority) { object = obj; methodIndex = method; @@ -170,30 +174,29 @@ private: using HandlerHash = QHash>; - inline const HandlerHash ®isteredHandlers() const { return _registeredHandlers; } - inline HandlerHash ®isteredHandlers() { return _registeredHandlers; } + inline const HandlerHash& registeredHandlers() const { return _registeredHandlers; } + inline HandlerHash& registeredHandlers() { return _registeredHandlers; } - inline const HandlerHash ®isteredFilters() const { return _registeredFilters; } - inline HandlerHash ®isteredFilters() { return _registeredFilters; } + 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 &newHandlers, QList &existing, bool checkDupes = false); + void insertHandlers(const QList& newHandlers, QList& existing, bool checkDupes = false); //! Add filters to an existing filter hash - void insertFilters(const QList &newFilters, QHash &existing); + void insertFilters(const QList& newFilters, QHash& existing); - int findEventType(const QString &methodSignature, const QString &methodPrefix) const; + int findEventType(const QString& methodSignature, const QString& methodPrefix) const; - void processEvent(Event *event); - void dispatchEvent(Event *event); + void processEvent(Event* event); + void dispatchEvent(Event* event); //! @return the EventType enum static QMetaEnum eventEnum(); HandlerHash _registeredHandlers; HandlerHash _registeredFilters; - QList _eventQueue; + QList _eventQueue; static QMetaEnum _enum; }; - Q_DECLARE_OPERATORS_FOR_FLAGS(EventManager::EventFlags)