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 |
|
33 |
|
34 QTM_USE_NAMESPACE |
32 |
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; |
43 EPhoneMemory, |
46 EPhoneMemory, |
44 EMassStorage, |
47 EMassStorage, |
45 EMemoryCard, |
48 EMemoryCard, |
46 EOtherDrive |
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 // ---------------------------------------------------------------------------- |
103 SifUiDialogContentWidget::SifUiDialogContentWidget(QGraphicsItem *parent, |
123 SifUiDialogContentWidget::SifUiDialogContentWidget(QGraphicsItem *parent, |
104 Qt::WindowFlags flags) : HbWidget(parent, flags), |
124 Qt::WindowFlags flags) : HbWidget(parent, flags), |
105 mAppIcon(0), mAppName(0), mAppSize(0), |
125 mAppIcon(0), mAppName(0), mAppSize(0), |
106 mMainLayout(0), mAppDetailsLayout(0), mStackedWidget(0), |
126 mMainLayout(0), mAppDetailsLayout(0), mStackedWidget(0), |
107 mMemorySelection(0), mProgressBar(0), mErrorText(0), |
127 mMemorySelection(0), mProgressBar(0), mErrorText(0), |
108 mBitmap(0), mMask(0) |
128 mBitmap(0), mMask(0), mPublisher(0), mSubscriber(0) |
109 { |
129 { |
110 } |
130 } |
111 |
131 |
112 // ---------------------------------------------------------------------------- |
132 // ---------------------------------------------------------------------------- |
113 // SifUiDialogContentWidget::~SifUiDialogContentWidget() |
133 // SifUiDialogContentWidget::~SifUiDialogContentWidget() |
123 // SifUiDialogContentWidget::constructFromParameters() |
143 // SifUiDialogContentWidget::constructFromParameters() |
124 // ---------------------------------------------------------------------------- |
144 // ---------------------------------------------------------------------------- |
125 // |
145 // |
126 void SifUiDialogContentWidget::constructFromParameters(const QVariantMap ¶meters) |
146 void SifUiDialogContentWidget::constructFromParameters(const QVariantMap ¶meters) |
127 { |
147 { |
|
148 FLOG1("SifUiDialogContentWidget::constructFromParameters"); |
|
149 |
128 Q_ASSERT(mMainLayout == 0); |
150 Q_ASSERT(mMainLayout == 0); |
129 mMainLayout = new QGraphicsLinearLayout(Qt::Vertical); |
151 mMainLayout = new QGraphicsLinearLayout(Qt::Vertical); |
130 |
152 |
131 // Application icon |
153 // Application icon |
132 QGraphicsLinearLayout *iconAndAppLayout = new QGraphicsLinearLayout(Qt::Horizontal); |
154 QGraphicsLinearLayout *iconAndAppLayout = new QGraphicsLinearLayout(Qt::Horizontal); |
156 Q_ASSERT(mStackedWidget == 0); |
178 Q_ASSERT(mStackedWidget == 0); |
157 mStackedWidget = new HbStackedWidget; |
179 mStackedWidget = new HbStackedWidget; |
158 |
180 |
159 Q_ASSERT(mMemorySelection == 0); |
181 Q_ASSERT(mMemorySelection == 0); |
160 mMemorySelection = new HbComboBox; |
182 mMemorySelection = new HbComboBox; |
161 connect(mMemorySelection, SIGNAL(currentIndexChanged(int)), |
|
162 this, SLOT(handleMemorySelectionChange(int))); |
|
163 mStackedWidget->addWidget(mMemorySelection); |
183 mStackedWidget->addWidget(mMemorySelection); |
164 |
184 |
165 Q_ASSERT(mProgressBar == 0); |
185 Q_ASSERT(mProgressBar == 0); |
166 mProgressBar = new HbProgressBar; |
186 mProgressBar = new HbProgressBar; |
167 mProgressBar->setRange(0,0); // busy indicator by default |
187 mProgressBar->setRange(0,0); // busy indicator by default |
185 // SifUiDialogContentWidget::updateFromParameters() |
205 // SifUiDialogContentWidget::updateFromParameters() |
186 // ---------------------------------------------------------------------------- |
206 // ---------------------------------------------------------------------------- |
187 // |
207 // |
188 void SifUiDialogContentWidget::updateFromParameters(const QVariantMap ¶meters) |
208 void SifUiDialogContentWidget::updateFromParameters(const QVariantMap ¶meters) |
189 { |
209 { |
|
210 FLOG1("SifUiDialogContentWidget::updateFromParameters"); |
|
211 |
190 // Application icon |
212 // Application icon |
191 updateAppIcon(parameters); |
213 updateAppIcon(parameters); |
192 |
214 |
193 // Application name and version |
215 // Application name and version |
194 if (parameters.contains(KSifUiApplicationName)) { |
216 if (parameters.contains(KSifUiApplicationName)) { |
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: |
248 break; |
272 break; |
249 } |
273 } |
250 } |
274 } |
251 |
275 |
252 // ---------------------------------------------------------------------------- |
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 // ---------------------------------------------------------------------------- |
253 // SifUiDialogContentWidget::handleMemorySelectionChange() |
289 // SifUiDialogContentWidget::handleMemorySelectionChange() |
254 // ---------------------------------------------------------------------------- |
290 // ---------------------------------------------------------------------------- |
255 // |
291 // |
256 void SifUiDialogContentWidget::handleMemorySelectionChange(int selectedIndex) |
292 void SifUiDialogContentWidget::handleMemorySelectionChange(int selectedIndex) |
257 { |
293 { |
|
294 FLOG2("SifUiDialogContentWidget::handleMemorySelectionChange", selectedIndex); |
|
295 |
258 QChar selectedDrive = mDriveLetterList[selectedIndex][0]; |
296 QChar selectedDrive = mDriveLetterList[selectedIndex][0]; |
259 |
297 saveSelectedDriveAsDefault( selectedDrive ); |
260 // TODO: save selected drive to cenrep |
|
261 |
|
262 emit memorySelectionChanged( selectedDrive ); |
298 emit memorySelectionChanged( selectedDrive ); |
263 } |
299 } |
264 |
300 |
265 // ---------------------------------------------------------------------------- |
301 // ---------------------------------------------------------------------------- |
266 // SifUiDialogContentWidget::applicationName() |
302 // SifUiDialogContentWidget::applicationName() |
275 QString versionParam = parameters.value(KSifUiApplicationVersion).toString(); |
311 QString versionParam = parameters.value(KSifUiApplicationVersion).toString(); |
276 //: Custom layout ID parent. Template for application name and version in SW install |
312 //: Custom layout ID parent. Template for application name and version in SW install |
277 //: confirmation query. %1 is the application name and %2 is the version number. |
313 //: confirmation query. %1 is the application name and %2 is the version number. |
278 //: Version number consist of major, minor, and build numbers. |
314 //: Version number consist of major, minor, and build numbers. |
279 //: For example: "Chess (v 1.01(123))". |
315 //: For example: "Chess (v 1.01(123))". |
280 appName = hbTrId("txt_installer_list_appname_version").arg(nameParam, versionParam); |
316 // TODO: use hbTrId when arg() starts to work with limited length arguments like "%[99]1" |
|
317 //appName = hbTrId("txt_installer_list_appname_version").arg(nameParam, versionParam); |
|
318 appName = QString("%1 (v %2)").arg(nameParam, versionParam); |
281 } else { |
319 } else { |
282 appName = nameParam; |
320 appName = nameParam; |
283 } |
321 } |
284 } |
322 } |
285 return appName; |
323 return appName; |
291 // |
329 // |
292 QString SifUiDialogContentWidget::applicationSize(const QVariantMap ¶meters) |
330 QString SifUiDialogContentWidget::applicationSize(const QVariantMap ¶meters) |
293 { |
331 { |
294 QString appSize = ""; |
332 QString appSize = ""; |
295 if (parameters.contains(KSifUiApplicationSize)) { |
333 if (parameters.contains(KSifUiApplicationSize)) { |
296 uint size = parameters.value(KSifUiApplicationSize).toUInt(); |
334 bool ok = false; |
297 if (size > 0) { |
335 uint size = parameters.value(KSifUiApplicationSize).toUInt(&ok); |
|
336 if (ok) { |
298 if (size > KSifUiMega) { |
337 if (size > KSifUiMega) { |
299 //: Application size in SW install confirmation query, %1 is in megabytes |
338 //: Application size in SW install confirmation query, %1 is in megabytes |
300 appSize = hbTrId("txt_installer_list_appsize_mb").arg(size/KSifUiMega); |
339 appSize = hbTrId("txt_installer_list_appsize_mb").arg(size/KSifUiMega); |
301 } else if(size > KSifUiKilo) { |
340 } else if(size > KSifUiKilo) { |
302 //: Application size in SW install confirmation query, %1 is in kilobytes |
341 //: Application size in SW install confirmation query, %1 is in kilobytes |
372 // |
411 // |
373 void SifUiDialogContentWidget::updateAppIcon(const QVariantMap ¶meters) |
412 void SifUiDialogContentWidget::updateAppIcon(const QVariantMap ¶meters) |
374 { |
413 { |
375 Q_ASSERT(mAppIcon != 0); |
414 Q_ASSERT(mAppIcon != 0); |
376 |
415 |
|
416 // TODO: proper icon handling |
377 if (parameters.contains(KSifUiDialogType) && |
417 if (parameters.contains(KSifUiDialogType) && |
378 (parameters.value(KSifUiDialogType).toInt() == SifUiErrorNote)) { |
418 (parameters.value(KSifUiDialogType).toInt() == SifUiErrorNote)) { |
379 mAppIcon->setIcon(HbIcon(KSifUiErrorIcon)); |
419 mAppIcon->setIcon(HbIcon(KSifUiErrorIcon)); |
380 } else if (parameters.contains(KSifUiApplicationIconHandle) && |
420 } else if (parameters.contains(KSifUiApplicationIconHandle) && |
381 parameters.contains(KSifUiApplicationIconMaskHandle)) { |
421 parameters.contains(KSifUiApplicationIconMaskHandle)) { |
430 { |
470 { |
431 if (parameters.contains(KSifUiMemorySelection)) { |
471 if (parameters.contains(KSifUiMemorySelection)) { |
432 QString drives = parameters.value(KSifUiMemorySelection).toString(); |
472 QString drives = parameters.value(KSifUiMemorySelection).toString(); |
433 mDriveLetterList = drives.split(","); |
473 mDriveLetterList = drives.split(","); |
434 |
474 |
|
475 QChar defaultDrive = readDefaultSelectedDrive(); |
|
476 int defaultDriveIndex = 0; |
|
477 |
435 QStringList driveList; |
478 QStringList driveList; |
436 QSystemStorageInfo info; |
479 QSystemStorageInfo info; |
437 QStringList volumeList = info.logicalDrives(); |
480 QStringList volumeList = info.logicalDrives(); |
438 foreach (QString volume, volumeList) { |
481 foreach (QString volume, volumeList) { |
439 if (mDriveLetterList.contains(volume)) { |
482 if (mDriveLetterList.contains(volume)) { |
440 qlonglong size = info.availableDiskSpace(volume); |
483 qlonglong size = info.availableDiskSpace(volume); |
441 switch (driveName(volume[0])) { |
484 |
|
485 QChar driveLetter(volume[0]); |
|
486 switch (driveName(driveLetter)) { |
442 case EPhoneMemory: |
487 case EPhoneMemory: |
443 if (size > KSifUiMega) { |
488 if (size > KSifUiMega) { |
444 //: Drive name for internal phone memory with megabytes of free space. |
489 //: Drive name for internal phone memory with megabytes of free space. |
445 //: %1 is replaced with drive letter (usually 'C') |
490 //: %1 is replaced with drive letter (usually 'C') |
446 //: %2 is replaced with available free space (in megabytes, MB) |
491 //: %2 is replaced with available free space (in megabytes, MB) |
520 driveList.append(tr("%1: Drive (%L2 kB)" |
565 driveList.append(tr("%1: Drive (%L2 kB)" |
521 ).arg(volume).arg(size/KSifUiKilo)); |
566 ).arg(volume).arg(size/KSifUiKilo)); |
522 } |
567 } |
523 break; |
568 break; |
524 } |
569 } |
|
570 |
|
571 if (driveLetter == defaultDrive) { |
|
572 defaultDriveIndex = driveList.count() - 1; |
|
573 } |
525 } |
574 } |
526 } |
575 } |
527 |
576 |
|
577 disconnect(mMemorySelection, SIGNAL(currentIndexChanged(int)), |
|
578 this, SLOT(handleMemorySelectionChange(int))); |
528 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))); |
529 mStackedWidget->setCurrentWidget(mMemorySelection); |
587 mStackedWidget->setCurrentWidget(mMemorySelection); |
530 |
|
531 // TODO: set selected item, read the default from cenrep |
|
532 |
588 |
533 return true; |
589 return true; |
534 } |
590 } |
535 return false; |
591 return false; |
536 } |
592 } |
546 mProgressBar->setMaximum(parameters.value(KSifUiProgressNoteFinalValue).toInt()); |
602 mProgressBar->setMaximum(parameters.value(KSifUiProgressNoteFinalValue).toInt()); |
547 progressBarChanged = true; |
603 progressBarChanged = true; |
548 } |
604 } |
549 if (parameters.contains(KSifUiProgressNoteValue)) { |
605 if (parameters.contains(KSifUiProgressNoteValue)) { |
550 int newValue = mProgressBar->progressValue(); |
606 int newValue = mProgressBar->progressValue(); |
551 newValue += parameters.value(KSifUiProgressNoteValue).toInt(); |
607 bool ok = false; |
552 mProgressBar->setProgressValue(newValue); |
608 newValue += parameters.value(KSifUiProgressNoteValue).toInt(&ok); |
553 progressBarChanged = true; |
609 if (ok) { |
|
610 mProgressBar->setProgressValue(newValue); |
|
611 progressBarChanged = true; |
|
612 } |
554 } |
613 } |
555 if (progressBarChanged) { |
614 if (progressBarChanged) { |
556 mStackedWidget->setCurrentWidget(mProgressBar); |
615 mStackedWidget->setCurrentWidget(mProgressBar); |
557 } |
616 } |
558 return progressBarChanged; |
617 return progressBarChanged; |
562 // SifUiDialogContentWidget::updateErrorText() |
621 // SifUiDialogContentWidget::updateErrorText() |
563 // ---------------------------------------------------------------------------- |
622 // ---------------------------------------------------------------------------- |
564 // |
623 // |
565 bool SifUiDialogContentWidget::updateErrorText(const QVariantMap ¶meters) |
624 bool SifUiDialogContentWidget::updateErrorText(const QVariantMap ¶meters) |
566 { |
625 { |
567 if (parameters.contains(KSifUiErrorCode)) { |
626 // TODO: move default error messages (category based) here |
568 // TODO: proper error texts |
627 if (parameters.contains(KSifUiErrorMessage)) { |
569 bool ok = false; |
628 QString errorText = parameters.value(KSifUiErrorMessage).toString(); |
570 int errorCode = parameters.value(KSifUiErrorCode).toInt(&ok); |
|
571 QString errorText; |
|
572 if (ok) { |
|
573 errorText = tr("Error %1").arg(errorCode); |
|
574 } else { |
|
575 errorText = tr("No error code."); |
|
576 } |
|
577 mErrorText->setPlainText(errorText); |
629 mErrorText->setPlainText(errorText); |
578 mStackedWidget->setCurrentWidget(mErrorText); |
630 mStackedWidget->setCurrentWidget(mErrorText); |
579 return true; |
631 return true; |
580 } |
632 } |
581 return false; |
633 return false; |
582 } |
634 } |
583 |
635 |
584 |
636 // ---------------------------------------------------------------------------- |
585 |
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 |