24 #include "synchtimer.moc" 32 SynchTimer::SynchTimer()
34 mTimer =
new TQTimer(
this,
"mTimer");
37 SynchTimer::~SynchTimer()
46 void SynchTimer::connecT(TQObject* receiver,
const char* member)
48 Connection connection(receiver, member);
49 if (mConnections.find(connection) != mConnections.end())
51 connect(mTimer, TQT_SIGNAL(timeout()), receiver, member);
52 mConnections.append(connection);
53 if (!mTimer->isActive())
55 connect(mTimer, TQT_SIGNAL(timeout()),
this, TQT_SLOT(slotTimer()));
63 void SynchTimer::disconnecT(TQObject* receiver,
const char* member)
67 mTimer->disconnect(receiver, member);
69 mConnections.remove(Connection(receiver, member));
72 for (TQValueList<Connection>::Iterator it = mConnections.begin(); it != mConnections.end(); )
74 if ((*it).receiver == receiver)
75 it = mConnections.remove(it);
80 if (mConnections.isEmpty())
109 void MinuteTimer::slotTimer()
111 kdDebug(5950) <<
"MinuteTimer::slotTimer()" << endl;
112 int interval = 62 - TQTime::currentTime().second();
113 mTimer->start(interval * 1000,
true);
122 TQValueList<DailyTimer*> DailyTimer::mFixedTimers;
129 mFixedTimers.append(
this);
132 DailyTimer::~DailyTimer()
135 mFixedTimers.remove(
this);
140 for (TQValueList<DailyTimer*>::Iterator it = mFixedTimers.begin(); it != mFixedTimers.end(); ++it)
141 if ((*it)->mTime == timeOfDay)
143 return create ?
new DailyTimer(timeOfDay,
true) : 0;
155 timer->disconnecT(receiver, member);
156 if (!timer->hasConnections())
167 if (mTimer->isActive())
170 bool triggerNow =
false;
173 TQTime now = TQTime::currentTime();
174 if (now >= newTimeOfDay && now < mTime)
181 mTime = newTimeOfDay;
183 mTimer->start(0,
true);
188 mTime = newTimeOfDay;
196 void DailyTimer::start()
199 TQDateTime now = TQDateTime::currentDateTime();
204 if (mLastDate.isValid())
205 today = (mLastDate < now.date());
207 today = (now.time() < mTime);
210 next = TQDateTime(now.date(), mTime);
212 next = TQDateTime(now.date().addDays(1), mTime);
213 uint interval = next.toTime_t() - now.toTime_t();
214 mTimer->start(interval * 1000,
true);
215 kdDebug(5950) <<
"DailyTimer::start(at " << mTime.hour() <<
":" << mTime.minute() <<
"): interval = " << interval/3600 <<
":" << (interval/60)%60 <<
":" << interval%60 << endl;
224 void DailyTimer::slotTimer()
227 TQDateTime now = TQDateTime::currentDateTime();
228 mLastDate = now.date();
229 TQDateTime next = TQDateTime(mLastDate.addDays(1), mTime);
230 uint interval = next.toTime_t() - now.toTime_t();
231 mTimer->start(interval * 1000,
true);
232 kdDebug(5950) <<
"DailyTimer::slotTimer(at " << mTime.hour() <<
":" << mTime.minute() <<
"): interval = " << interval/3600 <<
":" << (interval/60)%60 <<
":" << interval%60 << endl;
DailyTimer is an application-wide timer synchronised to a specified time of day, local time...
DailyTimer(const TQTime &, bool fixed)
Construct an instance.
MinuteTimer is an application-wide timer synchronised to the minute boundary.
static void disconnect(const TQTime &timeOfDay, TQObject *receiver, const char *member=0)
Disconnect from the timer signal which triggers at the given fixed time of day.
TQTime timeOfDay() const
Return the current time of day at which this variable timer triggers.
static DailyTimer * fixedInstance(const TQTime &timeOfDay, bool create=true)
Return the instance which triggers at the specified fixed time of day, optionally creating a new inst...
void changeTime(const TQTime &newTimeOfDay, bool triggerMissed=true)
Change the time at which this variable timer triggers.