brandingserver/BSClient/cbselement.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) 2009 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:  cbselement.cpp
hgs
parents:
diff changeset
    15
*
hgs
parents:
diff changeset
    16
*/
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
//  INCLUDE FILES
hgs
parents:
diff changeset
    19
hgs
parents:
diff changeset
    20
#include <utf.h>
hgs
parents:
diff changeset
    21
#include "e32base.h"
hgs
parents:
diff changeset
    22
#include "s32strm.h"
hgs
parents:
diff changeset
    23
#include "cbselement.h"
hgs
parents:
diff changeset
    24
#include "cbsbitmap.h"
hgs
parents:
diff changeset
    25
hgs
parents:
diff changeset
    26
hgs
parents:
diff changeset
    27
CBSElement* CBSElement::NewL(
hgs
parents:
diff changeset
    28
						const TDesC8& aElementId,
hgs
parents:
diff changeset
    29
						TInt aData )
hgs
parents:
diff changeset
    30
    {
hgs
parents:
diff changeset
    31
hgs
parents:
diff changeset
    32
	CBSElement* self = new ( ELeave ) CBSElement() ;
hgs
parents:
diff changeset
    33
    CleanupStack::PushL( self );
hgs
parents:
diff changeset
    34
    self->ConstructL( EBSInt,
hgs
parents:
diff changeset
    35
    				  aElementId,
hgs
parents:
diff changeset
    36
    				  aData,
hgs
parents:
diff changeset
    37
    				  ETrue,
hgs
parents:
diff changeset
    38
    				  NULL,
hgs
parents:
diff changeset
    39
    				  KNullDesC,
hgs
parents:
diff changeset
    40
    				  KNullDesC8,
hgs
parents:
diff changeset
    41
    				  NULL );
hgs
parents:
diff changeset
    42
    CleanupStack::Pop( self );  //self
hgs
parents:
diff changeset
    43
    return self;
hgs
parents:
diff changeset
    44
    }
hgs
parents:
diff changeset
    45
hgs
parents:
diff changeset
    46
hgs
parents:
diff changeset
    47
CBSElement* CBSElement::NewL(
hgs
parents:
diff changeset
    48
						const TDesC8& aElementId,
hgs
parents:
diff changeset
    49
						const TDesC& aData,
hgs
parents:
diff changeset
    50
						TBSElementType aType /*= EText*/ )
hgs
parents:
diff changeset
    51
    {
hgs
parents:
diff changeset
    52
    if( aType != EBSFile && aType != EBSText )
hgs
parents:
diff changeset
    53
        {
hgs
parents:
diff changeset
    54
        User::Leave( KErrArgument );
hgs
parents:
diff changeset
    55
        }
hgs
parents:
diff changeset
    56
hgs
parents:
diff changeset
    57
    CBSElement* self = new ( ELeave ) CBSElement() ;
hgs
parents:
diff changeset
    58
    CleanupStack::PushL( self );
hgs
parents:
diff changeset
    59
    self->ConstructL( aType,
hgs
parents:
diff changeset
    60
    				  aElementId,
hgs
parents:
diff changeset
    61
    				  0,
hgs
parents:
diff changeset
    62
    				  EFalse,
hgs
parents:
diff changeset
    63
    				  NULL,
hgs
parents:
diff changeset
    64
    				  aData,
hgs
parents:
diff changeset
    65
    				  KNullDesC8,
hgs
parents:
diff changeset
    66
    				  NULL);
hgs
parents:
diff changeset
    67
    CleanupStack::Pop( self );  //self
hgs
parents:
diff changeset
    68
    return self;
hgs
parents:
diff changeset
    69
    }
hgs
parents:
diff changeset
    70
hgs
parents:
diff changeset
    71
hgs
parents:
diff changeset
    72
CBSElement* CBSElement::NewL(
hgs
parents:
diff changeset
    73
						const TDesC8& aElementId,
hgs
parents:
diff changeset
    74
						const TDesC8& aData )
