idlefw/src/utility/contentprioritymap.cpp
changeset 0 79c6a41cd166
equal deleted inserted replaced
-1:000000000000 0:79c6a41cd166
       
     1 /*
       
     2 * Copyright (c) 2006 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:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "contentprioritymap.h"
       
    20 
       
    21 using namespace AiUtility;
       
    22 
       
    23 
       
    24 // ======== MEMBER FUNCTIONS ========
       
    25 
       
    26 CContentPriorityMap::CContentPriorityMap()
       
    27     {
       
    28     }
       
    29 
       
    30 EXPORT_C CContentPriorityMap* CContentPriorityMap::NewL()
       
    31     {
       
    32     CContentPriorityMap* self = new( ELeave ) CContentPriorityMap;
       
    33     return self;
       
    34     }
       
    35 
       
    36 CContentPriorityMap::~CContentPriorityMap()
       
    37     {
       
    38     iPriorityMap.ResetAndDestroy();
       
    39     }
       
    40 
       
    41 
       
    42 EXPORT_C TInt CContentPriorityMap::CurrentPriority( const TDesC8& aUiElementId ) const
       
    43     {
       
    44     // Find current priority value for aUiElementId
       
    45     const TInt* currentPriority = iPriorityMap.Find( aUiElementId );
       
    46     
       
    47     // Return current priority value or KErrNotFound if it has not been set
       
    48     return currentPriority ? *currentPriority : KErrNotFound;
       
    49     }
       
    50 
       
    51 EXPORT_C TInt CContentPriorityMap::SetCurrentPriority( const TDesC8& aUiElementId,
       
    52                                                        TInt aPriority )
       
    53     {
       
    54     TInt error = KErrNone;
       
    55     TInt* currentPriority = iPriorityMap.Find( aUiElementId );
       
    56     
       
    57     if ( currentPriority )
       
    58         {
       
    59         // Update old value
       
    60         *currentPriority = aPriority;
       
    61         }
       
    62     else
       
    63         {
       
    64         // Insert new <key,value> pair
       
    65         TRAP( error,
       
    66             {
       
    67             HBufC8* key = aUiElementId.AllocLC();
       
    68             TInt* value = new( ELeave ) TInt( aPriority );
       
    69             CleanupStack::PushL( value );
       
    70             iPriorityMap.InsertL( key, value );
       
    71             CleanupStack::Pop( 2, key );
       
    72             } );
       
    73         }
       
    74     
       
    75     return error;
       
    76     }
       
    77 
       
    78 EXPORT_C void CContentPriorityMap::ClearPriority( const TDesC8& aUiElementId )
       
    79     {
       
    80     TInt* currentPriority = iPriorityMap.Find( aUiElementId );
       
    81     
       
    82     if ( currentPriority )
       
    83         {
       
    84         // Clear old value. Use KErrNotFound to avoid future reallocations of
       
    85         // the same key.
       
    86         *currentPriority = KErrNotFound;
       
    87         }
       
    88     }
       
    89 
       
    90 EXPORT_C void CContentPriorityMap::Reset()
       
    91     {
       
    92     iPriorityMap.ResetAndDestroy();
       
    93     }
       
    94 
       
    95 EXPORT_C TBool CContentPriorityMap::OverrideContent( const TDesC8& aUiElementId,
       
    96                                                      TInt aNewPriority ) const
       
    97     {
       
    98     return ( aNewPriority >= CurrentPriority( aUiElementId ) );
       
    99     }
       
   100