satui/satapp/SATUISrc/csatuiiconhandler.cpp
branchRCL_3
changeset 20 987c9837762f
parent 0 ff3b6d0fd310
equal deleted inserted replaced
19:7d48bed6ce0c 20:987c9837762f
       
     1 /*
       
     2 * Copyright (c) 2006-2008 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: Implementation of CSatUiIconHandler class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include    <fbs.h>
       
    20 #include    <rsatservice.h>
       
    21 #include    <tsaticoninfo.h>
       
    22 
       
    23 #include    "csatuiiconhandler.h"
       
    24 #include    "tflogger.h"
       
    25 
       
    26 // ============================ MEMBER FUNCTIONS =============================
       
    27 
       
    28 // ---------------------------------------------------------------------------
       
    29 // First part of Two-phased constructor.
       
    30 // ---------------------------------------------------------------------------
       
    31 //
       
    32 CSatUiIconHandler* CSatUiIconHandler::NewL()
       
    33     {
       
    34     TFLOGSTRING( "CSatUiIconHandler::NewL enter" )
       
    35     CSatUiIconHandler* self = new ( ELeave ) CSatUiIconHandler;
       
    36     TFLOGSTRING( "CSatUiIconHandler::NewL exit" )
       
    37     return self;
       
    38     }
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 // Destructor
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 CSatUiIconHandler::~CSatUiIconHandler()
       
    45     {
       
    46     TFLOGSTRING( "CSatUiIconHandler::~CSatUiIconHandler enter" )
       
    47     // Close RSatService interface
       
    48     iSatService.Close();
       
    49     TFLOGSTRING( "CSatUiIconHandler::~CSatUiIconHandler exit" )
       
    50     }
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // Fetches first icon information, then the handle to the icon and at last
       
    54 // does the duplication of the icon bitmap. Object is set to wait the
       
    55 // completion of the request.
       
    56 // ---------------------------------------------------------------------------
       
    57 //
       
    58 CFbsBitmap* CSatUiIconHandler::FetchIconL( const RSatSession& aSatSession,
       
    59                                            const TUint8 aIconId,
       
    60                                            const TInt aOptWidth,
       
    61                                            const TInt aOptHeight,
       
    62                                            TBool& aIconSupport )
       
    63     {
       
    64     TFLOGSTRING( "CSatUiIconHandler::FetchIconL enter" )
       
    65     TFLOGSTRING3( "CSatUiIconHandler::FetchIconL aOptWidth=%d aOptHeight=%d",
       
    66             aOptWidth, aOptHeight )
       
    67             
       
    68     iSatService.OpenL( aSatSession );
       
    69     CleanupClosePushL( iSatService );
       
    70 
       
    71     RIconEf iconEf;
       
    72     CleanupClosePushL( iconEf );
       
    73     // Order of superiority list
       
    74     RArray<TInt> selectedIcons;
       
    75     CleanupClosePushL( selectedIcons );
       
    76     CFbsBitmap* iconBitmap = NULL;
       
    77     
       
    78     // Getting the information of the icon
       
    79     TRAPD( err, iSatService.GetIconInfoL( aIconId, iconEf ); );
       
    80     
       
    81     if ( KErrNone == err )
       
    82         {
       
    83         TFLOGSTRING( "CSatUiIconHandler::FetchIconL no error" )
       
    84         // Sorting into order of superiority
       
    85         SortIconsL( iconEf, selectedIcons, aOptWidth, aOptHeight );
       
    86         
       
    87         // Reset iconCount by approved icons
       
    88         const TInt iconCount = selectedIcons.Count() <= iconEf.Count() ? 
       
    89                                selectedIcons.Count() :
       
    90                                iconEf.Count();
       
    91         TBool fetchSuccess( EFalse );
       
    92         
       
    93         TFLOGSTRING2( "CSatUiIconHandler::FetchIconL iconCount: %d", iconCount )
       
    94         // If there were icons to be fetched
       
    95         if ( 0 < iconCount )
       
    96             {
       
    97             // start going through approved icons list from the 
       
    98             // first and biggest icon
       
    99             TInt counter( 0 );
       
   100             for ( counter = 0; ( counter < iconCount ) && !fetchSuccess;
       
   101                 counter++ )
       
   102                 {
       
   103                 TInt selectedIconCounter = selectedIcons.operator[]( counter );
       
   104                 TFLOGSTRING2( "CSatUiIconHandler::\
       
   105                     FetchIconL selectedIconCounter: %d", selectedIconCounter )
       
   106                 TRAPD( err, 
       
   107                        iconBitmap = iSatService.GetIconL( iconEf.operator[](
       
   108                            selectedIconCounter ) ) );
       
   109                 if ( KErrNone == err  )
       
   110                     {
       
   111                     fetchSuccess = ETrue;
       
   112                     TFLOGSTRING( "CSatUiIconHandler::FetchIconL fetchSuccess!" )
       
   113                     }
       
   114                 else
       
   115                     {
       
   116                     delete iconBitmap;
       
   117                     }
       
   118                 }
       
   119             }
       
   120         }
       
   121         
       
   122         TFLOGSTRING2( "CSatUiIconHandler::FetchIconL icon info error=%d", err )
       
   123         if ( KErrNotSupported == err )
       
   124             {
       
   125             TFLOGSTRING( "CSatUiIconHandler::FetchIconL icons not supported" )
       
   126             aIconSupport = EFalse;
       
   127             }
       
   128     
       
   129     // selectedIcons, iconEf and iSatService not deleted but closed
       
   130     CleanupStack::PopAndDestroy( 3, &iSatService );
       
   131 
       
   132     TFLOGSTRING( "CSatUiIconHandler::FetchIconL exit" )
       
   133     // Icon was not found, icons are not supported or an error was received.
       
   134     return iconBitmap;
       
   135     }
       
   136 
       
   137 // ---------------------------------------------------------------------------
       
   138 // C++ default constructor cannot contain any code that might leave.
       
   139 // ---------------------------------------------------------------------------
       
   140 //
       
   141 CSatUiIconHandler::CSatUiIconHandler()
       
   142     {
       
   143     TFLOGSTRING( "CSatUiIconHandler::CSatUiIconHandler enter - exit" )
       
   144     }
       
   145 
       
   146 // ---------------------------------------------------------------------------
       
   147 // Sorts icons into order of superiority
       
   148 // ---------------------------------------------------------------------------
       
   149 //
       
   150 void CSatUiIconHandler::SortIconsL( const RIconEf& aIconEf,
       
   151     RArray<TInt>& aSelectedIcons, const TInt aOptWidth,
       
   152     const TInt aOptHeight ) const
       
   153     {
       
   154     TFLOGSTRING( "CSatUiIconHandler::SortIcons enter" )
       
   155     
       
   156     const TInt iconCount = aIconEf.Count();
       
   157     TFLOGSTRING2( "CSatUiIconHandler::SortIcons iconCount=%d", iconCount )
       
   158     TInt counter( 0 );
       
   159     // Search icon from available iconarray
       
   160     for ( counter = 0; counter < iconCount; counter++ )
       
   161         {
       
   162         TFLOGSTRING3( "CSatUiIconHandler::SortIcons Icon Width=%d Height=%d",
       
   163             aIconEf.operator[]( counter ).IconSize().iWidth,
       
   164             aIconEf.operator[]( counter ).IconSize().iHeight )
       
   165 
       
   166         const TInt selectedCount( aSelectedIcons.Count() );
       
   167         TBool replacement( EFalse );
       
   168         
       
   169         // Count the difference of the icon versus layout
       
   170         TInt newWidthDifference(
       
   171             aOptWidth - aIconEf.operator[]( counter ).IconSize().iWidth );
       
   172         TInt newHeightDifference(
       
   173             aOptHeight - aIconEf.operator[]( counter ).IconSize().iHeight );
       
   174         
       
   175         // Make the difference absolute value
       
   176         if ( newWidthDifference < 0 )
       
   177             {
       
   178             newWidthDifference = -newWidthDifference;
       
   179             }
       
   180         
       
   181         if ( newHeightDifference < 0 )
       
   182             {
       
   183             newHeightDifference = -newHeightDifference;
       
   184             }
       
   185         TInt listCounter( 0 );
       
   186         // Going through the list of icons of suitable size
       
   187         for ( listCounter = 0; ( listCounter < selectedCount ) &&
       
   188             !replacement; listCounter++ )
       
   189             {
       
   190             
       
   191             // Count the difference of the icon versus layout
       
   192             TInt oldWidthDifference( aOptWidth - aIconEf.operator[](
       
   193               aSelectedIcons.operator[]( listCounter ) ).IconSize().iWidth );
       
   194             TInt oldHeightDifference( aOptHeight - aIconEf.operator[](
       
   195               aSelectedIcons.operator[]( listCounter ) ).IconSize().iHeight );
       
   196                
       
   197             // Make the difference absolute value
       
   198             if ( oldWidthDifference < 0 )
       
   199                 {
       
   200                 oldWidthDifference = -oldWidthDifference;
       
   201                 }
       
   202             
       
   203             if ( oldHeightDifference < 0 )
       
   204                 {
       
   205                 oldHeightDifference = -oldHeightDifference;
       
   206                 }
       
   207             
       
   208             // New icon is better either by being closer to the layout or by
       
   209             // being same size and color instead of black and white
       
   210             if ( ( ( newWidthDifference < oldWidthDifference ) &&
       
   211                   ( newHeightDifference <= oldHeightDifference ) ) ||
       
   212                 ( ( newWidthDifference <= oldWidthDifference ) &&
       
   213                   ( newHeightDifference < oldHeightDifference ) ) ||
       
   214                 ( ( newWidthDifference == oldWidthDifference ) &&
       
   215                   ( newHeightDifference == oldHeightDifference ) &&
       
   216                  ( TSatIconInfo::EBasic == aIconEf.operator[]( aSelectedIcons.
       
   217                     operator[]( listCounter ) ).CodingScheme() ) &&
       
   218                  ( TSatIconInfo::EColor ==  aIconEf.operator[]( counter ).
       
   219                     CodingScheme() ) ) )
       
   220                 {
       
   221                 TFLOGSTRING2( "CSatUiIconHandler::SortIcons \
       
   222                              newWidthDifference: %d", newWidthDifference ) 
       
   223                 TFLOGSTRING2( "CSatUiIconHandler::SortIcons \
       
   224                              oldHeightDifference: %d", oldHeightDifference )    
       
   225                 // Insert new icon to correct place
       
   226                 aSelectedIcons.InsertL( counter, listCounter );
       
   227                 replacement = ETrue;
       
   228                 }
       
   229             }
       
   230             
       
   231         TFLOGSTRING2( "CSatUiIconHandler::SortIcons listCounter: %d", \
       
   232             listCounter )    
       
   233         // Either first item or was not better than any in the list
       
   234         // New icon is added to the end of the array
       
   235         if ( !replacement )
       
   236             {
       
   237             aSelectedIcons.AppendL( counter );
       
   238             }
       
   239         }
       
   240         
       
   241     TFLOGSTRING2( "CSatUiIconHandler::SortIcons counter: %d", \
       
   242             counter )
       
   243     TFLOGSTRING( "CSatUiIconHandler::SortIcons exit" )
       
   244     }
       
   245