|
1 /* |
|
2 * Copyright (c) 2009 - 2010 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: Big clock Screensaver. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "snsrbigclockscreensaver.h" |
|
19 |
|
20 #ifdef Q_OS_SYMBIAN |
|
21 #include <e32std.h> |
|
22 #endif // Q_OS_SYMBIAN |
|
23 |
|
24 #include <QDebug> |
|
25 #include <QTime> |
|
26 #include <QTimer> |
|
27 #include <XQSettingsManager> |
|
28 #include <HbInstance> |
|
29 #include <HbMainWindow> |
|
30 |
|
31 #include <screensaverdomaincrkeys.h> |
|
32 #include "snsranalogclockcontainer.h" |
|
33 #include "snsrdigitalclockcontainer.h" |
|
34 #include "snsroledanalogclockcontainer.h" |
|
35 #include "snsroleddigitalclockcontainer.h" |
|
36 #include "snsrblankcontainer.h" |
|
37 #include "snsrindicatormodel.h" |
|
38 |
|
39 /*! |
|
40 \class SnsrBigClockScreensaver |
|
41 \ingroup group_snsrbigclockscreensaverplugin |
|
42 \brief Screensaver with big digital clock. |
|
43 */ |
|
44 |
|
45 /*! |
|
46 Constructs a new SnsrBigClockScreensaver. |
|
47 */ |
|
48 SnsrBigClockScreensaver::SnsrBigClockScreensaver() : |
|
49 mMainWindow(0), |
|
50 mCurrentContainer(0), |
|
51 mIndicatorModel(0), |
|
52 m_setManager(0) |
|
53 { |
|
54 mMainWindow = HbInstance::instance()->allMainWindows().at(0); |
|
55 // for nice looking clock hand transformations |
|
56 mMainWindow->setRenderHint(QPainter::SmoothPixmapTransform); |
|
57 |
|
58 // This model holds indicator status information and must exist as |
|
59 // long as screensaver does. |
|
60 mIndicatorModel = new SnsrIndicatorModel(this); |
|
61 } |
|
62 |
|
63 /*! |
|
64 Destructs the class. |
|
65 */ |
|
66 SnsrBigClockScreensaver::~SnsrBigClockScreensaver() |
|
67 { |
|
68 mMainWindow->unsetOrientation( /*animate*/false ); |
|
69 // mCurrentContainer, mIndicatorModel - deleted by the parent |
|
70 } |
|
71 |
|
72 /*! |
|
73 @copydoc Screensaver::onInitialize() |
|
74 */ |
|
75 bool SnsrBigClockScreensaver::onInitialize() |
|
76 { |
|
77 qDebug() << "SnsrBigClockScreensaver::onInitialize()"; |
|
78 return true; |
|
79 } |
|
80 |
|
81 /*! |
|
82 @copydoc Screensaver::onForeground() |
|
83 */ |
|
84 bool SnsrBigClockScreensaver::onForeground() |
|
85 { |
|
86 SCREENSAVER_TEST_FUNC_ENTRY("SnsrBigClockScreensaver::onForeground") |
|
87 qDebug() << "SnsrBigClockScreensaver::onForeground()"; |
|
88 |
|
89 removeCurrentContainer(); |
|
90 |
|
91 emit screenPowerModeRequested( Screensaver::ScreenModeFullPower ); |
|
92 |
|
93 SnsrBigClockContainer* newContainer( 0 ); |
|
94 if (clockFormat() == ClockFormatAnalog) { |
|
95 newContainer = new SnsrAnalogClockContainer(); |
|
96 } |
|
97 else { |
|
98 newContainer = new SnsrDigitalClockContainer(); |
|
99 } |
|
100 |
|
101 setCurrentContainer( newContainer ); |
|
102 |
|
103 SCREENSAVER_TEST_FUNC_EXIT("SnsrBigClockScreensaver::onForeground") |
|
104 return true; |
|
105 } |
|
106 |
|
107 /*! |
|
108 @copydoc Screensaver::onPartialForeground() |
|
109 */ |
|
110 bool SnsrBigClockScreensaver::onPartialForeground() |
|
111 { |
|
112 SCREENSAVER_TEST_FUNC_ENTRY("SnsrBigClockScreensaver::onPartialForeground") |
|
113 qDebug() << "SnsrBigClockScreensaver::onPartialForeground()"; |
|
114 |
|
115 removeCurrentContainer(); |
|
116 |
|
117 SnsrBigClockContainer* newContainer( 0 ); |
|
118 |
|
119 // Check ScreensaverStatus from repository |
|
120 XQSettingsManager::Error error; |
|
121 int screensaverOn = 1; |
|
122 XQCentralRepositorySettingsKey settingsKey( |
|
123 KCRUidScreensaverSettings.iUid, KScreensaverStatus ); // TUid as same repository used in control panel via Symbian APIs |
|
124 m_setManager = new XQSettingsManager(this); |
|
125 if (m_setManager) { |
|
126 screensaverOn = m_setManager->readItemValue(settingsKey, XQSettingsManager::TypeInt).toInt(); |
|
127 error = m_setManager->error(); |
|
128 if (error != XQSettingsManager::NoError) { |
|
129 qDebug("Error reading value from XQSettingsManager.. error = %d", error); |
|
130 } |
|
131 delete m_setManager; |
|
132 } |
|
133 |
|
134 if (screensaverOn) { |
|
135 if (clockFormat() == ClockFormatAnalog) { |
|
136 newContainer = new SnsrOledAnalogClockContainer(); |
|
137 } |
|
138 else { |
|
139 newContainer = new SnsrOledDigitalClockContainer(); |
|
140 } |
|
141 } |
|
142 else { |
|
143 newContainer = new SnsrBlankContainer(); |
|
144 } |
|
145 |
|
146 setCurrentContainer( newContainer ); |
|
147 |
|
148 SCREENSAVER_TEST_FUNC_EXIT("SnsrBigClockScreensaver::onPartialForeground") |
|
149 return true; |
|
150 } |
|
151 |
|
152 /*! |
|
153 @copydoc Screensaver::onBackground() |
|
154 */ |
|
155 bool SnsrBigClockScreensaver::onBackground() |
|
156 { |
|
157 SCREENSAVER_TEST_FUNC_ENTRY("SnsrBigClockScreensaver::onBackground") |
|
158 qDebug() << "SnsrBigClockScreensaver::onBackground()"; |
|
159 |
|
160 removeCurrentContainer(); |
|
161 |
|
162 SCREENSAVER_TEST_FUNC_EXIT("SnsrBigClockScreensaver::onBackground") |
|
163 return true; |
|
164 } |
|
165 |
|
166 /*! |
|
167 @copydoc Screensaver::onPowerSave() |
|
168 */ |
|
169 bool SnsrBigClockScreensaver::onPowerSave() |
|
170 { |
|
171 SCREENSAVER_TEST_FUNC_ENTRY("SnsrBigClockScreensaver::onPowerSave") |
|
172 qDebug() << "SnsrBigClockScreensaver::onPowerSave()"; |
|
173 |
|
174 SCREENSAVER_TEST_FUNC_EXIT("SnsrBigClockScreensaver::onPowerSave") |
|
175 return false; |
|
176 } |
|
177 |
|
178 /*! |
|
179 @copydoc Screensaver::onClose() |
|
180 */ |
|
181 bool SnsrBigClockScreensaver::onClose() |
|
182 { |
|
183 SCREENSAVER_TEST_FUNC_ENTRY("SnsrBigClockScreensaver::onClose") |
|
184 qDebug() << "SnsrBigClockScreensaver::onClose()"; |
|
185 |
|
186 bool ret(false); |
|
187 if (onBackground()) { |
|
188 delete mCurrentContainer; |
|
189 mCurrentContainer = 0; |
|
190 ret = true; |
|
191 } |
|
192 |
|
193 SCREENSAVER_TEST_FUNC_EXIT("SnsrBigClockScreensaver::onClose") |
|
194 return ret; |
|
195 } |
|
196 |
|
197 /*! |
|
198 @copydoc Screensaver::onHandleActiveIndicators |
|
199 */ |
|
200 void SnsrBigClockScreensaver::onHandleActiveIndicators( |
|
201 const QList<HbIndicatorInterface*> &activeIndicators) |
|
202 { |
|
203 mIndicatorModel->handleActiveIndicators(activeIndicators); |
|
204 } |
|
205 |
|
206 /*! |
|
207 @copydoc Screensaver::onHandleActivatedIndicator |
|
208 */ |
|
209 void SnsrBigClockScreensaver::onHandleActivatedIndicator( |
|
210 HbIndicatorInterface *activatedIndicator) |
|
211 { |
|
212 mIndicatorModel->handleActivatedIndicator(activatedIndicator); |
|
213 } |
|
214 |
|
215 /*! |
|
216 @copydoc Screensaver::onHandleDeactivatedIndicator |
|
217 */ |
|
218 void SnsrBigClockScreensaver::onHandleDeactivatedIndicator( |
|
219 HbIndicatorInterface *deactivatedIndicator) |
|
220 { |
|
221 mIndicatorModel->handleDeactivatedIndicator(deactivatedIndicator); |
|
222 } |
|
223 |
|
224 /*! |
|
225 @copydoc Screensaver::getActiveScreenRows |
|
226 */ |
|
227 void SnsrBigClockScreensaver::getActiveScreenRows(int *firstActiveRow, int *lastActiveRow) |
|
228 { |
|
229 if ( mCurrentContainer ) { |
|
230 mCurrentContainer->getActiveScreenRows( firstActiveRow, lastActiveRow ); |
|
231 } |
|
232 else { |
|
233 qWarning() << "No current container when active rows queried."; |
|
234 } |
|
235 } |
|
236 |
|
237 /*! |
|
238 @copydoc Screensaver::updateLayout |
|
239 */ |
|
240 void SnsrBigClockScreensaver::updateLayout() |
|
241 { |
|
242 if ( mCurrentContainer ) { |
|
243 if ( mCurrentContainer->isOrientationLocked() ) { |
|
244 mMainWindow->setOrientation( mMainWindow->orientation(), /*animate*/false ); |
|
245 } |
|
246 else { |
|
247 mMainWindow->unsetOrientation( /*animate*/false ); |
|
248 } |
|
249 mCurrentContainer->changeLayout( mMainWindow->orientation() ); |
|
250 } |
|
251 else { |
|
252 qWarning() << "No current container when updateLayout called."; |
|
253 } |
|
254 } |
|
255 |
|
256 /*! |
|
257 Update the area visible in the power save screen mode. Power save mode gets |
|
258 also activated on call if not already active. |
|
259 */ |
|
260 void SnsrBigClockScreensaver::updateActiveAreaForLowPower() |
|
261 { |
|
262 emit screenPowerModeRequested( Screensaver::ScreenModeLowPower ); |
|
263 } |
|
264 |
|
265 /*! |
|
266 Determines the curent clock format settings. |
|
267 \retval ClockFormat. |
|
268 */ |
|
269 SnsrBigClockScreensaver::ClockFormat SnsrBigClockScreensaver::clockFormat() |
|
270 { |
|
271 #ifdef Q_OS_SYMBIAN |
|
272 if (TLocale().ClockFormat() == EClockAnalog) { |
|
273 return ClockFormatAnalog; |
|
274 } else { |
|
275 return ClockFormatDigital; |
|
276 } |
|
277 #else |
|
278 // windows build - change the format every 30 seconds for testing purposes |
|
279 if (QTime::currentTime().second() < 30) { |
|
280 return ClockFormatAnalog; |
|
281 } else { |
|
282 return ClockFormatDigital; |
|
283 } |
|
284 #endif // Q_OS_SYMBIAN |
|
285 } |
|
286 |
|
287 void SnsrBigClockScreensaver::removeCurrentContainer() |
|
288 { |
|
289 if ( mCurrentContainer ) { |
|
290 disconnect( |
|
291 &mTimer, SIGNAL(timeout()), |
|
292 mCurrentContainer, SLOT(update()) |
|
293 ); |
|
294 disconnect( |
|
295 mCurrentContainer, SIGNAL(unlockRequested()), |
|
296 this, SIGNAL(unlockRequested()) ); |
|
297 if (mTimer.timerId()!= -1) { |
|
298 mTimer.stop(); |
|
299 } |
|
300 emit viewChanged(0); |
|
301 |
|
302 delete mCurrentContainer; |
|
303 mCurrentContainer = 0; |
|
304 } |
|
305 |
|
306 mMainWindow->unsetOrientation( /*animate*/false ); |
|
307 } |
|
308 |
|
309 void SnsrBigClockScreensaver::setCurrentContainer( SnsrBigClockContainer* newContainer ) |
|
310 { |
|
311 mCurrentContainer = newContainer; |
|
312 mCurrentContainer->setParent(this); |
|
313 connect( &mTimer, SIGNAL(timeout()), mCurrentContainer, SLOT(update()) ); |
|
314 connect( mCurrentContainer, SIGNAL(unlockRequested()), SIGNAL(unlockRequested()) ); |
|
315 connect( mCurrentContainer, SIGNAL(activeAreaMoved()), SLOT(updateActiveAreaForLowPower()) ); |
|
316 |
|
317 mCurrentContainer->setIndicatorModel(*mIndicatorModel); |
|
318 |
|
319 int updateInterval = mCurrentContainer->updateIntervalInMilliseconds(); |
|
320 // blankcontainer is empty one, don't start timer with -1 return value |
|
321 if ( updateInterval != -1) { |
|
322 mTimer.start(updateInterval); |
|
323 } |
|
324 |
|
325 |
|
326 emit viewChanged(mCurrentContainer); |
|
327 } |
|
328 |