contentstorage/casoftwareregistry/s60/src/casoftwareregistry_p.cpp
changeset 102 8b8b34fa9751
parent 99 7aaf39b772ac
child 106 e78d6e055a5b
--- a/contentstorage/casoftwareregistry/s60/src/casoftwareregistry_p.cpp	Tue Jun 29 10:20:30 2010 +0300
+++ b/contentstorage/casoftwareregistry/s60/src/casoftwareregistry_p.cpp	Fri Jul 09 14:19:08 2010 +0300
@@ -15,42 +15,35 @@
  *
  */
 #include <HbParameterLengthLimiter>
+#include <HbExtendedLocale>
 #include <QMetaType>
 #include <QScopedPointer>
 #include <QStringList>
-
+#include <QDateTime>
+#undef SYMBIAN_ENABLE_SPLIT_HEADERS //TODO this is work around
+#include <usif/scr/screntries.h>
 #include <usif/scr/scr.h>
-#include <usif/scr/screntries.h>
 #include <xqconversions.h>
 #include <driveinfo.h>
 
 #include "casoftwareregistry.h"
 #include "casoftwareregistry_p.h"
+#include "cadefs.h"
+#include "caarraycleanup.inl"
 
 using namespace Usif;
 
 _LIT(KConfirmMessageKey, "MIDlet-Delete-Confirm");
+_LIT(KCaScrPropertyDomainCategory, "Domain-Category");
+_LIT(KCaScrPropertyMidletDescryption, "MIDlet-Description");
+const int maxLogsCount = 20;
 
-template <typename RClass>
-struct RClassDeleter
-{
-    static inline void cleanup(RClass *ptr)
-    {
-        ptr->Close();
-    }
-};
-
-typedef QScopedPointer<RSoftwareComponentRegistry, 
-    RClassDeleter<RSoftwareComponentRegistry> > ScrScopedPointer;
-    
-typedef QScopedPointer<RFs, 
-    RClassDeleter<RFs> > RFSScopedPointer;
 /*!
  Constructor
  \param servicePublic Pointer to object of the public class.
  */
 CaSoftwareRegistryPrivate::CaSoftwareRegistryPrivate(
-    CaSoftwareRegistry *servicePublic):
+        CaSoftwareRegistry *servicePublic):
     m_q(servicePublic)
 {
 }
@@ -74,15 +67,15 @@
  */
 
 bool CaSoftwareRegistryPrivate::getUninstallDetails(int componentId,
-    QString &componentName,
-    QStringList &applicationsUids,
-    QString &confirmationMessage)
+        QString &componentName,
+        QStringList &applicationsUids,
+        QString &confirmationMessage)
 {
     TRAPD(error, getUninstallDetailsL(componentId,
-        componentName,
-        applicationsUids,
-        confirmationMessage)
-         );
+            componentName,
+            applicationsUids,
+            confirmationMessage)
+             );
     return error == KErrNone;
 }
 
@@ -95,7 +88,7 @@
  */
 
 bool CaSoftwareRegistryPrivate::getApplicationsUids(int componentId,
-    QStringList &applicationsUids)
+        QStringList &applicationsUids)
 {
     TRAPD(error, getApplicationsUidsL(componentId, applicationsUids));
     return error == KErrNone;
@@ -112,9 +105,9 @@
       null string means the lack of the message.
  */
 void CaSoftwareRegistryPrivate::getUninstallDetailsL(int componentId,
-    QString &componentName,
-    QStringList &appUids,
-    QString &confirmationMessage)
+        QString &componentName,
+        QStringList &appUids,
+        QString &confirmationMessage)
 {
     componentName.clear();
     appUids.clear();
@@ -132,18 +125,18 @@
 
         CComponentEntry *entry = CComponentEntry::NewLC();
         softwareComponentRegistry.GetComponentL(componentId, *entry);
-        softwareComponentRegistry.GetAppUidsForComponentL(componentIdValue,
-            appUidsArray);
+        softwareComponentRegistry.GetAppUidsForComponentL(
+                componentIdValue, appUidsArray);
 
-        CPropertyEntry *confirmationProperty =
-            softwareComponentRegistry.GetComponentPropertyL(componentId,
-            KConfirmMessageKey);
-        if (confirmationProperty &&
-            confirmationProperty->PropertyType() ==
-                CPropertyEntry::ELocalizedProperty) {
-            confirmationMessageProperty =
-                static_cast<CLocalizablePropertyEntry *>(
-                    confirmationProperty);
+        CPropertyEntry *confirmationProperty
+                = softwareComponentRegistry.GetComponentPropertyL(
+                        componentId, KConfirmMessageKey);
+        if (confirmationProperty
+                && confirmationProperty->PropertyType()
+                        == CPropertyEntry::ELocalizedProperty) {
+            confirmationMessageProperty
+                    = static_cast<CLocalizablePropertyEntry *>(
+                            confirmationProperty);
         } else {
             delete confirmationProperty;
             confirmationProperty = NULL;
@@ -156,7 +149,7 @@
             }
             if (confirmationMessageProperty) {
                 confirmationMessage = XQConversions::s60DescToQString(
-                    confirmationMessageProperty->StrValue());
+                        confirmationMessageProperty->StrValue());
             }
         );
 
