Introducing the first shiny stuff for our new event-based core backend
[quassel.git] / src / common / eventmanager.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2010 by the Quassel Project                        *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
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.                                           *
9  *                                                                         *
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.                          *
14  *                                                                         *
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  ***************************************************************************/
20
21 #ifndef EVENTMANAGER_H
22 #define EVENTMANAGER_H
23
24 #include <QHash>
25 #include <QObject>
26
27 class Event;
28
29 class EventManager : public QObject {
30   Q_OBJECT
31   Q_ENUMS(EventType)
32
33 public:
34
35   enum RegistrationMode {
36     Prepend,
37     Append
38   };
39
40   /*
41
42   */
43   enum EventType {
44     Invalid                     = 0xffffffff,
45     GenericEvent                  = 0x000000,
46
47     IrcServerEvent                = 0x010000,
48     IrcServerLooking              = 0x010001,
49     IrcServerConnecting           = 0x010002,
50     IrcServerConnected            = 0x010003,
51     IrcServerConnectionFailure    = 0x010004,
52     IrcServerDisconnected         = 0x010005,
53     IrcServerQuit                 = 0x010006,
54
55     IrcServerIncoming             = 0x010007,
56
57     IrcEvent                      = 0x020000,
58     IrcEventCap                   = 0x020001,
59     IrcEventCapAuthenticate       = 0x020002,
60     IrcEventInvite                = 0x020003,
61     IrcEventJoin                  = 0x020004,
62     IrcEventKick                  = 0x020005,
63     IrcEventMode                  = 0x020006,
64     IrcEventNick                  = 0x020007,
65     IrcEventNotice                = 0x020008,
66     IrcEventPart                  = 0x020009,
67     IrcEventPing                  = 0x02000a,
68     IrcEventPong                  = 0x02000b,
69     IrcEventPrivmsg               = 0x02000c,
70     IrcEventQuit                  = 0x02000d,
71     IrcEventTopic                 = 0x02000e,
72
73     IrcEventNumeric               = 0x021000 /* needs 1000 (0x03e8) consecutive free values! */
74   };
75
76   EventManager(QObject *parent = 0);
77   //virtual ~EventManager();
78
79   QStringList providesEnums();
80
81 public slots:
82   void registerObject(QObject *object, RegistrationMode mode = Append, const QString &methodPrefix = "handle");
83   void registerEventHandler(EventType event, QObject *object, const char *slot, RegistrationMode mode = Append);
84   void registerEventHandler(QList<EventType> events, QObject *object, const char *slot, RegistrationMode mode = Append);
85
86   //void sendEvent(Event *event);
87
88 private:
89   struct Handler {
90     QObject *object;
91     int methodIndex;
92
93     explicit Handler(QObject *obj = 0, int method = 0) {
94       object = obj;
95       methodIndex = method;
96     }
97   };
98
99   typedef QHash<EventType, QList<Handler> > HandlerHash;
100
101   inline const HandlerHash &registeredHandlers() const { return _registeredHandlers; }
102   inline HandlerHash &registeredHandlers() { return _registeredHandlers; }
103   HandlerHash _registeredHandlers;
104
105 };
106
107 #endif