|
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: Clock widget |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QTimer> |
|
19 #include <QGraphicsLinearLayout> |
|
20 |
|
21 #include "hsclockwidget.h" |
|
22 #include "hsclockwidgettimer.h" |
|
23 #include "hsanalogclockwidget.h" |
|
24 #include "hsdigitalclockwidget.h" |
|
25 |
|
26 #ifdef Q_OS_SYMBIAN |
|
27 #include "hsclocksettingsnotifier_symbian.h" |
|
28 #include <apgtask.h> |
|
29 #include <eikenv.h> |
|
30 #endif //Q_OS_SYMBIAN |
|
31 |
|
32 namespace |
|
33 { |
|
34 const char ANALOG[] = "analog"; |
|
35 const char DIGITAL[] = "digital"; |
|
36 const char TIME12[] = "TIME12"; |
|
37 const char TIME24[] = "TIME24"; |
|
38 |
|
39 const int clockUpdateInterval = 1000; // msec |
|
40 } |
|
41 |
|
42 #ifdef Q_OS_SYMBIAN |
|
43 #define KClockAppUid TUid::Uid(0x10005903) |
|
44 _LIT (KClockAppExe, "clock.exe"); |
|
45 #endif //Q_OS_SYMBIAN |
|
46 |
|
47 /*! |
|
48 \class HsClockWidget |
|
49 \ingroup group_hsclockwidgetplugin |
|
50 \brief Implementation for the homescreen clock widget. |
|
51 */ |
|
52 |
|
53 /*! |
|
54 Constructs widget. |
|
55 */ |
|
56 HsClockWidget::HsClockWidget(QGraphicsItem *parent, Qt::WindowFlags flags) |
|
57 : HbWidget(parent, flags), |
|
58 mWidget(0), |
|
59 mLayout(0), |
|
60 mClockType(ANALOG), |
|
61 mTimeType(TIME12) |
|
62 { |
|
63 #ifdef Q_OS_SYMBIAN |
|
64 mClockSettingsNotifier = new HsClockSettingsNotifier(this); |
|
65 mClockType = mClockSettingsNotifier->clockFormat(); |
|
66 mTimeType = mClockSettingsNotifier->timeFormat(); |
|
67 #endif |
|
68 } |
|
69 |
|
70 /*! |
|
71 Destructor. |
|
72 */ |
|
73 HsClockWidget::~HsClockWidget() |
|
74 { |
|
75 } |
|
76 |
|
77 /*! |
|
78 Return shape |
|
79 */ |
|
80 QPainterPath HsClockWidget::shape() const |
|
81 { |
|
82 return mWidget->shape(); |
|
83 } |
|
84 |
|
85 /*! |
|
86 Initializes this widget. |
|
87 */ |
|
88 void HsClockWidget::onInitialize() |
|
89 { |
|
90 mLayout = new QGraphicsLinearLayout(Qt::Vertical); |
|
91 mLayout->setContentsMargins(0, 0, 0, 0); |
|
92 mWidget = loadClockWidget(); |
|
93 mLayout->addItem(mWidget); |
|
94 setLayout(mLayout); |
|
95 #ifdef Q_OS_SYMBIAN |
|
96 connect(mClockSettingsNotifier, SIGNAL(settingsChanged(QString, QString)), this, SLOT(onSettingsChanged(QString, QString))); |
|
97 #endif |
|
98 |
|
99 } |
|
100 |
|
101 /*! |
|
102 Shows this widget. |
|
103 */ |
|
104 void HsClockWidget::onShow() |
|
105 { |
|
106 HsClockWidgetTimer::instance(); |
|
107 connect(HsClockWidgetTimer::instance(), |
|
108 SIGNAL(tick()), |
|
109 SLOT(updateTime()), |
|
110 Qt::UniqueConnection); |
|
111 } |
|
112 |
|
113 |
|
114 /*! |
|
115 Hides this widget. |
|
116 */ |
|
117 void HsClockWidget::onHide() |
|
118 { |
|
119 HsClockWidgetTimer::instance()->disconnect(this); |
|
120 } |
|
121 |
|
122 /*! |
|
123 Uninitializes this widget. |
|
124 */ |
|
125 void HsClockWidget::onUninitialize() |
|
126 { |
|
127 HsClockWidgetTimer::instance()->disconnect(this); |
|
128 } |
|
129 |
|
130 /*! |
|
131 Draws the clock with every second. |
|
132 */ |
|
133 void HsClockWidget::updateTime() |
|
134 { |
|
135 if (mClockType == DIGITAL) { |
|
136 static_cast<HsDigitalClockWidget*>(mWidget)->tick(); |
|
137 } else { |
|
138 static_cast<HsAnalogClockWidget*>(mWidget)->tick(); |
|
139 } |
|
140 } |
|
141 |
|
142 /*! |
|
143 \internal |
|
144 */ |
|
145 void HsClockWidget::onSettingsChanged(const QString &clockFormat, const QString &timeFormat) |
|
146 { |
|
147 if (mClockType != clockFormat) { |
|
148 mClockType = clockFormat; |
|
149 mLayout->removeItem(mWidget); |
|
150 delete mWidget; |
|
151 mWidget = 0; |
|
152 mWidget = loadClockWidget(); |
|
153 mLayout->addItem(mWidget); |
|
154 } |
|
155 |
|
156 if (mTimeType != timeFormat) { |
|
157 mTimeType = timeFormat; |
|
158 if (mClockType == DIGITAL) { |
|
159 if (mTimeType == TIME12) { |
|
160 static_cast<HsDigitalClockWidget*>(mWidget)->setAmPm(true); |
|
161 } else { |
|
162 static_cast<HsDigitalClockWidget*>(mWidget)->setAmPm(false); |
|
163 } |
|
164 } |
|
165 } |
|
166 } |
|
167 |
|
168 /*! |
|
169 Clock tapped. |
|
170 */ |
|
171 void HsClockWidget::onClockTapped() |
|
172 { |
|
173 #ifndef Q_OS_SYMBIAN |
|
174 if (mClockType == ANALOG) { |
|
175 mClockType = DIGITAL; |
|
176 if (mTimeType == TIME12) { |
|
177 mTimeType = TIME24; |
|
178 } else { |
|
179 mTimeType = TIME12; |
|
180 } |
|
181 } else { |
|
182 mClockType = ANALOG; |
|
183 } |
|
184 mLayout->removeItem(mWidget); |
|
185 delete mWidget; |
|
186 mWidget = 0; |
|
187 mWidget = loadClockWidget(); |
|
188 mLayout->addItem(mWidget); |
|
189 updateTime(); |
|
190 #else //Q_OS_SYMBIAN |
|
191 TApaTaskList taskList(CEikonEnv::Static()->WsSession()); |
|
192 TApaTask task = taskList.FindApp(KClockAppUid); |
|
193 if (task.Exists()){ |
|
194 task.BringToForeground(); |
|
195 } |
|
196 else { |
|
197 RProcess process; |
|
198 TInt error = process.Create(KClockAppExe, KNullDesC, EOwnerThread); |
|
199 |
|
200 if (error == KErrNone){ |
|
201 // start the process running. |
|
202 process.Resume(); |
|
203 process.Close(); |
|
204 } |
|
205 } |
|
206 #endif //Q_OS_SYMBIAN |
|
207 } |
|
208 |
|
209 /*! |
|
210 Loads the digital or analog clock widget. |
|
211 */ |
|
212 HbWidget *HsClockWidget::loadClockWidget() |
|
213 { |
|
214 HbWidget *clockWidget = 0; |
|
215 |
|
216 if (mClockType == DIGITAL) { |
|
217 bool useAmPm = true; |
|
218 if (mTimeType == TIME24) { |
|
219 useAmPm = false; |
|
220 } |
|
221 clockWidget = new HsDigitalClockWidget(useAmPm); |
|
222 } else { |
|
223 clockWidget = new HsAnalogClockWidget(); |
|
224 } |
|
225 |
|
226 connect(clockWidget, SIGNAL(clockTapped()), this, SLOT(onClockTapped()), Qt::QueuedConnection); |
|
227 return clockWidget; |
|
228 } |