KVIrc  4.9.2
DeveloperAPIs
KviKvsEventManager.h
Go to the documentation of this file.
1 #ifndef _KVI_KVS_EVENTMANAGER_H_
2 #define _KVI_KVS_EVENTMANAGER_H_
3 //=============================================================================
4 //
5 // File : KviKvsEventManager.h
6 // Creation date : Thu Aug 17 2000 13:59:12 by Szymon Stefanek
7 //
8 // This file is part of the KVIrc IRC client distribution
9 // Copyright (C) 2000-2010 Szymon Stefanek <pragma at kvirc dot net>
10 //
11 // This program is FREE software. You can redistribute it and/or
12 // modify it under the terms of the GNU General Public License
13 // as published by the Free Software Foundation; either version 2
14 // of the License, or (at your option) any later version.
15 //
16 // This program is distributed in the HOPE that it will be USEFUL,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 // See the GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program. If not, write to the Free Software Foundation,
23 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 //
25 //=============================================================================
26 
27 #include "kvi_settings.h"
28 
29 #include "KviKvsEvent.h"
30 #include "KviPointerList.h"
31 #include "KviKvsEventTable.h"
32 
33 class KviWindow;
35 class KviKvsVariantList;
36 
37 #define KVI_KVS_NUM_RAW_EVENTS 1000
38 
39 class KVIRC_API KviKvsEventManager : public QObject
40 {
41  Q_OBJECT
42  friend class KviModule; // compatibility only!
43 protected: // it only can be created and destroyed by KviKvsAliasManager::init()/done()
46 
47 protected:
49 
50  static KviKvsEvent m_appEventTable[KVI_KVS_NUM_APP_EVENTS];
52 
53 public:
54  static KviKvsEventManager * instance() { return m_pInstance; };
55  static void init(); // called by KviKvs::init()
56  static void done(); // called by KviKvs::done()
57 
58  KviKvsEvent * appEvent(unsigned int uEvIdx) { return &(m_appEventTable[uEvIdx]); };
59 
60  bool hasAppHandlers(unsigned int uEvIdx) { return m_appEventTable[uEvIdx].hasHandlers(); };
61  KviPointerList<KviKvsEventHandler> * appHandlers(unsigned int uEvIdx) { return m_appEventTable[uEvIdx].handlers(); };
62 
63  bool hasRawHandlers(unsigned int uEvIdx) { return m_rawEventTable[uEvIdx]; };
64  KviPointerList<KviKvsEventHandler> * rawHandlers(unsigned int uEvIdx) { return m_rawEventTable[uEvIdx]; };
65 
66  KviKvsEvent * findAppEventByName(const QString & szName);
67  unsigned int findAppEventIndexByName(const QString & szName);
68  bool isValidAppEvent(unsigned int uEvIdx) { return (uEvIdx < KVI_KVS_NUM_APP_EVENTS); };
69 
70  bool isValidRawEvent(unsigned int uEvIdx) { return (uEvIdx < KVI_KVS_NUM_RAW_EVENTS); };
71 
72  bool addAppHandler(unsigned int uEvIdx, KviKvsEventHandler * h);
73  bool addRawHandler(unsigned int uRawIdx, KviKvsEventHandler * h);
74 
75  bool removeScriptAppHandler(unsigned int uEvIdx, const QString & szName);
76  bool removeScriptRawHandler(unsigned int uEvIdx, const QString & szName);
77 
78  bool enableScriptAppHandler(unsigned int uEvIdx, const QString & szName, bool bEnable);
79  bool enableScriptRawHandler(unsigned int uEvIdx, const QString & szName, bool bEnable);
80 
81  bool removeModuleAppHandler(unsigned int uEvIdx, KviKvsModuleInterface * i);
82  bool removeModuleRawHandler(unsigned int uRawIdx, KviKvsModuleInterface * i);
83 
84  void removeAllModuleAppHandlers(KviKvsModuleInterface * i);
85  void removeAllModuleRawHandlers(KviKvsModuleInterface * i);
86 
87  void removeAllModuleHandlers(KviKvsModuleInterface * i);
88 
89  KviKvsScriptEventHandler * findScriptRawHandler(unsigned int uEvIdx, const QString & szName);
90  KviKvsScriptEventHandler * findScriptAppHandler(unsigned int uEvIdx, const QString & szName);
91 
92  // returns true if further processing should be stopped
93  // none of these functions takes params ownership, so be sure to delete them !
94  bool triggerHandlers(KviPointerList<KviKvsEventHandler> * pHandlers, KviWindow * pWnd, KviKvsVariantList * pParams);
95  bool trigger(unsigned int uEvIdx, KviWindow * pWnd, KviKvsVariantList * pParams)
96  {
97  return triggerHandlers(m_appEventTable[uEvIdx].handlers(), pWnd, pParams);
98  };
99  bool triggerRaw(unsigned int uEvIdx, KviWindow * pWnd, KviKvsVariantList * pParams)
100  {
101  return triggerHandlers(m_rawEventTable[uEvIdx], pWnd, pParams);
102  };
103 
104  // this is the only that takes parameter ownership and deletes them
105  bool triggerDeleteParams(unsigned int uEvIdx, KviWindow * pWnd, KviKvsVariantList * pParams)
106  {
107  bool bRet = triggerHandlers(m_appEventTable[uEvIdx].handlers(), pWnd, pParams);
108  delete pParams;
109  return bRet;
110  };
111 
112  void removeAllScriptAppHandlers();
113  void removeAllScriptRawHandlers();
114 
115  void clearAppEvents();
116  void clearRawEvents();
117  void clear();
118 
119  void loadAppEvents(const QString & szFileName);
120  void saveAppEvents(const QString & szFileName);
121  void loadRawEvents(const QString & szFileName);
122  void saveRawEvents(const QString & szFileName);
123 signals:
124  void eventHandlerDisabled(const QString &);
125 };
126 
127 #endif
Definition: KviKvsEventHandler.h:53
bool isValidAppEvent(unsigned int uEvIdx)
Definition: KviKvsEventManager.h:68
static KviKvsEventManager * m_pInstance
Definition: KviKvsEventManager.h:48
bool isValidRawEvent(unsigned int uEvIdx)
Definition: KviKvsEventManager.h:70
KviPointerList< KviKvsEventHandler > * rawHandlers(unsigned int uEvIdx)
Definition: KviKvsEventManager.h:64
#define KVIRC_API
Definition: kvi_settings.h:128
bool hasRawHandlers(unsigned int uEvIdx)
Definition: KviKvsEventManager.h:63
void saveAppEvents(const QString &szFileName)
Definition: KviKvs.cpp:97
void clearRawEvents()
Definition: KviKvs.cpp:117
Class to handle variant variables lists.
Definition: KviKvsVariantList.h:41
KviPointerList< KviKvsEventHandler > * appHandlers(unsigned int uEvIdx)
Definition: KviKvsEventManager.h:61
KviKvsEvent * appEvent(unsigned int uEvIdx)
Definition: KviKvsEventManager.h:58
void clearAppEvents()
Definition: KviKvs.cpp:102
#define i
Definition: detector.cpp:73
btnDict clear()
Definition: KviKvsEvent.h:33
Events table.
#define h
Definition: detector.cpp:72
void done()
Definition: KviKvs.cpp:50
Definition: KviKvsEventHandler.h:33
#define KVI_KVS_NUM_RAW_EVENTS
Definition: KviKvsEventManager.h:37
void loadAppEvents(const QString &szFileName)
Definition: KviKvs.cpp:92
bool triggerDeleteParams(unsigned int uEvIdx, KviWindow *pWnd, KviKvsVariantList *pParams)
Definition: KviKvsEventManager.h:105
bool hasAppHandlers(unsigned int uEvIdx)
Definition: KviKvsEventManager.h:60
#define KVI_KVS_NUM_APP_EVENTS
Definition: KviKvsEventTable.h:383
C++ Template based double linked pointer list class.
Base class for all windows in KVIrc.
Definition: KviWindow.h:74
Definition: KviModule.h:131
static KviKvsEventManager * instance()
Definition: KviKvsEventManager.h:54
int init()
Definition: winamp.cpp:118
void loadRawEvents(const QString &szFileName)
Definition: KviKvs.cpp:107
void saveRawEvents(const QString &szFileName)
Definition: KviKvs.cpp:112
This file contains compile time settings.
Definition: KviKvsModuleInterface.h:134
bool triggerRaw(unsigned int uEvIdx, KviWindow *pWnd, KviKvsVariantList *pParams)
Definition: KviKvsEventManager.h:99
bool trigger(unsigned int uEvIdx, KviWindow *pWnd, KviKvsVariantList *pParams)
Definition: KviKvsEventManager.h:95
Definition: KviKvsEventManager.h:39