hgs
parents:
diff changeset
    75
    {
hgs
parents:
diff changeset
    76
    CBSElement* self = new ( ELeave ) CBSElement() ;
hgs
parents:
diff changeset
    77
    CleanupStack::PushL( self );
hgs
parents:
diff changeset
    78
    self->ConstructL( EBSBuffer,
hgs
parents:
diff changeset
    79
    				  aElementId,
hgs
parents:
diff changeset
    80
    				  0,
hgs
parents:
diff changeset
    81
    				  EFalse,
hgs
parents:
diff changeset
    82
    				  NULL,
hgs
parents:
diff changeset
    83
    				  KNullDesC,
hgs
parents:
diff changeset
    84
    				  aData,
hgs
parents:
diff changeset
    85
    				  NULL);
hgs
parents:
diff changeset
    86
    CleanupStack::Pop( self );  //self
hgs
parents:
diff changeset
    87
    return self;
hgs
parents:
diff changeset
    88
    }
hgs
parents:
diff changeset
    89
hgs
parents:
diff changeset
    90
CBSElement* CBSElement::NewL(
hgs
parents:
diff changeset
    91
						const TDesC8& aElementId,
hgs
parents:
diff changeset
    92
						RBSObjOwningPtrArray<MBSElement>& aStructure )
hgs
parents:
diff changeset
    93
    {
hgs
parents:
diff changeset
    94
    CBSElement* self = new ( ELeave ) CBSElement();
hgs
parents:
diff changeset
    95
    CleanupStack::PushL( self );
hgs
parents:
diff changeset
    96
    self->ConstructL( EBSList,
hgs
parents:
diff changeset
    97
    				  aElementId,
hgs
parents:
diff changeset
    98
    				  0,
hgs
parents:
diff changeset
    99
    				  EFalse,
hgs
parents:
diff changeset
   100
    				  NULL,
hgs
parents:
diff changeset
   101
    				  KNullDesC,
hgs
parents:
diff changeset
   102
    				  KNullDesC8,
hgs
parents:
diff changeset
   103
    				  &aStructure );
hgs
parents:
diff changeset
   104
    CleanupStack::Pop( self );  //self
hgs
parents:
diff changeset
   105
    return self;
hgs
parents:
diff changeset
   106
    }
hgs
parents:
diff changeset
   107
hgs
parents:
diff changeset
   108
CBSElement* CBSElement::NewL(
hgs
parents:
diff changeset
   109
    					const TDesC8& aElementId,
hgs
parents:
diff changeset
   110
    					CBSBitmap* aBitmap )
hgs
parents:
diff changeset
   111
    {
hgs
parents:
diff changeset
   112
    CBSElement* self = new ( ELeave ) CBSElement() ;
hgs
parents:
diff changeset
   113
    CleanupStack::PushL( self );
hgs
parents:
diff changeset
   114
    self->ConstructL( EBSBitmap,
hgs
parents:
diff changeset
   115
    				  aElementId,
hgs
parents:
diff changeset
   116
    				  0,
hgs
parents:
diff changeset
   117
    				  EFalse,
hgs
parents:
diff changeset
   118
    				  aBitmap,
hgs
parents:
diff changeset
   119
    				  KNullDesC,
hgs
parents:
diff changeset
   120
    				  KNullDesC8,
hgs
parents:
diff changeset
   121
    				  NULL );
hgs
parents:
diff changeset
   122
hgs
parents:
diff changeset
   123
	if( !aBitmap )
hgs
parents:
diff changeset
   124
		{
hgs
parents:
diff changeset
   125
		User::Leave( KErrArgument );
hgs
parents:
diff changeset
   126
		}
hgs
parents:
diff changeset
   127
hgs
parents:
diff changeset
   128
    CleanupStack::Pop( self );  //self
hgs
parents:
diff changeset
   129
    return self;
hgs
parents:
diff changeset
   130
    }
hgs
parents:
diff changeset
   131
hgs
parents:
diff changeset
   132
void CBSElement::ConstructL(
hgs
parents:
diff changeset
   133
						 TBSElementType aElementType,
hgs
parents:
diff changeset
   134
					 	 const TDesC8& aElementId,
hgs
parents:
diff changeset
   135
					 	 TInt aIntData,
hgs
parents:
diff changeset
   136
					 	 TBool aIntDataInitialized,
hgs
parents:
diff changeset
   137
					 	 CBSBitmap* aBitmap,
hgs
parents:
diff changeset
   138
					 	 const TDesC& aTextData,
hgs
parents:
diff changeset
   139
					 	 const TDesC8& aBufferData,
hgs
parents:
diff changeset
   140
					 	 RBSObjOwningPtrArray<MBSElement>* aStructure )
