taskswitcher/contextengine/hgfswserver/engine/src/hgfswiconcache.cpp
changeset 4 4d54b72983ae
parent 3 fb3763350a08
child 5 c743ef5928ba
equal deleted inserted replaced
3:fb3763350a08 4:4d54b72983ae
     1 /*
       
     2  * ============================================================================
       
     3  *  Name        : hgfswiconcache.cpp
       
     4  *  Part of     : Hg Teleport
       
     5  *  Description : Icon cache
       
     6  *  Version     : %version: sa1spcx1#5 %
       
     7  *
       
     8  *  Copyright 2008 Nokia.  All rights reserved.
       
     9  *  This material, including documentation and any related computer
       
    10  *  programs, is protected by copyright controlled by Nokia.  All
       
    11  *  rights are reserved.  Copying, including reproducing, storing,
       
    12  *  adapting or translating, any or all of this material requires the
       
    13  *  prior written consent of Nokia.  This material also contains
       
    14  *  confidential information which may not be disclosed to others
       
    15  *  without the prior written consent of Nokia.
       
    16  * ============================================================================
       
    17  */
       
    18 
       
    19 #include "hgfswiconcache.h"
       
    20 #include <fbs.h>
       
    21 #include <AknsUtils.h>
       
    22 #include <gulicon.h>
       
    23 #include <avkon.mbg>
       
    24 
       
    25 // size for the created app icons
       
    26 const TInt KAppIconWidth = 96;
       
    27 const TInt KAppIconHeight = 96;
       
    28 
       
    29 // --------------------------------------------------------------------------
       
    30 // CHgFswIconCache::NewL
       
    31 // --------------------------------------------------------------------------
       
    32 //
       
    33 CHgFswIconCache* CHgFswIconCache::NewL()
       
    34     {
       
    35     CHgFswIconCache* self = new (ELeave) CHgFswIconCache;
       
    36     CleanupStack::PushL (self );
       
    37     self->ConstructL ( );
       
    38     CleanupStack::Pop ( self );
       
    39     return self;
       
    40     }
       
    41 
       
    42 // --------------------------------------------------------------------------
       
    43 // CHgFswIconCache::CHgFswIconCache
       
    44 // --------------------------------------------------------------------------
       
    45 //
       
    46 CHgFswIconCache::CHgFswIconCache()
       
    47     {
       
    48     }
       
    49 
       
    50 // --------------------------------------------------------------------------
       
    51 // CHgFswIconCache::~CHgFswIconCache
       
    52 // --------------------------------------------------------------------------
       
    53 //
       
    54 CHgFswIconCache::~CHgFswIconCache( )
       
    55     {
       
    56     THashMapIter<TInt, SHgBitmapPair> iter( iAppIcons );
       
    57     while ( const TInt* key = iter.NextKey() )
       
    58         {
       
    59         SHgBitmapPair* value = iter.CurrentValue();
       
    60         delete value->iBitmap;
       
    61         delete value->iMask;
       
    62         }
       
    63     iAppIcons.Close();
       
    64     delete iDefaultIcon;
       
    65     }
       
    66 
       
    67 // --------------------------------------------------------------------------
       
    68 // CHgFswIconCache::ConstructL
       
    69 // --------------------------------------------------------------------------
       
    70 //
       
    71 void CHgFswIconCache::ConstructL()
       
    72     {
       
    73     iDefaultIcon = AknsUtils::CreateGulIconL( 
       
    74         AknsUtils::SkinInstance(),
       
    75         KAknsIIDQgnMenuUnknownCxt,
       
    76         AknIconUtils::AvkonIconFileName(),
       
    77         EMbmAvkonQgn_menu_unknown_cxt,
       
    78         EMbmAvkonQgn_menu_unknown_cxt_mask );
       
    79     TSize sz( KAppIconWidth, KAppIconHeight );
       
    80     AknIconUtils::SetSize( iDefaultIcon->Bitmap(), sz );
       
    81     AknIconUtils::SetSize( iDefaultIcon->Mask(), sz );
       
    82     }
       
    83 
       
    84 // --------------------------------------------------------------------------
       
    85 // CHgFswIconCache::GetAppIconL
       
    86 // --------------------------------------------------------------------------
       
    87 //
       
    88 void CHgFswIconCache::GetAppIconL( const TUid& aAppUid,
       
    89         CFbsBitmap*& aBitmap, CFbsBitmap*& aMask )
       
    90     {
       
    91     aBitmap = aMask = 0;
       
    92     MAknsSkinInstance* skinInstance = AknsUtils::SkinInstance();
       
    93     if ( skinInstance )
       
    94         {
       
    95         AknsUtils::CreateAppIconLC( skinInstance, aAppUid, EAknsAppIconTypeList,
       
    96             aBitmap, aMask );
       
    97         // The CreateAppIconLC method leaves both the bitmaps in the cleanup stack.
       
    98         // The order in which they are pushed into the stack and types of 
       
    99         // the items in the stack are both undefined.
       
   100         CleanupStack::Pop( 2 ); // codescanner::cleanup
       
   101         TSize sz( KAppIconWidth, KAppIconHeight );
       
   102         AknIconUtils::SetSize( aBitmap, sz );
       
   103         AknIconUtils::SetSize( aMask, sz );
       
   104         }
       
   105     }
       
   106 
       
   107 // --------------------------------------------------------------------------
       
   108 // CHgFswIconCache::GetIconL
       
   109 // --------------------------------------------------------------------------
       
   110 //
       
   111 void CHgFswIconCache::GetIconL( const TUid& aAppUid,
       
   112         CFbsBitmap*& aBitmap, CFbsBitmap*& aMask )
       
   113     {
       
   114     aBitmap = aMask = 0;
       
   115     SHgBitmapPair* bp = iAppIcons.Find( aAppUid.iUid );
       
   116     if ( bp )
       
   117         {
       
   118         // ownership stays with the hash table
       
   119         aBitmap = bp->iBitmap;
       
   120         aMask = bp->iMask;
       
   121         }
       
   122     else
       
   123         {
       
   124         GetAppIconL( aAppUid, aBitmap, aMask ); // ownership of the bitmap is ours
       
   125         // insert to hash table and pass ownership
       
   126         iAppIcons.InsertL( aAppUid.iUid, SHgBitmapPair( aBitmap, aMask ) );
       
   127         }
       
   128     }
       
   129 
       
   130 // --------------------------------------------------------------------------
       
   131 // CHgFswIconCache::DefaultIcon
       
   132 // --------------------------------------------------------------------------
       
   133 //
       
   134 void CHgFswIconCache::DefaultIcon( CFbsBitmap*& aBitmap, CFbsBitmap*& aMask )
       
   135     {
       
   136     aBitmap = iDefaultIcon->Bitmap();
       
   137     aMask = iDefaultIcon->Mask();
       
   138     }
       
   139 
       
   140 
       
   141 // end of file