You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
1.8 KiB
85 lines
1.8 KiB
15 years ago
|
/*
|
||
|
This file is part of the KDE libraries
|
||
|
|
||
|
Copyright (c) 2003 George Staikos <staikos@kde.org>
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
|
||
|
*/
|
||
|
|
||
|
#include "ktimeout.h"
|
||
|
|
||
|
KTimeout::KTimeout(int size)
|
||
15 years ago
|
: TQObject(), _timers(size) {
|
||
15 years ago
|
_timers.setAutoDelete(true);
|
||
|
}
|
||
|
|
||
|
|
||
|
KTimeout::~KTimeout() {
|
||
|
clear();
|
||
|
}
|
||
|
|
||
|
|
||
|
void KTimeout::clear() {
|
||
|
_timers.clear();
|
||
|
}
|
||
|
|
||
|
|
||
|
void KTimeout::removeTimer(int id) {
|
||
14 years ago
|
TQTimer *t = _timers.find(id);
|
||
15 years ago
|
if (t != 0L) {
|
||
|
_timers.remove(id); // autodeletes
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
void KTimeout::addTimer(int id, int timeout) {
|
||
14 years ago
|
if (_timers.find(id) != 0L) {
|
||
15 years ago
|
return;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQTimer *t = new TQTimer;
|
||
15 years ago
|
connect(t, TQT_SIGNAL(timeout()), this, TQT_SLOT(timeout()));
|
||
15 years ago
|
t->start(timeout);
|
||
|
_timers.insert(id, t);
|
||
|
}
|
||
|
|
||
|
|
||
|
void KTimeout::resetTimer(int id, int timeout) {
|
||
14 years ago
|
TQTimer *t = _timers.find(id);
|
||
15 years ago
|
if (t) {
|
||
|
t->changeInterval(timeout);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
void KTimeout::timeout() {
|
||
15 years ago
|
const TQTimer *t = static_cast<const TQTimer*>(sender());
|
||
15 years ago
|
if (t) {
|
||
15 years ago
|
TQIntDictIterator<TQTimer> it(_timers);
|
||
15 years ago
|
for (; it.current(); ++it) {
|
||
|
if (it.current() == t) {
|
||
|
emit timedOut(it.currentKey());
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
#include "ktimeout.moc"
|
||
|
|