97
|
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 |
#include <XQSettingsManager>
|
|
23 |
#include <screensaverdomaincrkeys.h>
|
|
24 |
#endif // Q_OS_SYMBIAN
|
|
25 |
|
|
26 |
#include <QDebug>
|
|
27 |
#include <QTime>
|
|
28 |
#include <QTimer>
|
|
29 |
#include <HbInstance>
|
|
30 |
#include <HbMainWindow>
|
|
31 |
|
|
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 |
{
|
|
53 |
mMainWindow = HbInstance::instance()->allMainWindows().at(0);
|
|
54 |
// for nice looking clock hand transformations
|
|
55 |
mMainWindow->setRenderHint(QPainter::SmoothPixmapTransform);
|
|
56 |
|
|
57 |
// This model holds indicator status information and must exist as
|
|
58 |
// long as screensaver does.
|
|
59 |
mIndicatorModel = new SnsrIndicatorModel(this);
|
|
60 |
}
|
|
61 |
|
|
62 |
/*!
|
|
63 |
Destructs the class.
|
|
64 |
*/
|
|
65 |
SnsrBigClockScreensaver::~SnsrBigClockScreensaver()
|
|
66 |
{
|
|
67 |
// TODO: unlock orientation once the locking mechanism is available and used
|
|
68 |
// mCurrentContainer, mIndicatorModel - deleted by the parent
|
|
69 |
}
|
|
70 |
|
|
71 |
/*!
|
|
72 |
@copydoc Screensaver::onInitialize()
|
|
73 |
*/
|
|
74 |
bool SnsrBigClockScreensaver::onInitialize()
|
|
75 |
{
|
|
76 |
qDebug() << "SnsrBigClockScreensaver::onInitialize()";
|
|
77 |
return true;
|
|
78 |
}
|
|
79 |
|
|
80 |
/*!
|
|
81 |
@copydoc Screensaver::onForeground()
|
|
82 |
*/
|
|
83 |
bool SnsrBigClockScreensaver::onForeground()
|
|
84 |
{
|
|
85 |
SCREENSAVER_TEST_FUNC_ENTRY("SnsrBigClockScreensaver::onForeground")
|
|
86 |
qDebug() << "SnsrBigClockScreensaver::onForeground()";
|
|
87 |
|
|
88 |
removeCurrentContainer();
|
|
89 |
|
|
90 |
SnsrBigClockContainer* newContainer( 0 );
|
|
91 |
if (clockFormat() == ClockFormatAnalog) {
|
|
92 |
newContainer = new SnsrAnalogClockContainer();
|
|
93 |
}
|
|
94 |
else {
|
|
95 |
newContainer = new SnsrDigitalClockContainer();
|
|
96 |
}
|
|
97 |
|
|
98 |
setCurrentContainer( newContainer );
|
|
99 |
|
|
100 |
SCREENSAVER_TEST_FUNC_EXIT("SnsrBigClockScreensaver::onForeground")
|
|
101 |
return true;
|
|
102 |
}
|
|
103 |
|
|
104 |
/*!
|
|
105 |
@copydoc Screensaver::onPartialForeground()
|
|
106 |
*/
|
|
107 |
bool SnsrBigClockScreensaver::onPartialForeground()
|
|
108 |
{
|
|
109 |
SCREENSAVER_TEST_FUNC_ENTRY("SnsrBigClockScreensaver::onPartialForeground")
|
|
110 |
qDebug() << "SnsrBigClockScreensaver::onPartialForeground()";
|
|
111 |
|
|
112 |
removeCurrentContainer();
|
|
113 |
|
|
114 |
SnsrBigClockContainer* newContainer( 0 );
|
|
115 |
|
|
116 |
#ifdef Q_OS_SYMBIAN
|
|
117 |
// Check ScreensaverStatus from repository
|
|
118 |
XQSettingsManager::Error error;
|
|
119 |
XQCentralRepositorySettingsKey settingsKey(
|
|
120 |
KCRUidScreensaverSettings.iUid, KScreensaverStatus ); // TUid as same repository used in control panel via Symbian APIs
|
|
121 |
XQSettingsManager setManager;
|
|
122 |
int screensaverOn = setManager.readItemValue(settingsKey, XQSettingsManager::TypeInt).toInt();
|
|
123 |
error = setManager.error();
|
|
124 |
if (error != XQSettingsManager::NoError) {
|
|
125 |
qDebug("Error reading value from XQSettingsManager.. error = %d", error);
|
|
126 |
}
|
|
127 |
#else
|
|
128 |
int screensaverOn = 1;
|
|
129 |
#endif // Q_OS_SYMBIAN
|
|
130 |
|
|
131 |
if (screensaverOn) {
|
|
132 |
if (clockFormat() == ClockFormatAnalog) {
|
|
133 |
newContainer = new SnsrOledAnalogClockContainer();
|
|
134 |
}
|
|
135 |
else {
|
|
136 |
newContainer = new SnsrOledDigitalClockContainer();
|
|
137 |
}
|
|
138 |
}
|
|
139 |
else {
|
|
140 |
newContainer = new SnsrBlankContainer();
|
|
141 |
}
|
|
142 |
|
|
143 |
setCurrentContainer( newContainer );
|
|
144 |
|
|
145 |
SCREENSAVER_TEST_FUNC_EXIT("SnsrBigClockScreensaver::onPartialForeground")
|
|
146 |
return true;
|
|
147 |
}
|
|
148 |
|
|
149 |
/*!
|
|
150 |
@copydoc Screensaver::onBackground()
|
|
151 |
*/
|
|
152 |
bool SnsrBigClockScreensaver::onBackground()
|
|
153 |
{
|
|
154 |
SCREENSAVER_TEST_FUNC_ENTRY("SnsrBigClockScreensaver::onBackground")
|
|
155 |
qDebug() << "SnsrBigClockScreensaver::onBackground()";
|
|
156 |
|
|
157 |
removeCurrentContainer();
|
|
158 |
|
|
159 |
SCREENSAVER_TEST_FUNC_EXIT("SnsrBigClockScreensaver::onBackground")
|
|
160 |
return true;
|
|
161 |
}
|
|
162 |
|
|
163 |
/*!
|
|
164 |
@copydoc Screensaver::onPowerSave()
|
|
165 |
*/
|
|
166 |
bool SnsrBigClockScreensaver::onPowerSave()
|
|
167 |
{
|
|
168 |
SCREENSAVER_TEST_FUNC_ENTRY("SnsrBigClockScreensaver::onPowerSave")
|
|
169 |
qDebug() << "SnsrBigClockScreensaver::onPowerSave()";
|
|
170 |
|
|
171 |
SCREENSAVER_TEST_FUNC_EXIT("SnsrBigClockScreensaver::onPowerSave")
|
|
172 |
return false;
|
|
173 |
}
|
|
174 |
|
|
175 |
/*!
|
|
176 |
@copydoc Screensaver::onClose()
|
|
177 |
*/
|
|
178 |
bool SnsrBigClockScreensaver::onClose()
|
|
179 |
{
|
|
180 |
SCREENSAVER_TEST_FUNC_ENTRY("SnsrBigClockScreensaver::onClose")
|
|
181 |
qDebug() << "SnsrBigClockScreensaver::onClose()";
|
|
182 |
|
|
183 |
bool ret(false);
|
|
184 |
if (onBackground()) {
|
|
185 |
delete mCurrentContainer;
|
|
186 |
mCurrentContainer = 0;
|
|
187 |
ret = true;
|
|
188 |
}
|
|
189 |
|
|
190 |
SCREENSAVER_TEST_FUNC_EXIT("SnsrBigClockScreensaver::onClose")
|
|
191 |
return ret;
|
|
192 |
}
|
|
193 |
|
|
194 |
/*!
|
|
195 |
@copydoc Screensaver::onHandleActiveIndicators
|
|
196 |
*/
|
|
197 |
void SnsrBigClockScreensaver::onHandleActiveIndicators(
|
|
198 |
const QList<HbIndicatorInterface*> &activeIndicators)
|
|
199 |
{
|
|
200 |
mIndicatorModel->handleActiveIndicators(activeIndicators);
|
|
201 |
}
|
|
202 |
|
|
203 |
/*!
|
|
204 |
@copydoc Screensaver::onHandleActivatedIndicator
|
|
205 |
*/
|
|
206 |
void SnsrBigClockScreensaver::onHandleActivatedIndicator(
|
|
207 |
HbIndicatorInterface *activatedIndicator)
|
|
208 |
{
|
|
209 |
mIndicatorModel->handleActivatedIndicator(activatedIndicator);
|
|
210 |
}
|
|
211 |
|
|
212 |
/*!
|
|
213 |
@copydoc Screensaver::onHandleDeactivatedIndicator
|
|
214 |
*/
|
|
215 |
void SnsrBigClockScreensaver::onHandleDeactivatedIndicator(
|
|
216 |
HbIndicatorInterface *deactivatedIndicator)
|
|
217 |
{
|
|
218 |
mIndicatorModel->handleDeactivatedIndicator(deactivatedIndicator);
|
|
219 |
}
|
|
220 |
|
|
221 |
/*!
|
|
222 |
@copydoc Screensaver::currentPowerMode
|
|
223 |
*/
|
|
224 |
Screensaver::ScreenPowerMode SnsrBigClockScreensaver::currentPowerMode()
|
|
225 |
{
|
|
226 |
Screensaver::ScreenPowerMode mode( Screensaver::ScreenModeFullPower );
|
|
227 |
if ( mCurrentContainer ) {
|
|
228 |
mode = mCurrentContainer->displayPowerMode();
|
|
229 |
}
|
|
230 |
else {
|
|
231 |
qWarning() << "No current container when current power mode queried.";
|
|
232 |
}
|
|
233 |
return mode;
|
|
234 |
}
|
|
235 |
|
|
236 |
/*!
|
|
237 |
@copydoc Screensaver::getActiveScreenRows
|
|
238 |
*/
|
|
239 |
void SnsrBigClockScreensaver::getActiveScreenRows(int *firstActiveRow, int *lastActiveRow)
|
|
240 |
{
|
|
241 |
if ( mCurrentContainer ) {
|
|
242 |
mCurrentContainer->getActiveScreenRows( firstActiveRow, lastActiveRow );
|
|
243 |
}
|
|
244 |
else {
|
|
245 |
qWarning() << "No current container when active rows queried.";
|
|
246 |
}
|
|
247 |
}
|
|
248 |
|
|
249 |
/*!
|
|
250 |
@copydoc Screensaver::updateLayout
|
|
251 |
*/
|
|
252 |
void SnsrBigClockScreensaver::updateLayout()
|
|
253 |
{
|
|
254 |
if ( mCurrentContainer ) {
|
|
255 |
if ( mCurrentContainer->isOrientationLocked() ) {
|
|
256 |
// TODO: There is currently no way for device dialog to lock the display orientation.
|
|
257 |
// Orbit team has a backlog item about "global orientation lock" which could be
|
|
258 |
// used here when it is available.
|
|
259 |
}
|
|
260 |
else {
|
|
261 |
// TODO: There is currently no way for device dialog to lock the display orientation.
|
|
262 |
// Orbit team has a backlog item about "global orientation lock" which could be
|
|
263 |
// used here when it is available.
|
|
264 |
}
|
|
265 |
mCurrentContainer->changeLayout( mMainWindow->orientation() );
|
|
266 |
}
|
|
267 |
else {
|
|
268 |
qWarning() << "No current container when updateLayout called.";
|
|
269 |
}
|
|
270 |
}
|
|
271 |
|
|
272 |
/*!
|
|
273 |
Update clock time when timer is triggered
|
|
274 |
*/
|
|
275 |
void SnsrBigClockScreensaver::updateTime()
|
|
276 |
{
|
|
277 |
if ( mCurrentContainer ) {
|
|
278 |
mCurrentContainer->update();
|
|
279 |
|
|
280 |
// Move the active area of display device if current container uses the power save mode.
|
|
281 |
if ( mCurrentContainer->displayPowerMode() == Screensaver::ScreenModeLowPower ) {
|
|
282 |
emit activeAreaMoved();
|
|
283 |
}
|
|
284 |
|
|
285 |
// Ensure correct update interval is used. First timed update may be done
|
|
286 |
// with timeout differing from the normal update rate.
|
|
287 |
int updateInterval = mCurrentContainer->updateIntervalInMilliseconds();
|
|
288 |
if ( updateInterval > 0 ) {
|
|
289 |
mTimer.setInterval( updateInterval );
|
|
290 |
}
|
|
291 |
}
|
|
292 |
}
|
|
293 |
|
|
294 |
/*!
|
|
295 |
Determines the curent clock format settings.
|
|
296 |
\retval ClockFormat.
|
|
297 |
*/
|
|
298 |
SnsrBigClockScreensaver::ClockFormat SnsrBigClockScreensaver::clockFormat()
|
|
299 |
{
|
|
300 |
#ifdef Q_OS_SYMBIAN
|
|
301 |
if (TLocale().ClockFormat() == EClockAnalog) {
|
|
302 |
return ClockFormatAnalog;
|
|
303 |
} else {
|
|
304 |
return ClockFormatDigital;
|
|
305 |
}
|
|
306 |
#else
|
|
307 |
// windows build - change the format every 30 seconds for testing purposes
|
|
308 |
if (QTime::currentTime().second() < 30) {
|
|
309 |
return ClockFormatAnalog;
|
|
310 |
} else {
|
|
311 |
return ClockFormatDigital;
|
|
312 |
}
|
|
313 |
#endif // Q_OS_SYMBIAN
|
|
314 |
}
|
|
315 |
|
|
316 |
void SnsrBigClockScreensaver::removeCurrentContainer()
|
|
317 |
{
|
|
318 |
if ( mCurrentContainer ) {
|
|
319 |
disconnect(
|
|
320 |
&mTimer, SIGNAL(timeout()),
|
|
321 |
this, SLOT(updateTime())
|
|
322 |
);
|
|
323 |
disconnect(
|
|
324 |
mCurrentContainer, SIGNAL(unlockRequested()),
|
|
325 |
this, SIGNAL(unlockRequested()) );
|
|
326 |
if (mTimer.timerId()!= -1) {
|
|
327 |
mTimer.stop();
|
|
328 |
}
|
|
329 |
emit viewChanged(0);
|
|
330 |
|
|
331 |
delete mCurrentContainer;
|
|
332 |
mCurrentContainer = 0;
|
|
333 |
}
|
|
334 |
}
|
|
335 |
|
|
336 |
void SnsrBigClockScreensaver::setCurrentContainer( SnsrBigClockContainer* newContainer )
|
|
337 |
{
|
|
338 |
mCurrentContainer = newContainer;
|
|
339 |
mCurrentContainer->setParent(this);
|
|
340 |
connect( &mTimer, SIGNAL(timeout()), SLOT(updateTime()) );
|
|
341 |
connect( mCurrentContainer, SIGNAL(unlockRequested()), SIGNAL(unlockRequested()) );
|
|
342 |
|
|
343 |
mCurrentContainer->setIndicatorModel(*mIndicatorModel);
|
|
344 |
|
|
345 |
int updateInterval = mCurrentContainer->updateIntervalInMilliseconds();
|
|
346 |
|
|
347 |
// In case the container needs an update seldomly (at maximum once per minute),
|
|
348 |
// align these updates with the even minutes by doing the first update on the
|
|
349 |
// next even minute.
|
|
350 |
const int minute = 60*1000;
|
|
351 |
if ( updateInterval >= minute ) {
|
|
352 |
updateInterval = minute - QTime::currentTime().second()*1000;
|
|
353 |
}
|
|
354 |
// container can use negative updateInteval value to indicate that no recurring
|
|
355 |
// updates are needed
|
|
356 |
if ( updateInterval > 0 ) {
|
|
357 |
mTimer.start(updateInterval);
|
|
358 |
}
|
|
359 |
|
|
360 |
emit viewChanged(mCurrentContainer);
|
|
361 |
}
|
|
362 |
|