menucontentsrv/srvsrc/mcscachehandler.cpp
changeset 0 79c6a41cd166
child 31 8baec10861af
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 "mcscachehandler.h"
       
    24 #include "menueng.h"
       
    25 #include "menuengobject.h"
       
    26 #include "menusrvengutils.h"
       
    27 #include "mcsmenunotifier.h"
       
    28 
       
    29 
       
    30 // ============================ MEMBER FUNCTIONS ===============================
       
    31 // -----------------------------------------------------------------------------
       
    32 // CMcsCacheHandler::NewL
       
    33 // Two-phased constructor.
       
    34 // -----------------------------------------------------------------------------
       
    35 //
       
    36 EXPORT_C CMcsCacheHandler* CMcsCacheHandler::NewL( 
       
    37     CMenuEng& aEng,
       
    38     CMenuSrvEngUtils& aUtils )
       
    39     {
       
    40     CMcsCacheHandler* self = new( ELeave ) CMcsCacheHandler( aEng, aUtils );
       
    41     CleanupStack::PushL( self );
       
    42     self->ConstructL();
       
    43     CleanupStack::Pop( self );
       
    44     return self;
       
    45     }
       
    46 
       
    47 // -----------------------------------------------------------------------------    
       
    48 // Destructor
       
    49 // -----------------------------------------------------------------------------
       
    50 CMcsCacheHandler::~CMcsCacheHandler()
       
    51     {
       
    52     iAttrCache.ResetAndDestroy();
       
    53     }
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CMcsCacheHandler::CMcsCacheHandler
       
    57 // C++ default constructor can NOT contain any code, that
       
    58 // might leave.
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 CMcsCacheHandler::CMcsCacheHandler( 
       
    62     CMenuEng& aEng,
       
    63     CMenuSrvEngUtils& aUtils ): iEng( aEng ), iUtils( aUtils )
       
    64     {
       
    65     }
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // CMcsDrmHandler::ConstructL
       
    69 // Symbian 2nd phase constructor can leave.
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 void CMcsCacheHandler::ConstructL()
       
    73     {
       
    74     }
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // -----------------------------------------------------------------------------
       
    78 //     
       
    79 void CMcsCacheHandler::HandleRemoveId( TInt aId )
       
    80     {
       
    81     iAttrCache.RemoveId( aId );
       
    82     }
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // -----------------------------------------------------------------------------
       
    86 // 
       
    87 void CMcsCacheHandler::HandleRemoveAttribute( TInt aId, const TDesC& aAttrName )
       
    88 	{
       
    89 	iAttrCache.RemoveAttribute(aId, aAttrName);
       
    90 	}
       
    91 
       
    92 // -----------------------------------------------------------------------------
       
    93 // -----------------------------------------------------------------------------
       
    94 //        
       
    95 void CMcsCacheHandler::EngineEvents( TInt aEvents )
       
    96     {
       
    97     if( aEvents & RMenuNotifier::EItemsAddedRemoved )
       
    98         {
       
    99         RemoveNotExistItems();
       
   100         }
       
   101     if( aEvents & RMenuNotifier::EItemAttributeChanged )
       
   102         {
       
   103         TRAP_IGNORE(RemoveItemsWithChangedAttributesL());
       
   104         }
       
   105     }
       
   106 
       
   107 // ---------------------------------------------------------
       
   108 // RMenuSrvAttrArray::RemoveId
       
   109 // ---------------------------------------------------------
       
   110 //
       
   111 void CMcsCacheHandler::RemoveItemsWithChangedAttributesL()
       
   112     {
       
   113     for ( TInt i = 0; i < iAttrCache.Count(); i++ )
       
   114         {
       
   115         TBool dummy;
       
   116         TBool exist;
       
   117 
       
   118         TInt id = iAttrCache[i]->Id();
       
   119         TPtrC name = iAttrCache[i]->Name();
       
   120         TPtrC valueCache = iAttrCache[i]->Value();
       
   121         
       
   122         TPtrC valueXml(KNullDesC);
       
   123     
       
   124         exist = iEng.ObjectL(id).FindAttribute( name, valueXml, dummy );
       
   125         if( exist && valueXml != valueCache )
       
   126             {
       
   127             iAttrCache.RemoveAttribute( id, name );
       
   128             i--;
       
   129             }
       
   130         }
       
   131     }
       
   132 
       
   133 // ---------------------------------------------------------
       
   134 // RMenuSrvAttrArray::RemoveId
       
   135 // ---------------------------------------------------------
       
   136 //
       
   137 void CMcsCacheHandler::RemoveNotExistItems()
       
   138     {
       
   139     TInt id( KErrNone );
       
   140     for ( TInt i = 0; i < iAttrCache.Count(); i++ )
       
   141         {
       
   142         if( id != iAttrCache[i]->Id() )
       
   143             {
       
   144             id = iAttrCache[i]->Id();
       
   145             if( !iEng.Exist( id ) )
       
   146                 {
       
   147                 iAttrCache.RemoveId( id );
       
   148                 i--;
       
   149                 }
       
   150             }
       
   151         }
       
   152     }
       
   153 
       
   154 //  End of File