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 {
52 Q_DECLARE_FLAGS(EventFlags, EventFlag)
57 /* These values make sense! Don't change without knowing what you do! */
60 GenericEvent = 0x00000000,
62 // for event group handlers (handleIrcEvent() will handle all IrcEvent* enums)
63 // event groups are specified by bits 20-24
64 EventGroupMask = 0x00ff0000,
66 NetworkEvent = 0x00010000,
75 IrcServerEvent = 0x00020000,
79 IrcEvent = 0x00030000,
81 IrcEventCapAuthenticate,
94 IrcEventRawPrivmsg, ///< Undecoded privmsg (still needs CTCP parsing)
95 IrcEventRawNotice, ///< Undecoded notice (still needs CTCP parsing)
96 IrcEventUnknown, ///< Unknown non-numeric cmd
98 IrcEventNumeric = 0x00031000, /* needs 1000 (0x03e8) consecutive free values! */
100 MessageEvent = 0x00040000, ///< Stringified event suitable for converting to Message
103 EventManager(QObject *parent = 0);
104 //virtual ~EventManager();
106 EventType eventTypeByName(const QString &name) const;
107 EventType eventGroupByName(const QString &name) const;
108 QString enumName(EventType type) const;
111 void registerObject(QObject *object, Priority priority = NormalPriority, const QString &methodPrefix = "handle");
112 void registerEventHandler(EventType event, QObject *object, const char *slot, Priority priority = NormalPriority);
113 void registerEventHandler(QList<EventType> events, QObject *object, const char *slot, Priority priority = NormalPriority);
115 //! Send an event to the registered handlers
117 The EventManager takes ownership of the event and will delete it once it's processed.
118 NOTE: This method is not threadsafe!
119 @param event The event to be dispatched
121 void sendEvent(Event *event);
129 explicit Handler(QObject *obj = 0, int method = 0, Priority prio = NormalPriority) {
131 methodIndex = method;
136 typedef QHash<uint, QList<Handler> > HandlerHash;
138 inline const HandlerHash ®isteredHandlers() const { return _registeredHandlers; }
139 inline HandlerHash ®isteredHandlers() { return _registeredHandlers; }
141 //! Add handlers to an existing sorted (by priority) handler list
142 void insertHandlers(const QList<Handler> &newHandlers, QList<Handler> &existing);
144 void dispatchEvent(Event *event);
146 //! @return the EventType enum
147 QMetaEnum eventEnum() const;
149 HandlerHash _registeredHandlers;
150 mutable QMetaEnum _enum;
153 Q_DECLARE_OPERATORS_FOR_FLAGS(EventManager::EventFlags);