21 #include <hblabel.h> |
21 #include <hblabel.h> |
22 #include <hbpushbutton.h> |
22 #include <hbpushbutton.h> |
23 #include <hbcombobox.h> |
23 #include <hbcombobox.h> |
24 #include <hbprogressbar.h> |
24 #include <hbprogressbar.h> |
25 #include <QPixmap> |
25 #include <QPixmap> |
26 #include <QDir> |
26 #include <qsysteminfo.h> // QSystemStorageInfo |
27 #include <QFileInfoList> |
27 QTM_USE_NAMESPACE |
28 #if defined(Q_OS_SYMBIAN) |
28 #if defined(Q_OS_SYMBIAN) |
|
29 #include <driveinfo.h> // DriveInfo |
29 #include <fbs.h> // CFbsBitmap |
30 #include <fbs.h> // CFbsBitmap |
30 #endif // Q_OS_SYMBIAN |
31 #endif // Q_OS_SYMBIAN |
31 |
32 |
32 // See definitions in sifuidevicedialogplugin.qrc |
33 const char KSifUiDefaultApplicationIcon[] = "qtg_large_application.svg"; |
33 const char KSifUiDialogIconAppDefault[] = ":/default_app_icon.svg"; |
34 |
|
35 const int KSifUiKilo = 1024; |
|
36 const int KSifUiMega = 1024*1024; |
34 |
37 |
35 const int KAppNameIndex = 0; |
38 const int KAppNameIndex = 0; |
36 const int KAppSizeIndex = 1; |
39 const int KAppSizeIndex = 1; |
|
40 |
|
41 enum TSifUiDriveName { |
|
42 EUnknown, |
|
43 EPhoneMemory, |
|
44 EMassStorage, |
|
45 EMemoryCard |
|
46 }; |
37 |
47 |
38 |
48 |
39 // ======== LOCAL FUNCTIONS ======== |
49 // ======== LOCAL FUNCTIONS ======== |
40 |
50 |
41 // ---------------------------------------------------------------------------- |
51 // ---------------------------------------------------------------------------- |
55 } |
65 } |
56 #endif // Q_OS_SYMBIAN |
66 #endif // Q_OS_SYMBIAN |
57 return bitmap; |
67 return bitmap; |
58 } |
68 } |
59 |
69 |
|
70 // ---------------------------------------------------------------------------- |
|
71 // driveName() |
|
72 // ---------------------------------------------------------------------------- |
|
73 // |
|
74 TSifUiDriveName driveName(const QChar& volume) |
|
75 { |
|
76 #if defined(Q_OS_SYMBIAN) |
|
77 int err = 0; |
|
78 TChar drive; |
|
79 err = DriveInfo::GetDefaultDrive(DriveInfo::EDefaultPhoneMemory, drive); |
|
80 if (!err && volume.toAscii() == drive) { |
|
81 return EPhoneMemory; |
|
82 } |
|
83 err = DriveInfo::GetDefaultDrive(DriveInfo::EDefaultMassStorage, drive); |
|
84 if (!err && volume.toAscii() == drive) { |
|
85 return EMassStorage; |
|
86 } |
|
87 err = DriveInfo::GetDefaultDrive(DriveInfo::EDefaultRemovableMassStorage, drive); |
|
88 if (!err && volume.toAscii() == drive) { |
|
89 return EMemoryCard; |
|
90 } |
|
91 #endif // Q_OS_SYMBIAN |
|
92 return EUnknown; |
|
93 } |
|
94 |
60 |
95 |
61 // ======== MEMBER FUNCTIONS ======== |
96 // ======== MEMBER FUNCTIONS ======== |
62 |
97 |
63 // ---------------------------------------------------------------------------- |
98 // ---------------------------------------------------------------------------- |
64 // SifUiDialogContentWidget::SifUiDialogContentWidget() |
99 // SifUiDialogContentWidget::SifUiDialogContentWidget() |
121 Q_ASSERT(mStackedWidget == 0); |
156 Q_ASSERT(mStackedWidget == 0); |
122 mStackedWidget = new HbStackedWidget; |
157 mStackedWidget = new HbStackedWidget; |
123 |
158 |
124 Q_ASSERT(mMemorySelection == 0); |
159 Q_ASSERT(mMemorySelection == 0); |
125 mMemorySelection = new HbComboBox; |
160 mMemorySelection = new HbComboBox; |
126 connect(mMemorySelection, SIGNAL(currentIndexChanged(const QString &)), |
161 connect(mMemorySelection, SIGNAL(currentIndexChanged(int)), |
127 this, SIGNAL(memorySelectionChanged(const QString &))); |
162 this, SIGNAL(handleMemorySelectionChange(int))); |
128 mStackedWidget->addWidget(mMemorySelection); |
163 mStackedWidget->addWidget(mMemorySelection); |
129 |
164 |
130 Q_ASSERT(mProgressBar == 0); |
165 Q_ASSERT(mProgressBar == 0); |
131 mProgressBar = new HbProgressBar; |
166 mProgressBar = new HbProgressBar; |
132 mProgressBar->setRange(0,0); // busy indicator by default |
167 mProgressBar->setRange(0,0); // busy indicator by default |
175 removeDetails(); |
212 removeDetails(); |
176 addDetails(parameters.value(KSifUiApplicationDetails).toStringList()); |
213 addDetails(parameters.value(KSifUiApplicationDetails).toStringList()); |
177 } |
214 } |
178 |
215 |
179 // Stacked widgets: memory selection, progress bar and error text |
216 // Stacked widgets: memory selection, progress bar and error text |
180 updateMemorySelection(parameters); |
217 if (updateErrorText(parameters) || |
181 updateProgressBar(parameters); |
218 updateProgressBar(parameters) || |
182 updateErrorText(parameters); |
219 updateMemorySelection(parameters)) { |
|
220 if (!mStackedWidget->isVisible()) { |
|
221 mStackedWidget->show(); |
|
222 } |
|
223 } else { |
|
224 if (mStackedWidget->isVisible()) { |
|
225 mStackedWidget->hide(); |
|
226 } |
|
227 } |
183 } |
228 } |
184 |
229 |
185 // ---------------------------------------------------------------------------- |
230 // ---------------------------------------------------------------------------- |
186 // SifUiDialogContentWidget::changeType() |
231 // SifUiDialogContentWidget::changeType() |
187 // ---------------------------------------------------------------------------- |
232 // ---------------------------------------------------------------------------- |
284 { |
341 { |
285 QString appSize = ""; |
342 QString appSize = ""; |
286 if (parameters.contains(KSifUiApplicationSize)) { |
343 if (parameters.contains(KSifUiApplicationSize)) { |
287 uint size = parameters.value(KSifUiApplicationSize).toUInt(); |
344 uint size = parameters.value(KSifUiApplicationSize).toUInt(); |
288 if (size > 0) { |
345 if (size > 0) { |
289 if (size > KMega) { |
346 if (size > KSifUiMega) { |
290 //: Application size in SW install confirmation query, %1 is in megabytes |
347 //: Application size in SW install confirmation query, %1 is in megabytes |
291 // TODO: enable when translations ready |
348 // TODO: enable when translations ready |
292 //appSize = hbTrId("txt_sisxui_install_appsize_mb").arg(size/KMega); |
349 //appSize = hbTrId("txt_sisxui_install_appsize_mb").arg(size/KSifUiMega); |
293 appSize = tr("Size: %1 MB").arg(size/KMega); |
350 appSize = tr("%1 MB").arg(size/KSifUiMega); |
294 } else if(size > KKilo) { |
351 } else if(size > KSifUiKilo) { |
295 //: Application size in SW install confirmation query, %1 is in kilobytes |
352 //: Application size in SW install confirmation query, %1 is in kilobytes |
296 // TODO: enable when translations ready |
353 // TODO: enable when translations ready |
297 //appSize = hbTrId("txt_sisxui_install_appsize_kb").arg(size/KKilo); |
354 //appSize = hbTrId("txt_sisxui_install_appsize_kb").arg(size/KSifUiKilo); |
298 appSize = tr("Size: %1 kB").arg(size/KKilo); |
355 appSize = tr("%1 kB").arg(size/KSifUiKilo); |
299 } else { |
356 } else { |
300 //: Application size in SW install confirmation query, %1 is in bytes |
357 //: Application size in SW install confirmation query, %1 is in bytes |
301 // TODO: enable when translations ready |
358 // TODO: enable when translations ready |
302 //appSize = hbTrId("txt_sisxui_install_appsize_b").arg(size); |
359 //appSize = hbTrId("txt_sisxui_install_appsize_b").arg(size); |
303 appSize = tr("Size: %1 B").arg(size); |
360 appSize = tr("%1 B").arg(size); |
304 } |
361 } |
305 } |
362 } |
306 } |
363 } |
307 return appSize; |
364 return appSize; |
308 } |
365 } |
401 |
458 |
402 // ---------------------------------------------------------------------------- |
459 // ---------------------------------------------------------------------------- |
403 // SifUiDialogContentWidget::updateMemorySelection() |
460 // SifUiDialogContentWidget::updateMemorySelection() |
404 // ---------------------------------------------------------------------------- |
461 // ---------------------------------------------------------------------------- |
405 // |
462 // |
406 void SifUiDialogContentWidget::updateMemorySelection(const QVariantMap ¶meters) |
463 bool SifUiDialogContentWidget::updateMemorySelection(const QVariantMap ¶meters) |
407 { |
464 { |
408 if (parameters.contains(KSifUiMemorySelection)) { |
465 if (parameters.contains(KSifUiMemorySelection)) { |
409 |
466 QString drives = parameters.value(KSifUiMemorySelection).toString(); |
410 // TODO: get user visible drives, icons for them, and free sizes |
467 mDriveLetterList = drives.split(","); |
411 // it might be better to get this list from Symbian-side via SifUi API |
468 |
412 QStringList driveList; |
469 QStringList driveList; |
413 QFileInfoList driveInfoList = QDir::drives(); |
470 QSystemStorageInfo info; |
414 foreach(const QFileInfo &driveInfo, driveInfoList) { |
471 QStringList volumeList = info.logicalDrives(); |
415 const QChar driveName = driveInfo.absolutePath()[0]; |
472 foreach (QString volume, volumeList) { |
416 switch (driveName.toAscii()) { |
473 if (mDriveLetterList.contains(volume)) { |
417 case 'C': |
474 qlonglong size = info.availableDiskSpace(volume); |
418 driveList << "C: Phone memory"; |
475 switch (driveName(volume[0])) { |
|
476 case EPhoneMemory: |
|
477 if (size > KSifUiMega) { |
|
478 //: Drive name for internal phone memory with megabytes of free space. |
|
479 //: %1 is replaced with drive letter (usually 'C') |
|
480 //: %2 is replaced with available free space (in megabytes, MB) |
|
481 //TODO: use hbTrId("txt_sisxui_device_memory_mb") when available |
|
482 driveList.append(tr("%1: Device (%L2 MB free)" |
|
483 ).arg(volume).arg(size/KSifUiMega)); |
|
484 } else { |
|
485 //: Drive name for internal phone memory with kilobytes of free space. |
|
486 //: %1 is replaced with drive letter (usually 'C') |
|
487 //: %2 is replaced with available free space (in kilobytes, kB) |
|
488 //TODO: use hbTrId("txt_sisxui_device_memory_kb") when available |
|
489 driveList.append(tr("%1: Device (%L2 kB free)" |
|
490 ).arg(volume).arg(size/KSifUiKilo)); |
|
491 } |
419 break; |
492 break; |
420 case 'E': |
493 case EMassStorage: |
421 driveList << "E: Mass memory"; |
494 if (size > KSifUiMega) { |
|
495 //: Drive name for mass storage with megabytes of free space. |
|
496 //: %1 is replaced with drive letter (usually 'E') |
|
497 //: %2 is replaced with available free space (in megabytes, MB) |
|
498 // TODO: use hbTrId("txt_sisxui_mass_storage_mb") when available |
|
499 driveList.append(tr("%1: Mass.mem (%L2 MB free)" |
|
500 ).arg(volume).arg(size/KSifUiMega)); |
|
501 } else { |
|
502 //: Drive name for mass storage with kilobytes of free space. |
|
503 //: %1 is replaced with drive letter (usually 'E') |
|
504 //: %2 is replaced with available free space (in kilobytes, kB) |
|
505 // TODO: use hbTrId("txt_sisxui_mass_storage_kb") when available |
|
506 driveList.append(tr("%1: Mass.mem (%L2 kB free)" |
|
507 ).arg(volume).arg(size/KSifUiKilo)); |
|
508 } |
422 break; |
509 break; |
423 case 'F': |
510 case EMemoryCard: |
424 driveList << "F: Memory card"; |
511 if (size > KSifUiMega) { |
|
512 //: Drive name for memory card with megabytes of free space. |
|
513 //: %1 is replaced with drive letter (usually 'F') |
|
514 //: %2 is replaced with available free space (in megabytes, MB) |
|
515 // TODO: use hbTrId("txt_sisxui_memory_card_mb") when available |
|
516 driveList.append(tr("%1: Mem.card (%L2 MB free)" |
|
517 ).arg(volume).arg(size/KSifUiMega)); |
|
518 } else { |
|
519 //: Drive name for memory card with kilobytes of free space. |
|
520 //: %1 is replaced with drive letter (usually 'F') |
|
521 //: %2 is replaced with available free space (in kilobytes, kB) |
|
522 // TODO: use hbTrId("txt_sisxui_memory_card_kb") when available |
|
523 driveList.append(tr("%1: Mem.card (%L2 kB free)" |
|
524 ).arg(volume).arg(size/KSifUiKilo)); |
|
525 } |
425 break; |
526 break; |
426 default: |
527 default: |
427 break; |
528 break; |
|
529 } |
428 } |
530 } |
429 } |
531 } |
430 |
532 |
431 mMemorySelection->setItems(driveList); |
533 mMemorySelection->setItems(driveList); |
432 mStackedWidget->setCurrentWidget(mMemorySelection); |
534 mStackedWidget->setCurrentWidget(mMemorySelection); |
433 |
535 |
434 // TODO: set selected item, read the default from cenrep |
536 // TODO: set selected item, read the default from cenrep |
435 } |
537 |
|
538 return true; |
|
539 } |
|
540 return false; |
436 } |
541 } |
437 |
542 |
438 // ---------------------------------------------------------------------------- |
543 // ---------------------------------------------------------------------------- |
439 // SifUiDialogContentWidget::updateProgressBar() |
544 // SifUiDialogContentWidget::updateProgressBar() |
440 // ---------------------------------------------------------------------------- |
545 // ---------------------------------------------------------------------------- |
441 // |
546 // |
442 void SifUiDialogContentWidget::updateProgressBar(const QVariantMap ¶meters) |
547 bool SifUiDialogContentWidget::updateProgressBar(const QVariantMap ¶meters) |
443 { |
548 { |
444 bool progressBarChanged = false; |
549 bool progressBarChanged = false; |
445 if (parameters.contains(KSifUiProgressNoteFinalValue)) { |
550 if (parameters.contains(KSifUiProgressNoteFinalValue)) { |
446 mProgressBar->setMaximum(parameters.value(KSifUiProgressNoteFinalValue).toInt()); |
551 mProgressBar->setMaximum(parameters.value(KSifUiProgressNoteFinalValue).toInt()); |
447 progressBarChanged = true; |
552 progressBarChanged = true; |
453 progressBarChanged = true; |
558 progressBarChanged = true; |
454 } |
559 } |
455 if (progressBarChanged) { |
560 if (progressBarChanged) { |
456 mStackedWidget->setCurrentWidget(mProgressBar); |
561 mStackedWidget->setCurrentWidget(mProgressBar); |
457 } |
562 } |
|
563 return progressBarChanged; |
458 } |
564 } |
459 |
565 |
460 // ---------------------------------------------------------------------------- |
566 // ---------------------------------------------------------------------------- |
461 // SifUiDialogContentWidget::updateErrorText() |
567 // SifUiDialogContentWidget::updateErrorText() |
462 // ---------------------------------------------------------------------------- |
568 // ---------------------------------------------------------------------------- |
463 // |
569 // |
464 void SifUiDialogContentWidget::updateErrorText(const QVariantMap ¶meters) |
570 bool SifUiDialogContentWidget::updateErrorText(const QVariantMap ¶meters) |
465 { |
571 { |
466 if (parameters.contains(KSifUiErrorCode)) { |
572 if (parameters.contains(KSifUiErrorCode)) { |
467 // TODO: proper error texts |
573 // TODO: proper error texts |
468 QString errorText = tr("Error %1").arg(parameters.value(KSifUiErrorCode).toInt()); |
574 QString errorText = tr("Error %1").arg(parameters.value(KSifUiErrorCode).toInt()); |
469 mErrorText->setPlainText(errorText); |
575 mErrorText->setPlainText(errorText); |
470 mStackedWidget->setCurrentWidget(mErrorText); |
576 mStackedWidget->setCurrentWidget(mErrorText); |
471 } |
577 return true; |
472 } |
578 } |
473 |
579 return false; |
474 |
580 } |
475 |
581 |
|
582 |
|
583 |