brandingserver/BSServer/cbsbrandhandler.cpp
author hgs
Sun, 11 Apr 2010 15:33:49 +0530
changeset 31 9dbc70490d9a
permissions -rw-r--r--
201014
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
* Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
* All rights reserved.
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
*
hgs
parents:
diff changeset
     9
* Initial Contributors:
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
*
hgs
parents:
diff changeset
    12
* Contributors:
hgs
parents:
diff changeset
    13
*
hgs
parents:
diff changeset
    14
* Description:  CBSBrandHandler.cpp
hgs
parents:
diff changeset
    15
*
hgs
parents:
diff changeset
    16
*/
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
hgs
parents:
diff changeset
    19
hgs
parents:
diff changeset
    20
//  INCLUDE FILES
hgs
parents:
diff changeset
    21
hgs
parents:
diff changeset
    22
#include "cbsbrandhandler.h"
hgs
parents:
diff changeset
    23
#include "bselementfactory.h"
hgs
parents:
diff changeset
    24
#include "DebugTrace.h"
hgs
parents:
diff changeset
    25
#include "cbsstoragemanager.h"
hgs
parents:
diff changeset
    26
#include "cbsbitmap.h"
hgs
parents:
diff changeset
    27
#include "bsimportconstants.h"
hgs
parents:
diff changeset
    28
hgs
parents:
diff changeset
    29
#include <e32base.h>
hgs
parents:
diff changeset
    30
#include <utf.h>
hgs
parents:
diff changeset
    31
#include <s32file.h>
hgs
parents:
diff changeset
    32
hgs
parents:
diff changeset
    33
void Panic(TInt aPanic)
hgs
parents:
diff changeset
    34
    {
hgs
parents:
diff changeset
    35
    _LIT( KPanic, "CBS" );
hgs
parents:
diff changeset
    36
    User::Panic( KPanic, aPanic );
hgs
parents:
diff changeset
    37
    }
hgs
parents:
diff changeset
    38
hgs
parents:
diff changeset
    39
// Two-phased constructor.
hgs
parents:
diff changeset
    40
CBSBrandHandler* CBSBrandHandler::NewL( const TDesC& aApplicationId,
hgs
parents:
diff changeset
    41
									    const TDesC& aBrandId, 
hgs
parents:
diff changeset
    42
									    const TDesC& aDefaultBrandId, 
hgs
parents:
diff changeset
    43
									    TLanguage aLanguage,
hgs
parents:
diff changeset
    44
									    CBSSession* aSession,
hgs
parents:
diff changeset
    45
									    TInt aReserved )
hgs
parents:
diff changeset
    46
    {
hgs
parents:
diff changeset
    47
    CBSBrandHandler* self = new ( ELeave ) CBSBrandHandler( aLanguage, aReserved ) ;
hgs
parents:
diff changeset
    48
    CleanupStack::PushL( self );
hgs
parents:
diff changeset
    49
    self->ConstructL( aApplicationId, aBrandId, aDefaultBrandId, aSession );
hgs
parents:
diff changeset
    50
    CleanupStack::Pop( self );  //self
hgs
parents:
diff changeset
    51
    return self;
hgs
parents:
diff changeset
    52
    }
hgs
parents:
diff changeset
    53
hgs
parents:
diff changeset
    54
// Symbian OS default constructor can leave.
hgs
parents:
diff changeset
    55
void CBSBrandHandler::ConstructL( const TDesC& aApplicationId,
hgs
parents:
diff changeset
    56
						 		  const TDesC& aBrandId,
hgs
parents:
diff changeset
    57
						 		  const TDesC& aDefaultBrandId,
hgs
parents:
diff changeset
    58
						 		  CBSSession* aSession )
hgs
parents:
diff changeset
    59
    {
hgs
parents:
diff changeset
    60
	iApplicationId = aApplicationId.AllocL();
hgs
parents:
diff changeset
    61
	iBrandId = aBrandId.AllocL();
hgs
parents:
diff changeset
    62
	iDefaultBrandId = aDefaultBrandId.AllocL();
hgs
parents:
diff changeset
    63
	iSession = aSession;
hgs
parents:
diff changeset
    64
	
hgs
parents:
diff changeset
    65
	User::LeaveIfError( iFs.Connect() );
hgs
parents:
diff changeset
    66
	
hgs
parents:
diff changeset
    67
	iHandle = new(ELeave) RFile(); // CSI: 74 # this needs to be like this
hgs
parents:
diff changeset
    68
hgs
parents:
diff changeset
    69
	isDefaultBrandUsed = ETrue;
hgs
parents:
diff changeset
    70
	iStorageManager = CBSStorageManager::NewL( iSession, KNullDesC );
hgs
parents:
diff changeset
    71
    TInt err = -1;
hgs
parents:
diff changeset
    72
    TRAP (err, iStorageManager->BrandHandleL( *iApplicationId,
hgs
parents:
diff changeset
    73
                                   *iBrandId, iLanguage,
hgs
parents:
diff changeset
    74
                                   *iHandle,
hgs
parents:
diff changeset
    75
                                   iReserved ));
hgs
parents:
diff changeset
    76
hgs
parents:
diff changeset
    77
hgs
parents:
diff changeset
    78
    if (err != KErrNone)
hgs
parents:
diff changeset
    79
        {
hgs
parents:
diff changeset
    80
	iStorageManager->BrandHandleL( *iApplicationId,
hgs
parents:
diff changeset
    81
                                           *iDefaultBrandId, iLanguage,
hgs
parents:
diff changeset
    82
								   *iHandle,
hgs
parents:
diff changeset
    83
								   iReserved );
hgs
parents:
diff changeset
    84
        }
hgs
parents:
diff changeset
    85
	VerifyVersionL();
hgs
parents:
diff changeset
    86
    }