hgs
parents:
diff changeset
   141
    {
hgs
parents:
diff changeset
   142
	iElementType = aElementType;
hgs
parents:
diff changeset
   143
hgs
parents:
diff changeset
   144
	iElementId = aElementId.AllocL();
hgs
parents:
diff changeset
   145
hgs
parents:
diff changeset
   146
	iIntData = aIntData;
hgs
parents:
diff changeset
   147
	iIntDataInitialized = aIntDataInitialized;
hgs
parents:
diff changeset
   148
hgs
parents:
diff changeset
   149
	iBitmapData = aBitmap;
hgs
parents:
diff changeset
   150
hgs
parents:
diff changeset
   151
	if( 0 != aTextData.Compare( KNullDesC() ) )
hgs
parents:
diff changeset
   152
		{
hgs
parents:
diff changeset
   153
		iTextData = aTextData.AllocL();
hgs
parents:
diff changeset
   154
		}
hgs
parents:
diff changeset
   155
	if( 0 != aBufferData.Compare( KNullDesC8() ) )
hgs
parents:
diff changeset
   156
		{
hgs
parents:
diff changeset
   157
		iBufferData = aBufferData.AllocL();
hgs
parents:
diff changeset
   158
		}
hgs
parents:
diff changeset
   159
	if( aStructure )
hgs
parents:
diff changeset
   160
		{
hgs
parents:
diff changeset
   161
		iArrayInitialized = ETrue;
hgs
parents:
diff changeset
   162
		iArray = *aStructure;
hgs
parents:
diff changeset
   163
		}
hgs
parents:
diff changeset
   164
    }
hgs
parents:
diff changeset
   165
hgs
parents:
diff changeset
   166
hgs
parents:
diff changeset
   167
CBSElement::~CBSElement()
hgs
parents:
diff changeset
   168
    {
hgs
parents:
diff changeset
   169
	delete iTextData;
hgs
parents:
diff changeset
   170
	delete iBufferData;
hgs
parents:
diff changeset
   171
	delete iElementId;
hgs
parents:
diff changeset
   172
hgs
parents:
diff changeset
   173
	iArray.Close();
hgs
parents:
diff changeset
   174
	delete iBitmapData;
hgs
parents:
diff changeset
   175
    }
hgs
parents:
diff changeset
   176
hgs
parents:
diff changeset
   177
hgs
parents:
diff changeset
   178
CBSElement::CBSElement()
hgs
parents:
diff changeset
   179
	{
hgs
parents:
diff changeset
   180
	}
hgs
parents:
diff changeset
   181
hgs
parents:
diff changeset
   182
void CBSElement::Close()
hgs
parents:
diff changeset
   183
	{
hgs
parents:
diff changeset
   184
	delete this;
hgs
parents:
diff changeset
   185
	}
hgs
parents:
diff changeset
   186
	
hgs
parents:
diff changeset
   187
	
hgs
parents:
diff changeset
   188
TBSElementType CBSElement::ElementType()
hgs
parents:
diff changeset
   189
	{
hgs
parents:
diff changeset
   190
	return iElementType;
hgs
parents:
diff changeset
   191
	}
hgs
parents:
diff changeset
   192
hgs
parents:
diff changeset
   193
const TDesC8& CBSElement::ElementId()
hgs
parents:
diff changeset
   194
	{
hgs
parents:
diff changeset
   195
	return *iElementId;
hgs
parents:
diff changeset
   196
	}
hgs
parents:
diff changeset
   197
hgs
parents:
diff changeset
   198
TInt CBSElement::IntDataL()
hgs
parents:
diff changeset
   199
	{
hgs
parents:
diff changeset
   200
	if( !iIntDataInitialized )
hgs
parents:
diff changeset
   201
		{
hgs
parents:
diff changeset
   202
		User::Leave( KErrArgument );
hgs
parents:
diff changeset
   203
		}
hgs
parents:
diff changeset
   204
	return iIntData;
hgs
parents:
diff changeset
   205
	}
hgs
parents:
diff changeset
   206
hgs
parents:
diff changeset
   207
const TDesC& CBSElement::TextDataL()
hgs
parents:
diff changeset
   208
	{
hgs
parents:
diff changeset
   209
	if( !iTextData )
hgs
parents:
diff changeset
   210
		{
hgs
parents:
diff changeset
   211
		User::Leave( KErrArgument );
hgs
parents:
diff changeset
   212
		}
hgs
parents:
diff changeset
   213
	return *iTextData;
hgs
parents:
diff changeset
   214
	}
hgs
parents:
diff changeset
   215
hgs
parents:
diff changeset
   216
