|
1 /* |
|
2 * Copyright (c) 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: Software install notification plugin class. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "sifuidialog.h" |
|
19 #include "sifuidialogtitlewidget.h" |
|
20 #include "sifuidialogcontentwidget.h" |
|
21 #include "sifuiinstallindicatorparams.h" |
|
22 #include <hblabel.h> |
|
23 #include <hbaction.h> |
|
24 #include <hbindicator.h> |
|
25 #include <QTranslator> |
|
26 #include <QApplication> // qApp() |
|
27 #include <QFile> |
|
28 #include <hbmessagebox.h> |
|
29 #include <qvaluespacesubscriber.h> |
|
30 |
|
31 const QString KTranslationsPath = "resource/qt/translations/"; |
|
32 const QString KTranslationsFile = "sifuidevicedialogplugin"; |
|
33 const QString KSwiErrorsFile = "c:\\temp\\swierrors.txt"; |
|
34 const QString KSwiErrorFormat = " (%1)"; |
|
35 |
|
36 |
|
37 // ---------------------------------------------------------------------------- |
|
38 // SifUiDialog::SifUiDialog() |
|
39 // ---------------------------------------------------------------------------- |
|
40 // |
|
41 SifUiDialog::SifUiDialog(const QVariantMap ¶meters) : HbDialog(), |
|
42 mLastDialogError(KErrNone), mShowEventReceived(false), |
|
43 mDialogType(SifUiUnspecifiedDialog), |
|
44 mTitle(0), mContent(0), mResultMap(), |
|
45 mIgnoreCloseAction(0), mIndicator(0), mSubscriber(0) |
|
46 { |
|
47 // TODO: enable when translations ready |
|
48 //installTranslator(); |
|
49 constructDialog(parameters); |
|
50 } |
|
51 |
|
52 // ---------------------------------------------------------------------------- |
|
53 // SifUiDialog::~SifUiDialog() |
|
54 // ---------------------------------------------------------------------------- |
|
55 // |
|
56 SifUiDialog::~SifUiDialog() |
|
57 { |
|
58 delete mSubscriber; |
|
59 |
|
60 // TODO: enable when translations ready |
|
61 //removeTranslator(); |
|
62 } |
|
63 |
|
64 // ---------------------------------------------------------------------------- |
|
65 // SifUiDialog::dialogType() |
|
66 // ---------------------------------------------------------------------------- |
|
67 // |
|
68 SifUiDeviceDialogType SifUiDialog::dialogType(const QVariantMap ¶meters) |
|
69 { |
|
70 SifUiDeviceDialogType type = SifUiUnspecifiedDialog; |
|
71 if (parameters.contains(KeySifUiDialogType)) { |
|
72 type = static_cast<SifUiDeviceDialogType>(parameters.value(KeySifUiDialogType).toInt()); |
|
73 Q_ASSERT(type == SifUiConfirmationQuery || type == SifUiProgressNote || |
|
74 type == SifUiCompleteNote || type == SifUiErrorNote); |
|
75 } |
|
76 return type; |
|
77 } |
|
78 |
|
79 // ---------------------------------------------------------------------------- |
|
80 // SifUiDialog::dialogMode() |
|
81 // ---------------------------------------------------------------------------- |
|
82 // |
|
83 SifUiDeviceDialogMode SifUiDialog::dialogMode(const QVariantMap ¶meters) |
|
84 { |
|
85 SifUiDeviceDialogMode mode = SifUiUnspecified; |
|
86 if (parameters.contains(KSifUiDialogMode)) { |
|
87 mode = static_cast<SifUiDeviceDialogMode>(parameters.value(KSifUiDialogMode).toInt()); |
|
88 Q_ASSERT(mode == SifUiInstalling || mode == SifUiUninstalling); |
|
89 } |
|
90 return mode; |
|
91 } |
|
92 |
|
93 // ---------------------------------------------------------------------------- |
|
94 // SifUiDialog::setDeviceDialogParameters() |
|
95 // ---------------------------------------------------------------------------- |
|
96 // |
|
97 bool SifUiDialog::setDeviceDialogParameters(const QVariantMap ¶meters) |
|
98 { |
|
99 return updateFromParameters(parameters); |
|
100 } |
|
101 |
|
102 // ---------------------------------------------------------------------------- |
|
103 // SifUiDialog::deviceDialogError() |
|
104 // ---------------------------------------------------------------------------- |
|
105 // |
|
106 int SifUiDialog::deviceDialogError() const |
|
107 { |
|
108 return mLastDialogError; |
|
109 } |
|
110 |
|
111 // ---------------------------------------------------------------------------- |
|
112 // SifUiDialog::closeDeviceDialog() |
|
113 // ---------------------------------------------------------------------------- |
|
114 // |
|
115 void SifUiDialog::closeDeviceDialog(bool byClient) |
|
116 { |
|
117 Q_UNUSED(byClient); |
|
118 close(); |
|
119 |
|
120 // If show event has been received, close is signalled from hide event. |
|
121 // If not, hide event does not come and close is signalled from here. |
|
122 if (!mShowEventReceived) { |
|
123 emit deviceDialogClosed(); |
|
124 } |
|
125 } |
|
126 |
|
127 // ---------------------------------------------------------------------------- |
|
128 // SifUiDialog::deviceDialogWidget() |
|
129 // ---------------------------------------------------------------------------- |
|
130 // |
|
131 HbDialog *SifUiDialog::deviceDialogWidget() const |
|
132 { |
|
133 return const_cast<SifUiDialog*>(this); |
|
134 } |
|
135 |
|
136 // ---------------------------------------------------------------------------- |
|
137 // SifUiDialog::closeEvent() |
|
138 // ---------------------------------------------------------------------------- |
|
139 // |
|
140 void SifUiDialog::closeEvent(QCloseEvent *event) |
|
141 { |
|
142 if (mIgnoreCloseAction) { |
|
143 HbAction *closingAction = qobject_cast<HbAction *>(sender()); |
|
144 if (closingAction == mIgnoreCloseAction) { |
|
145 // Prevents the dialog from begin closed when "Ok" pressed |
|
146 event->ignore(); |
|
147 return; |
|
148 } |
|
149 } |
|
150 HbDialog::closeEvent(event); |
|
151 } |
|
152 |
|
153 // ---------------------------------------------------------------------------- |
|
154 // SifUiDialog::hideEvent() |
|
155 // ---------------------------------------------------------------------------- |
|
156 // |
|
157 void SifUiDialog::hideEvent(QHideEvent *event) |
|
158 { |
|
159 HbDialog::hideEvent(event); |
|
160 emit deviceDialogClosed(); |
|
161 } |
|
162 |
|
163 // ---------------------------------------------------------------------------- |
|
164 // SifUiDialog::showEvent() |
|
165 // ---------------------------------------------------------------------------- |
|
166 // |
|
167 void SifUiDialog::showEvent(QShowEvent *event) |
|
168 { |
|
169 HbDialog::showEvent(event); |
|
170 mShowEventReceived = true; |
|
171 } |
|
172 |
|
173 // ---------------------------------------------------------------------------- |
|
174 // SifUiDialog::installTranslator() |
|
175 // ---------------------------------------------------------------------------- |
|
176 // |
|
177 void SifUiDialog::installTranslator() |
|
178 { |
|
179 mTranslator = new QTranslator(this); |
|
180 QString lang = QLocale::system().name(); |
|
181 mTranslator->load(KTranslationsFile + lang, KTranslationsPath); |
|
182 qApp->installTranslator(mTranslator); |
|
183 } |
|
184 |
|
185 // ---------------------------------------------------------------------------- |
|
186 // SifUiDialog::removeTranslator() |
|
187 // ---------------------------------------------------------------------------- |
|
188 // |
|
189 void SifUiDialog::removeTranslator() |
|
190 { |
|
191 QApplication *app = qApp; |
|
192 if (mTranslator && app) { |
|
193 app->removeTranslator(mTranslator); |
|
194 mTranslator = 0; |
|
195 } |
|
196 } |
|
197 |
|
198 // ---------------------------------------------------------------------------- |
|
199 // SifUiDialog::constructDialog() |
|
200 // ---------------------------------------------------------------------------- |
|
201 // |
|
202 bool SifUiDialog::constructDialog(const QVariantMap ¶meters) |
|
203 { |
|
204 setTimeout(HbPopup::NoTimeout); |
|
205 setDismissPolicy(HbPopup::NoDismiss); |
|
206 setModal(true); |
|
207 |
|
208 mDialogType = dialogType(parameters); |
|
209 |
|
210 // Title |
|
211 Q_ASSERT(mTitle == 0); |
|
212 mTitle = new SifUiDialogTitleWidget(this); |
|
213 mTitle->constructFromParameters(parameters); |
|
214 connect(mTitle, SIGNAL(certificatesClicked()), |
|
215 this, SLOT(handleDisplayCertificateDetails())); |
|
216 setHeadingWidget(mTitle); |
|
217 |
|
218 // Content |
|
219 Q_ASSERT(mContent == 0); |
|
220 mContent = new SifUiDialogContentWidget(this); |
|
221 mContent->constructFromParameters(parameters); |
|
222 connect(mContent, SIGNAL(memorySelectionChanged(const QString &)), |
|
223 this, SLOT(handleMemorySelectionChanged(const QString &))); |
|
224 setContentWidget(mContent); |
|
225 |
|
226 // Buttons |
|
227 // build error in wk10: |
|
228 // Error: #20: identifier "mConfirmInstallAction" is undefined |
|
229 //Q_ASSERT(mConfirmInstallAction == 0); |
|
230 updateButtons(); |
|
231 |
|
232 return true; |
|
233 } |
|
234 |
|
235 // ---------------------------------------------------------------------------- |
|
236 // SifUiDialog::updateFromParameters() |
|
237 // ---------------------------------------------------------------------------- |
|
238 // |
|
239 bool SifUiDialog::updateFromParameters(const QVariantMap ¶meters) |
|
240 { |
|
241 SifUiDeviceDialogType prevDialogType = mDialogType; |
|
242 mDialogType = dialogType(parameters); |
|
243 if (mTitle) |
|
244 { |
|
245 mTitle->updateFromParameters(parameters); |
|
246 } |
|
247 if (mContent) |
|
248 { |
|
249 mContent->updateFromParameters(parameters); |
|
250 } |
|
251 if (prevDialogType != mDialogType) { |
|
252 updateButtons(); |
|
253 } |
|
254 if (parameters.contains(KSifUiErrorCode)) { |
|
255 mInstallError = parameters.value(KSifUiErrorCode).toInt(); |
|
256 } |
|
257 return true; |
|
258 } |
|
259 |
|
260 // ---------------------------------------------------------------------------- |
|
261 // SifUiDialog::updateButtons() |
|
262 // ---------------------------------------------------------------------------- |
|
263 // |
|
264 void SifUiDialog::updateButtons() |
|
265 { |
|
266 mIgnoreCloseAction = 0; |
|
267 |
|
268 HbAction *primaryAction = 0; |
|
269 switch (mDialogType) { |
|
270 case SifUiConfirmationQuery: |
|
271 //: Accepts the SW install confirmation query and starts installation. |
|
272 // TODO: enable when translations ready |
|
273 //primaryAction = new HbAction(hbTrId("txt_sisxui_install_ok"), this); |
|
274 primaryAction = new HbAction(tr("Ok"), this); |
|
275 connect(primaryAction, SIGNAL(triggered()), this, SLOT(handleAccepted())); |
|
276 mIgnoreCloseAction = primaryAction; |
|
277 break; |
|
278 case SifUiProgressNote: |
|
279 //: Hides the progress dialog. Progress note moves into universal indicator. |
|
280 // TODO: enable when translations ready |
|
281 //primaryAction = new HbAction(hbTrId("txt_sisxui_install_hide"), this); |
|
282 primaryAction = new HbAction(tr("Hide"), this); |
|
283 connect(primaryAction, SIGNAL(triggered()), this, SLOT(handleHide())); |
|
284 mIgnoreCloseAction = primaryAction; |
|
285 break; |
|
286 case SifUiCompleteNote: |
|
287 //: Opens Application Library to view the installed application. |
|
288 // TODO: enable when translations ready |
|
289 //primaryAction = new HbAction(hbTrId("txt_sisxui_install_show"), this); |
|
290 primaryAction = new HbAction(tr("Show"), this); |
|
291 connect(primaryAction, SIGNAL(triggered()), this, SLOT(handleShowInstalled())); |
|
292 mIgnoreCloseAction = primaryAction; |
|
293 break; |
|
294 case SifUiErrorNote: |
|
295 //: Shows a dialog with further info about the failure (i.e. why installation failed). |
|
296 // TODO: enable when translations ready |
|
297 //primaryAction = new HbAction(hbTrId("txt_sisxui_install_error_details"), this); |
|
298 primaryAction = new HbAction(tr("Details"), this); |
|
299 connect(primaryAction, SIGNAL(triggered()), this, SLOT(handleErrorDetails())); |
|
300 mIgnoreCloseAction = primaryAction; |
|
301 break; |
|
302 default: |
|
303 break; |
|
304 } |
|
305 setPrimaryAction(primaryAction); |
|
306 |
|
307 HbAction *secondaryAction = 0; |
|
308 switch (mDialogType) { |
|
309 case SifUiConfirmationQuery: |
|
310 case SifUiProgressNote: |
|
311 //: Cancels the SW install confirmation query and closes the dialog. |
|
312 // TODO: enable when translations ready |
|
313 //secondaryAction = new HbAction(hbTrId("txt_sisxui_install_cancel"), this); |
|
314 secondaryAction = new HbAction(tr("Cancel"), this); |
|
315 connect(secondaryAction, SIGNAL(triggered()), this, SLOT(handleCancelled())); |
|
316 break; |
|
317 case SifUiCompleteNote: |
|
318 case SifUiErrorNote: |
|
319 //: Closes the dialog. Control returns back to where the installation was started. |
|
320 // TODO: enable when translations ready |
|
321 //secondaryAction = new HbAction(hbTrId("txt_sisxui_install_close"), this); |
|
322 secondaryAction = new HbAction(tr("Close"), this); |
|
323 connect(secondaryAction, SIGNAL(triggered()), this, SLOT(close())); |
|
324 break; |
|
325 default: |
|
326 break; |
|
327 } |
|
328 setSecondaryAction(secondaryAction); |
|
329 } |
|
330 |
|
331 // ---------------------------------------------------------------------------- |
|
332 // SifUiDialog::sendResult() |
|
333 // ---------------------------------------------------------------------------- |
|
334 // |
|
335 void SifUiDialog::sendResult(bool accepted) |
|
336 { |
|
337 QVariant acceptedValue(accepted); |
|
338 mResultMap.insert(KSifUiQueryAccepted, acceptedValue); |
|
339 emit deviceDialogData(mResultMap); |
|
340 } |
|
341 |
|
342 // ---------------------------------------------------------------------------- |
|
343 // SifUiDialog::monitorIndicatorActivity() |
|
344 // ---------------------------------------------------------------------------- |
|
345 // |
|
346 void SifUiDialog::monitorIndicatorActivity() |
|
347 { |
|
348 if (!mSubscriber) { |
|
349 mSubscriber = new QTM_PREPEND_NAMESPACE(QValueSpaceSubscriber(KSifUiIndicatorPath)); |
|
350 connect(mSubscriber, SIGNAL(contentsChanged()), |
|
351 this, SLOT(handleIndicatorActivityChanged())); |
|
352 } |
|
353 } |
|
354 |
|
355 // ---------------------------------------------------------------------------- |
|
356 // SifUiDialog::handleAccepted() |
|
357 // ---------------------------------------------------------------------------- |
|
358 // |
|
359 void SifUiDialog::handleAccepted() |
|
360 { |
|
361 mContent->changeType(SifUiProgressNote); |
|
362 sendResult(true); |
|
363 } |
|
364 |
|
365 // ---------------------------------------------------------------------------- |
|
366 // SifUiDialog::handleCancelled() |
|
367 // ---------------------------------------------------------------------------- |
|
368 // |
|
369 void SifUiDialog::handleCancelled() |
|
370 { |
|
371 sendResult(false); |
|
372 } |
|
373 |
|
374 // ---------------------------------------------------------------------------- |
|
375 // SifUiDialog::handleMemorySelectionChanged() |
|
376 // ---------------------------------------------------------------------------- |
|
377 // |
|
378 void SifUiDialog::handleMemorySelectionChanged(const QString &text) |
|
379 { |
|
380 QVariant memorySelection(text); |
|
381 mResultMap.insert(KSifUiSelectedMemoryIndex, memorySelection); |
|
382 } |
|
383 |
|
384 // ---------------------------------------------------------------------------- |
|
385 // SifUiDialog::handleDisplayCertificateDetails() |
|
386 // ---------------------------------------------------------------------------- |
|
387 // |
|
388 void SifUiDialog::handleDisplayCertificateDetails() |
|
389 { |
|
390 // TODO: display certificate details dialog |
|
391 HbMessageBox::warning(tr("Not implemented yet")); |
|
392 } |
|
393 |
|
394 // ---------------------------------------------------------------------------- |
|
395 // SifUiDialog::handleHidePressed() |
|
396 // ---------------------------------------------------------------------------- |
|
397 // |
|
398 void SifUiDialog::handleHidePressed() |
|
399 { |
|
400 if (!mIndicator) { |
|
401 mIndicator = new HbIndicator(this); |
|
402 |
|
403 QVariantMap variantMap; |
|
404 QVariant applicationNameVariant(mContent->applicationName()); |
|
405 variantMap.insert(KSifUiIndicatorApplicationName, applicationNameVariant); |
|
406 |
|
407 if (!mContent->isDefaultIconUsed()) { |
|
408 int iconHandle = 0; |
|
409 int maskHandle = 0; |
|
410 mContent->iconHandles(iconHandle, maskHandle); |
|
411 QVariant iconHandleVariant(iconHandle); |
|
412 variantMap.insert(KSifUiIndicatorAppIconHandle, iconHandleVariant); |
|
413 QVariant maskHandleVariant(maskHandle); |
|
414 variantMap.insert(KSifUiIndicatorAppIconMaskHandle, maskHandleVariant); |
|
415 } |
|
416 |
|
417 int finalValue = 0; |
|
418 int progressValue = 0; |
|
419 mContent->progressInfo(finalValue, progressValue); |
|
420 QVariant finalValueVariant(finalValue); |
|
421 variantMap.insert(KSifUiIndicatorProgressFinal, finalValueVariant); |
|
422 QVariant progressValueVariant(progressValue); |
|
423 variantMap.insert(KSifUiIndicatorProgressValue, progressValueVariant); |
|
424 |
|
425 QVariant parameter(variantMap); |
|
426 if (mIndicator->activate(KSifUiIndicatorPlugin, parameter)) { |
|
427 hide(); |
|
428 monitorIndicatorActivity(); |
|
429 } |
|
430 } |
|
431 } |
|
432 |
|
433 // ---------------------------------------------------------------------------- |
|
434 // SifUiDialog::handleIndicatorActivityChanged() |
|
435 // ---------------------------------------------------------------------------- |
|
436 // |
|
437 void SifUiDialog::handleIndicatorActivityChanged() |
|
438 { |
|
439 QVariant variant = mSubscriber->value(KSifUiIndicatorActive); |
|
440 if (variant.isValid() && (variant.type() == QVariant::Int)) { |
|
441 bool valueOk = false; |
|
442 int intValue = variant.toInt(&valueOk); |
|
443 if (valueOk && intValue) { |
|
444 show(); |
|
445 } |
|
446 } |
|
447 } |
|
448 |
|
449 // ---------------------------------------------------------------------------- |
|
450 // SifUiDialog::handleShowInstalled() |
|
451 // ---------------------------------------------------------------------------- |
|
452 // |
|
453 void SifUiDialog::handleShowInstalled() |
|
454 { |
|
455 // TODO: launch applib |
|
456 HbMessageBox::warning(tr("Not implemented yet")); |
|
457 } |
|
458 |
|
459 // ---------------------------------------------------------------------------- |
|
460 // SifUiDialog::handleErrorDetails() |
|
461 // ---------------------------------------------------------------------------- |
|
462 // |
|
463 void SifUiDialog::handleErrorDetails() |
|
464 { |
|
465 // TODO: show proper error details dialog |
|
466 QString messageText; |
|
467 messageText = tr("Not implemented yet.\n\nError code %1").arg(mInstallError); |
|
468 |
|
469 if (QFile::exists(KSwiErrorsFile)) { |
|
470 messageText.append(KSwiErrorFormat.arg(mInstallError)); |
|
471 } |
|
472 HbMessageBox::warning(messageText); |
|
473 } |
|
474 |