psln/PslnFramework/src/PslnFWIconHelper.cpp
changeset 37 89c890c70182
parent 34 6b5204869ed5
child 45 667edd0b8678
equal deleted inserted replaced
34:6b5204869ed5 37:89c890c70182
     1 /*
       
     2 * Copyright (c) 2005-2007 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:  Utility class to get icons to setting lists and 
       
    15 *                   help with loc strings.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include "pslnfwiconhelper.h"
       
    23 
       
    24 // Icons
       
    25 #include <AknIconArray.h>
       
    26 #include <gulicon.h>
       
    27 #include <pslnicon.mbg>
       
    28 #include <variatedbitmaps.mbg>
       
    29 #include <data_caging_path_literals.hrh>
       
    30 
       
    31 // Resource loading
       
    32 #include <bautils.h>
       
    33 #include <barsread.h>
       
    34 #include <StringLoader.h>
       
    35 #include <ConeResLoader.h>
       
    36 
       
    37 // Listboxes
       
    38 #include <eikclb.h>
       
    39 #include <eikclbd.h>
       
    40 
       
    41 // Skins
       
    42 #include <AknsUtils.h>
       
    43 #include <aknconsts.h>
       
    44 
       
    45 // CONSTANTS
       
    46 // Location of icon file.
       
    47 _LIT( KPslnFWIconFilename, "z:Pslnicon.mbm" );
       
    48 // Granularity of icon array.
       
    49 const TInt KPslnIconArraySize = 6;
       
    50 
       
    51 // ============================ MEMBER FUNCTIONS ===============================
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // C++ default constructor can NOT contain any code, that might leave.
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 CPslnFWIconHelper::CPslnFWIconHelper()
       
    58     {
       
    59     }
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // Two-phased constructor.
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 EXPORT_C CPslnFWIconHelper* CPslnFWIconHelper::NewL()
       
    66     {
       
    67     CPslnFWIconHelper* self = new( ELeave ) CPslnFWIconHelper;
       
    68     return self;
       
    69     }
       
    70 
       
    71 // Destructor
       
    72 EXPORT_C CPslnFWIconHelper::~CPslnFWIconHelper()
       
    73     {
       
    74     }
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // Adds pre- and post-text icons to setting item lists.
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 EXPORT_C void CPslnFWIconHelper::AddIconsToSettingItemsL( 
       
    81     TBool aAll, TInt aMaxIndexToAdd, CEikTextListBox* aListBox )
       
    82     {
       
    83     // Check that the given parameters are valid.
       
    84     if ( !aAll && aMaxIndexToAdd <= 0 )
       
    85         {
       
    86         User::Leave( KErrArgument );
       
    87         }
       
    88 
       
    89     CAknIconArray* icons =
       
    90         new (ELeave) CAknIconArray( KPslnIconArraySize );
       
    91 
       
    92     CEikColumnListBox* columnListBox =
       
    93         static_cast<CEikColumnListBox*>( aListBox );
       
    94 
       
    95     CArrayPtr<CGulIcon>* previcons =
       
    96         columnListBox->ItemDrawer()->ColumnData()->IconArray();
       
    97     if ( previcons )
       
    98         {
       
    99         previcons->ResetAndDestroy();
       
   100         delete previcons;
       
   101         previcons = NULL;
       
   102         }
       
   103     columnListBox->ItemDrawer()->ColumnData()->SetIconArray( icons );
       
   104     
       
   105     if ( !icons )
       
   106         {
       
   107         return;
       
   108         }
       
   109 
       
   110     TInt bitmapIndex = 0;
       
   111     if ( aAll || aMaxIndexToAdd >= bitmapIndex )
       
   112         {
       
   113         // 0: Non active (empty bitmap)
       
   114         CFbsBitmap *bitmap = new (ELeave) CFbsBitmap;
       
   115         User::LeaveIfError(
       
   116             bitmap->Create( TSize(0, 0), EColor256 ) );
       
   117         icons->AppendL( CGulIcon::NewL( bitmap ) );
       
   118         bitmapIndex++;
       
   119         }
       
   120 
       
   121     HBufC* fileName = HBufC::NewLC( KMaxFileName );
       
   122     TPtr fileNamePtr = fileName->Des();
       
   123     GetIconFilePath( fileNamePtr );
       
   124 
       
   125     if ( aAll || aMaxIndexToAdd >= bitmapIndex )
       
   126         {
       
   127         // 1: Active mark
       
   128         AddIconL( icons,
       
   129             KAknsIIDQgnPropPslnActive,
       
   130             fileNamePtr,
       
   131             EMbmPslniconQgn_prop_psln_active,
       
   132             EMbmPslniconQgn_prop_psln_active_mask );
       
   133         bitmapIndex++;
       
   134         }
       
   135 
       
   136     if ( aAll || aMaxIndexToAdd >= bitmapIndex )
       
   137         {
       
   138         // 2: URL icon (in front of EEL)
       
   139         AddIconL( icons,
       
   140             KAknsIIDQgnPropLinkEmbdSmall,
       
   141             KAvkonVariatedBitmapsFile,
       
   142             EMbmVariatedbitmapsQgn_prop_link_embd_small,
       
   143             EMbmVariatedbitmapsQgn_prop_link_embd_small_mask );
       
   144         bitmapIndex++;
       
   145         }
       
   146 
       
   147     if ( aAll || aMaxIndexToAdd >= bitmapIndex )
       
   148         {
       
   149         // 3: MMC icon
       
   150         AddIconL( icons, 
       
   151             KAknsIIDQgnIndiMmcAdd,
       
   152             fileNamePtr,
       
   153             EMbmPslniconQgn_indi_mmc_add,
       
   154             EMbmPslniconQgn_indi_mmc_add_mask,
       
   155             ETrue );
       
   156         bitmapIndex++;
       
   157         }
       
   158 
       
   159     if ( aAll || aMaxIndexToAdd >= bitmapIndex )
       
   160         {
       
   161         //4: EAknsSrvProtected,
       
   162         AddIconL( icons,
       
   163             KAknsIIDQgnIndiDrmRightsAdd,
       
   164             fileNamePtr,
       
   165             EMbmPslniconQgn_indi_drm_rights_add,
       
   166             EMbmPslniconQgn_indi_drm_rights_add_mask,
       
   167             ETrue );
       
   168         bitmapIndex++;
       
   169         }
       
   170 
       
   171     if ( aAll || aMaxIndexToAdd >= bitmapIndex )
       
   172         {
       
   173         //5: EAknsSrvNoRights
       
   174         AddIconL( icons,
       
   175             KAknsIIDQgnIndiDrmRightsExpAdd,
       
   176             fileNamePtr,
       
   177             EMbmPslniconQgn_indi_drm_rights_exp_add,
       
   178             EMbmPslniconQgn_indi_drm_rights_exp_add_mask,
       
   179             ETrue );
       
   180         bitmapIndex++;
       
   181         }
       
   182 
       
   183     if ( aAll || aMaxIndexToAdd >= bitmapIndex )
       
   184         {
       
   185         //6: EAknsMinorGenericQgnIndiFmgrMsAdd - mass drive 
       
   186         AddIconL( icons,
       
   187             KAknsIIDQgnIndiFmgrMsAdd,
       
   188             fileNamePtr,
       
   189             EMbmPslniconQgn_indi_fmgr_ms_add,
       
   190             EMbmPslniconQgn_indi_fmgr_ms_add_mask,
       
   191             ETrue );
       
   192         bitmapIndex++;
       
   193         }
       
   194     CleanupStack::PopAndDestroy( fileName );
       
   195     }
       
   196 
       
   197 // ---------------------------------------------------------------------------
       
   198 // Retrieves localized string txt.
       
   199 // ---------------------------------------------------------------------------
       
   200 //
       
   201 EXPORT_C HBufC* CPslnFWIconHelper::GetLocalizedStringLC(
       
   202     const TDesC& aPath, TInt aResourceID, CCoeEnv* aCoeEnv )
       
   203     {
       
   204     RConeResourceLoader resLoader( *aCoeEnv );
       
   205     CleanupClosePushL( resLoader );
       
   206     // Open resource file:
       
   207     TFileName* file = new (ELeave) TFileName( aPath );
       
   208     CleanupStack::PushL( file );
       
   209     resLoader.OpenL( *file );
       
   210     CleanupStack::PopAndDestroy( file );
       
   211 
       
   212     HBufC* result = StringLoader::LoadL( aResourceID );
       
   213     CleanupStack::PopAndDestroy(); // resLoader - it is closed as well
       
   214     CleanupStack::PushL( result );
       
   215     return result;
       
   216     }
       
   217 
       
   218 // ---------------------------------------------------------------------------
       
   219 // Adds icon to an icon array.
       
   220 // ---------------------------------------------------------------------------
       
   221 //
       
   222 void CPslnFWIconHelper::AddIconL(
       
   223     CAknIconArray* aIcons,
       
   224     const TAknsItemID& aSkinId,
       
   225     const TDesC& aFileName,
       
   226     TInt aBitmapId,
       
   227     TInt aMaskId,
       
   228     TBool aColorIcon )
       
   229     {
       
   230     if ( aColorIcon )
       
   231         {
       
   232         CFbsBitmap* bitmap = NULL;
       
   233         CFbsBitmap* mask = NULL;
       
   234         AknsUtils::CreateColorIconL(
       
   235             AknsUtils::SkinInstance(),
       
   236             aSkinId,
       
   237             KAknsIIDQsnIconColors,
       
   238             EAknsCIQsnIconColorsCG13,
       
   239             bitmap,
       
   240             mask,
       
   241             aFileName,
       
   242             aBitmapId,
       
   243             aMaskId,
       
   244             KRgbBlack );
       
   245         CleanupStack::PushL( bitmap );
       
   246         CleanupStack::PushL( mask );
       
   247         CGulIcon* icon = CGulIcon::NewL( bitmap, mask );
       
   248         CleanupStack::Pop( 2, bitmap ); // bitmap, mask
       
   249         CleanupStack::PushL( icon );
       
   250         aIcons->AppendL( icon );
       
   251         CleanupStack::Pop( icon );
       
   252         }
       
   253     else
       
   254         {
       
   255         CFbsBitmap* bitmap = NULL;
       
   256         CFbsBitmap* mask = NULL;
       
   257         AknsUtils::CreateIconL(
       
   258             AknsUtils::SkinInstance(),
       
   259             aSkinId,
       
   260             bitmap,
       
   261             mask,
       
   262             aFileName,
       
   263             aBitmapId,
       
   264             aMaskId );
       
   265         CleanupStack::PushL( bitmap );
       
   266         CleanupStack::PushL( mask );
       
   267         CGulIcon* icon = CGulIcon::NewL( bitmap, mask );
       
   268         CleanupStack::Pop( 2, bitmap ); // bitmap, mask
       
   269         CleanupStack::PushL( icon );
       
   270         aIcons->AppendL( icon );
       
   271         CleanupStack::Pop( icon );
       
   272         }
       
   273     }
       
   274 
       
   275 // ---------------------------------------------------------------------------
       
   276 // Retrieves icon file path.
       
   277 // ---------------------------------------------------------------------------
       
   278 //
       
   279 void CPslnFWIconHelper::GetIconFilePath( TDes& aPath )
       
   280     {
       
   281     // Find the resource file:
       
   282     TParse parse;
       
   283     parse.Set( KPslnFWIconFilename, &KDC_APP_BITMAP_DIR, NULL );
       
   284     if ( aPath.MaxLength() >= parse.FullName().Length() )
       
   285         {
       
   286         aPath.Copy( parse.FullName() );
       
   287         }
       
   288     }
       
   289 
       
   290 
       
   291 //  End of File