logsui/logsserviceextension/src/tlogsextutil.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 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:  Class that contains util-functions for logsserviceextension.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32base.h>
       
    20 #include <f32file.h>
       
    21 #include <spsettings.h>
       
    22 #include <spproperty.h>
       
    23 #include <spdefinitions.h>
       
    24 #include <cbsfactory.h>
       
    25 #include <mbsaccess.h>
       
    26 #include <cbsbitmap.h>
       
    27 #include <mbselement.h>
       
    28 
       
    29 #include "tlogsextutil.h"
       
    30 #include "logsextconsts.h"
       
    31 #include "simpledebug.h"
       
    32 
       
    33 // ---------------------------------------------------------------------------
       
    34 // Retrieves File handle and bitmask/bitmask id and takes service id and 
       
    35 // element id as input parameters.
       
    36 // ---------------------------------------------------------------------------
       
    37 //
       
    38 void TLogsExtUtil::GetFileHandleL( 
       
    39     const TUint32 aServiceId,
       
    40     const TDesC8& aElementId,    
       
    41     RFile& aBitmapFile,
       
    42     TInt& aBitmapId,   
       
    43     TInt& aBitmapMaskId )
       
    44     {
       
    45     _LOG("TLogsExtUtil::GetFileHandleL() begin" ) 
       
    46     
       
    47     CSPSettings* spSettings = CSPSettings::NewLC();
       
    48     _LOG("TLogsExtUtil::GetFileHandleL() CSPSettings created" ) 
       
    49     
       
    50     // get the service provider settings
       
    51     
       
    52     // read the brand id from the settings table
       
    53     CSPProperty* spProperty = CSPProperty::NewLC();
       
    54     
       
    55     User::LeaveIfError( 
       
    56         spSettings->FindPropertyL( 
       
    57             aServiceId,
       
    58             EPropertyBrandId,
       
    59             *spProperty ) );
       
    60     
       
    61     if ( !spProperty ) // check if the property was found
       
    62         {
       
    63         User::Leave( KErrNotFound );   
       
    64         }       
       
    65     _LOG("TLogsExtUtil::GetFileHandleL() CSPProperty retrieved ok" )
       
    66       
       
    67     HBufC* brandId16 = HBufC::NewLC( KSPMaxDesLength );        
       
    68     TPtr brandIdPtr16( brandId16->Des() );    
       
    69     User::LeaveIfError( spProperty->GetValue( brandIdPtr16 ) );
       
    70     
       
    71     HBufC8* brandId8 = HBufC8::NewLC( brandIdPtr16.Length() );
       
    72     TPtr8 brandIdPtr8( brandId8->Des() );
       
    73     brandIdPtr8.Copy( *brandId16 );    
       
    74 
       
    75     // read the language property from the settings table        
       
    76     
       
    77     // workaround for missing brand language value from ServiceSettingsTable:
       
    78     // use hardcoded value
       
    79     TInt err( KErrNone );
       
    80     TInt languageId( ELangInternationalEnglish );
       
    81     TRAP( err, err = spSettings->FindPropertyL(
       
    82         aServiceId,
       
    83         EPropertyBrandLanguage,
       
    84         *spProperty ) );    
       
    85     
       
    86     if ( KErrNone == err )
       
    87         {
       
    88         User::LeaveIfError( spProperty->GetValue( languageId ) );
       
    89         _LOG("TLogsExtUtil::GetFileHandleL()..." )
       
    90         _LOG("...EPropertyBrandLanguage retrieved ok" )
       
    91         }
       
    92     else
       
    93         {        
       
    94         _LOG("TLogsExtUtil::GetFileHandleL() ...")
       
    95         _LOG("...retrieval of EPropertyBrandId failed.hardcoded...")
       
    96         _LOGPP("...language id(%d) used! error=%d", languageId, err )    
       
    97         }    
       
    98     
       
    99     // connect to branding server
       
   100     // KAppId defined in LogsExtConsts.h
       
   101     CBSFactory* factory = CBSFactory::NewL( KDefaultBrandId, KAppId );
       
   102     CleanupStack::PushL( factory );
       
   103     _LOG("TLogsExtUtil::GetFileHandleL() CBSFactory created" )
       
   104 
       
   105     // Create access to Branding server
       
   106     MBSAccess* access = 
       
   107         factory->CreateAccessL( *brandId8, TLanguage( languageId ) );    
       
   108     
       
   109     _LOG("TLogsExtUtil::GetFileHandleL() MBSAccess created" )
       
   110     CleanupClosePushL( *access );    
       
   111    
       
   112     // fetch the brand logo from the brand server    
       
   113     MBSElement* bitmapItem = NULL;    
       
   114       
       
   115     // get the structure containing the info for the bitmap
       
   116     bitmapItem = access->GetStructureL( aElementId );
       
   117     _LOG("TLogsExtUtil::GetFileHandleL() bitmapItem retrieved" ) 
       
   118     User::LeaveIfNull( bitmapItem );
       
   119     
       
   120     CleanupClosePushL( *bitmapItem );
       
   121     
       
   122     if ( EBSBitmap != bitmapItem->ElementType() ) 
       
   123         {
       
   124         User::Leave( KErrNotFound );
       
   125         }
       
   126         
       
   127     // get the bitmap data from the bitmap element
       
   128     const CBSBitmap* bsBitmap = &bitmapItem->BitmapDataL();
       
   129     _LOG("TLogsExtUtil::GetFileHandleL() bsBitmap retrieved" ) 
       
   130        
       
   131     // we need to get the bitmap file from where we can load the bitmap
       
   132     access->GetFileL( bsBitmap->BitmapFileId(), aBitmapFile );
       
   133     
       
   134     // set the return values
       
   135     aBitmapId = bsBitmap->BitmapId();
       
   136     aBitmapMaskId = bsBitmap->BitmapMaskId();
       
   137     
       
   138     CleanupStack::PopAndDestroy( bitmapItem );
       
   139     bitmapItem = NULL;
       
   140     CleanupStack::PopAndDestroy( access );
       
   141     access = NULL;
       
   142     CleanupStack::PopAndDestroy( factory );    
       
   143     factory = NULL;
       
   144     CleanupStack::PopAndDestroy( brandId8 ); 
       
   145     brandId8 = NULL;
       
   146     CleanupStack::PopAndDestroy( brandId16 ); 
       
   147     brandId16 = NULL;
       
   148     CleanupStack::PopAndDestroy( spProperty );
       
   149     spProperty = NULL;
       
   150     CleanupStack::PopAndDestroy( spSettings );
       
   151     spSettings = NULL;    
       
   152     }
       
   153