1 /***************************************************************************
2 * Copyright (C) 2005-2010 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #ifndef EVENTMANAGER_H
22 #define EVENTMANAGER_H
28 class EventManager : public QObject {
30 Q_FLAGS(EventFlag EventFlags)
35 enum RegistrationMode {
49 Self = 0x01, ///< Self-generated (user input) event
50 Fake = 0x08, ///< Ignore this in CoreSessionEventProcessor
51 Netsplit = 0x10, ///< Netsplit join/part, ignore on display
53 Silent = 0x40, ///< Don't generate a MessageEvent
56 Q_DECLARE_FLAGS(EventFlags, EventFlag);
61 /* These values make sense! Don't change without knowing what you do! */
64 GenericEvent = 0x00000000,
66 // for event group handlers (handleIrcEvent() will handle all IrcEvent* enums)
67 // event groups are specified by bits 20-24
68 EventGroupMask = 0x00ff0000,
70 NetworkEvent = 0x00010000,
81 IrcServerEvent = 0x00020000,
85 IrcEvent = 0x00030000,
100 IrcEventRawPrivmsg, ///< Undecoded privmsg (still needs CTCP parsing)
101 IrcEventRawNotice, ///< Undecoded notice (still needs CTCP parsing)
102 IrcEventUnknown, ///< Unknown non-numeric cmd
104 IrcEventNumeric = 0x00031000, /* needs 1000 (0x03e8) consecutive free values! */
105 IrcEventNumericMask = 0x00000fff, /* for checking if an event is numeric */
107 MessageEvent = 0x00040000, ///< Stringified event suitable for converting to Message
109 CtcpEvent = 0x00050000,
113 EventManager(QObject *parent = 0);
115 EventType eventTypeByName(const QString &name) const;
116 EventType eventGroupByName(const QString &name) const;
118 QString enumName(EventType type) const;
121 void registerObject(QObject *object, Priority priority = NormalPriority,
122 const QString &methodPrefix = "process",
123 const QString &filterPrefix = "filter");
124 void registerEventHandler(EventType event, QObject *object, const char *slot,
125 Priority priority = NormalPriority, bool isFilter = false);
126 void registerEventHandler(QList<EventType> events, QObject *object, const char *slot,
127 Priority priority = NormalPriority, bool isFilter = false);
129 void registerEventFilter(EventType event, QObject *object, const char *slot);
130 void registerEventFilter(QList<EventType> events, QObject *object, const char *slot);
132 //! Send an event to the registered handlers
134 The EventManager takes ownership of the event and will delete it once it's processed.
135 @param event The event to be dispatched
137 void postEvent(Event *event);
140 virtual void customEvent(QEvent *event);
148 explicit Handler(QObject *obj = 0, int method = 0, Priority prio = NormalPriority) {
150 methodIndex = method;
155 typedef QHash<uint, QList<Handler> > HandlerHash;
157 inline const HandlerHash ®isteredHandlers() const { return _registeredHandlers; }
158 inline HandlerHash ®isteredHandlers() { return _registeredHandlers; }
160 inline const HandlerHash ®isteredFilters() const { return _registeredFilters; }
161 inline HandlerHash ®isteredFilters() { return _registeredFilters; }
163 //! Add handlers to an existing sorted (by priority) handler list
164 void insertHandlers(const QList<Handler> &newHandlers, QList<Handler> &existing, bool checkDupes = false);
165 //! Add filters to an existing filter hash
166 void insertFilters(const QList<Handler> &newFilters, QHash<QObject *, Handler> &existing);
168 int findEventType(const QString &methodSignature, const QString &methodPrefix) const;
170 void processEvent(Event *event);
171 void dispatchEvent(Event *event);
173 //! @return the EventType enum
174 QMetaEnum eventEnum() const;
176 HandlerHash _registeredHandlers;
177 HandlerHash _registeredFilters;
178 mutable QMetaEnum _enum;
179 QList<Event *> _eventQueue;
182 Q_DECLARE_OPERATORS_FOR_FLAGS(EventManager::EventFlags);