~ubuntu-branches/ubuntu/gutsy/kde4libs/gutsy

« back to all changes in this revision

Viewing changes to kio/misc/kwalletd/ktimeout.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2007-02-21 11:00:12 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070221110012-6kw8khr9knv6lmg1
Tags: 3.80.3-0ubuntu1
New upstream unstable release

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
*/
22
22
 
23
23
#include "ktimeout.h"
 
24
#include <QTimerEvent>
24
25
 
25
 
KTimeout::KTimeout(int size)
26
 
: QObject(){
27
 
        _timers.reserve(size);
 
26
KTimeout::KTimeout()
 
27
: QObject() {
28
28
}
29
29
 
30
 
 
31
30
KTimeout::~KTimeout() {
32
 
        clear();
33
31
}
34
32
 
35
 
 
36
33
void KTimeout::clear() {
37
 
        qDeleteAll(_timers);
38
 
        _timers.clear();
 
34
    _timers.clear();
39
35
}
40
36
 
41
 
 
42
37
void KTimeout::removeTimer(int id) {
43
 
        QTimer *t = _timers.value(id);
44
 
        if (t != 0L) {
45
 
                _timers.remove(id);
46
 
                delete t;
47
 
        }
 
38
    _timers.remove(id);
48
39
}
49
40
 
50
 
 
51
41
void KTimeout::addTimer(int id, int timeout) {
52
 
        if (_timers.contains(id)) {
53
 
                return;
54
 
        }
55
 
 
56
 
        QTimer *t = new QTimer;
57
 
        connect(t, SIGNAL(timeout()), this, SLOT(timeout()));
58
 
        t->start(timeout);
59
 
        _timers.insert(id, t);
 
42
    if (_timers.contains(id)) {
 
43
        return;
 
44
    }
 
45
    _timers.insert(id, startTimer(timeout));
60
46
}
61
47
 
62
 
 
63
48
void KTimeout::resetTimer(int id, int timeout) {
64
 
        QTimer *t = _timers.value(id);
65
 
        if (t) {
66
 
                t->start(timeout);
67
 
        }
68
 
}
69
 
 
70
 
 
71
 
void KTimeout::timeout() {
72
 
        const QTimer *t = static_cast<const QTimer*>(sender());
73
 
        if (t) {
74
 
                QMultiHash<int, QTimer*>::const_iterator it = _timers.constBegin();
75
 
                while (it != _timers.constEnd()) {
76
 
                        if (it.value() == t) {
77
 
                                emit timedOut(it.key());
78
 
                                return;
79
 
                        }
80
 
                        ++it;
81
 
                }
82
 
        }
83
 
}
84
 
 
 
49
    int timerId = _timers.value(id, 0);
 
50
    if (timerId != 0) {
 
51
            killTimer(timerId);
 
52
            _timers.insert(id, startTimer(timeout));
 
53
    }
 
54
}
 
55
 
 
56
void KTimeout::timerEvent(QTimerEvent* ev) {
 
57
    QHash<int, int>::const_iterator it = _timers.constBegin();
 
58
    for ( ; it != _timers.constEnd(); ++it) {
 
59
        if (it.value() == ev->timerId()) {
 
60
            emit timedOut(it.key());
 
61
            return;
 
62
        }
 
63
    }
 
64
}
85
65
 
86
66
#include "ktimeout.moc"
87
67