hgs
parents:
diff changeset
    87
hgs
parents:
diff changeset
    88
// Destructor
hgs
parents:
diff changeset
    89
CBSBrandHandler::~CBSBrandHandler()
hgs
parents:
diff changeset
    90
    {
hgs
parents:
diff changeset
    91
    delete iDefaultBrand;
hgs
parents:
diff changeset
    92
    delete iApplicationId;
hgs
parents:
diff changeset
    93
    delete iBrandId;
hgs
parents:
diff changeset
    94
    delete iDefaultBrandId;
hgs
parents:
diff changeset
    95
  	if( iHandle )
hgs
parents:
diff changeset
    96
  		{
hgs
parents:
diff changeset
    97
  		iHandle->Close();
hgs
parents:
diff changeset
    98
		delete iHandle;
hgs
parents:
diff changeset
    99
		iHandle = NULL;
hgs
parents:
diff changeset
   100
  		}
hgs
parents:
diff changeset
   101
hgs
parents:
diff changeset
   102
    delete iStorageManager;
hgs
parents:
diff changeset
   103
  
hgs
parents:
diff changeset
   104
    iFs.Close();
hgs
parents:
diff changeset
   105
    }
hgs
parents:
diff changeset
   106
hgs
parents:
diff changeset
   107
// C++ default constructor can NOT contain any code, that
hgs
parents:
diff changeset
   108
// might leave.
hgs
parents:
diff changeset
   109
//
hgs
parents:
diff changeset
   110
CBSBrandHandler::CBSBrandHandler( TLanguage aLanguage,
hgs
parents:
diff changeset
   111
						 		  TInt aReserved )
hgs
parents:
diff changeset
   112
: iLanguage( aLanguage ), iReserved( aReserved)
hgs
parents:
diff changeset
   113
	{
hgs
parents:
diff changeset
   114
	}
hgs
parents:
diff changeset
   115
hgs
parents:
diff changeset
   116
hgs
parents:
diff changeset
   117
hgs
parents:
diff changeset
   118
TInt CBSBrandHandler:: isBrandUpdateRequiredL ()
hgs
parents:
diff changeset
   119
{
hgs
parents:
diff changeset
   120
	TRACE( T_LIT( "isBrandUpdateRequired  entered"));
hgs
parents:
diff changeset
   121
	TInt updateRequired = -1;
hgs
parents:
diff changeset
   122
	if (isDefaultBrandUsed)
hgs
parents:
diff changeset
   123
		{
hgs
parents:
diff changeset
   124
		TRACE( T_LIT( "isBrandUpdateRequired  isDefaultBrandused is TRUE."));
hgs
parents:
diff changeset
   125
		/* default brand is used, so can check if the actual brand is installed by anychance or not */
hgs
parents:
diff changeset
   126
		updateRequired = iStorageManager->isActualBrandInstalledL (*iApplicationId, *iBrandId, iLanguage );
hgs
parents:
diff changeset
   127
		if (1 == updateRequired)
hgs
parents:
diff changeset
   128
			{
hgs
parents:
diff changeset
   129
				TRACE( T_LIT( "isBrandUpdateRequired  isDefaultBrandused returned 1, so update required, setting defaultbrand FALSE."));
hgs
parents:
diff changeset
   130
				isDefaultBrandUsed = EFalse;
hgs
parents:
diff changeset
   131
			}
hgs
parents:
diff changeset
   132
		}
hgs
parents:
diff changeset
   133
	TRACE( T_LIT( "isBrandUpdateRequired  isDefaultBrandused leaving.."));		
hgs
parents:
diff changeset
   134
	return updateRequired;
hgs
parents:
diff changeset
   135
}
hgs
parents:
diff changeset
   136
hgs
parents:
diff changeset
   137
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   138
// CBSBrandHandler::SetDefaultBrandIdL()
hgs
parents:
diff changeset
   139
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   140
//
hgs
parents:
diff changeset
   141
void CBSBrandHandler::SetDefaultBrandIdL( const TDesC8& aBrandId )
hgs
parents:
diff changeset
   142
    {
hgs
parents:
diff changeset
   143
    HBufC* temp = CnvUtfConverter::ConvertToUnicodeFromUtf8L( aBrandId );
hgs
parents:
diff changeset
   144
    delete iDefaultBrand;
hgs
parents:
diff changeset
   145
    iDefaultBrand = temp;
hgs
parents:
diff changeset
   146
    }
hgs
parents:
diff changeset
   147
hgs
parents:
diff changeset
   148
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   149
// CBSBrandHandler::GetTextL()
hgs
parents:
diff changeset
   150
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   151
//
hgs
parents:
diff changeset
   152
HBufC* CBSBrandHandler::GetTextL( const TDesC8& aId )
hgs
parents:
diff changeset
   153
	{
hgs
parents:
diff changeset
   154
	TRACE( T_LIT( "CBranding::GetTextL begin [%S]"), &aId);
hgs
parents:
diff changeset
   155
	
hgs
parents:
diff changeset
   156
	MBSElement* element = ReadElementLC( aId );
hgs
parents:
diff changeset
   157
hgs
parents:
diff changeset
   158
	HBufC* returnValue = element->TextDataL().AllocL();
hgs
parents:
diff changeset
   159
hgs
parents:
diff changeset
   160
	CleanupStack::PopAndDestroy(); // element
hgs
parents:
diff changeset
   161
	TRACE( T_LIT( "CBranding::GetTextL end") );
hgs
parents:
diff changeset
   162
    return returnValue;
hgs
parents:
diff changeset
   163
	}
