File indexing completed on 2024-04-21 04:02:45
0001 /*************************************************************************** 0002 ctimerlist.cpp - list of timers 0003 ------------------- 0004 begin : St maj 8 2003 0005 copyright : (C) 2003-2008 by Tomas Mecir 0006 email : kmuddy@kmuddy.com 0007 ***************************************************************************/ 0008 0009 /*************************************************************************** 0010 * * 0011 * This program is free software; you can redistribute it and/or modify * 0012 * it under the terms of the GNU General Public License as published by * 0013 * the Free Software Foundation; either version 2 of the License, or * 0014 * (at your option) any later version. * 0015 * * 0016 ***************************************************************************/ 0017 0018 #include "ctimerlist.h" 0019 #include "ctimer.h" 0020 #include "ctimereditor.h" 0021 0022 #include <qtimer.h> 0023 0024 struct cTimerList::Private { 0025 int tickCount; 0026 QTimer *timer; 0027 }; 0028 0029 cTimerList::cTimerList () : 0030 cList ("timers") 0031 { 0032 d = new Private; 0033 0034 addIntProperty ("interval", "Execution interval", 60); 0035 addStringProperty ("command", "Command"); 0036 addStringProperty ("command-advance", "Command executed several seconds before the timer ticks.", "/echo TIMER TICK IN 5 SECONDS"); 0037 addBoolProperty ("advance", "Do we want to run a command in advance?", false); 0038 addIntProperty ("advance-seconds", "When to execute the advance command?", 5); 0039 // a single-shot timer disables itself after it fires 0040 addBoolProperty ("single-shot", "Single-shot timer", false); 0041 // script 0042 addStringProperty ("script", "Script to execute"); 0043 0044 d->tickCount = 0; 0045 d->timer = new QTimer; 0046 connect (d->timer, &QTimer::timeout, this, &cTimerList::timeout); 0047 d->timer->start (1000); 0048 } 0049 0050 cTimerList::~cTimerList () 0051 { 0052 delete d->timer; 0053 delete d; 0054 } 0055 0056 cListObject *cTimerList::newObject () 0057 { 0058 return new cTimer (this); 0059 } 0060 0061 cListEditor *cTimerList::editor (QWidget *parent) 0062 { 0063 return new cTimerEditor (parent); 0064 } 0065 0066 void cTimerList::setEnabled (bool en) 0067 { 0068 cList::setEnabled (en); 0069 if (en) { 0070 //reset tick counts first 0071 d->tickCount = 0; 0072 traverse (TIMER_RESET); 0073 d->timer->start (1000); 0074 } else { 0075 d->timer->stop (); 0076 } 0077 } 0078 0079 void cTimerList::timeout () 0080 { 0081 //update tick count 0082 d->tickCount++; 0083 //this does not check for overflow, therefore could stop working after 0084 //about 49 days on a 32-bit architecture 0085 0086 // advance each timer, executing the command if needed 0087 traverse (TIMER_TICK); 0088 } 0089 0090 int cTimerList::tickCount () 0091 { 0092 return d->tickCount; 0093 } 0094 0095 #include "moc_ctimerlist.cpp"