20 #include <QPainter> |
20 #include <QPainter> |
21 #include <QDebug> |
21 #include <QDebug> |
22 #include <QServiceManager> |
22 #include <QServiceManager> |
23 #include <QServiceFilter> |
23 #include <QServiceFilter> |
24 #include <QServiceInterfaceDescriptor> |
24 #include <QServiceInterfaceDescriptor> |
|
25 #include <QTimer> |
25 #include <XQSettingsManager> |
26 #include <XQSettingsManager> |
26 #include <HbMainWindow> |
27 #include <HbMainWindow> |
27 #include <HbIndicatorInterface> |
28 #include <HbIndicatorInterface> |
28 |
29 |
29 #include <screensaver.h> |
30 #include <screensaver.h> |
30 #include <screensaverdomaincrkeys.h> |
31 #include <screensaverdomaincrkeys.h> |
31 #include "snsrdevicedialog.h" |
32 #include "snsrdevicedialog.h" |
|
33 #include "snsrdevicedialogdisplaycontrol.h" |
32 |
34 |
33 const char *gBigClockInterfaceName = "com.nokia.screensaver.ISnsrBigClockScreensaver"; |
35 const char *gBigClockInterfaceName = "com.nokia.screensaver.ISnsrBigClockScreensaver"; |
34 |
36 |
35 /*! |
37 /*! |
36 \class SnsrDeviceDialog |
38 \class SnsrDeviceDialog |
79 SLOT(changeView(QGraphicsWidget*))); |
81 SLOT(changeView(QGraphicsWidget*))); |
80 connect(mScreensaver, SIGNAL(faulted()), |
82 connect(mScreensaver, SIGNAL(faulted()), |
81 SLOT(screensaverFaulted())); |
83 SLOT(screensaverFaulted())); |
82 connect( mScreensaver, SIGNAL(unlockRequested()), |
84 connect( mScreensaver, SIGNAL(unlockRequested()), |
83 SLOT(requestUnlock()) ); |
85 SLOT(requestUnlock()) ); |
84 connect( mScreensaver, SIGNAL(screenPowerModeRequested(Screensaver::ScreenPowerMode)), |
86 connect( mScreensaver, SIGNAL(activeAreaMoved()), |
85 SLOT(requestScreenMode(Screensaver::ScreenPowerMode)) ); |
87 SLOT(updateDisplayMode()) ); |
86 |
88 |
87 mScreensaver->initialize(); |
89 mScreensaver->initialize(); |
88 |
90 |
89 setBackgroundItem(0); |
91 setBackgroundItem(0); |
90 |
92 |
92 setTimeout(HbPopup::NoTimeout); |
94 setTimeout(HbPopup::NoTimeout); |
93 |
95 |
94 mainWindow()->setAutomaticOrientationEffectEnabled(false); |
96 mainWindow()->setAutomaticOrientationEffectEnabled(false); |
95 |
97 |
96 setDeviceDialogParameters( parameters ); |
98 setDeviceDialogParameters( parameters ); |
|
99 |
|
100 mDisplayControl = new SnsrDeviceDialogDisplayControl(); |
|
101 |
|
102 mDisplayModeTimer = new QTimer(this); |
|
103 connect( mDisplayModeTimer, SIGNAL(timeout()), SLOT(updateDisplayMode()) ); |
97 } |
104 } |
98 |
105 |
99 /*! |
106 /*! |
100 Destructor. |
107 Destructor. |
101 */ |
108 */ |
102 SnsrDeviceDialog::~SnsrDeviceDialog() |
109 SnsrDeviceDialog::~SnsrDeviceDialog() |
103 { |
110 { |
104 qDebug("SnsrDeviceDialog::~SnsrDeviceDialog()"); |
111 qDebug("SnsrDeviceDialog::~SnsrDeviceDialog()"); |
105 QServiceManager serviceManager; |
112 QServiceManager serviceManager; |
106 serviceManager.removeService(gBigClockInterfaceName); |
113 serviceManager.removeService(gBigClockInterfaceName); |
|
114 |
|
115 // We should get the FocusOut event when closing, but deactivate the |
|
116 // power save also here in case we haven't got the event for some reason. |
|
117 if ( mDisplayControl ) { |
|
118 mDisplayControl->setDisplayFullPower(); |
|
119 delete mDisplayControl; |
|
120 } |
107 } |
121 } |
108 |
122 |
109 /*! |
123 /*! |
110 Sets device dialog parameters. |
124 Sets device dialog parameters. |
111 \param parameters Device Dialog's parameters to be set. |
125 \param parameters Device Dialog's parameters to be set. |
132 if (viewType == ViewTypeInitial ) { |
146 if (viewType == ViewTypeInitial ) { |
133 XQSettingsManager::Error error; |
147 XQSettingsManager::Error error; |
134 int startupView = 0; |
148 int startupView = 0; |
135 XQCentralRepositorySettingsKey settingsKey( |
149 XQCentralRepositorySettingsKey settingsKey( |
136 KCRUidScreensaverSettings.iUid, KScreensaverStartupView ); // TUid as same repository used in control panel via Symbian APIs |
150 KCRUidScreensaverSettings.iUid, KScreensaverStartupView ); // TUid as same repository used in control panel via Symbian APIs |
137 m_setManager = new XQSettingsManager(this); |
151 XQSettingsManager settingsManager; |
138 if (m_setManager) { |
152 startupView = settingsManager.readItemValue(settingsKey, XQSettingsManager::TypeInt).toInt(); |
139 startupView = m_setManager->readItemValue(settingsKey, XQSettingsManager::TypeInt).toInt(); |
153 error = settingsManager.error(); |
140 error = m_setManager->error(); |
154 if (error == XQSettingsManager::NoError) { |
141 if (error == XQSettingsManager::NoError) { |
155 viewType = startupView; |
142 viewType = startupView; |
|
143 } |
|
144 delete m_setManager; |
|
145 } |
156 } |
146 } |
157 } |
147 |
158 |
148 switch (viewType) { |
159 switch (viewType) { |
149 case SnsrDeviceDialog::ViewTypeActive: |
160 case SnsrDeviceDialog::ViewTypeActive: |
202 |
213 |
203 // workaround for duplicating connections and emiting two signals |
214 // workaround for duplicating connections and emiting two signals |
204 // showEvent is called for HbDeviceDialogManager showDeviceDialog() |
215 // showEvent is called for HbDeviceDialogManager showDeviceDialog() |
205 // and for HbPopup itemChange(), both events are set to QEvent::Show type |
216 // and for HbPopup itemChange(), both events are set to QEvent::Show type |
206 disconnect(mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)), |
217 disconnect(mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)), |
207 this, SLOT(changeLayout(Qt::Orientation))); |
218 this, SLOT(handleOrientationChange(Qt::Orientation))); |
208 connect(mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)), |
219 connect(mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)), |
209 this, SLOT(changeLayout(Qt::Orientation))); |
220 this, SLOT(handleOrientationChange(Qt::Orientation))); |
210 |
221 |
211 changeLayout(mainWindow()->orientation()); |
222 changeLayout(); |
212 } |
223 } |
213 |
224 |
214 #ifdef COVERAGE_MEASUREMENT |
225 #ifdef COVERAGE_MEASUREMENT |
215 #pragma CTC SKIP |
226 #pragma CTC SKIP |
216 #endif //COVERAGE_MEASUREMENT |
227 #endif //COVERAGE_MEASUREMENT |
240 qDebug("SnsrDeviceDialog::closeEvent()"); |
251 qDebug("SnsrDeviceDialog::closeEvent()"); |
241 |
252 |
242 HbPopup::closeEvent(event); |
253 HbPopup::closeEvent(event); |
243 |
254 |
244 disconnect(mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)), |
255 disconnect(mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)), |
245 this, SLOT(changeLayout(Qt::Orientation))); |
256 this, SLOT(handleOrientationChange(Qt::Orientation))); |
246 mScreensaver->close(); |
257 mScreensaver->close(); |
|
258 } |
|
259 |
|
260 /*! |
|
261 Handle focus in/out events and just pass through the rest of the events |
|
262 */ |
|
263 bool SnsrDeviceDialog::event(QEvent *event) |
|
264 { |
|
265 if ( event->type() == QEvent::FocusOut ) { |
|
266 mHasFocus = false; |
|
267 // Some other dialog came on top of us (or dialog was closed). |
|
268 // Set screen to full power. |
|
269 mDisplayModeTimer->stop(); |
|
270 mDisplayControl->setDisplayFullPower(); |
|
271 } |
|
272 else if ( event->type() == QEvent::FocusIn ) { |
|
273 mHasFocus = true; |
|
274 // We became (again) the top-most dialog. Switch screen to |
|
275 // applicable power mode. |
|
276 updateDisplayModeDeferred(); |
|
277 } |
|
278 return HbPopup::event(event); |
247 } |
279 } |
248 |
280 |
249 /*! |
281 /*! |
250 Replaces layout's item. |
282 Replaces layout's item. |
251 \param widget New item to be added to layout. |
283 \param widget New item to be added to layout. |
282 qWarning() << "SnsrDeviceDialog::screensaverFaulted()"; |
319 qWarning() << "SnsrDeviceDialog::screensaverFaulted()"; |
283 // TODO: some error handling |
320 // TODO: some error handling |
284 } |
321 } |
285 |
322 |
286 /*! |
323 /*! |
|
324 Handle orientation change event |
|
325 \param orientation New orientation value. |
|
326 */ |
|
327 void SnsrDeviceDialog::handleOrientationChange(Qt::Orientation orientation) |
|
328 { |
|
329 Q_UNUSED(orientation) |
|
330 changeLayout(); |
|
331 updateDisplayMode(); |
|
332 } |
|
333 |
|
334 /*! |
287 Resize device dialog. |
335 Resize device dialog. |
288 \param orientation New orientation value. |
336 */ |
289 */ |
337 void SnsrDeviceDialog::changeLayout() |
290 void SnsrDeviceDialog::changeLayout(Qt::Orientation orientation) |
338 { |
291 { |
|
292 Q_UNUSED(orientation) |
|
293 |
|
294 QRectF rect = mainWindow()->layoutRect(); |
339 QRectF rect = mainWindow()->layoutRect(); |
295 setMinimumSize( rect.size() ); |
340 setMinimumSize( rect.size() ); |
296 setPreferredPos( QPointF(0,0) ); |
341 setPreferredPos( QPointF(0,0) ); |
297 QGraphicsSceneResizeEvent sceneResize; |
342 QGraphicsSceneResizeEvent sceneResize; |
298 sceneResize.setNewSize( rect.size() ); |
343 sceneResize.setNewSize( rect.size() ); |
299 event( &sceneResize ); |
344 event( &sceneResize ); |
300 mScreensaver->updateLayout(); |
345 mScreensaver->updateLayout(); |
301 } |
346 } |
302 |
347 |
303 /*! |
348 /*! |
|
349 Update power mode of the display device |
|
350 */ |
|
351 void SnsrDeviceDialog::updateDisplayMode() |
|
352 { |
|
353 // Cancel any pending deferred update order |
|
354 mDisplayModeTimer->stop(); |
|
355 |
|
356 // Check desidred display power mode from screensaver but only when |
|
357 // we are the top-most device dialog. If some other dialog is on top of us, |
|
358 // then always default to full power mode. |
|
359 Screensaver::ScreenPowerMode mode( Screensaver::ScreenModeFullPower ); |
|
360 if ( mHasFocus ) { |
|
361 mode = mScreensaver->currentPowerMode(); |
|
362 } |
|
363 |
|
364 switch ( mode ) { |
|
365 case Screensaver::ScreenModeOff: { |
|
366 mDisplayControl->setDisplayOff(); |
|
367 break; |
|
368 } |
|
369 case Screensaver::ScreenModeLowPower: { |
|
370 int firstRow(-1); |
|
371 int lastRow(-1); |
|
372 mScreensaver->getActiveScreenRows(&firstRow, &lastRow); |
|
373 mDisplayControl->setDisplayLowPower(firstRow, lastRow); |
|
374 break; |
|
375 } |
|
376 case Screensaver::ScreenModeFullPower: { |
|
377 mDisplayControl->setDisplayFullPower(); |
|
378 break; |
|
379 } |
|
380 } |
|
381 } |
|
382 |
|
383 /*! |
|
384 Update power mode of the display device after a short delay |
|
385 */ |
|
386 void SnsrDeviceDialog::updateDisplayModeDeferred() |
|
387 { |
|
388 mDisplayModeTimer->start(200); // milliseconds |
|
389 } |
|
390 |
|
391 /*! |
304 Send unlock signal to autolock. |
392 Send unlock signal to autolock. |
305 */ |
393 */ |
306 void SnsrDeviceDialog::requestUnlock() |
394 void SnsrDeviceDialog::requestUnlock() |
307 { |
395 { |
308 QVariantMap data; |
396 QVariantMap data; |
309 data.insert(dataKeyUnlock, 1); |
397 data.insert(dataKeyUnlock, 1); |
310 emit deviceDialogData(data); |
398 emit deviceDialogData(data); |
311 } |
399 } |
312 |
400 |
313 /*! |
401 /*! |
314 Send low power mode on/off request to autolock. |
|
315 */ |
|
316 void SnsrDeviceDialog::requestScreenMode(Screensaver::ScreenPowerMode mode) |
|
317 { |
|
318 /* TEMPORARY FIX for the "black screen jam" bug. To be re-enabled when proper fix is found. |
|
319 QVariantMap data; |
|
320 QVariantList rowLimits; |
|
321 if ( mode == Screensaver::ScreenModeOff ) { |
|
322 data.insert(dataKeySwitchLights, 0); |
|
323 data.insert(dataKeySwitchLowPower, rowLimits); // empty list means "low power off" |
|
324 } |
|
325 else if ( mode == Screensaver::ScreenModeLowPower ) { |
|
326 //data.insert(dataKeySwitchLights, 0); |
|
327 int firstRow; |
|
328 int lastRow; |
|
329 mScreensaver->getActiveScreenRows(&firstRow, &lastRow); |
|
330 rowLimits.append( firstRow ); |
|
331 rowLimits.append( lastRow ); |
|
332 data.insert(dataKeySwitchLowPower, rowLimits); |
|
333 } |
|
334 else if ( mode == Screensaver::ScreenModeFullPower ) { |
|
335 data.insert(dataKeySwitchLights, 30); |
|
336 data.insert(dataKeySwitchLowPower, rowLimits); // empty list means "low power off" |
|
337 } |
|
338 |
|
339 emit deviceDialogData(data); |
|
340 */ |
|
341 } |
|
342 |
|
343 /*! |
|
344 Called when the dialog is created if they are any currently |
402 Called when the dialog is created if they are any currently |
345 activate universal indicators present. |
403 activate universal indicators present. |
346 */ |
404 */ |
347 void SnsrDeviceDialog::indicatorsActivated( |
405 void SnsrDeviceDialog::indicatorsActivated( |
348 const QList<HbIndicatorInterface*> &activatedIndicators) |
406 const QList<HbIndicatorInterface*> &activatedIndicators) |