hgs
parents:
diff changeset
   164
hgs
parents:
diff changeset
   165
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   166
// CBSBrandHandler::GetBufferL()
hgs
parents:
diff changeset
   167
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   168
//
hgs
parents:
diff changeset
   169
HBufC8* CBSBrandHandler::GetBufferL( const TDesC8& aId )
hgs
parents:
diff changeset
   170
	{
hgs
parents:
diff changeset
   171
	TRACE( T_LIT( "CBSBrandHandler::GetBufferL begin") );
hgs
parents:
diff changeset
   172
	
hgs
parents:
diff changeset
   173
	MBSElement* element = ReadElementLC( aId );
hgs
parents:
diff changeset
   174
hgs
parents:
diff changeset
   175
	HBufC8* returnValue = element->BufferDataL().AllocL();
hgs
parents:
diff changeset
   176
hgs
parents:
diff changeset
   177
	CleanupStack::PopAndDestroy(); // element
hgs
parents:
diff changeset
   178
	TRACE( T_LIT( "CBSBrandHandler::GetBufferL end") );
hgs
parents:
diff changeset
   179
    return returnValue;
hgs
parents:
diff changeset
   180
	}
hgs
parents:
diff changeset
   181
hgs
parents:
diff changeset
   182
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   183
// CBSBrandHandler::GetIntL()
hgs
parents:
diff changeset
   184
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   185
//
hgs
parents:
diff changeset
   186
TInt CBSBrandHandler::GetIntL( const TDesC8& aId )
hgs
parents:
diff changeset
   187
	{
hgs
parents:
diff changeset
   188
    TRACE( T_LIT( "CBSBrandHandler::GetIntL begin") );
hgs
parents:
diff changeset
   189
	TInt value = 0;
hgs
parents:
diff changeset
   190
hgs
parents:
diff changeset
   191
	MBSElement* element = ReadElementLC( aId );
hgs
parents:
diff changeset
   192
hgs
parents:
diff changeset
   193
	value = element->IntDataL();
hgs
parents:
diff changeset
   194
hgs
parents:
diff changeset
   195
	CleanupStack::PopAndDestroy(); // element
hgs
parents:
diff changeset
   196
hgs
parents:
diff changeset
   197
	TRACE( T_LIT( "CBSBrandHandler::GetIntL end") );
hgs
parents:
diff changeset
   198
    return value;
hgs
parents:
diff changeset
   199
	}
hgs
parents:
diff changeset
   200
hgs
parents:
diff changeset
   201
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   202
// CBSBrandHandler::GetFileL()
hgs
parents:
diff changeset
   203
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   204
//
hgs
parents:
diff changeset
   205
void CBSBrandHandler::GetFileL( const TDesC8& aId, RFile& aFile )
hgs
parents:
diff changeset
   206
	{
hgs
parents:
diff changeset
   207
	TRACE( T_LIT( "CBSBrandHandler::GetFileL begin aId[%S] "), &aId );
hgs
parents:
diff changeset
   208
	RFile file;
hgs
parents:
diff changeset
   209
	User::LeaveIfError( iFs.ShareProtected() );
hgs
parents:
diff changeset
   210
hgs
parents:
diff changeset
   211
	if (iLanguage >= 100)
hgs
parents:
diff changeset
   212
		User::LeaveIfError (KErrNotFound);
hgs
parents:
diff changeset
   213
	HBufC* fileName = GetTextL( aId );
hgs
parents:
diff changeset
   214
hgs
parents:
diff changeset
   215
    TBuf<KLangBufLength> buffer;
hgs
parents:
diff changeset
   216
// append leading zero only if language code is <10.
hgs
parents:
diff changeset
   217
    if ( 10 > iLanguage )
hgs
parents:
diff changeset
   218
        {
hgs
parents:
diff changeset
   219
    	buffer.AppendNum( KLeadingZero );
hgs
parents:
diff changeset
   220
        }		
hgs
parents:
diff changeset
   221
hgs
parents:
diff changeset
   222
    buffer.AppendNum( iLanguage );
hgs
parents:
diff changeset
   223
hgs
parents:
diff changeset
   224
	TInt err = -1;
hgs
parents:
diff changeset
   225
	TRAP (err, iStorageManager->FileElementHandleL( *iApplicationId,
hgs
parents:
diff changeset
   226
						     			 *iBrandId,
hgs
parents:
diff changeset
   227
						     			 *fileName,
hgs
parents:
diff changeset
   228
						     			 buffer,
hgs
parents:
diff changeset
   229
						     			 file ));
hgs
parents:
diff changeset
   230
hgs
parents:
diff changeset
   231
	if (KErrNone != err)
hgs
parents:
diff changeset
   232
	    {
hgs
parents:
diff changeset
   233
		/* if the file is not found in the default brand also, then leave */
hgs
parents:
diff changeset
   234
	    iStorageManager->FileElementHandleL( *iApplicationId,
hgs
parents:
diff changeset
   235
	                                         *iDefaultBrandId,
hgs
parents:
diff changeset
   236
	                                         *fileName,
hgs
parents:
diff changeset
   237
	                                         buffer,
hgs
parents:
diff changeset
   238
	                                         file);
hgs
parents:
diff changeset
   239
hgs
parents:
diff changeset
   240
		TRACE( T_LIT( "CBSBrandHandler::GetFileL found in default brand") );
hgs
parents:
diff changeset
   241
	    
hgs
parents:
diff changeset
   242
	    }
hgs
parents:
diff changeset
   243
hgs
parents:
diff changeset
   244
	aFile = file;
hgs
parents:
diff changeset
   245
    TRACE( T_LIT( "CBSBrandHandler::GetFileL end") );
hgs
parents:
diff changeset
   246
	}
