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 content widget. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "sifuidialogcontentwidget.h" |
|
19 #include <QGraphicsLinearLayout> |
|
20 #include <hbstackedwidget.h> |
|
21 #include <hblabel.h> |
|
22 #include <hbpushbutton.h> |
|
23 #include <hbcombobox.h> |
|
24 #include <hbprogressbar.h> |
|
25 #include <QPixmap> |
|
26 #include <qsysteminfo.h> // QSystemStorageInfo |
|
27 #include <qvaluespacepublisher.h> // QValueSpacePublisher |
|
28 #include <qvaluespacesubscriber.h> // QValueSpaceSubscriber |
|
29 #if defined(Q_OS_SYMBIAN) |
|
30 #include <driveinfo.h> // DriveInfo |
|
31 #include <fbs.h> // CFbsBitmap |
|
32 #endif // Q_OS_SYMBIAN |
|
33 |
|
34 QTM_USE_NAMESPACE |
|
35 |
|
36 const char KSifUiDefaultApplicationIcon[] = "qtg_large_application"; |
|
37 const char KSifUiErrorIcon[] = "qtg_large_warning"; |
|
38 |
|
39 const int KSifUiKilo = 1024; |
|
40 const int KSifUiMega = 1024*1024; |
|
41 |
|
42 const int KAppNameIndex = 0; |
|
43 const int KAppSizeIndex = 1; |
|
44 |
|
45 enum TSifUiDriveName { |
|
46 EPhoneMemory, |
|
47 EMassStorage, |
|
48 EMemoryCard, |
|
49 EOtherDrive |
|
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 |
|
68 |
|
69 |
|
70 // ======== LOCAL FUNCTIONS ======== |
|
71 |
|
72 // ---------------------------------------------------------------------------- |
|
73 // fbsBitmap() |
|
74 // ---------------------------------------------------------------------------- |
|
75 // |
|
76 CFbsBitmap *fbsBitmap(int handle) |
|
77 { |
|
78 CFbsBitmap *bitmap = 0; |
|
79 #if defined(Q_OS_SYMBIAN) |
|
80 bitmap = new CFbsBitmap; |
|
81 if (bitmap) { |
|
82 if (!bitmap->Duplicate(handle)) { |
|
83 delete bitmap; |
|
84 bitmap = 0; |
|
85 } |
|
86 } |
|
87 #endif // Q_OS_SYMBIAN |
|
88 return bitmap; |
|
89 } |
|
90 |
|
91 // ---------------------------------------------------------------------------- |
|
92 // driveName() |
|
93 // ---------------------------------------------------------------------------- |
|
94 // |
|
95 TSifUiDriveName driveName(const QChar& volume) |
|
96 { |
|
97 #if defined(Q_OS_SYMBIAN) |
|
98 int err = 0; |
|
99 TChar drive; |
|
100 err = DriveInfo::GetDefaultDrive(DriveInfo::EDefaultPhoneMemory, drive); |
|
101 if (!err && volume.toAscii() == drive) { |
|
102 return EPhoneMemory; |
|
103 } |
|
104 err = DriveInfo::GetDefaultDrive(DriveInfo::EDefaultMassStorage, drive); |
|
105 if (!err && volume.toAscii() == drive) { |
|
106 return EMassStorage; |
|
107 } |
|
108 err = DriveInfo::GetDefaultDrive(DriveInfo::EDefaultRemovableMassStorage, drive); |
|
109 if (!err && volume.toAscii() == drive) { |
|
110 return EMemoryCard; |
|
111 } |
|
112 #endif // Q_OS_SYMBIAN |
|
113 return EOtherDrive; |
|
114 } |
|
115 |
|
116 |
|
117 // ======== MEMBER FUNCTIONS ======== |
|
118 |
|
119 // ---------------------------------------------------------------------------- |
|
120 // SifUiDialogContentWidget::SifUiDialogContentWidget() |
|
121 // ---------------------------------------------------------------------------- |
|
122 // |
|
123 SifUiDialogContentWidget::SifUiDialogContentWidget(QGraphicsItem *parent, |
|
124 Qt::WindowFlags flags) : HbWidget(parent, flags), |
|
125 mAppIcon(0), mAppName(0), mAppSize(0), |
|
126 mMainLayout(0), mAppDetailsLayout(0), mStackedWidget(0), |
|
127 mMemorySelection(0), mProgressBar(0), mErrorText(0), |
|
128 mBitmap(0), mMask(0), mPublisher(0), mSubscriber(0) |
|
129 { |
|
130 } |
|
131 |
|
132 // ---------------------------------------------------------------------------- |
|
133 // SifUiDialogContentWidget::~SifUiDialogContentWidget() |
|
134 // ---------------------------------------------------------------------------- |
|
135 // |
|
136 SifUiDialogContentWidget::~SifUiDialogContentWidget() |
|
137 { |
|
138 delete mBitmap; |
|
139 delete mMask; |
|
140 } |
|
141 |
|
142 // ---------------------------------------------------------------------------- |
|
143 // SifUiDialogContentWidget::constructFromParameters() |
|
144 // ---------------------------------------------------------------------------- |
|
145 // |
|
146 void SifUiDialogContentWidget::constructFromParameters(const QVariantMap ¶meters) |
|
147 { |
|
148 FLOG1("SifUiDialogContentWidget::constructFromParameters"); |
|
149 |
|
150 Q_ASSERT(mMainLayout == 0); |
|
151 mMainLayout = new QGraphicsLinearLayout(Qt::Vertical); |
|
152 |
|
153 // Application icon |
|
154 QGraphicsLinearLayout *iconAndAppLayout = new QGraphicsLinearLayout(Qt::Horizontal); |
|
155 Q_ASSERT(mAppIcon == 0); |
|
156 mAppIcon = new HbLabel; |
|
157 updateAppIcon(parameters); |
|
158 iconAndAppLayout->addItem(mAppIcon); |
|
159 |
|
160 // Application name and version |
|
161 Q_ASSERT(mAppDetailsLayout == 0); |
|
162 mAppDetailsLayout = new QGraphicsLinearLayout(Qt::Vertical); |
|
163 createAppName(applicationName(parameters)); |
|
164 mAppDetailsLayout->addItem(mAppName); |
|
165 |
|
166 // Application size |
|
167 Q_ASSERT(mAppSize == 0); |
|
168 updateAppSize(parameters); |
|
169 |
|
170 // Other application details |
|
171 if (parameters.contains(KSifUiApplicationDetails)) { |
|
172 addDetails(parameters.value(KSifUiApplicationDetails).toStringList()); |
|
173 } |
|
174 iconAndAppLayout->addItem(mAppDetailsLayout); |
|
175 mMainLayout->addItem(iconAndAppLayout); |
|
176 |
|
177 // Memory selection, progress bar, and error text within a stacked widget |
|
178 Q_ASSERT(mStackedWidget == 0); |
|
179 mStackedWidget = new HbStackedWidget; |
|
180 |
|
181 Q_ASSERT(mMemorySelection == 0); |
|
182 mMemorySelection = new HbComboBox; |
|
183 mStackedWidget->addWidget(mMemorySelection); |
|
184 |
|
185 Q_ASSERT(mProgressBar == 0); |
|
186 mProgressBar = new HbProgressBar; |
|
187 mProgressBar->setRange(0,0); // busy indicator by default |
|
188 mStackedWidget->addWidget(mProgressBar); |
|
189 |
|
190 Q_ASSERT(mErrorText == 0); |
|
191 mErrorText = new HbLabel; |
|
192 mStackedWidget->addWidget(mErrorText); |
|
193 |
|
194 mMainLayout->addItem(mStackedWidget); |
|
195 if (!updateErrorText(parameters) && |
|
196 !updateProgressBar(parameters) && |
|
197 !updateMemorySelection(parameters)) { |
|
198 mStackedWidget->hide(); |
|
199 } |
|
200 |
|
201 setLayout(mMainLayout); |
|
202 } |
|
203 |
|
204 // ---------------------------------------------------------------------------- |
|
205 // SifUiDialogContentWidget::updateFromParameters() |
|
206 // ---------------------------------------------------------------------------- |
|
207 // |
|
208 void SifUiDialogContentWidget::updateFromParameters(const QVariantMap ¶meters) |
|
209 { |
|
210 FLOG1("SifUiDialogContentWidget::updateFromParameters"); |
|
211 |
|
212 // Application icon |
|
213 updateAppIcon(parameters); |
|
214 |
|
215 // Application name and version |
|
216 if (parameters.contains(KSifUiApplicationName)) { |
|
217 QString appNameStr = applicationName(parameters); |
|
218 if (mAppName) { |
|
219 if (mAppName->plainText() != appNameStr) { |
|
220 mAppName->setPlainText(appNameStr); |
|
221 } |
|
222 } else { |
|
223 createAppName(appNameStr); |
|
224 mAppDetailsLayout->insertItem(KAppNameIndex, mAppName); |
|
225 } |
|
226 } |
|
227 |
|
228 // Application size |
|
229 updateAppSize(parameters); |
|
230 |
|
231 // Other application details |
|
232 if (parameters.contains(KSifUiApplicationDetails)) { |
|
233 removeDetails(); |
|
234 addDetails(parameters.value(KSifUiApplicationDetails).toStringList()); |
|
235 } |
|
236 |
|
237 // Stacked widgets: memory selection, progress bar and error text |
|
238 if (updateErrorText(parameters) || |
|
239 updateProgressBar(parameters) || |
|
240 updateMemorySelection(parameters)) { |
|
241 if (!mStackedWidget->isVisible()) { |
|
242 mStackedWidget->show(); |
|
243 } |
|
244 } else { |
|
245 if (mStackedWidget->isVisible()) { |
|
246 mStackedWidget->hide(); |
|
247 } |
|
248 } |
|
249 } |
|
250 |
|
251 // ---------------------------------------------------------------------------- |
|
252 // SifUiDialogContentWidget::changeType() |
|
253 // ---------------------------------------------------------------------------- |
|
254 // |
|
255 void SifUiDialogContentWidget::changeType(SifUiDeviceDialogType type) |
|
256 { |
|
257 FLOG2("SifUiDialogContentWidget::changeType", type); |
|
258 |
|
259 switch (type) { |
|
260 case SifUiConfirmationQuery: |
|
261 mStackedWidget->setCurrentWidget(mMemorySelection); |
|
262 break; |
|
263 case SifUiProgressNote: |
|
264 mStackedWidget->setCurrentWidget(mProgressBar); |
|
265 break; |
|
266 case SifUiCompleteNote: |
|
267 break; |
|
268 case SifUiErrorNote: |
|
269 mStackedWidget->setCurrentWidget(mErrorText); |
|
270 break; |
|
271 default: |
|
272 break; |
|
273 } |
|
274 } |
|
275 |
|
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 // ---------------------------------------------------------------------------- |
|
289 // SifUiDialogContentWidget::handleMemorySelectionChange() |
|
290 // ---------------------------------------------------------------------------- |
|
291 // |
|
292 void SifUiDialogContentWidget::handleMemorySelectionChange(int selectedIndex) |
|
293 { |
|
294 FLOG2("SifUiDialogContentWidget::handleMemorySelectionChange", selectedIndex); |
|
295 |
|
296 QChar selectedDrive = mDriveLetterList[selectedIndex][0]; |
|
297 saveSelectedDriveAsDefault( selectedDrive ); |
|
298 emit memorySelectionChanged( selectedDrive ); |
|
299 } |
|
300 |
|
301 // ---------------------------------------------------------------------------- |
|
302 // SifUiDialogContentWidget::applicationName() |
|
303 // ---------------------------------------------------------------------------- |
|
304 // |
|
305 QString SifUiDialogContentWidget::applicationName(const QVariantMap ¶meters) |
|
306 { |
|
307 QString appName = ""; |
|
308 if (parameters.contains(KSifUiApplicationName)) { |
|
309 QString nameParam = parameters.value(KSifUiApplicationName).toString(); |
|
310 if (parameters.contains(KSifUiApplicationVersion)) { |
|
311 QString versionParam = parameters.value(KSifUiApplicationVersion).toString(); |
|
312 //: Custom layout ID parent. Template for application name and version in SW install |
|
313 //: confirmation query. %1 is the application name and %2 is the version number. |
|
314 //: Version number consist of major, minor, and build numbers. |
|
315 //: For example: "Chess (v 1.01(123))". |
|
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); |
|
319 } else { |
|
320 appName = nameParam; |
|
321 } |
|
322 } |
|
323 return appName; |
|
324 } |
|
325 |
|
326 // ---------------------------------------------------------------------------- |
|
327 // SifUiDialogContentWidget::applicationSize() |
|
328 // ---------------------------------------------------------------------------- |
|
329 // |
|
330 QString SifUiDialogContentWidget::applicationSize(const QVariantMap ¶meters) |
|
331 { |
|
332 QString appSize = ""; |
|
333 if (parameters.contains(KSifUiApplicationSize)) { |
|
334 bool ok = false; |
|
335 uint size = parameters.value(KSifUiApplicationSize).toUInt(&ok); |
|
336 if (ok) { |
|
337 if (size > KSifUiMega) { |
|
338 //: Application size in SW install confirmation query, %1 is in megabytes |
|
339 appSize = hbTrId("txt_installer_list_appsize_mb").arg(size/KSifUiMega); |
|
340 } else if(size > KSifUiKilo) { |
|
341 //: Application size in SW install confirmation query, %1 is in kilobytes |
|
342 appSize = hbTrId("txt_installer_list_appsize_kb").arg(size/KSifUiKilo); |
|
343 } else { |
|
344 //: Application size in SW install confirmation query, %1 is in bytes |
|
345 appSize = hbTrId("txt_installer_list_appsize_b").arg(size); |
|
346 } |
|
347 } |
|
348 } |
|
349 return appSize; |
|
350 } |
|
351 |
|
352 // ---------------------------------------------------------------------------- |
|
353 // SifUiDialogContentWidget::removeDetails() |
|
354 // ---------------------------------------------------------------------------- |
|
355 // |
|
356 void SifUiDialogContentWidget::removeDetails() |
|
357 { |
|
358 int firstDetailsItemIndex = ( mAppName ? 1 : 0 ) + ( mAppSize ? 1 : 0 ); |
|
359 QGraphicsLayoutItem *item = 0; |
|
360 for (int i = 0; i < mAppDetailsLayout->count(); ++i) { |
|
361 if (i >= firstDetailsItemIndex) { |
|
362 item = mAppDetailsLayout->itemAt(i); |
|
363 mAppDetailsLayout->removeAt(i); |
|
364 delete item; |
|
365 item = 0; |
|
366 } |
|
367 } |
|
368 } |
|
369 |
|
370 // ---------------------------------------------------------------------------- |
|
371 // SifUiDialogContentWidget::addDetails() |
|
372 // ---------------------------------------------------------------------------- |
|
373 // |
|
374 void SifUiDialogContentWidget::addDetails(const QStringList &detailList) |
|
375 { |
|
376 QStringListIterator detailsIter(detailList); |
|
377 while (detailsIter.hasNext()) |
|
378 { |
|
379 addDetail(detailsIter.next()); |
|
380 } |
|
381 } |
|
382 |
|
383 // ---------------------------------------------------------------------------- |
|
384 // SifUiDialogContentWidget::addDetail() |
|
385 // ---------------------------------------------------------------------------- |
|
386 // |
|
387 void SifUiDialogContentWidget::addDetail(const QString &detailText) |
|
388 { |
|
389 Q_ASSERT(mAppDetailsLayout != 0); |
|
390 HbLabel *detailItem = new HbLabel(detailText); |
|
391 detailItem->setTextWrapping(Hb::TextWordWrap); |
|
392 detailItem->setFontSpec(HbFontSpec(HbFontSpec::Secondary)); |
|
393 mAppDetailsLayout->addItem(detailItem); |
|
394 } |
|
395 |
|
396 // ---------------------------------------------------------------------------- |
|
397 // SifUiDialogContentWidget::createAppName() |
|
398 // ---------------------------------------------------------------------------- |
|
399 // |
|
400 void SifUiDialogContentWidget::createAppName(const QString &appName) |
|
401 { |
|
402 Q_ASSERT(mAppName == 0); |
|
403 mAppName = new HbLabel(appName); |
|
404 mAppName->setTextWrapping(Hb::TextWordWrap); |
|
405 mAppName->setFontSpec(HbFontSpec(HbFontSpec::Secondary)); |
|
406 } |
|
407 |
|
408 // ---------------------------------------------------------------------------- |
|
409 // SifUiDialogContentWidget::updateAppIcon() |
|
410 // ---------------------------------------------------------------------------- |
|
411 // |
|
412 void SifUiDialogContentWidget::updateAppIcon(const QVariantMap ¶meters) |
|
413 { |
|
414 Q_ASSERT(mAppIcon != 0); |
|
415 |
|
416 // TODO: proper icon handling |
|
417 if (parameters.contains(KSifUiDialogType) && |
|
418 (parameters.value(KSifUiDialogType).toInt() == SifUiErrorNote)) { |
|
419 mAppIcon->setIcon(HbIcon(KSifUiErrorIcon)); |
|
420 } else if (parameters.contains(KSifUiApplicationIconHandle) && |
|
421 parameters.contains(KSifUiApplicationIconMaskHandle)) { |
|
422 int iconHandle = parameters.value(KSifUiApplicationIconHandle).toInt(); |
|
423 int maskHandle = parameters.value(KSifUiApplicationIconMaskHandle).toInt(); |
|
424 QPixmap pixmap; |
|
425 delete mBitmap; |
|
426 mBitmap = fbsBitmap(iconHandle); |
|
427 delete mMask; |
|
428 mMask = fbsBitmap(maskHandle); |
|
429 if (mBitmap && mMask) { |
|
430 pixmap = QPixmap::fromSymbianCFbsBitmap(mBitmap); |
|
431 pixmap.setAlphaChannel(QPixmap::fromSymbianCFbsBitmap(mMask)); |
|
432 } |
|
433 mAppIcon->setIcon(HbIcon(pixmap)); |
|
434 } else { |
|
435 if (mAppIcon->icon().isNull()) { |
|
436 mAppIcon->setIcon(HbIcon(KSifUiDefaultApplicationIcon)); |
|
437 } |
|
438 } |
|
439 } |
|
440 |
|
441 // ---------------------------------------------------------------------------- |
|
442 // SifUiDialogContentWidget::updateAppSize() |
|
443 // ---------------------------------------------------------------------------- |
|
444 // |
|
445 void SifUiDialogContentWidget::updateAppSize(const QVariantMap ¶meters) |
|
446 { |
|
447 if (parameters.contains(KSifUiApplicationSize)) { |
|
448 QString appSizeStr = applicationSize(parameters); |
|
449 if (appSizeStr.length() > 0) { |
|
450 if (mAppSize) { |
|
451 if (mAppSize->plainText() != appSizeStr) { |
|
452 mAppSize->setPlainText(appSizeStr); |
|
453 } |
|
454 } else { |
|
455 HbLabel *appSize = new HbLabel(appSizeStr); |
|
456 appSize->setTextWrapping(Hb::TextWordWrap); |
|
457 appSize->setFontSpec(HbFontSpec(HbFontSpec::Secondary)); |
|
458 mAppDetailsLayout->insertItem(KAppSizeIndex, appSize); |
|
459 mAppSize = appSize; |
|
460 } |
|
461 } |
|
462 } |
|
463 } |
|
464 |
|
465 // ---------------------------------------------------------------------------- |
|
466 // SifUiDialogContentWidget::updateMemorySelection() |
|
467 // ---------------------------------------------------------------------------- |
|
468 // |
|
469 bool SifUiDialogContentWidget::updateMemorySelection(const QVariantMap ¶meters) |
|
470 { |
|
471 if (parameters.contains(KSifUiMemorySelection)) { |
|
472 QString drives = parameters.value(KSifUiMemorySelection).toString(); |
|
473 mDriveLetterList = drives.split(","); |
|
474 |
|
475 QChar defaultDrive = readDefaultSelectedDrive(); |
|
476 int defaultDriveIndex = 0; |
|
477 |
|
478 QStringList driveList; |
|
479 QSystemStorageInfo info; |
|
480 QStringList volumeList = info.logicalDrives(); |
|
481 foreach (QString volume, volumeList) { |
|
482 if (mDriveLetterList.contains(volume)) { |
|
483 qlonglong size = info.availableDiskSpace(volume); |
|
484 |
|
485 QChar driveLetter(volume[0]); |
|
486 switch (driveName(driveLetter)) { |
|
487 case EPhoneMemory: |
|
488 if (size > KSifUiMega) { |
|
489 //: Drive name for internal phone memory with megabytes of free space. |
|
490 //: %1 is replaced with drive letter (usually 'C') |
|
491 //: %2 is replaced with available free space (in megabytes, MB) |
|
492 //TODO: enable when available |
|
493 //driveList.append(hbTrId("txt_installer_device_memory_mb") |
|
494 // .arg(volume).arg(size/KSifUiMega)); |
|
495 driveList.append(tr("%1: Phone mem. (%L2 MB)" |
|
496 ).arg(volume).arg(size/KSifUiMega)); |
|
497 } else { |
|
498 //: Drive name for internal phone memory with kilobytes of free space. |
|
499 //: %1 is replaced with drive letter (usually 'C') |
|
500 //: %2 is replaced with available free space (in kilobytes, kB) |
|
501 //TODO: enable when available |
|
502 //driveList.append(hbTrId("txt_installer_device_memory_kb") |
|
503 // .arg(volume).arg(size/KSifUiKilo)); |
|
504 driveList.append(tr("%1: Phone mem. (%L2 kB)" |
|
505 ).arg(volume).arg(size/KSifUiKilo)); |
|
506 } |
|
507 break; |
|
508 |
|
509 case EMassStorage: |
|
510 if (size > KSifUiMega) { |
|
511 //: Drive name for mass storage with megabytes of free space. |
|
512 //: %1 is replaced with drive letter (usually 'E') |
|
513 //: %2 is replaced with available free space (in megabytes, MB) |
|
514 // TODO: enable when available |
|
515 //driveList.append(hbTrId("txt_installer_mass_storage_mb") |
|
516 // .arg(volume).arg(size/KSifUiMega)); |
|
517 driveList.append(tr("%1: Mass.mem (%L2 MB)" |
|
518 ).arg(volume).arg(size/KSifUiMega)); |
|
519 } else { |
|
520 //: Drive name for mass storage with kilobytes of free space. |
|
521 //: %1 is replaced with drive letter (usually 'E') |
|
522 //: %2 is replaced with available free space (in kilobytes, kB) |
|
523 // TODO: enable when available |
|
524 //driveList.append(hbTrId("txt_installer_mass_storage_kb") |
|
525 // .arg(volume).arg(size/KSifUiKilo)); |
|
526 driveList.append(tr("%1: Mass.mem (%L2 kB)" |
|
527 ).arg(volume).arg(size/KSifUiKilo)); |
|
528 } |
|
529 break; |
|
530 |
|
531 case EMemoryCard: |
|
532 if (size > KSifUiMega) { |
|
533 //: Drive name for memory card with megabytes of free space. |
|
534 //: %1 is replaced with drive letter (usually 'F') |
|
535 //: %2 is replaced with available free space (in megabytes, MB) |
|
536 // TODO: enable when available |
|
537 //driveList.append(hbTrId("txt_installer_memory_card_mb") |
|
538 // .arg(volume).arg(size/KSifUiMega)); |
|
539 driveList.append(tr("%1: Mem.card (%L2 MB)" |
|
540 ).arg(volume).arg(size/KSifUiMega)); |
|
541 } else { |
|
542 //: Drive name for memory card with kilobytes of free space. |
|
543 //: %1 is replaced with drive letter (usually 'F') |
|
544 //: %2 is replaced with available free space (in kilobytes, kB) |
|
545 // TODO: enable when available |
|
546 //driveList.append(hbTrId("txt_installer_memory_card_kb") |
|
547 // .arg(volume).arg(size/KSifUiKilo)); |
|
548 driveList.append(tr("%1: Mem.card (%L2 kB)" |
|
549 ).arg(volume).arg(size/KSifUiKilo)); |
|
550 } |
|
551 break; |
|
552 |
|
553 case EOtherDrive: |
|
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 } |
|
568 break; |
|
569 } |
|
570 |
|
571 if (driveLetter == defaultDrive) { |
|
572 defaultDriveIndex = driveList.count() - 1; |
|
573 } |
|
574 } |
|
575 } |
|
576 |
|
577 disconnect(mMemorySelection, SIGNAL(currentIndexChanged(int)), |
|
578 this, SLOT(handleMemorySelectionChange(int))); |
|
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))); |
|
587 mStackedWidget->setCurrentWidget(mMemorySelection); |
|
588 |
|
589 return true; |
|
590 } |
|
591 return false; |
|
592 } |
|
593 |
|
594 // ---------------------------------------------------------------------------- |
|
595 // SifUiDialogContentWidget::updateProgressBar() |
|
596 // ---------------------------------------------------------------------------- |
|
597 // |
|
598 bool SifUiDialogContentWidget::updateProgressBar(const QVariantMap ¶meters) |
|
599 { |
|
600 bool progressBarChanged = false; |
|
601 if (parameters.contains(KSifUiProgressNoteFinalValue)) { |
|
602 mProgressBar->setMaximum(parameters.value(KSifUiProgressNoteFinalValue).toInt()); |
|
603 progressBarChanged = true; |
|
604 } |
|
605 if (parameters.contains(KSifUiProgressNoteValue)) { |
|
606 int newValue = mProgressBar->progressValue(); |
|
607 bool ok = false; |
|
608 newValue += parameters.value(KSifUiProgressNoteValue).toInt(&ok); |
|
609 if (ok) { |
|
610 mProgressBar->setProgressValue(newValue); |
|
611 progressBarChanged = true; |
|
612 } |
|
613 } |
|
614 if (progressBarChanged) { |
|
615 mStackedWidget->setCurrentWidget(mProgressBar); |
|
616 } |
|
617 return progressBarChanged; |
|
618 } |
|
619 |
|
620 // ---------------------------------------------------------------------------- |
|
621 // SifUiDialogContentWidget::updateErrorText() |
|
622 // ---------------------------------------------------------------------------- |
|
623 // |
|
624 bool SifUiDialogContentWidget::updateErrorText(const QVariantMap ¶meters) |
|
625 { |
|
626 // TODO: move default error messages (category based) here |
|
627 if (parameters.contains(KSifUiErrorMessage)) { |
|
628 QString errorText = parameters.value(KSifUiErrorMessage).toString(); |
|
629 mErrorText->setPlainText(errorText); |
|
630 mStackedWidget->setCurrentWidget(mErrorText); |
|
631 return true; |
|
632 } |
|
633 return false; |
|
634 } |
|
635 |
|
636 // ---------------------------------------------------------------------------- |
|
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 |
|