const TDesC8& CBSElement::BufferDataL()
hgs
parents:
diff changeset
   217
	{
hgs
parents:
diff changeset
   218
	if( !iBufferData )
hgs
parents:
diff changeset
   219
		{
hgs
parents:
diff changeset
   220
		User::Leave( KErrArgument );
hgs
parents:
diff changeset
   221
		}
hgs
parents:
diff changeset
   222
	return *iBufferData;
hgs
parents:
diff changeset
   223
	}
hgs
parents:
diff changeset
   224
hgs
parents:
diff changeset
   225
const CBSBitmap& CBSElement::BitmapDataL()
hgs
parents:
diff changeset
   226
    {
hgs
parents:
diff changeset
   227
	if( !iBitmapData )
hgs
parents:
diff changeset
   228
		{
hgs
parents:
diff changeset
   229
		User::Leave( KErrArgument );
hgs
parents:
diff changeset
   230
		}
hgs
parents:
diff changeset
   231
    return *iBitmapData;
hgs
parents:
diff changeset
   232
    }
hgs
parents:
diff changeset
   233
hgs
parents:
diff changeset
   234
TArray<MBSElement*> CBSElement::GetStructureL()
hgs
parents:
diff changeset
   235
	{
hgs
parents:
diff changeset
   236
	if( !iArrayInitialized )
hgs
parents:
diff changeset
   237
		{
hgs
parents:
diff changeset
   238
		User::Leave( KErrArgument );
hgs
parents:
diff changeset
   239
		}
hgs
parents:
diff changeset
   240
hgs
parents:
diff changeset
   241
	return iArray.Array();
hgs
parents:
diff changeset
   242
	}
hgs
parents:
diff changeset
   243
hgs
parents:
diff changeset
   244
const MBSElement& CBSElement::FindSubEntryL( const TDesC& aElementId )
hgs
parents:
diff changeset
   245
	{
hgs
parents:
diff changeset
   246
    if ( !iArray.Count() )
hgs
parents:
diff changeset
   247
        {
hgs
parents:
diff changeset
   248
        User::Leave( KErrNotFound );
hgs
parents:
diff changeset
   249
        }
hgs
parents:
diff changeset
   250
    
hgs
parents:
diff changeset
   251
	MBSElement* element = NULL;
hgs
parents:
diff changeset
   252
	HBufC8* id = CnvUtfConverter::ConvertFromUnicodeToUtf8L( aElementId );	
hgs
parents:
diff changeset
   253
	User::LeaveIfNull( id );
hgs
parents:
diff changeset
   254
	CleanupStack::PushL( id );
hgs
parents:
diff changeset
   255
	for ( TInt i( 0 ) ; i < iArray.Count() ; i++ )
hgs
parents:
diff changeset
   256
	    {
hgs
parents:
diff changeset
   257
	    if ( iArray[ i ] )
hgs
parents:
diff changeset
   258
	        {
hgs
parents:
diff changeset
   259
    	    if ( !iArray[ i ]->ElementId().CompareC( *id ) )
hgs
parents:
diff changeset
   260
    	        {
hgs
parents:
diff changeset
   261
    	        // Match found
hgs
parents:
diff changeset
   262
    	        element = iArray[ i ];
hgs
parents:
diff changeset
   263
    	        i = iArray.Count();// Exit loop.
hgs
parents:
diff changeset
   264
    	        }
hgs
parents:
diff changeset
   265
	        }
hgs
parents:
diff changeset
   266
	    }
hgs
parents:
diff changeset
   267
	CleanupStack::PopAndDestroy( id );
hgs
parents:
diff changeset
   268
	  
hgs
parents:
diff changeset
   269
	if ( !element )
hgs
parents:
diff changeset
   270
	    {
hgs
parents:
diff changeset
   271
	    User::Leave( KErrNotFound );
hgs
parents:
diff changeset
   272
	    }
hgs
parents:
diff changeset
   273
	      
hgs
parents:
diff changeset
   274
	return *element;
hgs
parents:
diff changeset
   275
	}
hgs
parents:
diff changeset
   276
hgs
parents:
diff changeset
   277
