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