1 /***************************************************************************
2 * Copyright (C) 2005-2016 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 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #ifndef EVENTMANAGER_H
22 #define EVENTMANAGER_H
31 class EventManager : public QObject
34 Q_FLAGS(EventFlag EventFlags)
39 enum RegistrationMode {
53 Self = 0x01, ///< Self-generated (user input) event
54 Fake = 0x08, ///< Ignore this in CoreSessionEventProcessor
55 Netsplit = 0x10, ///< Netsplit join/part, ignore on display
57 Silent = 0x40, ///< Don't generate a MessageEvent
60 Q_DECLARE_FLAGS(EventFlags, EventFlag)
65 /* These values make sense! Don't change without knowing what you do! */
68 GenericEvent = 0x00000000,
70 // for event group handlers (handleIrcEvent() will handle all IrcEvent* enums)
71 // event groups are specified by bits 20-24
72 EventGroupMask = 0x00ff0000,
74 NetworkEvent = 0x00010000,
85 IrcServerEvent = 0x00020000,
89 IrcEvent = 0x00030000,
107 IrcEventError, /// ERROR message from server
109 IrcEventRawPrivmsg, ///< Undecoded privmsg (still needs CTCP parsing)
110 IrcEventRawNotice, ///< Undecoded notice (still needs CTCP parsing)
111 IrcEventUnknown, ///< Unknown non-numeric cmd
113 IrcEventNumeric = 0x00031000, /* needs 1000 (0x03e8) consecutive free values! */
114 IrcEventNumericMask = 0x00000fff, /* for checking if an event is numeric */
116 MessageEvent = 0x00040000, ///< Stringified event suitable for converting to Message
118 CtcpEvent = 0x00050000,
121 KeyEvent = 0x00060000
124 EventManager(QObject *parent = 0);
126 static EventType eventTypeByName(const QString &name);
127 static EventType eventGroupByName(const QString &name);
128 static QString enumName(EventType type);
129 static QString enumName(int type); // for sanity tests
131 Event *createEvent(const QVariantMap &map);
134 void registerObject(QObject *object, Priority priority = NormalPriority,
135 const QString &methodPrefix = "process",
136 const QString &filterPrefix = "filter");
137 void registerEventHandler(EventType event, QObject *object, const char *slot,
138 Priority priority = NormalPriority, bool isFilter = false);
139 void registerEventHandler(QList<EventType> events, QObject *object, const char *slot,
140 Priority priority = NormalPriority, bool isFilter = false);
142 void registerEventFilter(EventType event, QObject *object, const char *slot);
143 void registerEventFilter(QList<EventType> events, QObject *object, const char *slot);
145 //! Send an event to the registered handlers
147 The EventManager takes ownership of the event and will delete it once it's processed.
148 @param event The event to be dispatched
150 void postEvent(Event *event);
153 virtual Network *networkById(NetworkId id) const = 0;
154 virtual void customEvent(QEvent *event);
162 explicit Handler(QObject *obj = 0, int method = 0, Priority prio = NormalPriority)
165 methodIndex = method;
170 typedef QHash<uint, QList<Handler> > HandlerHash;
172 inline const HandlerHash ®isteredHandlers() const { return _registeredHandlers; }
173 inline HandlerHash ®isteredHandlers() { return _registeredHandlers; }
175 inline const HandlerHash ®isteredFilters() const { return _registeredFilters; }
176 inline HandlerHash ®isteredFilters() { return _registeredFilters; }
178 //! Add handlers to an existing sorted (by priority) handler list
179 void insertHandlers(const QList<Handler> &newHandlers, QList<Handler> &existing, bool checkDupes = false);
180 //! Add filters to an existing filter hash
181 void insertFilters(const QList<Handler> &newFilters, QHash<QObject *, Handler> &existing);
183 int findEventType(const QString &methodSignature, const QString &methodPrefix) const;
185 void processEvent(Event *event);
186 void dispatchEvent(Event *event);
188 //! @return the EventType enum
189 static QMetaEnum eventEnum();
191 HandlerHash _registeredHandlers;
192 HandlerHash _registeredFilters;
193 QList<Event *> _eventQueue;
194 static QMetaEnum _enum;
198 Q_DECLARE_OPERATORS_FOR_FLAGS(EventManager::EventFlags);