menucontentsrv/extsrc/mcssathandler.cpp
changeset 0 79c6a41cd166
equal deleted inserted replaced
-1:000000000000 0:79c6a41cd166
       
     1 /*
       
     2 * Copyright (c) 2002-2005 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:  Used for receive SIM Application name, icon or 
       
    15 *                visibility information.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 
       
    23 #include <e32property.h>
       
    24 // From SatClient
       
    25 #include "mcsdef.h"
       
    26 #include <bitdev.h>
       
    27 
       
    28 #include "mcssathandler.h"
       
    29 
       
    30 
       
    31 // ============================ MEMBER FUNCTIONS ===============================
       
    32 // -----------------------------------------------------------------------------
       
    33 // CMcsSatHandler::NewL
       
    34 // Two-phased constructor.
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 EXPORT_C CMcsSatHandler* CMcsSatHandler::NewL()
       
    38     {
       
    39     CMcsSatHandler* self = new( ELeave ) CMcsSatHandler( );
       
    40     CleanupStack::PushL( self );
       
    41     self->ConstructL();
       
    42     CleanupStack::Pop( self );
       
    43     return self;
       
    44     }
       
    45 
       
    46 // -----------------------------------------------------------------------------    
       
    47 // Destructor
       
    48 // -----------------------------------------------------------------------------
       
    49 CMcsSatHandler::~CMcsSatHandler()
       
    50     {
       
    51     iSatIcon.Close(); 
       
    52     iSatSession.Close();
       
    53     }
       
    54 
       
    55 // -----------------------------------------------------------------------------    
       
    56 // Destructor
       
    57 // -----------------------------------------------------------------------------
       
    58 EXPORT_C CAknIcon* CMcsSatHandler::LoadIconL()
       
    59     {
       
    60     TInt iconId( KErrNone );
       
    61     User::LeaveIfError( RProperty::Get( KCRUidMenu, KMenuSatUIIconId, iconId ) );
       
    62     CAknIcon* icon = CAknIcon::NewL(); 
       
    63     CleanupStack::PushL(icon);
       
    64     if( iconId != KErrNone )
       
    65         {
       
    66         RIconEf iIconEf;
       
    67         iSatIcon.GetIconInfoL( TUint8( iconId ), iIconEf ); 
       
    68         CleanupClosePushL( iIconEf );
       
    69         CFbsBitmap* bitmap = GetBitmapL( iIconEf );
       
    70             if( !bitmap )
       
    71                 {
       
    72                 CFbsBitmap* mask( NULL );
       
    73                 CleanupStack::PushL( mask );    
       
    74                 
       
    75                 icon->SetBitmap( bitmap );
       
    76                 // create and set mask
       
    77                 User::LeaveIfError( mask->Create( bitmap->SizeInPixels(), EGray256 ) );
       
    78                 
       
    79                 CFbsBitmapDevice* maskDevice = CFbsBitmapDevice::NewL( mask );
       
    80                 CleanupStack::PushL( maskDevice ); 
       
    81                 CFbsBitGc* maskGc;
       
    82                 User::LeaveIfError( maskDevice->CreateContext( maskGc ) );
       
    83                 CleanupStack::PushL( maskGc );
       
    84                 maskGc->SetBrushStyle( CGraphicsContext::ESolidBrush );
       
    85                 maskGc->SetDrawMode( CGraphicsContext::EDrawModePEN );
       
    86                 maskGc->SetBrushColor( KRgbBlack );
       
    87                 maskGc->Clear();            
       
    88                 maskGc->SetBrushColor( KRgbWhite );             
       
    89                 maskGc->DrawRect( TRect( TPoint( ), bitmap->SizeInPixels() ) );                
       
    90                 icon->SetMask( mask );
       
    91                 
       
    92                 CleanupStack::PopAndDestroy( maskGc );
       
    93                 CleanupStack::PopAndDestroy( maskDevice );
       
    94                 CleanupStack::Pop( mask );
       
    95                 }
       
    96         CleanupStack::PopAndDestroy( &iIconEf ); // iIconEf
       
    97         CleanupStack::Pop( icon );
       
    98         }
       
    99     else
       
   100         {
       
   101         CleanupStack::PopAndDestroy( icon );
       
   102         icon = NULL;
       
   103         }
       
   104     return icon;    
       
   105     }
       
   106 
       
   107 // ---------------------------------------------------------------------------
       
   108 // CMenuSATHandler::GetName
       
   109 // ---------------------------------------------------------------------------
       
   110 //    
       
   111 EXPORT_C TInt CMcsSatHandler::GetName( TDes& aName )
       
   112     {
       
   113     return RProperty::Get( KCRUidMenu, KMenuSatUIName, aName );
       
   114     }
       
   115 
       
   116 // ---------------------------------------------------------------------------
       
   117 // CMenuSATHandler::GetVisibility
       
   118 // ---------------------------------------------------------------------------
       
   119 //        
       
   120 EXPORT_C TBool CMcsSatHandler::CheckVisibility() 
       
   121     {
       
   122     TInt visibility( KErrNone );
       
   123     TInt err = RProperty::Get( KCRUidMenu, KMenuShowSatUI, visibility );
       
   124     if( err == KErrNone && visibility )
       
   125         return ETrue;
       
   126     else
       
   127         return EFalse;
       
   128     }
       
   129 
       
   130 
       
   131 // -----------------------------------------------------------------------------
       
   132 // CMcsSatHandler::CMcsSatHandler
       
   133 // C++ default constructor can NOT contain any code, that
       
   134 // might leave.
       
   135 // -----------------------------------------------------------------------------
       
   136 //
       
   137 CMcsSatHandler::CMcsSatHandler()
       
   138     {
       
   139     }
       
   140 
       
   141 // -----------------------------------------------------------------------------
       
   142 // CMcsSatHandler::ConstructL
       
   143 // Symbian 2nd phase constructor can leave.
       
   144 // -----------------------------------------------------------------------------
       
   145 //
       
   146 void CMcsSatHandler::ConstructL()
       
   147     {
       
   148     iSatSession.ConnectL();
       
   149     iSatIcon.OpenL( iSatSession ); 
       
   150     }
       
   151 
       
   152 // ---------------------------------------------------------------------------
       
   153 // CMenuSATHandler::GetVisibility
       
   154 // ---------------------------------------------------------------------------
       
   155 // 
       
   156 CFbsBitmap* CMcsSatHandler::GetBitmapL( const RIconEf& aIconEF )
       
   157     {
       
   158     TInt selectedIconIndex( KErrNotFound );
       
   159     TSize selectedIconSize( 0, 0 );
       
   160     CFbsBitmap* bitmap( NULL );
       
   161     for ( TInt i = 0; i < aIconEF.Count(); ++i )
       
   162         {
       
   163         if( ( aIconEF[i].IconSize().iHeight * aIconEF[i].IconSize().iWidth ) >= 
       
   164             ( selectedIconSize.iHeight * selectedIconSize.iWidth ) )
       
   165             if( bitmap )
       
   166                 {
       
   167                 delete bitmap;
       
   168                 bitmap = NULL;
       
   169                 }
       
   170             // test and select index of iIcon which is not too big
       
   171             TRAPD( bitmapErr, bitmap = iSatIcon.GetIconL( aIconEF[ i ] ) );
       
   172             if( !bitmapErr && bitmap ) //!iBitmap if iIcon is too big
       
   173                 {
       
   174                 selectedIconSize = aIconEF[i].IconSize();
       
   175                 selectedIconIndex = i;
       
   176                 }
       
   177             else if( bitmapErr )
       
   178                 {
       
   179                 User::Leave( bitmapErr );
       
   180                 }
       
   181             }
       
   182     if( selectedIconIndex != KErrNotFound )
       
   183         {
       
   184         if( bitmap )
       
   185             {
       
   186             delete bitmap;
       
   187             bitmap = NULL;
       
   188             }
       
   189         TRAPD( bitmapErr, bitmap = iSatIcon.GetIconL( aIconEF[ selectedIconIndex ] ) );
       
   190         User::LeaveIfError( bitmapErr );    
       
   191         return bitmap;
       
   192         }
       
   193     else 
       
   194         {
       
   195         return NULL;
       
   196         }    
       
   197     }    
       
   198     
       
   199 //  End of File