hgs
parents:
diff changeset
   247
hgs
parents:
diff changeset
   248
hgs
parents:
diff changeset
   249
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   250
// CBSBrandHandler::GetSeveralL()
hgs
parents:
diff changeset
   251
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   252
//
hgs
parents:
diff changeset
   253
MBSElement* CBSBrandHandler::GetSeveralL( RBSObjOwningPtrArray<HBufC8>& aIds )
hgs
parents:
diff changeset
   254
	{
hgs
parents:
diff changeset
   255
	MBSElement* returnValue = NULL;
hgs
parents:
diff changeset
   256
	TInt count = aIds.Count();
hgs
parents:
diff changeset
   257
	
hgs
parents:
diff changeset
   258
	RBSObjOwningPtrArray<MBSElement> listData;
hgs
parents:
diff changeset
   259
	CleanupClosePushL( listData );
hgs
parents:
diff changeset
   260
	for(TInt i = 0; i < count; i++ )
hgs
parents:
diff changeset
   261
		{
hgs
parents:
diff changeset
   262
		MBSElement* subElement = ReadElementLC( *aIds[ i ] );
hgs
parents:
diff changeset
   263
		listData.AppendL( subElement );
hgs
parents:
diff changeset
   264
		CleanupStack::Pop( subElement );
hgs
parents:
diff changeset
   265
		}
hgs
parents:
diff changeset
   266
	returnValue = BSElementFactory::CreateBSElementL( KNullDesC8,
hgs
parents:
diff changeset
   267
													  EBSList,
hgs
parents:
diff changeset
   268
													  listData );
hgs
parents:
diff changeset
   269
	CleanupStack::Pop(); // listData
hgs
parents:
diff changeset
   270
	return returnValue;
hgs
parents:
diff changeset
   271
	}
hgs
parents:
diff changeset
   272
hgs
parents:
diff changeset
   273
hgs
parents:
diff changeset
   274
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   275
// CBSBrandHandler::GetStructureL()
hgs
parents:
diff changeset
   276
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   277
//
hgs
parents:
diff changeset
   278
MBSElement* CBSBrandHandler::GetStructureL( TDesC8& aId )
hgs
parents:
diff changeset
   279
	{
hgs
parents:
diff changeset
   280
	MBSElement* returnValue = NULL;
hgs
parents:
diff changeset
   281
hgs
parents:
diff changeset
   282
	TRACE( T_LIT( "CBSBrandHandler::GetStructureL begin") );
hgs
parents:
diff changeset
   283
	
hgs
parents:
diff changeset
   284
	returnValue = ReadElementLC( aId );
hgs
parents:
diff changeset
   285
hgs
parents:
diff changeset
   286
	CleanupStack::Pop(); // element
hgs
parents:
diff changeset
   287
hgs
parents:
diff changeset
   288
	TRACE( T_LIT( "CBSBrandHandler::GetStructureL end") );
hgs
parents:
diff changeset
   289
hgs
parents:
diff changeset
   290
	return returnValue;
hgs
parents:
diff changeset
   291
	}
hgs
parents:
diff changeset
   292
hgs
parents:
diff changeset
   293
hgs
parents:
diff changeset
   294
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   295
// CBSBrandHandler::ReadElementLC()
hgs
parents:
diff changeset
   296
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   297
//
hgs
parents:
diff changeset
   298
