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