void CBSElement::ExternalizeL( RWriteStream& aWriteStream )
hgs
parents:
diff changeset
   278
    {
hgs
parents:
diff changeset
   279
    // Write common header for all elements
hgs
parents:
diff changeset
   280
    aWriteStream.WriteInt16L( iElementType );
hgs
parents:
diff changeset
   281
    aWriteStream.WriteInt16L( iElementId->Length() );
hgs
parents:
diff changeset
   282
    if( iElementId->Length() > 0 )
hgs
parents:
diff changeset
   283
        {
hgs
parents:
diff changeset
   284
        // Write ID only if it's defined
hgs
parents:
diff changeset
   285
        aWriteStream.WriteL( *iElementId );
hgs
parents:
diff changeset
   286
        }
hgs
parents:
diff changeset
   287
hgs
parents:
diff changeset
   288
    // Write element type specific data
hgs
parents:
diff changeset
   289
    switch( iElementType )
hgs
parents:
diff changeset
   290
        {
hgs
parents:
diff changeset
   291
        case EBSInt:
hgs
parents:
diff changeset
   292
            {
hgs
parents:
diff changeset
   293
            aWriteStream.WriteInt16L( iIntData );
hgs
parents:
diff changeset
   294
            break;
hgs
parents:
diff changeset
   295
            }
hgs
parents:
diff changeset
   296
        case EBSText:     // flowthrough
hgs
parents:
diff changeset
   297
        case EBSFile:
hgs
parents:
diff changeset
   298
            {
hgs
parents:
diff changeset
   299
            aWriteStream.WriteInt16L( iTextData->Length() );
hgs
parents:
diff changeset
   300
            aWriteStream.WriteL( *iTextData );
hgs
parents:
diff changeset
   301
            break;
hgs
parents:
diff changeset
   302
            }
hgs
parents:
diff changeset
   303
        case EBSList:
hgs
parents:
diff changeset
   304
            {
hgs
parents:
diff changeset
   305
			TInt count = iArray.Count();
hgs
parents:
diff changeset
   306
            aWriteStream.WriteInt16L( count );
hgs
parents:
diff changeset
   307
            // Write all subitems to stream
hgs
parents:
diff changeset
   308
            for( TInt i = 0; i < count; i++ )
hgs
parents:
diff changeset
   309
                {
hgs
parents:
diff changeset
   310
				MBSElement* element = iArray[i];
hgs
parents:
diff changeset
   311
                element->ExternalizeL( aWriteStream );
hgs
parents:
diff changeset
   312
                }
hgs
parents:
diff changeset
   313
            break;
hgs
parents:
diff changeset
   314
            }
hgs
parents:
diff changeset
   315
        case EBSBitmap:
hgs
parents:
diff changeset
   316
            {
hgs
parents:
diff changeset
   317
			TPtrC8 ptr = iBitmapData->BitmapFileId();
hgs
parents:
diff changeset
   318
			aWriteStream.WriteInt16L( ptr.Length() );
hgs
parents:
diff changeset
   319
            aWriteStream.WriteL( ptr );
hgs
parents:
diff changeset
   320
            
hgs
parents:
diff changeset
   321
            aWriteStream.WriteInt16L( iBitmapData->BitmapId() );
hgs
parents:
diff changeset
   322
            aWriteStream.WriteInt16L( iBitmapData->BitmapMaskId() );
hgs
parents:
diff changeset
   323
            aWriteStream.WriteInt16L( iBitmapData->SkinIdMajor() );
hgs
parents:
diff changeset
   324
            aWriteStream.WriteInt16L( iBitmapData->SkinIdMinor() );
hgs
parents:
diff changeset
   325
hgs
parents:
diff changeset
   326
            break;
hgs
parents:
diff changeset
   327
            }
hgs
parents:
diff changeset
   328
        case EBSBuffer:
hgs
parents:
diff changeset
   329
        	{
hgs
parents:
diff changeset
   330
            aWriteStream.WriteInt16L( iBufferData->Length() );
hgs
parents:
diff changeset
   331
            aWriteStream.WriteL( *iBufferData );
hgs
parents:
diff changeset
   332
        	break;
hgs
parents:
diff changeset
   333
        	}
hgs
parents:
diff changeset
   334
        default:
hgs
parents:
diff changeset
   335
            {
hgs
parents:
diff changeset
   336
            // unknown type!
hgs
parents:
diff changeset
   337
            User::Leave( KErrCorrupt );
hgs
parents:
diff changeset
   338
            break;
hgs
parents:
diff changeset
   339
            }
hgs
parents:
diff changeset
   340
        }
hgs
parents:
diff changeset
   341
    }
hgs
parents:
diff changeset
   342
hgs
parents:
diff changeset
   343
hgs
parents:
diff changeset
   344
//  END OF FILE