--- a/appinstaller/AppinstUi/sifuidevicedialogplugin/src/sifuidialogcontentwidget.cpp Tue Jul 06 14:23:31 2010 +0300
+++ b/appinstaller/AppinstUi/sifuidevicedialogplugin/src/sifuidialogcontentwidget.cpp Wed Aug 18 09:55:45 2010 +0300
@@ -24,12 +24,15 @@
#include <hbprogressbar.h>
#include <QPixmap>
#include <qsysteminfo.h> // QSystemStorageInfo
-QTM_USE_NAMESPACE
+#include <qvaluespacepublisher.h> // QValueSpacePublisher
+#include <qvaluespacesubscriber.h> // QValueSpaceSubscriber
#if defined(Q_OS_SYMBIAN)
#include <driveinfo.h> // DriveInfo
#include <fbs.h> // CFbsBitmap
#endif // Q_OS_SYMBIAN
+QTM_USE_NAMESPACE
+
const char KSifUiDefaultApplicationIcon[] = "qtg_large_application";
const char KSifUiErrorIcon[] = "qtg_large_warning";
@@ -40,12 +43,29 @@
const int KAppSizeIndex = 1;
enum TSifUiDriveName {
- EUnknown,
EPhoneMemory,
EMassStorage,
- EMemoryCard
+ EMemoryCard,
+ EOtherDrive
};
+const char KInitialDefaultDrive = 'C';
+
+// Path and value name for QValueSpacePublisher/QValueSpaceSubscriber.
+const QString KSifUiCenRepPath = "/KCRUIDSifUiDefaults";
+const QString KSifUiCenRepDefaultDrive = "KCRUIDSifUiDefaultDrive";
+
+// TODO: replace with proper logging
+#ifdef _DEBUG
+#define FLOG1(x) qDebug() << (x)
+#define FLOG2(x,y) qDebug() << (x) << (y)
+#define FLOG3(x,y,z) qDebug() << (x) << (y) << (z)
+#else
+#define FLOG1(x)
+#define FLOG2(x,y)
+#define FLOG3(x,y,z)
+#endif
+
// ======== LOCAL FUNCTIONS ========
@@ -90,7 +110,7 @@
return EMemoryCard;
}
#endif // Q_OS_SYMBIAN
- return EUnknown;
+ return EOtherDrive;
}
@@ -105,7 +125,7 @@
mAppIcon(0), mAppName(0), mAppSize(0),
mMainLayout(0), mAppDetailsLayout(0), mStackedWidget(0),
mMemorySelection(0), mProgressBar(0), mErrorText(0),
- mBitmap(0), mMask(0)
+ mBitmap(0), mMask(0), mPublisher(0), mSubscriber(0)
{
}
@@ -125,6 +145,8 @@
//
void SifUiDialogContentWidget::constructFromParameters(const QVariantMap ¶meters)
{
+ FLOG1("SifUiDialogContentWidget::constructFromParameters");
+
Q_ASSERT(mMainLayout == 0);
mMainLayout = new QGraphicsLinearLayout(Qt::Vertical);
@@ -158,8 +180,6 @@
Q_ASSERT(mMemorySelection == 0);
mMemorySelection = new HbComboBox;
- connect(mMemorySelection, SIGNAL(currentIndexChanged(int)),
- this, SLOT(handleMemorySelectionChange(int)));
mStackedWidget->addWidget(mMemorySelection);
Q_ASSERT(mProgressBar == 0);
@@ -187,6 +207,8 @@
//
void SifUiDialogContentWidget::updateFromParameters(const QVariantMap ¶meters)
{
+ FLOG1("SifUiDialogContentWidget::updateFromParameters");
+
// Application icon
updateAppIcon(parameters);
@@ -232,6 +254,8 @@
//
void SifUiDialogContentWidget::changeType(SifUiDeviceDialogType type)
{
+ FLOG2("SifUiDialogContentWidget::changeType", type);
+
switch (type) {
case SifUiConfirmationQuery:
mStackedWidget->setCurrentWidget(mMemorySelection);
@@ -240,7 +264,6 @@
mStackedWidget->setCurrentWidget(mProgressBar);
break;
case SifUiCompleteNote:
- // TODO: remove mStackedWidget?
break;
case SifUiErrorNote:
mStackedWidget->setCurrentWidget(mErrorText);
@@ -251,15 +274,27 @@
}
// ----------------------------------------------------------------------------
+// SifUiDialogContentWidget::applicationName()
+// ----------------------------------------------------------------------------
+//
+QString SifUiDialogContentWidget::applicationName() const
+{
+ if (mAppName) {
+ return mAppName->plainText();
+ }
+ return QString();
+}
+
+// ----------------------------------------------------------------------------
// SifUiDialogContentWidget::handleMemorySelectionChange()
// ----------------------------------------------------------------------------
//
void SifUiDialogContentWidget::handleMemorySelectionChange(int selectedIndex)
{
- QChar selectedDrive = mDriveLetterList[selectedIndex][0];
+ FLOG2("SifUiDialogContentWidget::handleMemorySelectionChange", selectedIndex);
- // TODO: save selected drive to cenrep
-
+ QChar selectedDrive = mDriveLetterList[selectedIndex][0];
+ saveSelectedDriveAsDefault( selectedDrive );
emit memorySelectionChanged( selectedDrive );
}
@@ -278,7 +313,9 @@
//: confirmation query. %1 is the application name and %2 is the version number.
//: Version number consist of major, minor, and build numbers.
//: For example: "Chess (v 1.01(123))".
- appName = hbTrId("txt_installer_list_appname_version").arg(nameParam, versionParam);
+ // TODO: use hbTrId when arg() starts to work with limited length arguments like "%[99]1"
+ //appName = hbTrId("txt_installer_list_appname_version").arg(nameParam, versionParam);
+ appName = QString("%1 (v %2)").arg(nameParam, versionParam);
} else {
appName = nameParam;
}
@@ -294,8 +331,9 @@
{
QString appSize = "";
if (parameters.contains(KSifUiApplicationSize)) {
- uint size = parameters.value(KSifUiApplicationSize).toUInt();
- if (size > 0) {
+ bool ok = false;
+ uint size = parameters.value(KSifUiApplicationSize).toUInt(&ok);
+ if (ok) {
if (size > KSifUiMega) {
//: Application size in SW install confirmation query, %1 is in megabytes
appSize = hbTrId("txt_installer_list_appsize_mb").arg(size/KSifUiMega);
@@ -375,6 +413,7 @@
{
Q_ASSERT(mAppIcon != 0);
+ // TODO: proper icon handling
if (parameters.contains(KSifUiDialogType) &&
(parameters.value(KSifUiDialogType).toInt() == SifUiErrorNote)) {
mAppIcon->setIcon(HbIcon(KSifUiErrorIcon));
@@ -433,13 +472,18 @@
QString drives = parameters.value(KSifUiMemorySelection).toString();
mDriveLetterList = drives.split(",");
+ QChar defaultDrive = readDefaultSelectedDrive();
+ int defaultDriveIndex = 0;
+
QStringList driveList;
QSystemStorageInfo info;
QStringList volumeList = info.logicalDrives();
foreach (QString volume, volumeList) {
if (mDriveLetterList.contains(volume)) {
qlonglong size = info.availableDiskSpace(volume);
- switch (driveName(volume[0])) {
+
+ QChar driveLetter(volume[0]);
+ switch (driveName(driveLetter)) {
case EPhoneMemory:
if (size > KSifUiMega) {
//: Drive name for internal phone memory with megabytes of free space.
@@ -448,7 +492,7 @@
//TODO: enable when available
//driveList.append(hbTrId("txt_installer_device_memory_mb")
// .arg(volume).arg(size/KSifUiMega));
- driveList.append(tr("%1: Device (%L2 MB free)"
+ driveList.append(tr("%1: Phone mem. (%L2 MB)"
).arg(volume).arg(size/KSifUiMega));
} else {
//: Drive name for internal phone memory with kilobytes of free space.
@@ -457,10 +501,11 @@
//TODO: enable when available
//driveList.append(hbTrId("txt_installer_device_memory_kb")
// .arg(volume).arg(size/KSifUiKilo));
- driveList.append(tr("%1: Device (%L2 kB free)"
+ driveList.append(tr("%1: Phone mem. (%L2 kB)"
).arg(volume).arg(size/KSifUiKilo));
}
break;
+
case EMassStorage:
if (size > KSifUiMega) {
//: Drive name for mass storage with megabytes of free space.
@@ -469,7 +514,7 @@
// TODO: enable when available
//driveList.append(hbTrId("txt_installer_mass_storage_mb")
// .arg(volume).arg(size/KSifUiMega));
- driveList.append(tr("%1: Mass.mem (%L2 MB free)"
+ driveList.append(tr("%1: Mass.mem (%L2 MB)"
).arg(volume).arg(size/KSifUiMega));
} else {
//: Drive name for mass storage with kilobytes of free space.
@@ -478,10 +523,11 @@
// TODO: enable when available
//driveList.append(hbTrId("txt_installer_mass_storage_kb")
// .arg(volume).arg(size/KSifUiKilo));
- driveList.append(tr("%1: Mass.mem (%L2 kB free)"
+ driveList.append(tr("%1: Mass.mem (%L2 kB)"
).arg(volume).arg(size/KSifUiKilo));
}
break;
+
case EMemoryCard:
if (size > KSifUiMega) {
//: Drive name for memory card with megabytes of free space.
@@ -490,7 +536,7 @@
// TODO: enable when available
//driveList.append(hbTrId("txt_installer_memory_card_mb")
// .arg(volume).arg(size/KSifUiMega));
- driveList.append(tr("%1: Mem.card (%L2 MB free)"
+ driveList.append(tr("%1: Mem.card (%L2 MB)"
).arg(volume).arg(size/KSifUiMega));
} else {
//: Drive name for memory card with kilobytes of free space.
@@ -499,21 +545,47 @@
// TODO: enable when available
//driveList.append(hbTrId("txt_installer_memory_card_kb")
// .arg(volume).arg(size/KSifUiKilo));
- driveList.append(tr("%1: Mem.card (%L2 kB free)"
+ driveList.append(tr("%1: Mem.card (%L2 kB)"
).arg(volume).arg(size/KSifUiKilo));
}
break;
+
+ case EOtherDrive:
default:
+ if (size > KSifUiMega) {
+ //: Generic drive name for other removable drives, like
+ //: USB memories attached via USB OTG adapter.
+ // TODO: proper localisation needed
+ driveList.append(tr("%1: Drive (%L2 MB)"
+ ).arg(volume).arg(size/KSifUiMega));
+ } else {
+ //: Generic drive name for other removable drives, like
+ //: USB memories attached via USB OTG adapter.
+ // TODO: proper localisation needed
+ driveList.append(tr("%1: Drive (%L2 kB)"
+ ).arg(volume).arg(size/KSifUiKilo));
+ }
break;
}
+
+ if (driveLetter == defaultDrive) {
+ defaultDriveIndex = driveList.count() - 1;
+ }
}
}
+ disconnect(mMemorySelection, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(handleMemorySelectionChange(int)));
mMemorySelection->setItems(driveList);
+ if (defaultDriveIndex) {
+ FLOG2("SifUiDialogContentWidget::updateMemorySelection, setCurrentIndex",
+ defaultDriveIndex);
+ mMemorySelection->setCurrentIndex(defaultDriveIndex);
+ }
+ connect(mMemorySelection, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(handleMemorySelectionChange(int)));
mStackedWidget->setCurrentWidget(mMemorySelection);
- // TODO: set selected item, read the default from cenrep
-
return true;
}
return false;
@@ -532,9 +604,12 @@
}
if (parameters.contains(KSifUiProgressNoteValue)) {
int newValue = mProgressBar->progressValue();
- newValue += parameters.value(KSifUiProgressNoteValue).toInt();
- mProgressBar->setProgressValue(newValue);
- progressBarChanged = true;
+ bool ok = false;
+ newValue += parameters.value(KSifUiProgressNoteValue).toInt(&ok);
+ if (ok) {
+ mProgressBar->setProgressValue(newValue);
+ progressBarChanged = true;
+ }
}
if (progressBarChanged) {
mStackedWidget->setCurrentWidget(mProgressBar);
@@ -548,16 +623,9 @@
//
bool SifUiDialogContentWidget::updateErrorText(const QVariantMap ¶meters)
{
- if (parameters.contains(KSifUiErrorCode)) {
- // TODO: proper error texts
- bool ok = false;
- int errorCode = parameters.value(KSifUiErrorCode).toInt(&ok);
- QString errorText;
- if (ok) {
- errorText = tr("Error %1").arg(errorCode);
- } else {
- errorText = tr("No error code.");
- }
+ // TODO: move default error messages (category based) here
+ if (parameters.contains(KSifUiErrorMessage)) {
+ QString errorText = parameters.value(KSifUiErrorMessage).toString();
mErrorText->setPlainText(errorText);
mStackedWidget->setCurrentWidget(mErrorText);
return true;
@@ -565,5 +633,45 @@
return false;
}
+// ----------------------------------------------------------------------------
+// SifUiDialogContentWidget::saveSelectedDriveAsDefault()
+// ----------------------------------------------------------------------------
+//
+void SifUiDialogContentWidget::saveSelectedDriveAsDefault(const QChar& drive)
+{
+ if (drive != readDefaultSelectedDrive()) {
+ if (!mPublisher) {
+ mPublisher = new QValueSpacePublisher(KSifUiCenRepPath, this);
+ }
+ FLOG2("SifUiDialogContentWidget::saveSelectedDriveAsDefault", drive);
+ // QValueSpacePublisher supports integer and byte array types in Symbian
+ int asciiValue = drive.toAscii();
+ mPublisher->setValue(KSifUiCenRepDefaultDrive, asciiValue);
+ mPublisher->sync();
+ }
+}
+// ----------------------------------------------------------------------------
+// SifUiDialogContentWidget::readDefaultSelectedDrive()
+// ----------------------------------------------------------------------------
+//
+QChar SifUiDialogContentWidget::readDefaultSelectedDrive()
+{
+ QChar selectedDrive = KInitialDefaultDrive;
+ if (!mSubscriber) {
+ mSubscriber = new QValueSpaceSubscriber(KSifUiCenRepPath, this);
+ }
+ QVariant variant = mSubscriber->value(KSifUiCenRepDefaultDrive);
+ if (variant.isValid() && !variant.isNull()) {
+ bool ok = false;
+ int asciiValue = variant.toInt(&ok);
+ if (ok) {
+ selectedDrive = QChar(asciiValue);
+ }
+ }
+
+ FLOG2("SifUiDialogContentWidget::readDefaultSelectedDrive", selectedDrive);
+ return selectedDrive;
+}
+