MBSElement* CBSBrandHandler::ReadElementLC( const TDesC8& aId, TBool aForceDefault /*= EFalse*/ )
hgs
parents:
diff changeset
   299
	{
hgs
parents:
diff changeset
   300
	TRACE( T_LIT( "CBSBrandHandler::ReadElementLC begin aId"));
hgs
parents:
diff changeset
   301
hgs
parents:
diff changeset
   302
	if( aForceDefault )
hgs
parents:
diff changeset
   303
		{
hgs
parents:
diff changeset
   304
		TRACE( T_LIT( "CBSBrandHandler::ReadElementLC default brand"));
hgs
parents:
diff changeset
   305
		iStorageManager->BrandHandleL( *iApplicationId,
hgs
parents:
diff changeset
   306
									   *iDefaultBrandId, iLanguage,
hgs
parents:
diff changeset
   307
									   *iHandle,
hgs
parents:
diff changeset
   308
									   iReserved );		
hgs
parents:
diff changeset
   309
		}
hgs
parents:
diff changeset
   310
	else
hgs
parents:
diff changeset
   311
		{
hgs
parents:
diff changeset
   312
		TInt err = -1;
hgs
parents:
diff changeset
   313
		TRAP (err, iStorageManager->BrandHandleL( *iApplicationId,
hgs
parents:
diff changeset
   314
									   *iBrandId, iLanguage,
hgs
parents:
diff changeset
   315
									   *iHandle,
hgs
parents:
diff changeset
   316
									   iReserved ));
hgs
parents:
diff changeset
   317
		if (KErrNone != err)
hgs
parents:
diff changeset
   318
			{
hgs
parents:
diff changeset
   319
			iStorageManager->BrandHandleL( *iApplicationId,
hgs
parents:
diff changeset
   320
										   *iDefaultBrandId, iLanguage,
hgs
parents:
diff changeset
   321
										   *iHandle,
hgs
parents:
diff changeset
   322
										   iReserved ); 	
hgs
parents:
diff changeset
   323
			}
hgs
parents:
diff changeset
   324
		}
hgs
parents:
diff changeset
   325
	
hgs
parents:
diff changeset
   326
	RFileReadStream stream;
hgs
parents:
diff changeset
   327
	stream.Attach( *iHandle );
hgs
parents:
diff changeset
   328
	CleanupClosePushL( stream );
hgs
parents:
diff changeset
   329
	
hgs
parents:
diff changeset
   330
	VerifyVersionL( stream );
hgs
parents:
diff changeset
   331
	
hgs
parents:
diff changeset
   332
	TInt count = stream.ReadInt16L();
hgs
parents:
diff changeset
   333
	
hgs
parents:
diff changeset
   334
	MBSElement* returnValue = NULL;
hgs
parents:
diff changeset
   335
hgs
parents:
diff changeset
   336
	for( TInt i = 0; i < count; i++ )
hgs
parents:
diff changeset
   337
		{
hgs
parents:
diff changeset
   338
		TRAPD( err, returnValue = ReadStreamL( aId, stream ) );
hgs
parents:
diff changeset
   339
		
hgs
parents:
diff changeset
   340
		if( err == KErrEof )
hgs
parents:
diff changeset
   341
			{
hgs
parents:
diff changeset
   342
			TRACE( T_LIT( "CBSBrandHandler::ReadElementLC EOF!") );
hgs
parents:
diff changeset
   343
			// the id is not found in this file
hgs
parents:
diff changeset
   344
			User::Leave( KErrNotFound );
hgs
parents:
diff changeset
   345
			}
hgs
parents:
diff changeset
   346
		if( returnValue )
hgs
parents:
diff changeset
   347
			{
hgs
parents:
diff changeset
   348
			TRACE( T_LIT( "CBSBrandHandler::ReadElementLC ELEMENT FOUND.. at position %d"), i);
hgs
parents:
diff changeset
   349
			// we found what we are looking for
hgs
parents:
diff changeset
   350
			break;
hgs
parents:
diff changeset
   351
			}
hgs
parents:
diff changeset
   352
		}
hgs
parents:
diff changeset
   353
		
hgs
parents:
diff changeset
   354
	CleanupStack::PopAndDestroy( &stream ); // stream	
hgs
parents:
diff changeset
   355
	
hgs
parents:
diff changeset
   356
	TBool popElementFromCleanupStack( EFalse );
hgs
parents:
diff changeset
   357
	
hgs
parents:
diff changeset
   358
	/* If retur value is not found and if its read the actual brand, then try in default brand as well. aForceDefault will decide that. */
hgs
parents:
diff changeset
   359
	if( !returnValue && !aForceDefault)
hgs
parents:
diff changeset
   360
		{
hgs
parents:
diff changeset
   361
		TRACE( T_LIT( "CBSBrandHandler::ReadElementLC force default is true") );
hgs
parents:
diff changeset
   362
hgs
parents:
diff changeset
   363
		// the element was not found
hgs
parents:
diff changeset
   364
		// try the default brand if it's not the same as wanted brand
hgs
parents:
diff changeset
   365
		if( 0 != iBrandId->Compare( *iDefaultBrandId ) )
hgs
parents:
diff changeset
   366
			{
hgs
parents:
diff changeset
   367
			TRACE( T_LIT( "CBSBrandHandler::ReadElementLC calling READELEMENTLC again") );
hgs
parents:
diff changeset
   368
hgs
parents:
diff changeset
   369
			/* Call ReadElementLC wiht aForceDefault set to TRUE */
hgs
parents:
diff changeset
   370
			returnValue = ReadElementLC( aId, ETrue );
hgs
parents:
diff changeset
   371
hgs
parents:
diff changeset
   372
			if ( returnValue )
hgs
parents:
diff changeset
   373
			    {
hgs
parents:
diff changeset
   374
				TRACE( T_LIT( "CBSBrandHandler::ReadElementLC VALUE IS FOUND!!!") );
hgs
parents:
diff changeset
   375
			    popElementFromCleanupStack = ETrue;
hgs
parents:
diff changeset
   376
			    }
hgs
parents:
diff changeset
   377
			else
hgs
parents:
diff changeset
   378
				{
hgs
parents:
diff changeset
   379
				TRACE( T_LIT( "CBSBrandHandler::ReadElementLC VALUE IS NOT FOUND!!!") );
hgs
parents:
diff changeset
   380
				CleanupStack :: Pop (returnValue);
hgs
parents:
diff changeset
   381
				}
hgs
parents:
diff changeset
   382
			}
hgs
parents:
diff changeset
   383
		if( !returnValue )
hgs
parents:
diff changeset
   384
			{
hgs
parents:
diff changeset
   385
			TRACE( T_LIT( "CBSBrandHandler::ReadElementLC VALUE not FOUND LEAVING WITH -1 !!!") );
hgs
parents:
diff changeset
   386
			User::Leave( KErrNotFound );			
hgs
parents:
diff changeset
   387
			}
hgs
parents:
diff changeset
   388
		}
hgs
parents:
diff changeset
   389
	
hgs
parents:
diff changeset
   390
	CleanupClosePushL( *returnValue );
hgs
parents:
diff changeset
   391
    // since we make one function call to ReadElementLC in case the default 
hgs
parents:
diff changeset
   392
	// brand id is used to retrieved the element, we have to pop one returnValue
hgs
parents:
diff changeset
   393
	// pointer from CleanupStack (otherwise we have two identical pointers on 
hgs
parents:
diff changeset
   394
	// the stack!!!)
hgs
parents:
diff changeset
   395
	if ( popElementFromCleanupStack )
hgs
parents:
diff changeset
   396
   		{
hgs
parents:
diff changeset
   397
   	 	CleanupStack::Pop( returnValue );
hgs
parents:
diff changeset
   398
    	}
hgs
parents:
diff changeset
   399
	
hgs
parents:
diff changeset
   400
	TRACE( T_LIT( "CBSBrandHandler::ReadElementLC end ") );
hgs
parents:
diff changeset
   401
	return returnValue;
hgs
parents:
diff changeset
   402
	}
