|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QTimer> |
|
19 #include "hsclockwidgettimer.h" |
|
20 |
|
21 /*! |
|
22 \class HsClockWidgetTimer |
|
23 \ingroup group_hsclockwidgetplugin |
|
24 \brief Common timer for all clock widgets that run in the HS process. |
|
25 */ |
|
26 |
|
27 /*! |
|
28 Constructs new timer with the given \a parent. |
|
29 */ |
|
30 HsClockWidgetTimer::HsClockWidgetTimer(QObject *parent) |
|
31 : QObject(parent), |
|
32 mTimer(0) |
|
33 { |
|
34 mTimer = new QTimer(this); |
|
35 mTimer->setInterval(1000); |
|
36 connect(mTimer, SIGNAL(timeout()), SLOT(onTick())); |
|
37 } |
|
38 |
|
39 /*! |
|
40 Destructor. |
|
41 */ |
|
42 HsClockWidgetTimer::~HsClockWidgetTimer() |
|
43 { |
|
44 mTimer->stop(); |
|
45 } |
|
46 |
|
47 /*! |
|
48 Return the static timer instance. |
|
49 */ |
|
50 HsClockWidgetTimer *HsClockWidgetTimer::instance() |
|
51 { |
|
52 if (!mInstance) { |
|
53 mInstance = new HsClockWidgetTimer; |
|
54 } |
|
55 return mInstance; |
|
56 } |
|
57 |
|
58 /*! |
|
59 \internal |
|
60 */ |
|
61 void HsClockWidgetTimer::connectNotify(const char *signal) |
|
62 { |
|
63 mTimer->start(); |
|
64 QObject::connectNotify(signal); |
|
65 } |
|
66 |
|
67 /*! |
|
68 \internal |
|
69 */ |
|
70 void HsClockWidgetTimer::disconnectNotify(const char *signal) |
|
71 { |
|
72 if (receivers(SIGNAL(tick())) == 0) { |
|
73 mTimer->stop(); |
|
74 } |
|
75 QObject::disconnectNotify(signal); |
|
76 } |
|
77 |
|
78 /*! |
|
79 \internal |
|
80 */ |
|
81 void HsClockWidgetTimer::onTick() |
|
82 { |
|
83 if (0 < receivers(SIGNAL(tick()))) { |
|
84 emit tick(); |
|
85 } else { |
|
86 mTimer->stop(); |
|
87 } |
|
88 } |
|
89 |
|
90 /*! |
|
91 Static timer. |
|
92 */ |
|
93 HsClockWidgetTimer *HsClockWidgetTimer::mInstance = 0; |