menufw/hierarchynavigator/hnmetadatamodel/src/hnmdmenuitem.cpp
branchv5backport
changeset 14 1abc632eb502
parent 13 6205fd287e8a
child 20 636d517f67e6
equal deleted inserted replaced
13:6205fd287e8a 14:1abc632eb502
     1 /*
       
     2 * Copyright (c) 2007-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:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "hnmdmenuitem.h"
       
    20 #include "hnglobals.h"
       
    21 #include "hnconvutils.h"
       
    22 #include "hnstringhandler.h"
       
    23 #include "hnconditioninterface.h"
       
    24 #include "hnmdeventmappingelement.h"
       
    25 #include "hnmdevent.h"
       
    26 #include "hnmenuitemmodel.h"
       
    27 #include "hnconditionfactory.h"
       
    28 
       
    29 // ======== MEMBER FUNCTIONS ========
       
    30 
       
    31 // ---------------------------------------------------------------------------
       
    32 // 
       
    33 // ---------------------------------------------------------------------------
       
    34 //
       
    35 TBool CHnMdMenuItem::IsMenuItemElementName( const TDesC8& aNameToCompare )    
       
    36     {
       
    37     return !aNameToCompare.Compare( KMenuItemElementName8 )
       
    38         || !aNameToCompare.Compare( KMenuItemSpecificElementName8 )
       
    39         || !aNameToCompare.Compare( KMenuItemActionElementName8 );
       
    40     }
       
    41 
       
    42 // ---------------------------------------------------------------------------
       
    43 // 
       
    44 // ---------------------------------------------------------------------------
       
    45 //
       
    46 void CHnMdMenuItem::AppendChildItemL( CHnMdMenuItem* aMenuItem )
       
    47     {
       
    48     iChildren.AppendL( aMenuItem );
       
    49     }
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // 
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 void CHnMdMenuItem::EvaluateL( CHnMenuItemModel* aMenuModel,
       
    56         const CLiwGenericParamList& aQueriesResultsList, TInt aPos )
       
    57     {
       
    58     for ( TInt i( 0 ); i < iChildren.Count(); i++ )
       
    59       {
       
    60       CHnMdMenuItem* mdMenu = iChildren[ i ];
       
    61       if ( mdMenu->IsValidL( aQueriesResultsList, aPos ) )
       
    62           {
       
    63           CHnMenuItemModel* menu = CHnMenuItemModel::NewL( mdMenu->NameL() );
       
    64           mdMenu->EvaluateL( menu, aQueriesResultsList, aPos );
       
    65           aMenuModel->AppendChildMenuL( menu );
       
    66           }
       
    67       }
       
    68     aMenuModel->SetCommand( iEvent );
       
    69     aMenuModel->SetPosition( iPosition );
       
    70     aMenuModel->SetMenuItemType( iType );
       
    71     }
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 // ConstructL takes as an argument an item xml element. It iterates through 
       
    75 // item elements in order to find menuitems.
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 void CHnMdMenuItem::CreatePropertiesL( TXmlEngElement aElement,
       
    79                                  THnMdCommonPointers* /* aCmnPtrs */ )
       
    80     {
       
    81     iType = CHnMenuItemModel::EItemApplication;
       
    82     if ( !aElement.Name().Compare( KMenuItemSpecificElementName8 ) )
       
    83     	{
       
    84     	iType = CHnMenuItemModel::EItemSpecific;
       
    85     	}
       
    86     else if ( !aElement.Name().Compare( KMenuItemActionElementName8 ) )
       
    87     	{
       
    88     	iType = CHnMenuItemModel::EItemAction;
       
    89     	}
       
    90     
       
    91     // name
       
    92     HBufC* name = HnConvUtils::Str8ToStrLC(
       
    93             aElement.AttributeValueL( KName8 ) );
       
    94     iName.Assign(name);
       
    95     CleanupStack::Pop( name );
       
    96 
       
    97     // position
       
    98     TPtrC8 pos = aElement.AttributeValueL( KPositionAttrName8 );
       
    99     TLex8 lexPosition ( pos );
       
   100     User::LeaveIfError( lexPosition.Val( iPosition ) );
       
   101 
       
   102     // event
       
   103     if( aElement.AttributeValueL( KEventAttrName8 ).Length() && 
       
   104                                             !aElement.HasChildNodes() )
       
   105         { // there might not be the event attribute - submenues
       
   106         TPtrC8 event = aElement.AttributeValueL( KEventAttrName8 );
       
   107         TLex8 lex( event );
       
   108         User::LeaveIfError( lex.Val( iEvent ) );
       
   109         }
       
   110     
       
   111     // condition
       
   112     if( aElement.AttributeValueL( KMenuConditionAttrName8 ).Length() )
       
   113         {
       
   114         iCondition = HnConditionFactory::NewL(  
       
   115           aElement.AttributeNodeL( KMenuConditionAttrName8 ) );
       
   116         }
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------------------------
       
   120 // 
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 void CHnMdMenuItem::CreateChildrenL( TXmlEngElement aElement,
       
   124                                         THnMdCommonPointers* aCmnPtrs )
       
   125     { 
       
   126     RXmlEngNodeList< TXmlEngElement > children;
       
   127     CleanupClosePushL( children );
       
   128     aElement.GetChildElements( children );
       
   129     TInt count = children.Count();
       
   130 
       
   131     for ( TInt i = 0; i < count; i++ )
       
   132         {
       
   133         TXmlEngElement child = children.Next();
       
   134         if ( IsMenuItemElementName( child.Name() ) )
       
   135             {
       
   136             AppendChildItemL( CHnMdMenuItem::NewL( child, aCmnPtrs ) );
       
   137             }
       
   138         }
       
   139     CleanupStack::PopAndDestroy( &children );
       
   140     }
       
   141 
       
   142 // ---------------------------------------------------------------------------
       
   143 // ConstructL takes as an argument an item xml element. It iterates through 
       
   144 // item elements in order to find menuitems.
       
   145 // ---------------------------------------------------------------------------
       
   146 //
       
   147 void CHnMdMenuItem::ConstructL( TXmlEngElement aElement,
       
   148                                 THnMdCommonPointers* aCmnPtrs )
       
   149     {
       
   150     if ( IsMenuItemElementName( aElement.Name() ) )
       
   151         { // this is an ordinary menu item
       
   152         CreatePropertiesL( aElement, aCmnPtrs );
       
   153         CreateChildrenL( aElement, aCmnPtrs ); // in case there are subitems
       
   154         }
       
   155     else
       
   156         { // this is the root level
       
   157         CreateChildrenL( aElement, aCmnPtrs );
       
   158         }
       
   159     }
       
   160 
       
   161 // ---------------------------------------------------------------------------
       
   162 // 
       
   163 // ---------------------------------------------------------------------------
       
   164 //
       
   165 CHnMdMenuItem* CHnMdMenuItem::NewL( TXmlEngElement aElement,
       
   166         THnMdCommonPointers* aCmnPtrs )
       
   167     {
       
   168     CHnMdMenuItem* self = CHnMdMenuItem::NewLC( aElement, aCmnPtrs );
       
   169     CleanupStack::Pop( self );
       
   170     return self;
       
   171     }
       
   172 
       
   173 // ---------------------------------------------------------------------------
       
   174 // 
       
   175 // ---------------------------------------------------------------------------
       
   176 //
       
   177 CHnMdMenuItem* CHnMdMenuItem::NewLC( TXmlEngElement aElement, 
       
   178         THnMdCommonPointers* aCmnPtrs )
       
   179     {
       
   180     CHnMdMenuItem* self = new( ELeave ) CHnMdMenuItem;
       
   181     CleanupStack::PushL( self );
       
   182     self->ConstructL( aElement, aCmnPtrs );
       
   183     return self;
       
   184     }
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 // 
       
   188 // ---------------------------------------------------------------------------
       
   189 //
       
   190 CHnMdMenuItem::CHnMdMenuItem()
       
   191     {
       
   192     }
       
   193 
       
   194 // ---------------------------------------------------------------------------
       
   195 // 
       
   196 // ---------------------------------------------------------------------------
       
   197 //
       
   198 CHnMdMenuItem::~CHnMdMenuItem()
       
   199     {
       
   200     iName.Close();
       
   201     iChildren.ResetAndDestroy();
       
   202     iNameValueCache.Close();
       
   203     delete iCondition;
       
   204     }
       
   205 
       
   206 // ---------------------------------------------------------------------------
       
   207 // 
       
   208 // ---------------------------------------------------------------------------
       
   209 //
       
   210 const TDesC& CHnMdMenuItem::NameL() 
       
   211     {
       
   212     iNameValueCache.Close();
       
   213     HnStringHandler::LocaliseL( iNameValueCache, iName, NULL /*common params*/);
       
   214     return iNameValueCache;
       
   215     }
       
   216 
       
   217 // ---------------------------------------------------------------------------
       
   218 // 
       
   219 // ---------------------------------------------------------------------------
       
   220 //
       
   221 TBool CHnMdMenuItem::IsValidL( const CLiwGenericParamList& aQueryResults, 
       
   222         TInt aPos )    
       
   223     {
       
   224     TBool ret( EFalse );
       
   225     if( !iCondition || iCondition->ResultL( aQueryResults, aPos ) )
       
   226         {
       
   227         ret = ETrue;
       
   228         }
       
   229     return ret;
       
   230     }
       
   231