hgs
parents:
diff changeset
   403
hgs
parents:
diff changeset
   404
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   405
// CBSBrandHandler::VerifyVersionL()
hgs
parents:
diff changeset
   406
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   407
//
hgs
parents:
diff changeset
   408
void CBSBrandHandler::VerifyVersionL( RFileReadStream& aStream )
hgs
parents:
diff changeset
   409
	{
hgs
parents:
diff changeset
   410
	TInt version = aStream.ReadInt16L();
hgs
parents:
diff changeset
   411
	if( version != iReserved )
hgs
parents:
diff changeset
   412
		{
hgs
parents:
diff changeset
   413
		User::Leave( KErrArgument );
hgs
parents:
diff changeset
   414
		}
hgs
parents:
diff changeset
   415
	}
hgs
parents:
diff changeset
   416
hgs
parents:
diff changeset
   417
hgs
parents:
diff changeset
   418
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   419
// CBSBrandHandler::VerifyVersionL()
hgs
parents:
diff changeset
   420
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   421
//
hgs
parents:
diff changeset
   422
void CBSBrandHandler::VerifyVersionL()
hgs
parents:
diff changeset
   423
	{
hgs
parents:
diff changeset
   424
	if( !iHandle )
hgs
parents:
diff changeset
   425
		{
hgs
parents:
diff changeset
   426
		User::Leave( KErrNotReady );
hgs
parents:
diff changeset
   427
		}
hgs
parents:
diff changeset
   428
	RFileReadStream stream;
hgs
parents:
diff changeset
   429
	stream.Attach( *iHandle );
hgs
parents:
diff changeset
   430
	CleanupClosePushL( stream );
hgs
parents:
diff changeset
   431
	
hgs
parents:
diff changeset
   432
	VerifyVersionL( stream );
hgs
parents:
diff changeset
   433
	
hgs
parents:
diff changeset
   434
	CleanupStack::PopAndDestroy(); // stream
hgs
parents:
diff changeset
   435
	}
hgs
parents:
diff changeset
   436
hgs
parents:
diff changeset
   437
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   438
// CBSBrandHandler::ReadStreamL()
hgs
parents:
diff changeset
   439
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   440
//
hgs
parents:
diff changeset
   441
MBSElement* CBSBrandHandler::ReadStreamL( const TDesC8& aId, RFileReadStream& aStream,
hgs
parents:
diff changeset
   442
										  TBool aAllowEmptyId /* = EFalse */ )
