psln/PslnFramework/src/PslnFWIconHelper.cpp
changeset 0 2f259fa3e83a
child 14 3320e4e6e8bb
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     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         CFbsBitmap *mask = new (ELeave) CFbsBitmap;
       
   118         User::LeaveIfError(
       
   119             mask->Create( TSize(0, 0), EColor16 ) );
       
   120         icons->AppendL( CGulIcon::NewL( bitmap, mask ) );
       
   121         bitmapIndex++;
       
   122         }
       
   123 
       
   124     HBufC* fileName = HBufC::NewLC( KMaxFileName );
       
   125     TPtr fileNamePtr = fileName->Des();
       
   126     GetIconFilePath( fileNamePtr );
       
   127 
       
   128     if ( aAll || aMaxIndexToAdd >= bitmapIndex )
       
   129         {
       
   130         // 1: Active mark
       
   131         AddIconL( icons,
       
   132             KAknsIIDQgnPropPslnActive,
       
   133             fileNamePtr,
       
   134             EMbmPslniconQgn_prop_psln_active,
       
   135             EMbmPslniconQgn_prop_psln_active_mask );
       
   136         bitmapIndex++;
       
   137         }
       
   138 
       
   139     if ( aAll || aMaxIndexToAdd >= bitmapIndex )
       
   140         {
       
   141         // 2: URL icon (in front of EEL)
       
   142         AddIconL( icons,
       
   143             KAknsIIDQgnPropLinkEmbdSmall,
       
   144             KAvkonVariatedBitmapsFile,
       
   145             EMbmVariatedbitmapsQgn_prop_link_embd_small,
       
   146             EMbmVariatedbitmapsQgn_prop_link_embd_small_mask );
       
   147         bitmapIndex++;
       
   148         }
       
   149 
       
   150     if ( aAll || aMaxIndexToAdd >= bitmapIndex )
       
   151         {
       
   152         // 3: MMC icon
       
   153         AddIconL( icons, 
       
   154             KAknsIIDQgnIndiMmcAdd,
       
   155             fileNamePtr,
       
   156             EMbmPslniconQgn_indi_mmc_add,
       
   157             EMbmPslniconQgn_indi_mmc_add_mask,
       
   158             ETrue );
       
   159         bitmapIndex++;
       
   160         }
       
   161 
       
   162     if ( aAll || aMaxIndexToAdd >= bitmapIndex )
       
   163         {
       
   164         //4: EAknsSrvProtected,
       
   165         AddIconL( icons,
       
   166             KAknsIIDQgnIndiDrmRightsAdd,
       
   167             fileNamePtr,
       
   168             EMbmPslniconQgn_indi_drm_rights_add,
       
   169             EMbmPslniconQgn_indi_drm_rights_add_mask,
       
   170             ETrue );
       
   171         bitmapIndex++;
       
   172         }
       
   173 
       
   174     if ( aAll || aMaxIndexToAdd >= bitmapIndex )
       
   175         {
       
   176         //5: EAknsSrvNoRights
       
   177         AddIconL( icons,
       
   178             KAknsIIDQgnIndiDrmRightsExpAdd,
       
   179             fileNamePtr,
       
   180             EMbmPslniconQgn_indi_drm_rights_exp_add,
       
   181             EMbmPslniconQgn_indi_drm_rights_exp_add_mask,
       
   182             ETrue );
       
   183         bitmapIndex++;
       
   184         }
       
   185 
       
   186     if ( aAll || aMaxIndexToAdd >= bitmapIndex )
       
   187         {
       
   188         //6: EAknsMinorGenericQgnIndiFmgrMsAdd - mass drive 
       
   189         AddIconL( icons,
       
   190             KAknsIIDQgnIndiFmgrMsAdd,
       
   191             fileNamePtr,
       
   192             EMbmPslniconQgn_indi_fmgr_ms_add,
       
   193             EMbmPslniconQgn_indi_fmgr_ms_add_mask,
       
   194             ETrue );
       
   195         bitmapIndex++;
       
   196         }
       
   197     CleanupStack::PopAndDestroy( fileName );
       
   198     }
       
   199 
       
   200 // ---------------------------------------------------------------------------
       
   201 // Retrieves localized string txt.
       
   202 // ---------------------------------------------------------------------------
       
   203 //
       
   204 EXPORT_C HBufC* CPslnFWIconHelper::GetLocalizedStringLC(
       
   205     const TDesC& aPath, TInt aResourceID, CCoeEnv* aCoeEnv )
       
   206     {
       
   207     RConeResourceLoader resLoader( *aCoeEnv );
       
   208     CleanupClosePushL( resLoader );
       
   209     // Open resource file:
       
   210     TFileName* file = new (ELeave) TFileName( aPath );
       
   211     CleanupStack::PushL( file );
       
   212     resLoader.OpenL( *file );
       
   213     CleanupStack::PopAndDestroy( file );
       
   214 
       
   215     HBufC* result = StringLoader::LoadL( aResourceID );
       
   216     CleanupStack::PopAndDestroy(); // resLoader - it is closed as well
       
   217     CleanupStack::PushL( result );
       
   218     return result;
       
   219     }
       
   220 
       
   221 // ---------------------------------------------------------------------------
       
   222 // Adds icon to an icon array.
       
   223 // ---------------------------------------------------------------------------
       
   224 //
       
   225 void CPslnFWIconHelper::AddIconL(
       
   226     CAknIconArray* aIcons,
       
   227     const TAknsItemID& aSkinId,
       
   228     const TDesC& aFileName,
       
   229     TInt aBitmapId,
       
   230     TInt aMaskId,
       
   231     TBool aColorIcon )
       
   232     {
       
   233     if ( aColorIcon )
       
   234         {
       
   235         CFbsBitmap* bitmap = NULL;
       
   236         CFbsBitmap* mask = NULL;
       
   237         AknsUtils::CreateColorIconL(
       
   238             AknsUtils::SkinInstance(),
       
   239             aSkinId,
       
   240             KAknsIIDQsnIconColors,
       
   241             EAknsCIQsnIconColorsCG13,
       
   242             bitmap,
       
   243             mask,
       
   244             aFileName,
       
   245             aBitmapId,
       
   246             aMaskId,
       
   247             KRgbBlack );
       
   248         CleanupStack::PushL( bitmap );
       
   249         CleanupStack::PushL( mask );
       
   250         CGulIcon* icon = CGulIcon::NewL( bitmap, mask );
       
   251         CleanupStack::Pop( 2, bitmap ); // bitmap, mask
       
   252         CleanupStack::PushL( icon );
       
   253         aIcons->AppendL( icon );
       
   254         CleanupStack::Pop( icon );
       
   255         }
       
   256     else
       
   257         {
       
   258         CFbsBitmap* bitmap = NULL;
       
   259         CFbsBitmap* mask = NULL;
       
   260         AknsUtils::CreateIconL(
       
   261             AknsUtils::SkinInstance(),
       
   262             aSkinId,
       
   263             bitmap,
       
   264             mask,
       
   265             aFileName,
       
   266             aBitmapId,
       
   267             aMaskId );
       
   268         CleanupStack::PushL( bitmap );
       
   269         CleanupStack::PushL( mask );
       
   270         CGulIcon* icon = CGulIcon::NewL( bitmap, mask );
       
   271         CleanupStack::Pop( 2, bitmap ); // bitmap, mask
       
   272         CleanupStack::PushL( icon );
       
   273         aIcons->AppendL( icon );
       
   274         CleanupStack::Pop( icon );
       
   275         }
       
   276     }
       
   277 
       
   278 // ---------------------------------------------------------------------------
       
   279 // Retrieves icon file path.
       
   280 // ---------------------------------------------------------------------------
       
   281 //
       
   282 void CPslnFWIconHelper::GetIconFilePath( TDes& aPath )
       
   283     {
       
   284     // Find the resource file:
       
   285     TParse parse;
       
   286     parse.Set( KPslnFWIconFilename, &KDC_APP_BITMAP_DIR, NULL );
       
   287     if ( aPath.MaxLength() >= parse.FullName().Length() )
       
   288         {
       
   289         aPath.Copy( parse.FullName() );
       
   290         }
       
   291     }
       
   292 
       
   293 
       
   294 //  End of File