brandingserver/BSClient/cbsaccess.cpp
changeset 31 9dbc70490d9a
child 33 bb46c9d56bcb
equal deleted inserted replaced
30:1fa9b890f29c 31:9dbc70490d9a
       
     1 /*
       
     2 * Copyright (c) 2006 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 the License "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:  CBSAccess.cpp
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 //  INCLUDE FILES
       
    21 
       
    22 #include <e32base.h>
       
    23 #include <AknsSkinInstance.h>	// skins 
       
    24 #include <AknsUtils.h>
       
    25 #include <coemain.h>
       
    26 
       
    27 #include "cbsaccess.h"
       
    28 #include "cbsbitmap.h"
       
    29 #include "DebugTrace.h"
       
    30 #include "mbsaccess.h"
       
    31 #include "mbsupdater.h"
       
    32 #include "cbsiconfileprovider.h"
       
    33 
       
    34 void Panic(TInt aPanic)
       
    35     {
       
    36     _LIT( KPanic, "CBS" );
       
    37     User::Panic( KPanic, aPanic );
       
    38     }
       
    39 
       
    40 // Two-phased constructor.
       
    41 CBSAccess* CBSAccess::NewL( const TDesC8& aBrandId,
       
    42 							const TDesC8& aAppId,
       
    43     					 	const TDesC8& aDefaultBrandId,
       
    44 							TLanguage aLanguageId,
       
    45     					  	TBool aCacheData,
       
    46 							TInt aReserved )
       
    47     {
       
    48     CBSAccess* self = new ( ELeave ) CBSAccess( aLanguageId, aCacheData, aReserved) ;
       
    49     CleanupStack::PushL( self );
       
    50     self->ConstructL( aBrandId, aAppId, aDefaultBrandId );
       
    51     CleanupStack::Pop( self );  //self
       
    52     return self;
       
    53     }
       
    54 
       
    55 // Symbian OS default constructor can leave.
       
    56 void CBSAccess::ConstructL( const TDesC8& aBrandId, const TDesC8& aAppId, 
       
    57     					 	const TDesC8& aDefaultBrandId )
       
    58     {
       
    59     iBrand = aBrandId.AllocL();
       
    60     iDefaultBrand = aDefaultBrandId.AllocL();
       
    61     iAppId = aAppId.AllocL();
       
    62     User::LeaveIfError( iClient.Connect() );
       
    63     
       
    64 	iClient.StartTransactionL( *iAppId, *iBrand, aDefaultBrandId,
       
    65 								iLanguageId, EBSTxAccess, iReserved );
       
    66     }
       
    67 
       
    68 // Destructor
       
    69 CBSAccess::~CBSAccess()
       
    70     {
       
    71     delete iBrand;
       
    72     delete iDefaultBrand;
       
    73     delete iAppId;
       
    74     iClient.Close();
       
    75     }
       
    76 
       
    77 // C++ default constructor can NOT contain any code, that
       
    78 // might leave.
       
    79 //
       
    80 CBSAccess::CBSAccess( TLanguage aLanguageId, TBool aCacheData, TInt aReserved )
       
    81 : iLanguageId( aLanguageId ), iUseCache( aCacheData ), iReserved( aReserved )
       
    82 	{
       
    83 	}
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CBSAccess::Close()
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 void CBSAccess::Close()
       
    90 	{
       
    91 	delete this;
       
    92 	}
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CBSAccess::GetTextL()
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 HBufC* CBSAccess::GetTextL( const TDesC8& aId )
       
    99 	{
       
   100 	HBufC* buffer = NULL;
       
   101 
       
   102 	iClient.GetTextL( aId, buffer );
       
   103 		
       
   104     TRACE( T_LIT("iClient.GetText( iBrandId, aId, buffer )") );
       
   105     return buffer;
       
   106 	}
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // CBSAccess::GetTextLC()
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 HBufC* CBSAccess::GetTextLC( const TDesC8& aId )
       
   113 	{
       
   114 	HBufC* buffer = NULL;
       
   115     iClient.GetTextL( aId, buffer );
       
   116     TRACE( T_LIT("iClient.GetText( aBrandId, aId, buffer )") );
       
   117 
       
   118     CleanupStack::PushL( buffer );
       
   119     return buffer;
       
   120 	}
       
   121 
       
   122 
       
   123 // -----------------------------------------------------------------------------
       
   124 // CBSAccess::GetIntL()
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 TInt CBSAccess::GetIntL( const TDesC8& aId )
       
   128 	{
       
   129 	TInt value = 0;
       
   130 
       
   131 	iClient.GetIntL( aId, value );
       
   132     return value;
       
   133 	}
       
   134 
       
   135 TInt CBSAccess :: isBrandUpdateRequiredL ()
       
   136 {
       
   137 	TInt updateRequired = -1; 
       
   138 	iClient.isBrandUpdateRequiredL (updateRequired);
       
   139  	return updateRequired;
       
   140 
       
   141 }
       
   142 
       
   143 // -----------------------------------------------------------------------------
       
   144 // CBSAccess::GetSeveralIntL()
       
   145 // -----------------------------------------------------------------------------
       
   146 //
       
   147 MBSElement* CBSAccess::GetSeveralL( MDesC8Array& aIds )
       
   148 	{
       
   149 	MBSElement* returnValue = iClient.GetSeveralL( aIds );
       
   150 	return returnValue;
       
   151 	}
       
   152 
       
   153 // -----------------------------------------------------------------------------
       
   154 // CBSAccess::GetFileL()
       
   155 // -----------------------------------------------------------------------------
       
   156 //
       
   157 void CBSAccess::GetFileL( const TDesC8& aId,
       
   158 					   	  RFile& aFile )
       
   159 	{
       
   160 	iClient.GetFileL( aId, aFile );
       
   161 	}
       
   162 
       
   163 // -----------------------------------------------------------------------------
       
   164 // CBSAccess::GetStructureL()
       
   165 // -----------------------------------------------------------------------------
       
   166 //
       
   167 MBSElement* CBSAccess::GetStructureL( const TDesC8& aId )
       
   168 	{
       
   169 	MBSElement* returnValue = NULL;
       
   170 
       
   171 	returnValue = iClient.GetStructureL( aId );
       
   172 	
       
   173 	return returnValue;
       
   174 	
       
   175 	}
       
   176 
       
   177 // -----------------------------------------------------------------------------
       
   178 // CBSAccess::GetBufferL()
       
   179 // -----------------------------------------------------------------------------
       
   180 //
       
   181 HBufC8* CBSAccess::GetBufferL( const TDesC8& aId )
       
   182 	{
       
   183 	HBufC8* buffer = NULL;
       
   184 	iClient.GetBufferL( aId, buffer );
       
   185 	return buffer;
       
   186 	}
       
   187 
       
   188 // -----------------------------------------------------------------------------
       
   189 // CBSAccess::GetBufferLC()
       
   190 // -----------------------------------------------------------------------------
       
   191 //
       
   192 HBufC8* CBSAccess::GetBufferLC( const TDesC8& aId )
       
   193 	{
       
   194 	HBufC8* buffer = GetBufferL( aId );
       
   195 	CleanupStack::PushL( buffer );
       
   196 	return buffer;
       
   197 	}
       
   198 
       
   199 // -----------------------------------------------------------------------------
       
   200 // CBSAccess::RegisterObserverL()
       
   201 // -----------------------------------------------------------------------------
       
   202 //
       
   203 void CBSAccess::RegisterObserverL( MBSBrandChangeObserver* aObserver, MBSBackupRestoreStateObserver* aBackupObserver)
       
   204 	{
       
   205 	iClient.RegisterObserverL( aObserver, aBackupObserver );
       
   206 	}
       
   207 
       
   208 // -----------------------------------------------------------------------------
       
   209 // CBSAccess::UnRegisterObserverL()
       
   210 // -----------------------------------------------------------------------------
       
   211 //
       
   212 void CBSAccess::UnRegisterObserverL( MBSBrandChangeObserver* aObserver, MBSBackupRestoreStateObserver* aBackupObserver )
       
   213 	{
       
   214 	iClient.UnRegisterObserverL( aObserver, aBackupObserver );
       
   215 	}
       
   216 
       
   217 // -----------------------------------------------------------------------------
       
   218 // CBSAccess::GetBitmapL()
       
   219 // -----------------------------------------------------------------------------
       
   220 //
       
   221 void CBSAccess::GetBitmapL( const TDesC8& aBitmapId,
       
   222 				 CFbsBitmap*& aBitmap,
       
   223 				 CFbsBitmap*& aMask )
       
   224 	{
       
   225 	TBool useSkins = ETrue;
       
   226 	CCoeEnv* coeEnv = CCoeEnv::Static();
       
   227 	if( !coeEnv )
       
   228 		{
       
   229 		TRACE( T_LIT("GETBITMAPL NO COE ENV ") );
       
   230 		// no CONE -> don't try to use skins
       
   231 		useSkins = EFalse;
       
   232 		}
       
   233 	
       
   234 	MBSElement* bitmapItem = NULL;
       
   235 
       
   236 	// get the structure containing the info for the bitmap
       
   237 	bitmapItem = GetStructureL( aBitmapId );
       
   238 	CleanupClosePushL( *bitmapItem );
       
   239 
       
   240 	// get the list from the bitmap element
       
   241 	const CBSBitmap* bitmap = &bitmapItem->BitmapDataL();
       
   242 	
       
   243 	RFile bitmapFile;
       
   244 	
       
   245 	// we need to get the bitmap file from where we can load the bitmap
       
   246 	GetFileL( bitmap->BitmapFileId(), bitmapFile );
       
   247 	
       
   248 	TInt err = KErrNotFound;
       
   249 	CFbsBitmap* skinBitmap = NULL;
       
   250 	if( useSkins )
       
   251 		{
       
   252 		MAknsSkinInstance* skin = AknsUtils::SkinInstance();	
       
   253 
       
   254 		TAknsItemID itemId;
       
   255 		itemId.Set( bitmap->SkinIdMajor(), bitmap->SkinIdMinor() );
       
   256 
       
   257 	    // Codescanner warning: neglected to put variable on cleanup stack (id:35)
       
   258 	    // This method cannot leave after this line if the bitmap is created
       
   259 	    TRAP( err, skinBitmap = AknsUtils::CreateBitmapL( skin, itemId ) ); // CSI: 35 # See above	
       
   260 		}
       
   261     // if useSkins is TRUE that means there is a COE Env, and icons can be created
       
   262 	// otherwise, without CoeEnv, we cannot create icons, hence leave 
       
   263     if( err == KErrNotFound && useSkins)
       
   264     	{
       
   265 		// no skin bitmap found
       
   266 		
       
   267 	    // icon server take ownership of of icon file provider
       
   268 	    CBSIconFileProvider* ifp = CBSIconFileProvider::NewL( bitmapFile );
       
   269 	    CleanupStack::PushL( ifp );
       
   270 	
       
   271 	    AknIconUtils::CreateIconLC( aBitmap, aMask,
       
   272                 					*ifp,
       
   273                 					bitmap->BitmapId(), bitmap->BitmapMaskId() ); 
       
   274                 					  
       
   275 		CleanupStack::Pop( 2 ); // aBitmap, aMask
       
   276 		CleanupStack::Pop(ifp) ; 
       
   277     	}
       
   278     else if( err )
       
   279     	{
       
   280     	User::Leave( err );
       
   281     	}
       
   282 	else
       
   283 		{
       
   284 		aBitmap = skinBitmap;
       
   285 		aMask = NULL;
       
   286 		}
       
   287 	bitmapFile.Close() ;
       
   288 	CleanupStack::PopAndDestroy(); // structure
       
   289 	}
       
   290 
       
   291 //  END OF FILE
       
   292