hgs
parents:
diff changeset
   443
	{
hgs
parents:
diff changeset
   444
	TRACE( T_LIT( "CBSBrandHandler::ReadStreamL BEGIN"));
hgs
parents:
diff changeset
   445
	TBSElementType type = (TBSElementType)aStream.ReadInt16L();
hgs
parents:
diff changeset
   446
	MBSElement* returnValue = NULL;
hgs
parents:
diff changeset
   447
	
hgs
parents:
diff changeset
   448
	TInt idSize = aStream.ReadInt16L();
hgs
parents:
diff changeset
   449
	
hgs
parents:
diff changeset
   450
	HBufC8* elementId = HBufC8::NewLC( idSize );
hgs
parents:
diff changeset
   451
	TPtr8 elementIdPtr = elementId->Des();
hgs
parents:
diff changeset
   452
hgs
parents:
diff changeset
   453
	if( idSize == 0 && aAllowEmptyId )
hgs
parents:
diff changeset
   454
		{
hgs
parents:
diff changeset
   455
		// we don't read empty ID
hgs
parents:
diff changeset
   456
		}
hgs
parents:
diff changeset
   457
	else
hgs
parents:
diff changeset
   458
		{
hgs
parents:
diff changeset
   459
		aStream.ReadL( elementIdPtr, idSize );
hgs
parents:
diff changeset
   460
        elementIdPtr.SetLength( idSize );// Set length
hgs
parents:
diff changeset
   461
		}
hgs
parents:
diff changeset
   462
	
hgs
parents:
diff changeset
   463
hgs
parents:
diff changeset
   464
	TBool match = EFalse;
hgs
parents:
diff changeset
   465
	if( aAllowEmptyId || ( 0 == elementIdPtr.Compare( aId ) ) )
hgs
parents:
diff changeset
   466
		{
hgs
parents:
diff changeset
   467
		match = ETrue;
hgs
parents:
diff changeset
   468
		}
hgs
parents:
diff changeset
   469
		
hgs
parents:
diff changeset
   470
    TPtrC8 idPtrC( *elementId );// idPtrC creation moved here so it will be updated correctly.
hgs
parents:
diff changeset
   471
	if( elementId->Length() == 0 )
hgs
parents:
diff changeset
   472
		{
hgs
parents:
diff changeset
   473
		CleanupStack::PopAndDestroy( elementId );
hgs
parents:
diff changeset
   474
		elementId = NULL;
hgs
parents:
diff changeset
   475
		idPtrC.Set( KNullDesC8 );
hgs
parents:
diff changeset
   476
		}
hgs
parents:
diff changeset
   477
hgs
parents:
diff changeset
   478
	switch( type )
hgs
parents:
diff changeset
   479
		{
hgs
parents:
diff changeset
   480
		case EBSInt:
hgs
parents:
diff changeset
   481
			{
hgs
parents:
diff changeset
   482
			TInt intData = aStream.ReadInt16L();
hgs
parents:
diff changeset
   483
			TRACE( T_LIT( "CBSBrandHandler::ReadStreamL type INT"));
hgs
parents:
diff changeset
   484
			if( match )
hgs
parents:
diff changeset
   485
				{
hgs
parents:
diff changeset
   486
                // Codescanner warning: neglected to put variable on cleanup stack (id:35)
hgs
parents:
diff changeset
   487
                // This method cannot leave after this line
hgs
parents:
diff changeset
   488
				returnValue = BSElementFactory::CreateBSElementL( idPtrC, // CSI: 35 # See above
hgs
parents:
diff changeset
   489
																  EBSInt,
hgs
parents:
diff changeset
   490
																  intData ); 
hgs
parents:
diff changeset
   491
				}
hgs
parents:
diff changeset
   492
			break;
hgs
parents:
diff changeset
   493
			}		
hgs
parents:
diff changeset
   494
		case EBSText:
hgs
parents:
diff changeset
   495
		case EBSFile: // flow through
hgs
parents:
diff changeset
   496
			{
hgs
parents:
diff changeset
   497
			TInt textSize = aStream.ReadInt16L();
hgs
parents:
diff changeset
   498
			HBufC* textData = HBufC::NewLC( textSize );
hgs
parents:
diff changeset
   499
hgs
parents:
diff changeset
   500
			TPtr textPtr = textData->Des();
hgs
parents:
diff changeset
   501
			aStream.ReadL( textPtr, textSize );
hgs
parents:
diff changeset
   502
hgs
parents:
diff changeset
   503
			TRACE( T_LIT( "CBSBrandHandler::ReadStreamL type TEXT/ FILE"));
hgs
parents:
diff changeset
   504
			if( match )
hgs
parents:
diff changeset
   505
				{
hgs
parents:
diff changeset
   506
                // Codescanner warning: neglected to put variable on cleanup stack (id:35)
hgs
parents:
diff changeset
   507
                // This method cannot leave after this line
hgs
parents:
diff changeset
   508
				returnValue = BSElementFactory::CreateBSElementL( idPtrC, // CSI: 35 # See above
hgs
parents:
diff changeset
   509
																  type,
hgs
parents:
diff changeset
   510
																  *textData ); 
hgs
parents:
diff changeset
   511
				}
hgs
parents:
diff changeset
   512
hgs
parents:
diff changeset
   513
			CleanupStack::PopAndDestroy( textData );
hgs
parents:
diff changeset
   514
			break;
hgs
parents:
diff changeset
   515
			}
hgs
parents:
diff changeset
   516
		case EBSList:
hgs
parents:
diff changeset
   517
			{
hgs
parents:
diff changeset
   518
			RBSObjOwningPtrArray<MBSElement> listData;
hgs
parents:
diff changeset
   519
			CleanupClosePushL( listData );
hgs
parents:
diff changeset
   520
			TInt count = aStream.ReadInt16L();
hgs
parents:
diff changeset
   521
			
hgs
parents:
diff changeset
   522
			for( TInt i = 0; i < count; i++ )
hgs
parents:
diff changeset
   523
				{
hgs
parents:
diff changeset
   524
				MBSElement* subElement = ReadStreamL( KNullDesC8, aStream, ETrue );
hgs
parents:
diff changeset
   525
				CleanupDeletePushL( subElement );
hgs
parents:
diff changeset
   526
				listData.AppendL( subElement );
hgs
parents:
diff changeset
   527
				CleanupStack::Pop(); // subElement
hgs
parents:
diff changeset
   528
				}
hgs
parents:
diff changeset
   529
				
hgs
parents:
diff changeset
   530
			if( match )
hgs
parents:
diff changeset
   531
				{
hgs
parents:
diff changeset
   532
                // Codescanner warning: neglected to put variable on cleanup stack (id:35)
hgs
parents:
diff changeset
   533
                // This method cannot leave after this line
hgs
parents:
diff changeset
   534
				returnValue = BSElementFactory::CreateBSElementL( idPtrC, // CSI: 35 # See above
hgs
parents:
diff changeset
   535
																  EBSList,
hgs
parents:
diff changeset
   536
																  listData ); 
hgs
parents:
diff changeset
   537
				}
hgs
parents:
diff changeset
   538
			CleanupStack::Pop(); // listData
hgs
parents:
diff changeset
   539
			break;
hgs
parents:
diff changeset
   540
			}
hgs
parents:
diff changeset
   541
		case EBSBuffer:
hgs
parents:
diff changeset
   542
			{
hgs
parents:
diff changeset
   543
			TInt bufferSize = aStream.ReadInt16L();
hgs
parents:
diff changeset
   544
			HBufC8* buffeData = HBufC8::NewLC( bufferSize );
hgs
parents:
diff changeset
   545
hgs
parents:
diff changeset
   546
			TPtr8 bufferPtr = buffeData->Des();
hgs
parents:
diff changeset
   547
			aStream.ReadL( bufferPtr, bufferSize );
hgs
parents:
diff changeset
   548
hgs
parents:
diff changeset
   549
			if( match )
hgs
parents:
diff changeset
   550
				{
hgs
parents:
diff changeset
   551
                // Codescanner warning: neglected to put variable on cleanup stack (id:35)
hgs
parents:
diff changeset
   552
                // This method cannot leave after this line				
hgs
parents:
diff changeset
   553
				returnValue = BSElementFactory::CreateBSElementL( idPtrC, // CSI: 35 # See above
hgs
parents:
diff changeset
   554
																  EBSBuffer,
hgs
parents:
diff changeset
   555
																  *buffeData ); 
hgs
parents:
diff changeset
   556
				}
hgs
parents:
diff changeset
   557
hgs
parents:
diff changeset
   558
			CleanupStack::PopAndDestroy( buffeData );
hgs
parents:
diff changeset
   559
			break;
hgs
parents:
diff changeset
   560
			}
hgs
parents:
diff changeset
   561
		case EBSBitmap:
hgs
parents:
diff changeset
   562
			{
hgs
parents:
diff changeset
   563
			TInt length = aStream.ReadInt16L();
hgs
parents:
diff changeset
   564
			HBufC8* fileId = HBufC8::NewLC( length );
hgs
parents:
diff changeset
   565
			
hgs
parents:
diff changeset
   566
			TPtr8 fileIdPtr = fileId->Des();
hgs
parents:
diff changeset
   567
			aStream.ReadL( fileIdPtr, length );
hgs
parents:
diff changeset
   568
			
hgs
parents:
diff changeset
   569
			TInt bitmapId = aStream.ReadInt16L();
hgs
parents:
diff changeset
   570
			TInt maskId = aStream.ReadInt16L();
hgs
parents:
diff changeset
   571
			TInt skinId = aStream.ReadInt16L();
hgs
parents:
diff changeset
   572
			TInt skinMaskId = aStream.ReadInt16L();
hgs
parents:
diff changeset
   573
hgs
parents:
diff changeset
   574
			TRACE( T_LIT( "CBSBrandHandler::ReadStreamL type BITMAP .. bitmap ID is [%d]"), bitmapId);
hgs
parents:
diff changeset
   575
			if( match )
hgs
parents:
diff changeset
   576
				{
hgs
parents:
diff changeset
   577
				CBSBitmap* bitmap = CBSBitmap::NewLC( bitmapId,
hgs
parents:
diff changeset
   578
													  maskId,
hgs
parents:
diff changeset
   579
													  skinId,
hgs
parents:
diff changeset
   580
													  skinMaskId,
hgs
parents:
diff changeset
   581
													  fileIdPtr );
hgs
parents:
diff changeset
   582
hgs
parents:
diff changeset
   583
                // Codescanner warning: neglected to put variable on cleanup stack (id:35)
hgs
parents:
diff changeset
   584
                // This method cannot leave after this line
hgs
parents:
diff changeset
   585
				returnValue = BSElementFactory::CreateBSElementL( idPtrC, // CSI: 35 # See above
hgs
parents:
diff changeset
   586
																  EBSBitmap,
hgs
parents:
diff changeset
   587
																  bitmap ); 
hgs
parents:
diff changeset
   588
				CleanupStack::Pop( bitmap ); 
hgs
parents:
diff changeset
   589
				}
hgs
parents:
diff changeset
   590
		    CleanupStack::PopAndDestroy( fileId ); 
hgs
parents:
diff changeset
   591
hgs
parents:
diff changeset
   592
			break;
hgs
parents:
diff changeset
   593
			}
hgs
parents:
diff changeset
   594
		default:
hgs
parents:
diff changeset
   595
			{
hgs
parents:
diff changeset
   596
			TRACE( T_LIT( "CBSBrandHandler::ReadStreamL type DEFAULT : corrupt"));
hgs
parents:
diff changeset
   597
			User::Leave( KErrCorrupt );
hgs
parents:
diff changeset
   598
			break;
hgs
parents:
diff changeset
   599
			}
hgs
parents:
diff changeset
   600
		}
hgs
parents:
diff changeset
   601
hgs
parents:
diff changeset
   602
	if( elementId )
hgs
parents:
diff changeset
   603
		{
hgs
parents:
diff changeset
   604
		CleanupStack::PopAndDestroy( elementId );
hgs
parents:
diff changeset
   605
		}
hgs
parents:
diff changeset
   606
hgs
parents:
diff changeset
   607
	TRACE( T_LIT( "CBSBrandHandler::ReadStreamL END"));
hgs
parents:
diff changeset
   608
	return returnValue;
hgs
parents:
diff changeset
   609
	}
hgs
parents:
diff changeset
   610
hgs
parents:
diff changeset
   611
//  END OF FILE
hgs
parents:
diff changeset
   612