62
|
1 |
/*
|
69
|
2 |
* Copyright (c) 2009 - 2010 Nokia Corporation and/or its subsidiary(-ies).
|
62
|
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: Default Screensaver runtime.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <QGraphicsLinearLayout>
|
69
|
19 |
#include <QGraphicsSceneResizeEvent>
|
62
|
20 |
#include <QPainter>
|
|
21 |
#include <QDebug>
|
69
|
22 |
#include <QServiceManager>
|
|
23 |
#include <QServiceFilter>
|
|
24 |
#include <QServiceInterfaceDescriptor>
|
|
25 |
#include <XQSettingsManager>
|
|
26 |
#include <HbMainWindow>
|
62
|
27 |
#include <HbIndicatorInterface>
|
|
28 |
|
|
29 |
#include <screensaver.h>
|
69
|
30 |
#include <screensaverdomaincrkeys.h>
|
62
|
31 |
#include "snsrdevicedialog.h"
|
|
32 |
|
|
33 |
const char *gBigClockInterfaceName = "com.nokia.screensaver.ISnsrBigClockScreensaver";
|
|
34 |
|
|
35 |
/*!
|
|
36 |
\class SnsrDeviceDialog
|
|
37 |
\ingroup group_snsrdevicedialogplugin
|
|
38 |
\brief Screensaver Device Dialog.
|
|
39 |
*/
|
|
40 |
|
|
41 |
extern const char *lViewType;
|
|
42 |
|
|
43 |
const char *SnsrDeviceDialog::dataKeyUnlock = "unlock";
|
69
|
44 |
const char *SnsrDeviceDialog::dataKeySwitchLights = "switch_lights";
|
|
45 |
const char *SnsrDeviceDialog::dataKeySwitchLowPower = "switch_low_power";
|
62
|
46 |
|
|
47 |
QTM_USE_NAMESPACE
|
|
48 |
|
|
49 |
/*!
|
|
50 |
Constructor.
|
|
51 |
\param viewType Initial view type (active or standby).
|
|
52 |
\param parent Parent.
|
|
53 |
*/
|
|
54 |
SnsrDeviceDialog::SnsrDeviceDialog(const QVariantMap ¶meters, QGraphicsItem *parent) :
|
69
|
55 |
HbPopup(parent),
|
|
56 |
mScreensaver(0),
|
|
57 |
mLayout(0),
|
|
58 |
m_setManager(0)
|
62
|
59 |
{
|
|
60 |
qDebug("SnsrDeviceDialog::SnsrDeviceDialog()");
|
|
61 |
|
|
62 |
|
|
63 |
// load screensaver plugin
|
|
64 |
// Workaround to QtSF bug. Create in stack after the bug is fixed.
|
|
65 |
QServiceManager manager;
|
|
66 |
QServiceFilter filter(gBigClockInterfaceName);
|
|
67 |
QList<QServiceInterfaceDescriptor> interfaces = manager.findInterfaces(
|
|
68 |
filter);
|
|
69 |
Q_ASSERT(interfaces.count());
|
|
70 |
|
|
71 |
mScreensaver = manager.loadLocalTypedInterface<Screensaver>(
|
|
72 |
interfaces.first().interfaceName() );
|
|
73 |
if (mScreensaver) {
|
|
74 |
mScreensaver->setParent(this);
|
|
75 |
} else {
|
|
76 |
// TODO: error state
|
|
77 |
}
|
|
78 |
connect(mScreensaver, SIGNAL(viewChanged(QGraphicsWidget*)),
|
|
79 |
SLOT(changeView(QGraphicsWidget*)));
|
|
80 |
connect(mScreensaver, SIGNAL(faulted()),
|
|
81 |
SLOT(screensaverFaulted()));
|
69
|
82 |
connect( mScreensaver, SIGNAL(unlockRequested()),
|
|
83 |
SLOT(requestUnlock()) );
|
|
84 |
connect( mScreensaver, SIGNAL(screenPowerModeRequested(Screensaver::ScreenPowerMode)),
|
|
85 |
SLOT(requestScreenMode(Screensaver::ScreenPowerMode)) );
|
62
|
86 |
|
|
87 |
mScreensaver->initialize();
|
|
88 |
|
|
89 |
setBackgroundItem(0);
|
|
90 |
|
|
91 |
setDismissPolicy(HbPopup::NoDismiss);
|
|
92 |
setTimeout(HbPopup::NoTimeout);
|
69
|
93 |
|
|
94 |
mainWindow()->setAutomaticOrientationEffectEnabled(false);
|
62
|
95 |
|
|
96 |
setDeviceDialogParameters( parameters );
|
|
97 |
}
|
|
98 |
|
|
99 |
/*!
|
|
100 |
Destructor.
|
|
101 |
*/
|
|
102 |
SnsrDeviceDialog::~SnsrDeviceDialog()
|
|
103 |
{
|
|
104 |
qDebug("SnsrDeviceDialog::~SnsrDeviceDialog()");
|
|
105 |
QServiceManager serviceManager;
|
|
106 |
serviceManager.removeService(gBigClockInterfaceName);
|
|
107 |
}
|
|
108 |
|
|
109 |
/*!
|
|
110 |
Sets device dialog parameters.
|
|
111 |
\param parameters Device Dialog's parameters to be set.
|
|
112 |
\ret return true if parameters are correct.
|
|
113 |
*/
|
|
114 |
bool SnsrDeviceDialog::setDeviceDialogParameters(const QVariantMap ¶meters)
|
|
115 |
{
|
|
116 |
qDebug("SnsrDeviceDialog::setDeviceDialogParameters()");
|
|
117 |
|
|
118 |
// default to initial state if no other state given
|
|
119 |
int viewType( ViewTypeInitial );
|
|
120 |
|
|
121 |
QVariantMap::const_iterator it = parameters.find(lViewType);
|
|
122 |
if (it != parameters.end() && !it.value().isNull() && it.value().isValid()) {
|
|
123 |
bool ok(false);
|
|
124 |
viewType = it.value().toInt(&ok);
|
|
125 |
if ( !ok ) {
|
|
126 |
qWarning() << "SnsrDeviceDialog::setDeviceDialogParameters() - int cast failed";
|
|
127 |
return false;
|
|
128 |
}
|
|
129 |
}
|
|
130 |
|
|
131 |
// Check initial view from repository
|
|
132 |
if (viewType == ViewTypeInitial ) {
|
69
|
133 |
XQSettingsManager::Error error;
|
62
|
134 |
int startupView = 0;
|
69
|
135 |
XQCentralRepositorySettingsKey settingsKey(
|
62
|
136 |
KCRUidScreensaverSettings.iUid, KScreensaverStartupView ); // TUid as same repository used in control panel via Symbian APIs
|
|
137 |
m_setManager = new XQSettingsManager(this);
|
69
|
138 |
if (m_setManager) {
|
|
139 |
startupView = m_setManager->readItemValue(settingsKey, XQSettingsManager::TypeInt).toInt();
|
62
|
140 |
error = m_setManager->error();
|
69
|
141 |
if (error == XQSettingsManager::NoError) {
|
62
|
142 |
viewType = startupView;
|
69
|
143 |
}
|
62
|
144 |
delete m_setManager;
|
69
|
145 |
}
|
62
|
146 |
}
|
|
147 |
|
|
148 |
switch (viewType) {
|
|
149 |
case SnsrDeviceDialog::ViewTypeActive:
|
|
150 |
mScreensaver->foreground();
|
|
151 |
return true;
|
|
152 |
case SnsrDeviceDialog::ViewTypeStandby:
|
|
153 |
mScreensaver->partialForeground();
|
|
154 |
return true;
|
|
155 |
default:
|
|
156 |
qWarning() << QString("SnsrDeviceDialog::setDeviceDialogParameters() "
|
|
157 |
"- unspecefied view type: %1").arg(viewType);
|
|
158 |
}
|
|
159 |
|
|
160 |
return false;
|
|
161 |
}
|
|
162 |
|
|
163 |
/*!
|
|
164 |
Returns error code.
|
|
165 |
\ret error code.
|
|
166 |
*/
|
|
167 |
int SnsrDeviceDialog::deviceDialogError() const
|
|
168 |
{
|
|
169 |
return 0;
|
|
170 |
}
|
|
171 |
|
|
172 |
/*!
|
|
173 |
Closes device dialog.
|
|
174 |
\param byClient If dialog is close by client.
|
|
175 |
*/
|
|
176 |
void SnsrDeviceDialog::closeDeviceDialog(bool byClient)
|
|
177 |
{
|
|
178 |
qDebug("SnsrDeviceDialog::closeDeviceDialog()");
|
|
179 |
Q_UNUSED(byClient)
|
|
180 |
hide();
|
|
181 |
emit deviceDialogClosed();
|
|
182 |
}
|
|
183 |
|
|
184 |
/*!
|
|
185 |
Returns device dialog instance.
|
|
186 |
\ret Device dialog instance.
|
|
187 |
*/
|
|
188 |
HbPopup *SnsrDeviceDialog::deviceDialogWidget() const
|
|
189 |
{
|
|
190 |
return const_cast<SnsrDeviceDialog*>(this);
|
|
191 |
}
|
|
192 |
|
|
193 |
/*!
|
|
194 |
Shows widget.
|
|
195 |
\param event.
|
|
196 |
*/
|
|
197 |
void SnsrDeviceDialog::showEvent(QShowEvent *event)
|
|
198 |
{
|
|
199 |
qDebug("SnsrDeviceDialog::showEvent()");
|
|
200 |
|
|
201 |
HbPopup::showEvent(event);
|
|
202 |
|
|
203 |
// workaround for duplicating connections and emiting two signals
|
|
204 |
// showEvent is called for HbDeviceDialogManager showDeviceDialog()
|
|
205 |
// and for HbPopup itemChange(), both events are set to QEvent::Show type
|
|
206 |
disconnect(mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)),
|
|
207 |
this, SLOT(changeLayout(Qt::Orientation)));
|
|
208 |
connect(mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)),
|
|
209 |
this, SLOT(changeLayout(Qt::Orientation)));
|
|
210 |
|
|
211 |
changeLayout(mainWindow()->orientation());
|
|
212 |
}
|
|
213 |
|
|
214 |
#ifdef COVERAGE_MEASUREMENT
|
|
215 |
#pragma CTC SKIP
|
|
216 |
#endif //COVERAGE_MEASUREMENT
|
|
217 |
|
|
218 |
/*!
|
|
219 |
Hides widget.
|
|
220 |
\param event.
|
|
221 |
*/
|
|
222 |
void SnsrDeviceDialog::hideEvent(QHideEvent *event)
|
|
223 |
{
|
|
224 |
qDebug("SnsrDeviceDialog::hideEvent()");
|
|
225 |
|
|
226 |
HbPopup::hideEvent(event);
|
|
227 |
mScreensaver->background();
|
|
228 |
}
|
|
229 |
|
|
230 |
#ifdef COVERAGE_MEASUREMENT
|
|
231 |
#pragma CTC ENDSKIP
|
|
232 |
#endif //COVERAGE_MEASUREMENT
|
|
233 |
|
|
234 |
/*!
|
|
235 |
Close widget.
|
|
236 |
\param event.
|
|
237 |
*/
|
|
238 |
void SnsrDeviceDialog::closeEvent(QCloseEvent *event)
|
|
239 |
{
|
|
240 |
qDebug("SnsrDeviceDialog::closeEvent()");
|
|
241 |
|
|
242 |
HbPopup::closeEvent(event);
|
|
243 |
|
|
244 |
disconnect(mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)),
|
|
245 |
this, SLOT(changeLayout(Qt::Orientation)));
|
|
246 |
mScreensaver->close();
|
|
247 |
}
|
|
248 |
|
|
249 |
/*!
|
|
250 |
Replaces layout's item.
|
|
251 |
\param widget New item to be added to layout.
|
|
252 |
*/
|
|
253 |
void SnsrDeviceDialog::changeView(QGraphicsWidget *widget)
|
|
254 |
{
|
|
255 |
qDebug("SnsrDeviceDialog::changeView() - widget: 0x%X", (int)widget);
|
|
256 |
if (!mLayout) {
|
|
257 |
mLayout = new QGraphicsLinearLayout(Qt::Vertical);
|
|
258 |
mLayout->setContentsMargins(0,0,0,0);
|
|
259 |
setLayout(mLayout);
|
|
260 |
}
|
|
261 |
|
|
262 |
if (mLayout->count()) {
|
|
263 |
mLayout->removeAt(0);
|
69
|
264 |
}
|
62
|
265 |
if (widget) {
|
|
266 |
widget->show();
|
|
267 |
mLayout->addItem(widget);
|
69
|
268 |
|
|
269 |
if ( isVisible() ) {
|
|
270 |
changeLayout( mainWindow()->orientation() );
|
|
271 |
}
|
62
|
272 |
}
|
69
|
273 |
|
|
274 |
|
62
|
275 |
}
|
|
276 |
|
|
277 |
/*!
|
|
278 |
Handles faults in loaded screensaver model.
|
|
279 |
*/
|
|
280 |
void SnsrDeviceDialog::screensaverFaulted()
|
|
281 |
{
|
|
282 |
qWarning() << "SnsrDeviceDialog::screensaverFaulted()";
|
|
283 |
// TODO: some error handling
|
|
284 |
}
|
|
285 |
|
|
286 |
/*!
|
|
287 |
Resize device dialog.
|
|
288 |
\param orientation New orientation value.
|
|
289 |
*/
|
|
290 |
void SnsrDeviceDialog::changeLayout(Qt::Orientation orientation)
|
|
291 |
{
|
|
292 |
Q_UNUSED(orientation)
|
|
293 |
|
|
294 |
QRectF rect = mainWindow()->layoutRect();
|
|
295 |
setMinimumSize( rect.size() );
|
|
296 |
setPreferredPos( QPointF(0,0) );
|
69
|
297 |
QGraphicsSceneResizeEvent sceneResize;
|
|
298 |
sceneResize.setNewSize( rect.size() );
|
|
299 |
event( &sceneResize );
|
|
300 |
mScreensaver->updateLayout();
|
62
|
301 |
}
|
|
302 |
|
|
303 |
/*!
|
|
304 |
Send unlock signal to autolock.
|
|
305 |
*/
|
|
306 |
void SnsrDeviceDialog::requestUnlock()
|
|
307 |
{
|
|
308 |
QVariantMap data;
|
|
309 |
data.insert(dataKeyUnlock, 1);
|
|
310 |
emit deviceDialogData(data);
|
|
311 |
}
|
69
|
312 |
|
|
313 |
/*!
|
|
314 |
Send low power mode on/off request to autolock.
|
|
315 |
*/
|
|
316 |
void SnsrDeviceDialog::requestScreenMode(Screensaver::ScreenPowerMode mode)
|
|
317 |
{
|
|
318 |
QVariantMap data;
|
|
319 |
QVariantList rowLimits;
|
|
320 |
if ( mode == Screensaver::ScreenModeOff ) {
|
|
321 |
data.insert(dataKeySwitchLights, 0);
|
|
322 |
data.insert(dataKeySwitchLowPower, rowLimits); // empty list means "low power off"
|
|
323 |
}
|
|
324 |
else if ( mode == Screensaver::ScreenModeLowPower ) {
|
|
325 |
//data.insert(dataKeySwitchLights, 0);
|
|
326 |
int firstRow;
|
|
327 |
int lastRow;
|
|
328 |
mScreensaver->getActiveScreenRows(&firstRow, &lastRow);
|
|
329 |
rowLimits.append( firstRow );
|
|
330 |
rowLimits.append( lastRow );
|
|
331 |
data.insert(dataKeySwitchLowPower, rowLimits);
|
|
332 |
}
|
|
333 |
else if ( mode == Screensaver::ScreenModeFullPower ) {
|
|
334 |
data.insert(dataKeySwitchLights, 30);
|
|
335 |
data.insert(dataKeySwitchLowPower, rowLimits); // empty list means "low power off"
|
|
336 |
}
|
|
337 |
|
|
338 |
emit deviceDialogData(data);
|
|
339 |
}
|
|
340 |
|
62
|
341 |
/*!
|
|
342 |
Called when the dialog is created if they are any currently
|
|
343 |
activate universal indicators present.
|
|
344 |
*/
|
|
345 |
void SnsrDeviceDialog::indicatorsActivated(
|
|
346 |
const QList<HbIndicatorInterface*> &activatedIndicators)
|
|
347 |
{
|
|
348 |
mScreensaver->handleActiveIndicators(activatedIndicators);
|
|
349 |
}
|
|
350 |
|
|
351 |
/*!
|
|
352 |
Called when some universal indicator is activated.
|
|
353 |
Ownership of activatedIndicator is not transferred.
|
|
354 |
*/
|
|
355 |
void SnsrDeviceDialog::indicatorActivated(
|
|
356 |
HbIndicatorInterface *activatedIndicator)
|
|
357 |
{
|
|
358 |
mScreensaver->handleActivatedIndicator(activatedIndicator);
|
|
359 |
}
|
|
360 |
|
|
361 |
/*!
|
|
362 |
Called when some universal indicator is deactivated.
|
|
363 |
*/
|
|
364 |
void SnsrDeviceDialog::indicatorRemoved(
|
|
365 |
HbIndicatorInterface *indicatorRemoved)
|
|
366 |
{
|
|
367 |
mScreensaver->handleDeactivatedIndicator(indicatorRemoved);
|
|
368 |
}
|
|
369 |
|
|
370 |
// end of file
|
|
371 |
|