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