1
#ifndef _KVI_KVS_EVENTMANAGER_H_
2
#define _KVI_KVS_EVENTMANAGER_H_
3
//=============================================================================
5
// File : kvi_kvs_eventmanager.h
6
// Creation date : Thu Aug 17 2000 13:59:12 by Szymon Stefanek
8
// This file is part of the KVIrc IRC client distribution
9
// Copyright (C) 2000-2008 Szymon Stefanek <pragma at kvirc dot net>
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 opinion) any later version.
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.
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.
25
//=============================================================================
27
#include "kvi_settings.h"
29
#include "kvi_kvs_event.h"
30
#include "kvi_pointerlist.h"
31
#include "kvi_kvs_eventtable.h"
34
class KviKvsModuleInterface;
35
class KviKvsVariantList;
37
#define KVI_KVS_NUM_RAW_EVENTS 1000
39
class KVIRC_API KviKvsEventManager
41
friend class KviModule; // compatibility only!
42
protected: // it only can be created and destroyed by KviKvsAliasManager::init()/done()
44
~KviKvsEventManager();
46
static KviKvsEventManager * m_pInstance;
48
static KviKvsEvent m_appEventTable[KVI_KVS_NUM_APP_EVENTS];
49
KviPointerList<KviKvsEventHandler> * m_rawEventTable[KVI_KVS_NUM_RAW_EVENTS];
51
static KviKvsEventManager * instance(){ return m_pInstance; };
52
static void init(); // called by KviKvs::init()
53
static void done(); // called by KviKvs::done()
55
KviKvsEvent * appEvent(unsigned int uEvIdx){ return &(m_appEventTable[uEvIdx]); };
57
bool hasAppHandlers(unsigned int uEvIdx){ return m_appEventTable[uEvIdx].hasHandlers(); };
58
KviPointerList<KviKvsEventHandler> * appHandlers(unsigned int uEvIdx){ return m_appEventTable[uEvIdx].handlers(); };
60
bool hasRawHandlers(unsigned int uEvIdx){ return m_rawEventTable[uEvIdx]; };
61
KviPointerList<KviKvsEventHandler> * rawHandlers(unsigned int uEvIdx){ return m_rawEventTable[uEvIdx]; };
63
KviKvsEvent * findAppEventByName(const QString &szName);
64
unsigned int findAppEventIndexByName(const QString &szName);
65
bool isValidAppEvent(unsigned int uEvIdx){ return (uEvIdx < KVI_KVS_NUM_APP_EVENTS); };
67
bool isValidRawEvent(unsigned int uEvIdx){ return (uEvIdx < KVI_KVS_NUM_RAW_EVENTS); };
69
bool addAppHandler(unsigned int uEvIdx,KviKvsEventHandler * h);
70
bool addRawHandler(unsigned int uRawIdx,KviKvsEventHandler * h);
72
bool removeScriptAppHandler(unsigned int uEvIdx,const QString &szName);
73
bool removeScriptRawHandler(unsigned int uEvIdx,const QString &szName);
75
bool enableScriptAppHandler(unsigned int uEvIdx,const QString &szName,bool bEnable);
76
bool enableScriptRawHandler(unsigned int uEvIdx,const QString &szName,bool bEnable);
78
bool removeModuleAppHandler(unsigned int uEvIdx,KviKvsModuleInterface *i);
79
bool removeModuleRawHandler(unsigned int uRawIdx,KviKvsModuleInterface *i);
81
void removeAllModuleAppHandlers(KviKvsModuleInterface *i);
82
void removeAllModuleRawHandlers(KviKvsModuleInterface *i);
84
void removeAllModuleHandlers(KviKvsModuleInterface * i);
86
KviKvsScriptEventHandler * findScriptRawHandler(unsigned int uEvIdx,const QString &szName);
87
KviKvsScriptEventHandler * findScriptAppHandler(unsigned int uEvIdx,const QString &szName);
89
// returns true if further processing should be stopped
90
// none of these functions takes params ownership, so be sure to delete them !
91
bool triggerHandlers(KviPointerList<KviKvsEventHandler> * pHandlers,KviWindow *pWnd,KviKvsVariantList *pParams);
92
bool trigger(unsigned int uEvIdx,KviWindow * pWnd,KviKvsVariantList * pParams)
93
{ return triggerHandlers(m_appEventTable[uEvIdx].handlers(),pWnd,pParams); };
94
bool triggerRaw(unsigned int uEvIdx,KviWindow *pWnd,KviKvsVariantList * pParams)
95
{ return triggerHandlers(m_rawEventTable[uEvIdx],pWnd,pParams); };
97
// this is the only that takes parameter ownership and deletes them
98
bool triggerDeleteParams(unsigned int uEvIdx,KviWindow * pWnd,KviKvsVariantList * pParams)
100
bool bRet = triggerHandlers(m_appEventTable[uEvIdx].handlers(),pWnd,pParams);
105
void removeAllScriptAppHandlers();
106
void removeAllScriptRawHandlers();
108
void clearAppEvents();
109
void clearRawEvents();
112
void loadAppEvents(const QString &szFileName);
113
void saveAppEvents(const QString &szFileName);
114
void loadRawEvents(const QString &szFileName);
115
void saveRawEvents(const QString &szFileName);
120
#endif //!_KVI_KVS_EVENTMANAGER_H_