@@ -184,8 +177,8 @@
         CleanupClosePushL(softwareComponentRegistry);
         User::LeaveIfError(softwareComponentRegistry.Connect());
 
-        softwareComponentRegistry.GetAppUidsForComponentL(componentIdValue,
-            appUidsArray);
+        softwareComponentRegistry.GetAppUidsForComponentL(
+                componentIdValue, appUidsArray);
 
         QT_TRYCATCH_LEAVING(
             for (TInt i = 0; i<appUidsArray.Count(); i++) {
@@ -199,30 +192,71 @@
 /*!
  \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. 
+ empty map otherwise.
  */
 CaSoftwareRegistryPrivate::DetailMap CaSoftwareRegistryPrivate::entryDetails(
     int componentId) const
 {
     CaSoftwareRegistry::DetailMap result;
+    TRAP_IGNORE(result=entryDetailsL(componentId));
+    return result;
+}
+
+/*!
+ \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.
+ */
+CaSoftwareRegistryPrivate::DetailMap CaSoftwareRegistryPrivate::entryDetailsL(
+    int componentId) const
+{
+    CaSoftwareRegistry::DetailMap result;
 
     if (componentId >= 1) {
-        RSoftwareComponentRegistry softwareComponentRegistry;
-        ScrScopedPointer scr(&softwareComponentRegistry);
-        if (scr->Connect() == KErrNone) {
-            
-            QScopedPointer<CComponentEntry> entry;
-            
-            QT_TRAP_THROWING(entry.reset(CComponentEntry::NewL()));
-            
+        RSoftwareComponentRegistry scr;
+        CleanupClosePushL(scr);
+        if (scr.Connect() == KErrNone) {
+            CComponentEntry* entry = CComponentEntry::NewLC();
+
             TBool resultCode = EFalse;
-            TRAPD(leaveCode, resultCode = scr->GetComponentL(componentId, *entry));
-            if (leaveCode == KErrNone && resultCode) {
-                result = entryDetails(*entry);
+            resultCode = scr.GetComponentL(componentId, *entry);
+            if ( resultCode) {
+                result = entryDetailsL(*entry);
             }
+
+            if (entry->SoftwareType().Compare(KSoftwareTypeJava) == 0) {
+                CPropertyEntry* domainProperty =
+                    scr.GetComponentPropertyL(componentId,
+                        KCaScrPropertyDomainCategory);
+                CleanupStack::PushL(domainProperty);
+                if (domainProperty &&
+                    domainProperty->PropertyType() ==
+                        CPropertyEntry::ELocalizedProperty) {
+                    result[CaSoftwareRegistry::componentProtectionDomainKey()] =
+                        XQConversions::s60DescToQString(
+                            static_cast<CLocalizablePropertyEntry*>(
+                                domainProperty)->StrValue());
+                }
+
+                CPropertyEntry *midletDescryption =
+                    scr.GetComponentPropertyL(componentId,
+                        KCaScrPropertyMidletDescryption);
+                CleanupStack::PushL(midletDescryption);
+                if (midletDescryption &&
+                    midletDescryption->PropertyType() ==
+                        CPropertyEntry::ELocalizedProperty) {
+                    result[CaSoftwareRegistry::componentDescriptionKey()] =
+                        XQConversions::s60DescToQString(
+                            static_cast<CLocalizablePropertyEntry*>(
+                                midletDescryption)->StrValue());
+                }
+                CleanupStack::PopAndDestroy(midletDescryption);
+                CleanupStack::PopAndDestroy(domainProperty);
+            }
+            CleanupStack::PopAndDestroy(entry);
         }
+        CleanupStack::PopAndDestroy(&scr);
     }
-    
     return result;
 }
 
@@ -230,97 +264,182 @@
  \param entry Software registry entry providing details.
  \return Map with details for the component represented by \entry.
  */
-CaSoftwareRegistryPrivate::DetailMap CaSoftwareRegistryPrivate::entryDetails(
+CaSoftwareRegistryPrivate::DetailMap CaSoftwareRegistryPrivate::entryDetailsL(
     const CComponentEntry& entry) const
 {
     CaSoftwareRegistry::DetailMap detailMap;
-    
-    detailMap[CaSoftwareRegistry::componentNameKey()] = 
+
+    detailMap[CaSoftwareRegistry::componentNameKey()] =
         XQConversions::s60DescToQString(entry.Name());
-        
-    detailMap[CaSoftwareRegistry::componentVersionKey()] = 
+
+    detailMap[CaSoftwareRegistry::componentVersionKey()] =
         XQConversions::s60DescToQString(entry.Version());
-    
-    detailMap[CaSoftwareRegistry::componentVendorKey()] = 
+
+    detailMap[CaSoftwareRegistry::componentVendorKey()] =
         XQConversions::s60DescToQString(entry.Vendor());
-        
+
     QString drives;
     QString drv;
-    TChar drive;    
-    
+    TChar drive;
+
     const TInt driveListLen(entry.InstalledDrives().Length());
     for (TInt i( 0 ); i < driveListLen; ++i) {
         if (entry.InstalledDrives()[i] != '\0') {
-            
+
             if (!drives.isEmpty()) {
                 drives = drives.append(",");
-            }  
+            }
             drv = QString(QChar('A'+ i)).append(":");
             if(DriveInfo::GetDefaultDrive(
-                    DriveInfo::EDefaultPhoneMemory, drive ) == KErrNone 
-                    && QChar('A'+ i) == QChar(drive))
-                {
-                drives = drives.append(
-                        HbParameterLengthLimiter("txt_applib_dialog_1_device_memory").arg(
-                          QString(QChar('A'+ i))));
-                }
-            else if(DriveInfo::GetDefaultDrive(
-                    DriveInfo::EDefaultMassStorage, drive ) == KErrNone 
-                    && QChar('A'+ i) == QChar(drive))
-                {
-                drives = drives.append(
-                        HbParameterLengthLimiter("txt_applib_dialog_1_mass_storage").arg(
-                          QString(QChar('A'+ i))));
-                }
-            else if(DriveInfo::GetDefaultDrive(
-                    DriveInfo::EDefaultRemovableMassStorage, drive ) == KErrNone 
-                    && QChar('A'+ i) == QChar(drive))
-                {
+                    DriveInfo::EDefaultPhoneMemory, drive ) == KErrNone
+                    && QChar('A'+ i) == QChar(drive)) {
+                drives = drives.append(HbParameterLengthLimiter(
+                        "txt_applib_dialog_1_device_memory").arg(
+                                QString(QChar('A'+ i))));
+            } else if(DriveInfo::GetDefaultDrive(
+                    DriveInfo::EDefaultMassStorage, drive ) == KErrNone
+                    && QChar('A'+ i) == QChar(drive)) {
+                drives = drives.append(HbParameterLengthLimiter(
+                        "txt_applib_dialog_1_mass_storage").arg(
+                                QString(QChar('A'+ i))));
+                } else if(DriveInfo::GetDefaultDrive(
+                    DriveInfo::EDefaultRemovableMassStorage, drive ) == KErrNone
+                    && QChar('A'+ i) == QChar(drive)) {
                 RFs fs;
-                RFSScopedPointer fSPointer(&fs);
+                CleanupClosePushL(fs);
                 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))).arg(
-                                           XQConversions::s60DescToQString(tv.iName)));                       
-                    }
-                    else {
-                        drives = drives.append(
-                            HbParameterLengthLimiter("txt_applib_dialog_1_memory_card").arg(
-                              QString(QChar('A'+ i))));           
+                            DriveInfo::EDefaultRemovableMassStorage,
+                            driveNumber );
+                    User::LeaveIfError(fs.Volume(tv, driveNumber));
+                    if(tv.iName.Length()) {
+                        drives = drives.append(HbParameterLengthLimiter(
+                                "txt_applib_dialog_1_2").arg(
+                                        QString(QChar('A'+ i))).arg(
+                                                XQConversions::s60DescToQString(
+                                                        tv.iName)));
+                    } else {
+                        drives = drives.append(HbParameterLengthLimiter(
+                                "txt_applib_dialog_1_memory_card").arg(
+                                        QString(QChar('A'+ i))));
                     }
                 }
+                CleanupStack::PopAndDestroy(&fs);
             } else {
-                drives = drives.append(QChar('A'+ i)).append(":");   
+                drives = drives.append(QChar('A'+ i)).append(":");
             }
         }
     }
