1 /* |
|
2 * Copyright (c) 2009 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 |
|
28 #include <hbinstance.h> |
|
29 #include <hbmainwindow.h> |
|
30 |
|
31 #include "snsranalogclockcontainer.h" |
|
32 #include "snsrdigitalclockcontainer.h" |
|
33 #include "snsroledanalogclockcontainer.h" |
|
34 #include "snsroleddigitalclockcontainer.h" |
|
35 |
|
36 /*! |
|
37 \class SnsrBigClockScreensaver |
|
38 \ingroup group_snsrbigclockscreensaverprovider |
|
39 \brief Screensaver with big digital clock. |
|
40 */ |
|
41 |
|
42 /*! |
|
43 Constructs a new SnsrBigClockScreensaver. |
|
44 */ |
|
45 SnsrBigClockScreensaver::SnsrBigClockScreensaver() : |
|
46 mMainWindow(0), |
|
47 mCurrentContainer(0) |
|
48 { |
|
49 mMainWindow = HbInstance::instance()->allMainWindows().at(0); |
|
50 // for nice looking clock hand transformations |
|
51 mMainWindow->setRenderHint(QPainter::SmoothPixmapTransform); |
|
52 } |
|
53 |
|
54 /*! |
|
55 Destructs the class. |
|
56 */ |
|
57 SnsrBigClockScreensaver::~SnsrBigClockScreensaver() |
|
58 { |
|
59 // mCurrentContainer - deleted by the parent |
|
60 } |
|
61 |
|
62 /*! |
|
63 @copydoc Screensaver::onInitialize() |
|
64 */ |
|
65 bool SnsrBigClockScreensaver::onInitialize() |
|
66 { |
|
67 qDebug() << "SnsrBigClockScreensaver::onInitialize()"; |
|
68 return true; |
|
69 } |
|
70 |
|
71 /*! |
|
72 @copydoc Screensaver::onForeground() |
|
73 */ |
|
74 bool SnsrBigClockScreensaver::onForeground() |
|
75 { |
|
76 SCREENSAVER_TEST_FUNC_ENTRY("SnsrBigClockScreensaver::onForeground") |
|
77 qDebug() << "SnsrBigClockScreensaver::onForeground()"; |
|
78 |
|
79 bool ret(false); |
|
80 |
|
81 if (mCurrentContainer) { |
|
82 disconnect( |
|
83 mMainWindow, SIGNAL(orientationChanged(Qt::Orientation)), |
|
84 mCurrentContainer, SLOT(changeLayout(Qt::Orientation)) |
|
85 ); |
|
86 disconnect( |
|
87 &mTimer, SIGNAL(timeout()), |
|
88 mCurrentContainer, SLOT(update()) |
|
89 ); |
|
90 emit viewChanged(0); |
|
91 delete mCurrentContainer; |
|
92 mCurrentContainer = 0; |
|
93 } |
|
94 |
|
95 if (clockFormat() == ClockFormatAnalog) { |
|
96 mCurrentContainer = new SnsrAnalogClockContainer(); |
|
97 } |
|
98 else { |
|
99 mCurrentContainer = new SnsrDigitalClockContainer(); |
|
100 } |
|
101 connect( |
|
102 mMainWindow, SIGNAL(orientationChanged(Qt::Orientation)), |
|
103 mCurrentContainer, SLOT(changeLayout(Qt::Orientation)) |
|
104 ); |
|
105 connect(&mTimer, SIGNAL(timeout()), mCurrentContainer, SLOT(update())); |
|
106 |
|
107 mCurrentContainer->changeLayout(mMainWindow->orientation()); |
|
108 mTimer.start(1000); |
|
109 emit viewChanged(mCurrentContainer); |
|
110 |
|
111 ret = true; |
|
112 |
|
113 SCREENSAVER_TEST_FUNC_EXIT("SnsrBigClockScreensaver::onForeground") |
|
114 return ret; |
|
115 } |
|
116 |
|
117 /*! |
|
118 @copydoc Screensaver::onPartialForeground() |
|
119 */ |
|
120 bool SnsrBigClockScreensaver::onPartialForeground() |
|
121 { |
|
122 SCREENSAVER_TEST_FUNC_ENTRY("SnsrBigClockScreensaver::onPartialForeground") |
|
123 qDebug() << "SnsrBigClockScreensaver::onPartialForeground()"; |
|
124 |
|
125 bool ret(false); |
|
126 |
|
127 if (mCurrentContainer) { |
|
128 disconnect( |
|
129 mMainWindow, SIGNAL(orientationChanged(Qt::Orientation)), |
|
130 mCurrentContainer, SLOT(changeLayout(Qt::Orientation)) |
|
131 ); |
|
132 disconnect( |
|
133 &mTimer, SIGNAL(timeout()), |
|
134 mCurrentContainer, SLOT(update()) |
|
135 ); |
|
136 emit viewChanged(0); |
|
137 delete mCurrentContainer; |
|
138 mCurrentContainer = 0; |
|
139 } |
|
140 |
|
141 if (clockFormat() == ClockFormatAnalog) { |
|
142 mCurrentContainer = new SnsrOledAnalogClockContainer(); |
|
143 } |
|
144 else { |
|
145 mCurrentContainer = new SnsrOledDigitalClockContainer(); |
|
146 } |
|
147 connect( |
|
148 mMainWindow, SIGNAL(orientationChanged(Qt::Orientation)), |
|
149 mCurrentContainer, SLOT(changeLayout(Qt::Orientation)) |
|
150 ); |
|
151 connect(&mTimer, SIGNAL(timeout()), mCurrentContainer, SLOT(update())); |
|
152 |
|
153 mCurrentContainer->changeLayout(mMainWindow->orientation()); |
|
154 mTimer.start(1000); |
|
155 emit viewChanged(mCurrentContainer); |
|
156 |
|
157 ret = true; |
|
158 |
|
159 SCREENSAVER_TEST_FUNC_EXIT("SnsrBigClockScreensaver::onPartialForeground") |
|
160 return ret; |
|
161 } |
|
162 |
|
163 /*! |
|
164 @copydoc Screensaver::onBackground() |
|
165 */ |
|
166 bool SnsrBigClockScreensaver::onBackground() |
|
167 { |
|
168 SCREENSAVER_TEST_FUNC_ENTRY("SnsrBigClockScreensaver::onBackground") |
|
169 qDebug() << "SnsrBigClockScreensaver::onBackground()"; |
|
170 |
|
171 disconnect( |
|
172 mMainWindow, SIGNAL(orientationChanged(Qt::Orientation)), |
|
173 mCurrentContainer, SLOT(changeLayout(Qt::Orientation)) |
|
174 ); |
|
175 disconnect( |
|
176 &mTimer, SIGNAL(timeout()), |
|
177 mCurrentContainer, SLOT(update()) |
|
178 ); |
|
179 mTimer.stop(); |
|
180 emit viewChanged(0); |
|
181 |
|
182 SCREENSAVER_TEST_FUNC_EXIT("SnsrBigClockScreensaver::onBackground") |
|
183 return true; |
|
184 } |
|
185 |
|
186 /*! |
|
187 @copydoc Screensaver::onPowerSave() |
|
188 */ |
|
189 bool SnsrBigClockScreensaver::onPowerSave() |
|
190 { |
|
191 SCREENSAVER_TEST_FUNC_ENTRY("SnsrBigClockScreensaver::onPowerSave") |
|
192 qDebug() << "SnsrBigClockScreensaver::onPowerSave()"; |
|
193 |
|
194 SCREENSAVER_TEST_FUNC_EXIT("SnsrBigClockScreensaver::onPowerSave") |
|
195 return false; |
|
196 } |
|
197 |
|
198 /*! |
|
199 @copydoc Screensaver::onClose() |
|
200 */ |
|
201 bool SnsrBigClockScreensaver::onClose() |
|
202 { |
|
203 SCREENSAVER_TEST_FUNC_ENTRY("SnsrBigClockScreensaver::onClose") |
|
204 qDebug() << "SnsrBigClockScreensaver::onClose()"; |
|
205 |
|
206 bool ret(false); |
|
207 if (onBackground()) { |
|
208 delete mCurrentContainer; |
|
209 mCurrentContainer = 0; |
|
210 ret = true; |
|
211 } |
|
212 |
|
213 SCREENSAVER_TEST_FUNC_EXIT("SnsrBigClockScreensaver::onClose") |
|
214 return ret; |
|
215 } |
|
216 |
|
217 /*! |
|
218 Determines the curent clock format settings. |
|
219 \retval ClockFormat. |
|
220 */ |
|
221 SnsrBigClockScreensaver::ClockFormat SnsrBigClockScreensaver::clockFormat() |
|
222 { |
|
223 #ifdef Q_OS_SYMBIAN |
|
224 if (TLocale().ClockFormat() == EClockAnalog) { |
|
225 return ClockFormatAnalog; |
|
226 } else { |
|
227 return ClockFormatDigital; |
|
228 } |
|
229 #else |
|
230 // windows build - change the format every 30 seconds for testing purposes |
|
231 if (QTime::currentTime().second() < 30) { |
|
232 return ClockFormatAnalog; |
|
233 } else { |
|
234 return ClockFormatDigital; |
|
235 } |
|
236 #endif // Q_OS_SYMBIAN |
|
237 } |
|