appinstall_plat/appmngr2runtimeapi/src/appmngr2infoiterator.cpp
changeset 0 ba25891c3a9e
child 25 98b66e4fb0be
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2008-2009 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:   Implements MCUIInfoIterator API for CCUIDetailsDialog
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "appmngr2infoiterator.h"       // CAppMngr2InfoIterator
       
    20 #include "appmngr2infobase.h"           // CAppMngr2InfoBase
       
    21 #include <badesca.h>                    // CDesC8Array
       
    22 #include <StringLoader.h>               // StringLoader
       
    23 #include <appmngr2.rsg>                 // Resource IDs
       
    24 #include <SWInstCommonUI.rsg>           // Resource IDs
       
    25 
       
    26 const TInt KGranularity = 8;
       
    27 
       
    28 
       
    29 // ======== MEMBER FUNCTIONS ========
       
    30 
       
    31 // ---------------------------------------------------------------------------
       
    32 // CAppMngr2InfoIterator::CAppMngr2InfoIterator()
       
    33 // ---------------------------------------------------------------------------
       
    34 //
       
    35 EXPORT_C CAppMngr2InfoIterator::CAppMngr2InfoIterator( CAppMngr2InfoBase& aInfo,
       
    36         TAppMngr2InfoType aInfoType ) : iInfo( aInfo ), iInfoType( aInfoType )
       
    37     {
       
    38     }
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 // CAppMngr2InfoIterator::BaseConstructL()
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 EXPORT_C void CAppMngr2InfoIterator::BaseConstructL()
       
    45     {
       
    46     iKeys = new ( ELeave ) CDesCArrayFlat( KGranularity );
       
    47     iValues = new ( ELeave ) CDesCArrayFlat( KGranularity );
       
    48     SetAllFieldsL();
       
    49     }
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // CAppMngr2InfoIterator::~CAppMngr2InfoIterator()
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 EXPORT_C CAppMngr2InfoIterator::~CAppMngr2InfoIterator()
       
    56     {
       
    57     if( iKeys )
       
    58         {
       
    59         iKeys->Reset();
       
    60         delete iKeys;
       
    61         }
       
    62     if( iValues )
       
    63         {
       
    64         iValues->Reset();
       
    65         delete iValues;
       
    66         }
       
    67     }
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 // CAppMngr2InfoIterator::HasNext()
       
    71 // ---------------------------------------------------------------------------
       
    72 //
       
    73 EXPORT_C TBool CAppMngr2InfoIterator::HasNext() const
       
    74     {
       
    75     TInt keysCount = iKeys->Count();
       
    76     return ( keysCount > 0 && keysCount > iCurrentIndex );
       
    77     }
       
    78 
       
    79 // ---------------------------------------------------------------------------
       
    80 // CAppMngr2InfoIterator::Next()
       
    81 // ---------------------------------------------------------------------------
       
    82 //
       
    83 EXPORT_C void CAppMngr2InfoIterator::Next( TPtrC& aKey, TPtrC& aValue )
       
    84     {
       
    85     aKey.Set( ( *iKeys )[ iCurrentIndex ] );
       
    86     aValue.Set( ( *iValues )[ iCurrentIndex ] );
       
    87     iCurrentIndex++;
       
    88     }
       
    89 
       
    90 // ---------------------------------------------------------------------------
       
    91 // CAppMngr2InfoIterator::Reset()
       
    92 // ---------------------------------------------------------------------------
       
    93 //
       
    94 EXPORT_C void CAppMngr2InfoIterator::Reset()
       
    95     {
       
    96     iCurrentIndex = 0;
       
    97     }
       
    98 
       
    99 // ---------------------------------------------------------------------------
       
   100 // CAppMngr2InfoIterator::SetFieldL()
       
   101 // ---------------------------------------------------------------------------
       
   102 //
       
   103 EXPORT_C void CAppMngr2InfoIterator::SetFieldL( TInt aResourceId, const TDesC& aValue )
       
   104     {
       
   105     HBufC* fieldName = StringLoader::LoadLC( aResourceId );
       
   106     iKeys->AppendL( fieldName->Des() );
       
   107     CleanupStack::PopAndDestroy( fieldName );
       
   108     iValues->AppendL( aValue );
       
   109     }
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 // CAppMngr2InfoIterator::SetAllFieldsL()
       
   113 // ---------------------------------------------------------------------------
       
   114 //
       
   115 EXPORT_C void CAppMngr2InfoIterator::SetAllFieldsL()
       
   116     {
       
   117     SetFieldL( R_SWCOMMON_DETAIL_NAME, iInfo.Name() );
       
   118     SetStatusL();
       
   119     SetLocationL();
       
   120     SetFieldL( R_SWCOMMON_DETAIL_APPSIZE, iInfo.Details() );
       
   121     SetOtherFieldsL();
       
   122     }
       
   123 
       
   124 // ---------------------------------------------------------------------------
       
   125 // CAppMngr2InfoIterator::SetStatusL()
       
   126 // ---------------------------------------------------------------------------
       
   127 //
       
   128 EXPORT_C void CAppMngr2InfoIterator::SetStatusL()
       
   129     {
       
   130     HBufC* status = NULL;
       
   131     if( iInfoType == EAppMngr2StatusInstalled )
       
   132         {
       
   133         status = StringLoader::LoadLC( R_SWCOMMON_DETAIL_VALUE_INSTALLED );
       
   134         }
       
   135     else // iInfoType is EAppMngr2StatusNotInstalled
       
   136         {
       
   137         status = StringLoader::LoadLC( R_SWCOMMON_DETAIL_VALUE_NOT_INSTALLED );
       
   138         }
       
   139     SetFieldL( R_SWCOMMON_DETAIL_STATUS, *status );
       
   140     CleanupStack::PopAndDestroy( status );
       
   141     }
       
   142 
       
   143 // ---------------------------------------------------------------------------
       
   144 // CAppMngr2InfoIterator::SetLocationL()
       
   145 // ---------------------------------------------------------------------------
       
   146 //
       
   147 EXPORT_C void CAppMngr2InfoIterator::SetLocationL()
       
   148     {
       
   149     TChar driveChar;
       
   150     RFs::DriveToChar( iInfo.LocationDrive(), driveChar );
       
   151     const TInt KSingleLetter = 1;
       
   152     TBuf<KSingleLetter> driveLetter;
       
   153     driveLetter.Append( driveChar );
       
   154 
       
   155     HBufC* memory = NULL;
       
   156     if( iInfo.Location() == EAppMngr2LocationMemoryCard )
       
   157         {
       
   158         memory = StringLoader::LoadLC( R_SWCOMMON_DETAIL_VALUE_MMC, driveLetter );
       
   159         }
       
   160     else if( iInfo.Location() == EAppMngr2LocationMassStorage )
       
   161         {
       
   162         memory = StringLoader::LoadLC( R_SWCOMMON_DETAIL_VALUE_MASS_STORAGE, driveLetter );
       
   163         }
       
   164     else
       
   165         {
       
   166         memory = StringLoader::LoadLC( R_SWCOMMON_DETAIL_VALUE_DEVICE, driveLetter );
       
   167         }
       
   168     SetFieldL( R_SWCOMMON_DETAIL_LOCATION, *memory );
       
   169     CleanupStack::PopAndDestroy( memory );
       
   170     }
       
   171 
       
   172 // ---------------------------------------------------------------------------
       
   173 // CAppMngr2InfoIterator::SetOtherFieldsL()
       
   174 // ---------------------------------------------------------------------------
       
   175 //
       
   176 EXPORT_C void CAppMngr2InfoIterator::SetOtherFieldsL()
       
   177     {
       
   178     // empty default implementation
       
   179     }
       
   180