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