contentstorage/casoftwareregistry/s60/src/casoftwareregistry_p.cpp
changeset 98 d2f833ab7940
parent 96 5d243a69bdda
child 99 7aaf39b772ac
--- a/contentstorage/casoftwareregistry/s60/src/casoftwareregistry_p.cpp	Tue Jun 01 11:30:17 2010 +0300
+++ b/contentstorage/casoftwareregistry/s60/src/casoftwareregistry_p.cpp	Fri Jun 11 16:13:51 2010 +0300
@@ -14,10 +14,10 @@
  * Description:  ?Description
  *
  */
-#include <QtGlobal>
+#include <HbParameterLengthLimiter>
 #include <QMetaType>
 #include <QScopedPointer>
-#include <QString>
+#include <QStringList>
 
 #include <usif/scr/scr.h>
 #include <usif/scr/screntries.h>
@@ -29,6 +29,8 @@
 
 using namespace Usif;
 
+_LIT(KConfirmMessageKey, "MIDlet-Delete-Confirm");
+
 template <typename RClass>
 struct RClassDeleter
 {
@@ -61,6 +63,140 @@
 }
 
 /*!
+ Provides details needed for uninstalling process of Java applications.
+ \param[in] componentId component id of an application to be uninstalled.
+ \param[out] componentName a name of the component.
+ \param[out] applicationsUids a list of uids of applications in the package
+      of the given component id.
+ \param[out] confirmationMessage optional deletion confirmation message,
+      null string means the lack of the message.
+ \retval true if there is no error.
+ */
+
+bool CaSoftwareRegistryPrivate::getUninstallDetails(int componentId,
+    QString &componentName,
+    QStringList &applicationsUids,
+    QString &confirmationMessage)
+{
+    TRAPD(error, getUninstallDetailsL(componentId,
+        componentName,
+        applicationsUids,
+        confirmationMessage)
+         );
+    return error == KErrNone;
+}
+
+/*!
+ Provides a list of uids of applications installed by the given package.
+ \param[in] componentId component id of an application to be uninstalled.
+ \param[out] applicationsUids a list of uids of applications in the package
+      of the given component id.
+ \retval true if there is no error.
+ */
+
+bool CaSoftwareRegistryPrivate::getApplicationsUids(int componentId,
+    QStringList &applicationsUids)
+{
+    TRAPD(error, getApplicationsUidsL(componentId, applicationsUids));
+    return error == KErrNone;
+}
+
+/*!
+ Provides details needed for uninstalling process of Java applications
+   (leaving version).
+ \param[in] componentId component id of an application to be uninstalled.
+ \param[out] componentName a name of the component.
+ \param[out] applicationsUids a list of uids of applications in the package
+      of the given component id.
+ \param[out] confirmationMessage optional deletion confirmation message,
+      null string means the lack of the message.
+ */
+void CaSoftwareRegistryPrivate::getUninstallDetailsL(int componentId,
+    QString &componentName,
+    QStringList &appUids,
+    QString &confirmationMessage)
+{
+    componentName.clear();
+    appUids.clear();
+    confirmationMessage.clear();
+
+    if (componentId >= 1) {
+        TComponentId componentIdValue(componentId);
+        RArray<TUid> appUidsArray;
+        CleanupClosePushL(appUidsArray);
+        CLocalizablePropertyEntry *confirmationMessageProperty = NULL;
+
+        RSoftwareComponentRegistry softwareComponentRegistry;
+        CleanupClosePushL(softwareComponentRegistry);
+        User::LeaveIfError(softwareComponentRegistry.Connect());
+
+        CComponentEntry *entry = CComponentEntry::NewLC();
+        softwareComponentRegistry.GetComponentL(componentId, *entry);
+        softwareComponentRegistry.GetAppUidsForComponentL(componentIdValue,
+            appUidsArray);
+
+        CPropertyEntry *confirmationProperty =
+            softwareComponentRegistry.GetComponentPropertyL(componentId,
+            KConfirmMessageKey);
+        if (confirmationProperty &&
+            confirmationProperty->PropertyType() ==
+                CPropertyEntry::ELocalizedProperty) {
+            confirmationMessageProperty =
+                static_cast<CLocalizablePropertyEntry *>(
+                    confirmationProperty);
+        } else {
+            delete confirmationProperty;
+            confirmationProperty = NULL;
+        }
+
+        QT_TRYCATCH_LEAVING(componentName =
+            XQConversions::s60DescToQString(entry->Name());
+            for (TInt i = 0; i<appUidsArray.Count(); i++) {
+                appUids.append(QString::number(appUidsArray[i].iUid));
+            }
+            if (confirmationMessageProperty) {
+                confirmationMessage = XQConversions::s60DescToQString(
+                    confirmationMessageProperty->StrValue());
+            }
+        );
+
+        CleanupStack::PopAndDestroy(3, &appUidsArray);
+    }
+}
+
+/*!
+ Provides details needed for uninstalling process of Java applications
+   (leaving version).
+ \param[in] componentId component id of an application to be uninstalled.
+ \param[out] applicationsUids a list of uids of applications in the package
+      of the given component id.
+ */
+void CaSoftwareRegistryPrivate::getApplicationsUidsL(int componentId,
+    QStringList &appUids)
+{
+    appUids.clear();
+    if (componentId >= 1) {
+        TComponentId componentIdValue(componentId);
+        RArray<TUid> appUidsArray;
+        CleanupClosePushL(appUidsArray);
+
+        RSoftwareComponentRegistry softwareComponentRegistry;
+        CleanupClosePushL(softwareComponentRegistry);
+        User::LeaveIfError(softwareComponentRegistry.Connect());
+
+        softwareComponentRegistry.GetAppUidsForComponentL(componentIdValue,
+            appUidsArray);
+
+        QT_TRYCATCH_LEAVING(
+            for (TInt i = 0; i<appUidsArray.Count(); i++) {
+                appUids.append(QString::number(appUidsArray[i].iUid));
+            }
+        );
+        CleanupStack::PopAndDestroy(2, &appUidsArray);
+    }
+}
+
+/*!
  \param componentId Component id of the entry which details are requested for.
  \return Map of component details if component id was greater than 0 or
  empty map otherwise. 
@@ -73,13 +209,18 @@
     if (componentId >= 1) {
         RSoftwareComponentRegistry softwareComponentRegistry;
         ScrScopedPointer scr(&softwareComponentRegistry);
-        QT_TRAP_THROWING(User::LeaveIfError(scr->Connect()));
-        
-        QScopedPointer<CComponentEntry> entry;
-        
-        QT_TRAP_THROWING(entry.reset(CComponentEntry::NewL()));
-        QT_TRAP_THROWING(scr->GetComponentL(componentId, *entry));
-        result = entryDetails(*entry);
+        if (scr->Connect() == KErrNone) {
+            
+            QScopedPointer<CComponentEntry> entry;
+            
+            QT_TRAP_THROWING(entry.reset(CComponentEntry::NewL()));
+            
+            TBool resultCode = EFalse;
+            TRAPD(leaveCode, resultCode = scr->GetComponentL(componentId, *entry));
+            if (leaveCode == KErrNone && resultCode) {
+                result = entryDetails(*entry);
+            }
+        }
     }
     
     return result;
@@ -104,7 +245,8 @@
         XQConversions::s60DescToQString(entry.Vendor());
         
     QString drives;
-    TChar drive;
+    QString drv;
+    TChar drive;    
     
     const TInt driveListLen(entry.InstalledDrives().Length());
     for (TInt i( 0 ); i < driveListLen; ++i) {
@@ -112,50 +254,70 @@
             
             if (!drives.isEmpty()) {
                 drives = drives.append(",");
-             }  
-            
-            if(DriveInfo::GetDefaultDrive(DriveInfo::EDefaultPhoneMemory, drive ) == KErrNone 
+            }  
+            drv = QString(QChar('A'+ i)).append(":");
+            if(DriveInfo::GetDefaultDrive(
+                    DriveInfo::EDefaultPhoneMemory, drive ) == KErrNone 
                     && QChar('A'+ i) == QChar(drive))
                 {
-                drives = drives.append(QChar('A'+ i)).append(":").append(
-                        " txt_applib_dialog_1_device_memory");
+                drives = drives.append(
+                        HbParameterLengthLimiter("txt_applib_dialog_1_device_memory").arg(
+                          QString(QChar('A'+ i)).append(":")));
                 }
-            else if(DriveInfo::GetDefaultDrive(DriveInfo::EDefaultMassStorage, drive ) == KErrNone 
+            else if(DriveInfo::GetDefaultDrive(
+                    DriveInfo::EDefaultMassStorage, drive ) == KErrNone 
                     && QChar('A'+ i) == QChar(drive))
                 {
-                drives = drives.append(QChar('A'+ i)).append(":").append(
-                        " txt_applib_dialog_1_mass_storage");
+                drives = drives.append(
+                        HbParameterLengthLimiter("txt_applib_dialog_1_mass_storage").arg(
+                          QString(QChar('A'+ i)).append(":")));
                 }
-            else if(DriveInfo::GetDefaultDrive(DriveInfo::EDefaultRemovableMassStorage, drive ) == KErrNone 
+            else if(DriveInfo::GetDefaultDrive(
+                    DriveInfo::EDefaultRemovableMassStorage, drive ) == KErrNone 
                     && QChar('A'+ i) == QChar(drive))
                 {
                 RFs fs;
                 RFSScopedPointer fSPointer(&fs);
-                qt_symbian_throwIfError(fs.Connect());
-
-                TInt driveNumber;
-                TVolumeInfo tv;
-                DriveInfo::GetDefaultDrive(DriveInfo::EDefaultRemovableMassStorage, driveNumber );
-                
-                qt_symbian_throwIfError(fs.Volume(tv, driveNumber));
-                if(tv.iName.Length()) {
-                    drives = drives.append(QChar('A'+ i)).append(": ").append(
-                                XQConversions::s60DescToQString(tv.iName));                
+                if (fs.Connect() == KErrNone) {
+                    TInt driveNumber;
+                    TVolumeInfo tv;
+                    DriveInfo::GetDefaultDrive(
+                            DriveInfo::EDefaultRemovableMassStorage, driveNumber );
+                    qt_symbian_throwIfError(fs.Volume(tv, driveNumber));
+                    if(tv.iName.Length()) { 
+                        drives = drives.append(
+                                HbParameterLengthLimiter("txt_applib_dialog_1_2").arg(
+                                   QString(QChar('A'+ i)).append(":")).arg(
+                                           XQConversions::s60DescToQString(tv.iName)));                       
+                    }
+                    else {
+                        drives = drives.append(
+                            HbParameterLengthLimiter("txt_applib_dialog_1_memory_card").arg(
+                              QString(QChar('A'+ i)).append(":")));           
+                    }
                 }
-                else {
-                    drives = drives.append(QChar('A'+ i)).append(":").append(
-                        " txt_applib_dialog_1_memory_card");                
-                }
-            }
-            else {
+            } else {
                 drives = drives.append(QChar('A'+ i)).append(":");   
             }
         }
     }
     
     detailMap[CaSoftwareRegistry::componentDriveInfoKey()] = drives;
-    detailMap[CaSoftwareRegistry::componentSizeKey()].setNum(
-        entry.ComponentSize() / 1024);
+    
+
+    static const TInt64 KKilo = 1024;
+    static const TInt64 KMega = KKilo * KKilo;
+    if(entry.ComponentSize() >= KMega) {
+        detailMap[CaSoftwareRegistry::componentSizeKey()] = 
+            HbParameterLengthLimiter("txt_applib_dialog_l1_mb").arg(QString().setNum(
+                    static_cast<double>(entry.ComponentSize() / KMega)));
+    }
+    else {
+        detailMap[CaSoftwareRegistry::componentSizeKey()] = 
+            HbParameterLengthLimiter("txt_applib_dialog_l1_kb").arg(QString().setNum(
+                    static_cast<double>(entry.ComponentSize() / KKilo)));
+    }
+
     
     detailMap[CaSoftwareRegistry::componentTypeKey()] = 
         XQConversions::s60DescToQString(entry.SoftwareType());