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 <qsysteminfo.h> // QSystemStorageInfo |
26 #include <qsysteminfo.h> // QSystemStorageInfo |
27 QTM_USE_NAMESPACE |
27 #include <qvaluespacepublisher.h> // QValueSpacePublisher |
|
28 #include <qvaluespacesubscriber.h> // QValueSpaceSubscriber |
28 #if defined(Q_OS_SYMBIAN) |
29 #if defined(Q_OS_SYMBIAN) |
29 #include <driveinfo.h> // DriveInfo |
30 #include <driveinfo.h> // DriveInfo |
30 #include <fbs.h> // CFbsBitmap |
31 #include <fbs.h> // CFbsBitmap |
31 #endif // Q_OS_SYMBIAN |
32 #endif // Q_OS_SYMBIAN |
32 |
33 |
|
34 QTM_USE_NAMESPACE |
|
35 |
33 const char KSifUiDefaultApplicationIcon[] = "qtg_large_application"; |
36 const char KSifUiDefaultApplicationIcon[] = "qtg_large_application"; |
34 const char KSifUiErrorIcon[] = "qtg_large_warning"; |
37 const char KSifUiErrorIcon[] = "qtg_large_warning"; |
35 |
38 |
36 const int KSifUiKilo = 1024; |
39 const int KSifUiKilo = 1024; |
37 const int KSifUiMega = 1024*1024; |
40 const int KSifUiMega = 1024*1024; |
38 |
41 |
39 const int KAppNameIndex = 0; |
42 const int KAppNameIndex = 0; |
40 const int KAppSizeIndex = 1; |
43 const int KAppSizeIndex = 1; |
41 |
44 |
42 enum TSifUiDriveName { |
45 enum TSifUiDriveName { |
43 EUnknown, |
|
44 EPhoneMemory, |
46 EPhoneMemory, |
45 EMassStorage, |
47 EMassStorage, |
46 EMemoryCard |
48 EMemoryCard, |
|
49 EOtherDrive |
47 }; |
50 }; |
|
51 |
|
52 const char KInitialDefaultDrive = 'C'; |
|
53 |
|
54 // Path and value name for QValueSpacePublisher/QValueSpaceSubscriber. |
|
55 const QString KSifUiCenRepPath = "/KCRUIDSifUiDefaults"; |
|
56 const QString KSifUiCenRepDefaultDrive = "KCRUIDSifUiDefaultDrive"; |
|
57 |
|
58 // TODO: replace with proper logging |
|
59 #ifdef _DEBUG |
|
60 #define FLOG1(x) qDebug() << (x) |
|
61 #define FLOG2(x,y) qDebug() << (x) << (y) |
|
62 #define FLOG3(x,y,z) qDebug() << (x) << (y) << (z) |
|
63 #else |
|
64 #define FLOG1(x) |
|
65 #define FLOG2(x,y) |
|
66 #define FLOG3(x,y,z) |
|
67 #endif |
48 |
68 |
49 |
69 |
50 // ======== LOCAL FUNCTIONS ======== |
70 // ======== LOCAL FUNCTIONS ======== |
51 |
71 |
52 // ---------------------------------------------------------------------------- |
72 // ---------------------------------------------------------------------------- |
230 // SifUiDialogContentWidget::changeType() |
252 // SifUiDialogContentWidget::changeType() |
231 // ---------------------------------------------------------------------------- |
253 // ---------------------------------------------------------------------------- |
232 // |
254 // |
233 void SifUiDialogContentWidget::changeType(SifUiDeviceDialogType type) |
255 void SifUiDialogContentWidget::changeType(SifUiDeviceDialogType type) |
234 { |
256 { |
|
257 FLOG2("SifUiDialogContentWidget::changeType", type); |
|
258 |
235 switch (type) { |
259 switch (type) { |
236 case SifUiConfirmationQuery: |
260 case SifUiConfirmationQuery: |
237 mStackedWidget->setCurrentWidget(mMemorySelection); |
261 mStackedWidget->setCurrentWidget(mMemorySelection); |
238 break; |
262 break; |
239 case SifUiProgressNote: |
263 case SifUiProgressNote: |
240 mStackedWidget->setCurrentWidget(mProgressBar); |
264 mStackedWidget->setCurrentWidget(mProgressBar); |
241 break; |
265 break; |
242 case SifUiCompleteNote: |
266 case SifUiCompleteNote: |
243 // TODO: remove mStackedWidget? |
|
244 break; |
267 break; |
245 case SifUiErrorNote: |
268 case SifUiErrorNote: |
246 mStackedWidget->setCurrentWidget(mErrorText); |
269 mStackedWidget->setCurrentWidget(mErrorText); |
247 break; |
270 break; |
248 default: |
271 default: |
249 break; |
272 break; |
250 } |
273 } |
251 } |
274 } |
252 |
275 |
253 // ---------------------------------------------------------------------------- |
276 // ---------------------------------------------------------------------------- |
|
277 // SifUiDialogContentWidget::applicationName() |
|
278 // ---------------------------------------------------------------------------- |
|
279 // |
|
280 QString SifUiDialogContentWidget::applicationName() const |
|
281 { |
|
282 if (mAppName) { |
|
283 return mAppName->plainText(); |
|
284 } |
|
285 return QString(); |
|
286 } |
|
287 |
|
288 // ---------------------------------------------------------------------------- |
254 // SifUiDialogContentWidget::handleMemorySelectionChange() |
289 // SifUiDialogContentWidget::handleMemorySelectionChange() |
255 // ---------------------------------------------------------------------------- |
290 // ---------------------------------------------------------------------------- |
256 // |
291 // |
257 void SifUiDialogContentWidget::handleMemorySelectionChange(int selectedIndex) |
292 void SifUiDialogContentWidget::handleMemorySelectionChange(int selectedIndex) |
258 { |
293 { |
|
294 FLOG2("SifUiDialogContentWidget::handleMemorySelectionChange", selectedIndex); |
|
295 |
259 QChar selectedDrive = mDriveLetterList[selectedIndex][0]; |
296 QChar selectedDrive = mDriveLetterList[selectedIndex][0]; |
260 |
297 saveSelectedDriveAsDefault( selectedDrive ); |
261 // TODO: save selected drive to cenrep |
|
262 |
|
263 emit memorySelectionChanged( selectedDrive ); |
298 emit memorySelectionChanged( selectedDrive ); |
264 } |
299 } |
265 |
300 |
266 // ---------------------------------------------------------------------------- |
301 // ---------------------------------------------------------------------------- |
267 // SifUiDialogContentWidget::applicationName() |
302 // SifUiDialogContentWidget::applicationName() |
431 { |
470 { |
432 if (parameters.contains(KSifUiMemorySelection)) { |
471 if (parameters.contains(KSifUiMemorySelection)) { |
433 QString drives = parameters.value(KSifUiMemorySelection).toString(); |
472 QString drives = parameters.value(KSifUiMemorySelection).toString(); |
434 mDriveLetterList = drives.split(","); |
473 mDriveLetterList = drives.split(","); |
435 |
474 |
|
475 QChar defaultDrive = readDefaultSelectedDrive(); |
|
476 int defaultDriveIndex = 0; |
|
477 |
436 QStringList driveList; |
478 QStringList driveList; |
437 QSystemStorageInfo info; |
479 QSystemStorageInfo info; |
438 QStringList volumeList = info.logicalDrives(); |
480 QStringList volumeList = info.logicalDrives(); |
439 foreach (QString volume, volumeList) { |
481 foreach (QString volume, volumeList) { |
440 if (mDriveLetterList.contains(volume)) { |
482 if (mDriveLetterList.contains(volume)) { |
441 qlonglong size = info.availableDiskSpace(volume); |
483 qlonglong size = info.availableDiskSpace(volume); |
442 switch (driveName(volume[0])) { |
484 |
|
485 QChar driveLetter(volume[0]); |
|
486 switch (driveName(driveLetter)) { |
443 case EPhoneMemory: |
487 case EPhoneMemory: |
444 if (size > KSifUiMega) { |
488 if (size > KSifUiMega) { |
445 //: Drive name for internal phone memory with megabytes of free space. |
489 //: Drive name for internal phone memory with megabytes of free space. |
446 //: %1 is replaced with drive letter (usually 'C') |
490 //: %1 is replaced with drive letter (usually 'C') |
447 //: %2 is replaced with available free space (in megabytes, MB) |
491 //: %2 is replaced with available free space (in megabytes, MB) |
448 //TODO: enable when available |
492 //TODO: enable when available |
449 //driveList.append(hbTrId("txt_installer_device_memory_mb") |
493 //driveList.append(hbTrId("txt_installer_device_memory_mb") |
450 // .arg(volume).arg(size/KSifUiMega)); |
494 // .arg(volume).arg(size/KSifUiMega)); |
451 driveList.append(tr("%1: Device (%L2 MB free)" |
495 driveList.append(tr("%1: Phone mem. (%L2 MB)" |
452 ).arg(volume).arg(size/KSifUiMega)); |
496 ).arg(volume).arg(size/KSifUiMega)); |
453 } else { |
497 } else { |
454 //: Drive name for internal phone memory with kilobytes of free space. |
498 //: Drive name for internal phone memory with kilobytes of free space. |
455 //: %1 is replaced with drive letter (usually 'C') |
499 //: %1 is replaced with drive letter (usually 'C') |
456 //: %2 is replaced with available free space (in kilobytes, kB) |
500 //: %2 is replaced with available free space (in kilobytes, kB) |
457 //TODO: enable when available |
501 //TODO: enable when available |
458 //driveList.append(hbTrId("txt_installer_device_memory_kb") |
502 //driveList.append(hbTrId("txt_installer_device_memory_kb") |
459 // .arg(volume).arg(size/KSifUiKilo)); |
503 // .arg(volume).arg(size/KSifUiKilo)); |
460 driveList.append(tr("%1: Device (%L2 kB free)" |
504 driveList.append(tr("%1: Phone mem. (%L2 kB)" |
461 ).arg(volume).arg(size/KSifUiKilo)); |
505 ).arg(volume).arg(size/KSifUiKilo)); |
462 } |
506 } |
463 break; |
507 break; |
|
508 |
464 case EMassStorage: |
509 case EMassStorage: |
465 if (size > KSifUiMega) { |
510 if (size > KSifUiMega) { |
466 //: Drive name for mass storage with megabytes of free space. |
511 //: Drive name for mass storage with megabytes of free space. |
467 //: %1 is replaced with drive letter (usually 'E') |
512 //: %1 is replaced with drive letter (usually 'E') |
468 //: %2 is replaced with available free space (in megabytes, MB) |
513 //: %2 is replaced with available free space (in megabytes, MB) |
469 // TODO: enable when available |
514 // TODO: enable when available |
470 //driveList.append(hbTrId("txt_installer_mass_storage_mb") |
515 //driveList.append(hbTrId("txt_installer_mass_storage_mb") |
471 // .arg(volume).arg(size/KSifUiMega)); |
516 // .arg(volume).arg(size/KSifUiMega)); |
472 driveList.append(tr("%1: Mass.mem (%L2 MB free)" |
517 driveList.append(tr("%1: Mass.mem (%L2 MB)" |
473 ).arg(volume).arg(size/KSifUiMega)); |
518 ).arg(volume).arg(size/KSifUiMega)); |
474 } else { |
519 } else { |
475 //: Drive name for mass storage with kilobytes of free space. |
520 //: Drive name for mass storage with kilobytes of free space. |
476 //: %1 is replaced with drive letter (usually 'E') |
521 //: %1 is replaced with drive letter (usually 'E') |
477 //: %2 is replaced with available free space (in kilobytes, kB) |
522 //: %2 is replaced with available free space (in kilobytes, kB) |
478 // TODO: enable when available |
523 // TODO: enable when available |
479 //driveList.append(hbTrId("txt_installer_mass_storage_kb") |
524 //driveList.append(hbTrId("txt_installer_mass_storage_kb") |
480 // .arg(volume).arg(size/KSifUiKilo)); |
525 // .arg(volume).arg(size/KSifUiKilo)); |
481 driveList.append(tr("%1: Mass.mem (%L2 kB free)" |
526 driveList.append(tr("%1: Mass.mem (%L2 kB)" |
482 ).arg(volume).arg(size/KSifUiKilo)); |
527 ).arg(volume).arg(size/KSifUiKilo)); |
483 } |
528 } |
484 break; |
529 break; |
|
530 |
485 case EMemoryCard: |
531 case EMemoryCard: |
486 if (size > KSifUiMega) { |
532 if (size > KSifUiMega) { |
487 //: Drive name for memory card with megabytes of free space. |
533 //: Drive name for memory card with megabytes of free space. |
488 //: %1 is replaced with drive letter (usually 'F') |
534 //: %1 is replaced with drive letter (usually 'F') |
489 //: %2 is replaced with available free space (in megabytes, MB) |
535 //: %2 is replaced with available free space (in megabytes, MB) |
490 // TODO: enable when available |
536 // TODO: enable when available |
491 //driveList.append(hbTrId("txt_installer_memory_card_mb") |
537 //driveList.append(hbTrId("txt_installer_memory_card_mb") |
492 // .arg(volume).arg(size/KSifUiMega)); |
538 // .arg(volume).arg(size/KSifUiMega)); |
493 driveList.append(tr("%1: Mem.card (%L2 MB free)" |
539 driveList.append(tr("%1: Mem.card (%L2 MB)" |
494 ).arg(volume).arg(size/KSifUiMega)); |
540 ).arg(volume).arg(size/KSifUiMega)); |
495 } else { |
541 } else { |
496 //: Drive name for memory card with kilobytes of free space. |
542 //: Drive name for memory card with kilobytes of free space. |
497 //: %1 is replaced with drive letter (usually 'F') |
543 //: %1 is replaced with drive letter (usually 'F') |
498 //: %2 is replaced with available free space (in kilobytes, kB) |
544 //: %2 is replaced with available free space (in kilobytes, kB) |
499 // TODO: enable when available |
545 // TODO: enable when available |
500 //driveList.append(hbTrId("txt_installer_memory_card_kb") |
546 //driveList.append(hbTrId("txt_installer_memory_card_kb") |
501 // .arg(volume).arg(size/KSifUiKilo)); |
547 // .arg(volume).arg(size/KSifUiKilo)); |
502 driveList.append(tr("%1: Mem.card (%L2 kB free)" |
548 driveList.append(tr("%1: Mem.card (%L2 kB)" |
503 ).arg(volume).arg(size/KSifUiKilo)); |
549 ).arg(volume).arg(size/KSifUiKilo)); |
504 } |
550 } |
505 break; |
551 break; |
|
552 |
|
553 case EOtherDrive: |
506 default: |
554 default: |
|
555 if (size > KSifUiMega) { |
|
556 //: Generic drive name for other removable drives, like |
|
557 //: USB memories attached via USB OTG adapter. |
|
558 // TODO: proper localisation needed |
|
559 driveList.append(tr("%1: Drive (%L2 MB)" |
|
560 ).arg(volume).arg(size/KSifUiMega)); |
|
561 } else { |
|
562 //: Generic drive name for other removable drives, like |
|
563 //: USB memories attached via USB OTG adapter. |
|
564 // TODO: proper localisation needed |
|
565 driveList.append(tr("%1: Drive (%L2 kB)" |
|
566 ).arg(volume).arg(size/KSifUiKilo)); |
|
567 } |
507 break; |
568 break; |
508 } |
569 } |
|
570 |
|
571 if (driveLetter == defaultDrive) { |
|
572 defaultDriveIndex = driveList.count() - 1; |
|
573 } |
509 } |
574 } |
510 } |
575 } |
511 |
576 |
|
577 disconnect(mMemorySelection, SIGNAL(currentIndexChanged(int)), |
|
578 this, SLOT(handleMemorySelectionChange(int))); |
512 mMemorySelection->setItems(driveList); |
579 mMemorySelection->setItems(driveList); |
|
580 if (defaultDriveIndex) { |
|
581 FLOG2("SifUiDialogContentWidget::updateMemorySelection, setCurrentIndex", |
|
582 defaultDriveIndex); |
|
583 mMemorySelection->setCurrentIndex(defaultDriveIndex); |
|
584 } |
|
585 connect(mMemorySelection, SIGNAL(currentIndexChanged(int)), |
|
586 this, SLOT(handleMemorySelectionChange(int))); |
513 mStackedWidget->setCurrentWidget(mMemorySelection); |
587 mStackedWidget->setCurrentWidget(mMemorySelection); |
514 |
|
515 // TODO: set selected item, read the default from cenrep |
|
516 |
588 |
517 return true; |
589 return true; |
518 } |
590 } |
519 return false; |
591 return false; |
520 } |
592 } |
546 // SifUiDialogContentWidget::updateErrorText() |
621 // SifUiDialogContentWidget::updateErrorText() |
547 // ---------------------------------------------------------------------------- |
622 // ---------------------------------------------------------------------------- |
548 // |
623 // |
549 bool SifUiDialogContentWidget::updateErrorText(const QVariantMap ¶meters) |
624 bool SifUiDialogContentWidget::updateErrorText(const QVariantMap ¶meters) |
550 { |
625 { |
551 if (parameters.contains(KSifUiErrorCode)) { |
626 // TODO: move default error messages (category based) here |
552 // TODO: proper error texts |
627 if (parameters.contains(KSifUiErrorMessage)) { |
553 bool ok = false; |
628 QString errorText = parameters.value(KSifUiErrorMessage).toString(); |
554 int errorCode = parameters.value(KSifUiErrorCode).toInt(&ok); |
|
555 QString errorText; |
|
556 if (ok) { |
|
557 errorText = tr("Error %1").arg(errorCode); |
|
558 } else { |
|
559 errorText = tr("No error code."); |
|
560 } |
|
561 mErrorText->setPlainText(errorText); |
629 mErrorText->setPlainText(errorText); |
562 mStackedWidget->setCurrentWidget(mErrorText); |
630 mStackedWidget->setCurrentWidget(mErrorText); |
563 return true; |
631 return true; |
564 } |
632 } |
565 return false; |
633 return false; |
566 } |
634 } |
567 |
635 |
568 |
636 // ---------------------------------------------------------------------------- |
569 |
637 // SifUiDialogContentWidget::saveSelectedDriveAsDefault() |
|
638 // ---------------------------------------------------------------------------- |
|
639 // |
|
640 void SifUiDialogContentWidget::saveSelectedDriveAsDefault(const QChar& drive) |
|
641 { |
|
642 if (drive != readDefaultSelectedDrive()) { |
|
643 if (!mPublisher) { |
|
644 mPublisher = new QValueSpacePublisher(KSifUiCenRepPath, this); |
|
645 } |
|
646 FLOG2("SifUiDialogContentWidget::saveSelectedDriveAsDefault", drive); |
|
647 // QValueSpacePublisher supports integer and byte array types in Symbian |
|
648 int asciiValue = drive.toAscii(); |
|
649 mPublisher->setValue(KSifUiCenRepDefaultDrive, asciiValue); |
|
650 mPublisher->sync(); |
|
651 } |
|
652 } |
|
653 |
|
654 // ---------------------------------------------------------------------------- |
|
655 // SifUiDialogContentWidget::readDefaultSelectedDrive() |
|
656 // ---------------------------------------------------------------------------- |
|
657 // |
|
658 QChar SifUiDialogContentWidget::readDefaultSelectedDrive() |
|
659 { |
|
660 QChar selectedDrive = KInitialDefaultDrive; |
|
661 |
|
662 if (!mSubscriber) { |
|
663 mSubscriber = new QValueSpaceSubscriber(KSifUiCenRepPath, this); |
|
664 } |
|
665 QVariant variant = mSubscriber->value(KSifUiCenRepDefaultDrive); |
|
666 if (variant.isValid() && !variant.isNull()) { |
|
667 bool ok = false; |
|
668 int asciiValue = variant.toInt(&ok); |
|
669 if (ok) { |
|
670 selectedDrive = QChar(asciiValue); |
|
671 } |
|
672 } |
|
673 |
|
674 FLOG2("SifUiDialogContentWidget::readDefaultSelectedDrive", selectedDrive); |
|
675 return selectedDrive; |
|
676 } |
|
677 |