X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Feventmanager.h;h=e3b29800fc80e2093e4900f56134bda479b25289;hp=4030cffa7760370ae8cd808ad74d0eb85a1a8567;hb=be7f9fcb48b8587e59aefb26cec1caf3fcb95da2;hpb=46a76ffbf0e9e7af3d4ceb074c0b8dff461b4a86 diff --git a/src/common/eventmanager.h b/src/common/eventmanager.h index 4030cffa..e3b29800 100644 --- a/src/common/eventmanager.h +++ b/src/common/eventmanager.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2010 by the Quassel Project * + * Copyright (C) 2005-2014 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #ifndef EVENTMANAGER_H @@ -23,156 +23,174 @@ #include -class Event; +#include "types.h" -class EventManager : public QObject { - Q_OBJECT - Q_FLAGS(EventFlag EventFlags) - Q_ENUMS(EventType) - -public: - - enum RegistrationMode { - Prepend, - Append - }; - - enum Priority { - VeryLowPriority, - LowPriority, - NormalPriority, - HighPriority, - HighestPriority - }; - - enum EventFlag { - Backlog = 0x20, - Silent = 0x40, ///< Don't generate a MessageEvent - Stopped = 0x80 - }; - Q_DECLARE_FLAGS(EventFlags, EventFlag) - - /* - - */ - /* These values make sense! Don't change without knowing what you do! */ - 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, - - NetworkEvent = 0x00010000, - NetworkConnecting, - NetworkInitializing, - NetworkInitialized, - NetworkReconnecting, - NetworkDisconnecting, - NetworkDisconnected, - NetworkIncoming, - - IrcServerEvent = 0x00020000, - IrcServerIncoming, - IrcServerParseError, - - IrcEvent = 0x00030000, - IrcEventAuthenticate, - IrcEventCap, - IrcEventInvite, - IrcEventJoin, - IrcEventKick, - IrcEventMode, - IrcEventNick, - IrcEventNotice, - IrcEventPart, - IrcEventPing, - IrcEventPong, - 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 - }; - - EventManager(QObject *parent = 0); - virtual ~EventManager(); - - EventType eventTypeByName(const QString &name) const; - EventType eventGroupByName(const QString &name) const; - QString enumName(EventType type) const; +class Event; +class Network; + +class EventManager : public QObject +{ + Q_OBJECT + Q_FLAGS(EventFlag EventFlags) + Q_ENUMS(EventType) + +public : + + enum RegistrationMode { + Prepend, + Append + }; + + enum Priority { + VeryLowPriority, + LowPriority, + NormalPriority, + HighPriority, + 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) + + /* + + */ + /* These values make sense! Don't change without knowing what you do! */ + 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, + + NetworkEvent = 0x00010000, + NetworkConnecting, + NetworkInitializing, + NetworkInitialized, + NetworkReconnecting, + NetworkDisconnecting, + NetworkDisconnected, + NetworkSplitJoin, + NetworkSplitQuit, + NetworkIncoming, + + IrcServerEvent = 0x00020000, + IrcServerIncoming, + IrcServerParseError, + + IrcEvent = 0x00030000, + IrcEventAuthenticate, + IrcEventCap, + IrcEventInvite, + IrcEventJoin, + IrcEventKick, + IrcEventMode, + IrcEventNick, + IrcEventNotice, + IrcEventPart, + IrcEventPing, + IrcEventPong, + IrcEventPrivmsg, + IrcEventQuit, + IrcEventTopic, + IrcEventWallops, + 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, + + KeyEvent = 0x00060000 + }; + + EventManager(QObject *parent = 0); + + 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 + + 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 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. - NOTE: This method is not threadsafe! - @param event The event to be dispatched - */ - void sendEvent(Event *event); + 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); + + //! 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); protected: - virtual void customEvent(QEvent *event); + virtual Network *networkById(NetworkId id) const = 0; + virtual void customEvent(QEvent *event); private: - struct Handler { - QObject *object; - int methodIndex; - Priority priority; + struct Handler { + QObject *object; + int methodIndex; + Priority priority; - explicit Handler(QObject *obj = 0, int method = 0, Priority prio = NormalPriority) { - object = obj; - methodIndex = method; - priority = prio; - } - }; + explicit Handler(QObject *obj = 0, int method = 0, Priority prio = NormalPriority) + { + object = obj; + methodIndex = method; + priority = prio; + } + }; - typedef QHash > HandlerHash; + typedef QHash > HandlerHash; - inline const HandlerHash ®isteredHandlers() const { return _registeredHandlers; } - inline HandlerHash ®isteredHandlers() { return _registeredHandlers; } + inline const HandlerHash ®isteredHandlers() const { return _registeredHandlers; } + inline HandlerHash ®isteredHandlers() { return _registeredHandlers; } - inline const HandlerHash ®isteredFilters() const { return _registeredFilters; } - inline HandlerHash ®isteredFilters() { return _registeredFilters; } + inline const HandlerHash ®isteredFilters() const { return _registeredFilters; } + inline HandlerHash ®isteredFilters() { return _registeredFilters; } - //! Add handlers to an existing sorted (by priority) handler list - void insertHandlers(const QList &newHandlers, QList &existing); - //! Add filters to an existing filter hash - void insertFilters(const QList &newFilters, QHash &existing); + //! Add handlers to an existing sorted (by priority) handler list + void insertHandlers(const QList &newHandlers, QList &existing, bool checkDupes = false); + //! Add filters to an existing filter hash + 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 processEvents(); - void dispatchEvent(Event *event); + void processEvent(Event *event); + void dispatchEvent(Event *event); - //! @return the EventType enum - QMetaEnum eventEnum() const; + //! @return the EventType enum + static QMetaEnum eventEnum(); - HandlerHash _registeredHandlers; - HandlerHash _registeredFilters; - mutable QMetaEnum _enum; - - QList _eventQueue; + HandlerHash _registeredHandlers; + HandlerHash _registeredFilters; + QList _eventQueue; + static QMetaEnum _enum; }; + Q_DECLARE_OPERATORS_FOR_FLAGS(EventManager::EventFlags); #endif