commsconfig/cscengine/src/cscengbrandinghandler.cpp
branchRCL_3
changeset 21 f742655b05bf
parent 20 65a3ef1d5bd0
child 22 d38647835c2e
equal deleted inserted replaced
20:65a3ef1d5bd0 21:f742655b05bf
     1 /*
       
     2 * Copyright (c) 2007-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:  For CSC needed branding server handling
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <coemain.h>
       
    20 #include <AknsUtils.h>
       
    21 #include <cbsbitmap.h>
       
    22 #include <mbsaccess.h>
       
    23 #include <mbsupdater.h>
       
    24 #include <mbselement.h>
       
    25 #include <cbsfactory.h>
       
    26 #include <bselementfactory.h>
       
    27 #include <AknsSkinInstance.h> 
       
    28 
       
    29 #include "cscenglogger.h"
       
    30 #include "cscengbrandinghandler.h"
       
    31 
       
    32 
       
    33 _LIT8( KDefaultAppId, "xsp" );
       
    34 _LIT8( KBrandedBitmapItemId, "default_brand_image" );
       
    35 
       
    36 const TUint KVersion( 1 );
       
    37 
       
    38 // ======== MEMBER FUNCTIONS ========
       
    39 
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 CCSCEngBrandingHandler::CCSCEngBrandingHandler()
       
    45     {    
       
    46     }
       
    47 
       
    48 // ---------------------------------------------------------------------------
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 void CCSCEngBrandingHandler::ConstructL()
       
    52     {
       
    53     CSCENGDEBUG( "CCSCEngBrandingHandler::ConstructL - begin" ); 
       
    54     
       
    55     iFactory = CBSFactory::NewL( KNullDesC8, KDefaultAppId );
       
    56         
       
    57     CSCENGDEBUG( "CCSCEngBrandingHandler::ConstructL - end" );
       
    58     }   
       
    59     
       
    60     
       
    61 // ---------------------------------------------------------------------------
       
    62 // ---------------------------------------------------------------------------
       
    63 //
       
    64 EXPORT_C CCSCEngBrandingHandler* CCSCEngBrandingHandler::NewL()
       
    65     {
       
    66     CCSCEngBrandingHandler* self = new (ELeave) CCSCEngBrandingHandler;
       
    67     CleanupStack::PushL( self );
       
    68     self->ConstructL();
       
    69     CleanupStack::Pop( self );
       
    70     return self;
       
    71     }
       
    72 
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 CCSCEngBrandingHandler::~CCSCEngBrandingHandler()
       
    78     {
       
    79     CSCENGDEBUG( 
       
    80         "CCSCEngBrandingHandler::~CCSCEngBrandingHandler - begin" ); 
       
    81 
       
    82     delete iFactory;
       
    83     
       
    84     CSCENGDEBUG( 
       
    85         "CCSCEngBrandingHandler::~CCSCEngBrandingHandler - end" ); 
       
    86     }
       
    87     
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 // ---------------------------------------------------------------------------
       
    91 // 
       
    92 EXPORT_C void CCSCEngBrandingHandler::GetServiceBrandIconL( 
       
    93     const TDesC8& aBrandId, CFbsBitmap*& aBitmap, CFbsBitmap*& aMask,
       
    94     TInt aIconSize )
       
    95     {
       
    96     CSCENGDEBUG( 
       
    97         "CCSCEngBrandingHandler::GetServiceBrandIconL - begin" ); 
       
    98         
       
    99     // Create access to Branding server
       
   100     MBSAccess* access = iFactory->CreateAccessL( 
       
   101         aBrandId, ELangInternationalEnglish, KVersion );
       
   102     CleanupClosePushL( *access );
       
   103             
       
   104     // start fetching of branding image     
       
   105 	// get structure containing the info needed to load brand image
       
   106 	MBSElement* bitmapItem = NULL;
       
   107 	bitmapItem = access->GetStructureL( KBrandedBitmapItemId );
       
   108 	CleanupClosePushL( *bitmapItem );
       
   109 
       
   110 	// get info from the bitmap element
       
   111 	const CBSBitmap& bsBitmap = bitmapItem->BitmapDataL();
       
   112 	
       
   113 	RFile bitmapFile;
       
   114 	CleanupClosePushL( bitmapFile ); 
       
   115 	
       
   116 	// get the bitmap file from where we can load the bitmap
       
   117 	access->GetFileL( bsBitmap.BitmapFileId(), bitmapFile );	
       
   118 	
       
   119 	TInt err = KErrNotFound;
       
   120 	CFbsBitmap* skinBitmap = NULL;
       
   121 	
       
   122 	// Try getting skinned images first
       
   123 	
       
   124 	if( CCoeEnv::Static() )
       
   125 		{
       
   126 		MAknsSkinInstance* skin = AknsUtils::SkinInstance();	
       
   127 
       
   128 		TAknsItemID itemId;
       
   129 		itemId.Set( bsBitmap.SkinIdMajor(), bsBitmap.SkinIdMinor() );
       
   130 		
       
   131 		CleanupStack::PushL( skinBitmap );
       
   132 		
       
   133 	    TRAP( err, skinBitmap = AknsUtils::CreateBitmapL( skin, itemId ) );
       
   134 		
       
   135 		CleanupStack::Pop( skinBitmap );
       
   136 		}
       
   137     
       
   138     if( err == KErrNotFound ) 	// no skin bitmap found
       
   139     	{
       
   140     	iFile = bitmapFile;    	    
       
   141 	    AknIconUtils::CreateIconLC( aBitmap, 
       
   142 	                                aMask,
       
   143                 					*this,
       
   144                 					bsBitmap.BitmapId(), 
       
   145                 					bsBitmap.BitmapMaskId() );
       
   146 
       
   147         CleanupStack::Pop( aMask );
       
   148         CleanupStack::Pop( aBitmap );
       
   149     	}
       
   150     else if( err )
       
   151     	{
       
   152     	User::Leave( err );
       
   153     	}
       
   154 	else
       
   155 		{
       
   156 		aBitmap = skinBitmap;
       
   157 		aMask = NULL;
       
   158 		}
       
   159     
       
   160     TSize size( aIconSize, aIconSize );
       
   161     if ( aBitmap )
       
   162         {
       
   163         AknIconUtils::SetSize( aBitmap, size );
       
   164         }
       
   165 	
       
   166 	if ( aMask )
       
   167         {
       
   168         AknIconUtils::SetSize( aMask, size );
       
   169         }
       
   170 		
       
   171 	CleanupStack::PopAndDestroy( &bitmapFile );
       
   172 	CleanupStack::PopAndDestroy( bitmapItem );
       
   173     CleanupStack::PopAndDestroy( access );
       
   174     
       
   175     CSCENGDEBUG( 
       
   176         "CCSCEngBrandingHandler::GetServiceBrandIconL - end" ); 
       
   177     } 
       
   178 
       
   179 
       
   180 // ---------------------------------------------------------------------------
       
   181 // From class MAknIconFileProvider
       
   182 // For getting an open file handle to the icon file.
       
   183 // ---------------------------------------------------------------------------
       
   184 //
       
   185 void CCSCEngBrandingHandler::RetrieveIconFileHandleL(
       
   186             RFile& aFile, const TIconFileType /*aType*/ )
       
   187     {
       
   188     aFile.Duplicate( iFile );
       
   189     }
       
   190 
       
   191 
       
   192     
       
   193 
       
   194