-    
     detailMap[CaSoftwareRegistry::componentDriveInfoKey()] = drives;
-    
 
     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(
-                    static_cast<double>(entry.ComponentSize() / KMega));
+        detailMap[CaSoftwareRegistry::componentSizeKey()]
+                  = HbParameterLengthLimiter("txt_applib_dialog_l1_mb").arg(
+                          static_cast<double>(entry.ComponentSize() / KMega));
+    } else {
+        detailMap[CaSoftwareRegistry::componentSizeKey()]
+                  = HbParameterLengthLimiter("txt_applib_dialog_l1_kb").arg(
+                          static_cast<double>(entry.ComponentSize() / KKilo));
     }
-    else {
-        detailMap[CaSoftwareRegistry::componentSizeKey()] = 
-            HbParameterLengthLimiter("txt_applib_dialog_l1_kb").arg(
-                    static_cast<double>(entry.ComponentSize() / KKilo));
-    }
-
-    
-    detailMap[CaSoftwareRegistry::componentTypeKey()] = 
+    detailMap[CaSoftwareRegistry::componentTypeKey()] =
         XQConversions::s60DescToQString(entry.SoftwareType());
 
     return detailMap;
 }
+
+/*!
+ \param entry Software registry entry providing details.
+ \return Map with details for the component represented by \entry.
+ */
+QList<CaSoftwareRegistryPrivate::DetailMap>
+        CaSoftwareRegistryPrivate::retrieveLogEntries() const
+{
+    QList<CaSoftwareRegistryPrivate::DetailMap> logMap;
+    TRAP_IGNORE(logMap = retrieveLogEntriesL());
+    return logMap;
+}
+
+/*!
+ \param entry Software registry entry providing installation log.
+ \return List of Maps with installation log.
+ */
+QList<CaSoftwareRegistryPrivate::DetailMap>
+        CaSoftwareRegistryPrivate::retrieveLogEntriesL() const
+{
+    QList<CaSoftwareRegistryPrivate::DetailMap> logList;
+
+    RSoftwareComponentRegistry scr;
+    CleanupClosePushL(scr);
+    User::LeaveIfError(scr.Connect());
+
+    RPointerArray<CScrLogEntry> logEntries;
+    CleanupResetAndDestroyPushL(logEntries);
+    scr.RetrieveLogEntriesL(logEntries);
+
+    // 50 log items or less - ui spec
+    TInt lastLog(0);
+    if (logEntries.Count() > maxLogsCount) {
+        lastLog = logEntries.Count() - maxLogsCount;
+    }
+    // iteration through most recent log to the last
+    for (TInt i = logEntries.Count() - 1; i >= lastLog; i--) {
+        CScrLogEntry* entry = logEntries[i];
+        DetailMap logMap;
+        logMap[CaSoftwareRegistry::componentNameKey()]
+               = XQConversions::s60DescToQString(entry->ComponentName());
+        logMap[CaSoftwareRegistry::componentVersionKey()]
+               = XQConversions::s60DescToQString(entry->ComponentVersion());
+        logMap[CaSoftwareRegistry::componentTimeKey()]
+               = operationTime(entry->OperationTime());
+        logMap[CaSoftwareRegistry::componentOperationTypeKey()]
+               = operationTypeL(entry->OperationType());
+        logList.append(logMap);
+    }
+    CleanupStack::PopAndDestroy(&logEntries);
+    CleanupStack::PopAndDestroy(&scr);
+
+    return logList;
+}
+
+/*!
+ \param operation type.
+ \return string representing operation type.
+ */
+QString CaSoftwareRegistryPrivate::operationTypeL(int operationType) const
+{
+    QString opType;
+    switch (operationType) {
+        case EScrCompInstall:
+            opType = CaSoftwareRegistry::componentInstallValue();
+            break;
+        case EScrCompUnInstall:
+            opType = CaSoftwareRegistry::componentUninstallValue();
+            break;
+        case EScrCompUpgrade:
+            opType = CaSoftwareRegistry::componentUpgradeValue();
+            break;
+        case EScrCompHidden:
+            opType = CaSoftwareRegistry::componentHiddenValue();
+            break;
+        default:
+            User::Leave(KErrNotSupported);
+            break;
+    }
+    return opType;
+}
+
+/*!
+ \param operation type.
+ \return string representing operation type.
+ */
+QString CaSoftwareRegistryPrivate::operationTime(TTime time) const
+{
+    TDateTime dt = time.DateTime();
+    QDate date(dt.Year(), dt.Month()+1, dt.Day());
+    HbExtendedLocale hbLoc;
+    return hbLoc.format(date, r_qtn_date_usual_with_zero);
+}