KVIrc  4.9.2
DeveloperAPIs
KviKvsTimerManager.h
Go to the documentation of this file.
1 #ifndef _KVI_KVS_TIMERMANAGER_H_
2 #define _KVI_KVS_TIMERMANAGER_H_
3 //=============================================================================
4 //
5 // File : KviKvsTimerManager.h
6 // Creation date : Fri 19 Dec 2003 01:29:22 by Szymon Stefanek
7 //
8 // This file is part of the KVIrc IRC client distribution
9 // Copyright (C) 2003-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 #include "KviQString.h"
29 
30 #include "KviPointerHashTable.h"
31 #include "KviPointerList.h"
32 
33 #include <QObject>
34 
35 class KviKvsTimerManager;
36 class KviKvsScript;
37 class KviKvsHash;
38 class KviKvsVariantList;
40 
41 class KviWindow;
42 
43 // FIXME: This stuff could be moved to a module
44 // called timer
45 // timer.start(){}
46 // timer.stop
47 // timer.exists
48 // timer.timeout
49 // timer.suspend
50 // etc...
51 // Then we could remap timer.start to the old /timer call
52 // by hardcoding it...
53 
55 {
56  friend class KviKvsTimerManager;
57 
58 public:
59  enum Lifetime
60  {
63  Persistent
64  };
65 
66 protected:
67  KviKvsTimer(const QString & szName, Lifetime l, KviWindow * pWnd, int iDelay, int iId, KviKvsScript * pCallback, KviKvsVariantList * pParams);
68 
69 public:
70  ~KviKvsTimer();
71 
72 protected:
73  Lifetime m_eLifetime; // the type of this timer
74  KviWindow * m_pWnd; // the window that this timer is (currently) bound to
75  QString m_szName; // this timer name
76  KviKvsScript * m_pCallback; // callback to be executed at timer shots
77  int m_iDelay; // the timer delay in msecs
78  int m_iId; // the system id of this timer
79  KviKvsExtendedRunTimeData * m_pRunTimeData; // ext run time data for this timer object
80  KviKvsVariantList * m_pParameterList; // parameter list
81 public:
82  KviWindow * window() { return m_pWnd; };
83  const QString & name() { return m_szName; };
84  const KviKvsScript * callback() { return m_pCallback; };
85  Lifetime lifetime() { return m_eLifetime; };
86  int delay() { return m_iDelay; };
87  int id() { return m_iId; };
88  //KviKvsHash * variables(){ return m_pVariables; };
89  KviKvsExtendedRunTimeData * runTimeData() { return m_pRunTimeData; };
90  KviKvsVariantList * parameterList() { return m_pParameterList; };
91 protected:
92  void setWindow(KviWindow * pWnd) { m_pWnd = pWnd; };
93 };
94 
95 class KVIRC_API KviKvsTimerManager : public QObject
96 {
97  Q_OBJECT
98 protected: // it only can be created and destroyed by KviKvsTimerManager::init()/done()
101 
102 private:
105  static KviKvsTimerManager * m_pInstance; // the one and only timer manager instance
106  KviPointerList<KviKvsTimer> * m_pKilledTimerList; // list of timers for that killing has been scheduled
107  int m_iAssassinTimer; // assassin timer id
108  int m_iCurrentTimer; // the timer currently executed
109 public:
110  static KviKvsTimerManager * instance() { return m_pInstance; };
111  static void init();
112  static void done();
113  // the pCallback and pParams are owned by the timer: they WILL be deleted
114  bool addTimer(const QString & szName, KviKvsTimer::Lifetime l, KviWindow * pWnd, int iDelay, KviKvsScript * pCallback, KviKvsVariantList * pParams);
115  bool deleteTimer(const QString & szName);
116  bool deleteTimer(int iId);
117  // the timer manager does not trigger timers concurrently
118  // this means that if this is called from a timer handler
119  // the current timer will be unique
120  bool deleteCurrentTimer();
121  void deleteAllTimers();
122  bool timerExists(const QString & szName) { return m_pTimerDictByName->find(szName); };
124  {
125  return m_pTimerDictByName;
126  };
127 
128 protected:
129  void scheduleKill(KviKvsTimer * t);
130  virtual void timerEvent(QTimerEvent * e);
131 };
132 
133 #endif
int m_iId
Definition: KviKvsTimerManager.h:78
QString m_szName
Definition: KviKvsTimerManager.h:75
Definition: KviKvsTimerManager.h:95
static KviKvsTimerManager * m_pInstance
Definition: KviKvsTimerManager.h:105
#define KVIRC_API
Definition: kvi_settings.h:128
m_iId
Definition: KvsObject_buttonGroup.cpp:62
Class to handle variant variables lists.
Definition: KviKvsVariantList.h:41
const KviKvsScript * callback()
Definition: KviKvsTimerManager.h:84
const QString & name()
Definition: KviKvsTimerManager.h:83
The KVIrc Script class.
Definition: KviKvsScript.h:59
#define l
Definition: detector.cpp:76
int m_iCurrentTimer
Definition: KviKvsTimerManager.h:108
int delay()
Definition: KviKvsTimerManager.h:86
int m_iDelay
Definition: KviKvsTimerManager.h:77
KviWindow * window()
Definition: KviKvsTimerManager.h:82
int id()
Definition: KviKvsTimerManager.h:87
KviWindow * m_pWnd
Definition: KviKvsTimerManager.h:74
KviPointerHashTable< int, KviKvsTimer > * m_pTimerDictById
Definition: KviKvsTimerManager.h:103
Definition: KviKvsTimerManager.h:54
Lifetime lifetime()
Definition: KviKvsTimerManager.h:85
KviKvsExtendedRunTimeData * m_pRunTimeData
Definition: KviKvsTimerManager.h:79
Definition: KviKvsRunTimeContext.h:43
#define e
Definition: detector.cpp:69
int m_iAssassinTimer
Definition: KviKvsTimerManager.h:107
This class defines a new data type which contains hash data.
Definition: KviKvsHash.h:47
void setWindow(KviWindow *pWnd)
Definition: KviKvsTimerManager.h:92
KviPointerHashTable< QString, KviKvsTimer > * timerDict()
Definition: KviKvsTimerManager.h:123
Definition: KviKvsTimerManager.h:61
Pointer Hash Table.
Lifetime
Definition: KviKvsTimerManager.h:59
void done()
Definition: KviKvs.cpp:50
static KviKvsTimerManager * instance()
Definition: KviKvsTimerManager.h:110
KviPointerHashTable< QString, KviKvsTimer > * m_pTimerDictByName
Definition: KviKvsTimerManager.h:104
KviKvsVariantList * m_pParameterList
Definition: KviKvsTimerManager.h:80
KviKvsVariantList * parameterList()
Definition: KviKvsTimerManager.h:90
Definition: KviKvsTimerManager.h:62
QHashIterator< int, QFile * > t(getDict)
C++ Template based double linked pointer list class.
Base class for all windows in KVIrc.
Definition: KviWindow.h:74
KviKvsScript * m_pCallback
Definition: KviKvsTimerManager.h:76
KviKvsExtendedRunTimeData * runTimeData()
Definition: KviKvsTimerManager.h:89
bool timerExists(const QString &szName)
Definition: KviKvsTimerManager.h:122
KviPointerList< KviKvsTimer > * m_pKilledTimerList
Definition: KviKvsTimerManager.h:106
Lifetime m_eLifetime
Definition: KviKvsTimerManager.h:73
int init()
Definition: winamp.cpp:118
This file contains compile time settings.
Helper functions for the QString class.