menufw/hierarchynavigator/hnmetadatamodel/src/hnmdmenuitem.cpp
changeset 0 f72a12da539e
child 4 4d54b72983ae
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/menufw/hierarchynavigator/hnmetadatamodel/src/hnmdmenuitem.cpp	Thu Dec 17 08:40:49 2009 +0200
@@ -0,0 +1,214 @@
+/*
+* Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:  
+*
+*/
+
+
+#include "hnmdmenuitem.h"
+#include "hnglobals.h"
+#include "hnconvutils.h"
+#include "hnstringhandler.h"
+#include "hnconditioninterface.h"
+#include "hnmdeventmappingelement.h"
+#include "hnmdevent.h"
+#include "hnmenuitemmodel.h"
+#include "hnconditionfactory.h"
+
+// ======== MEMBER FUNCTIONS ========
+
+// ---------------------------------------------------------------------------
+// 
+// ---------------------------------------------------------------------------
+//
+void CHnMdMenuItem::AppendChildItemL( CHnMdMenuItem* aMenuItem )
+    {
+    iChildren.AppendL( aMenuItem );
+    }
+
+// ---------------------------------------------------------------------------
+// 
+// ---------------------------------------------------------------------------
+//
+void CHnMdMenuItem::EvaluateL( CHnMenuItemModel* aMenuModel,
+        const CLiwGenericParamList& aQueriesResultsList, TInt aPos )
+    {
+    for ( TInt i( 0 ); i < iChildren.Count(); i++ )
+      {
+      CHnMdMenuItem* mdMenu = iChildren[ i ];
+      if ( mdMenu->IsValidL( aQueriesResultsList, aPos ) )
+          {
+          CHnMenuItemModel* menu = CHnMenuItemModel::NewL( mdMenu->NameL() );
+          mdMenu->EvaluateL( menu, aQueriesResultsList, aPos );
+          aMenuModel->AppendChildMenuL( menu );
+          }
+      }
+    aMenuModel->SetCommand( iEvent );
+    aMenuModel->SetPosition( iPosition );
+    aMenuModel->SetItemSpecific( iSpecific );
+    }
+
+// ---------------------------------------------------------------------------
+// ConstructL takes as an argument an item xml element. It iterates through 
+// item elements in order to find menuitems.
+// ---------------------------------------------------------------------------
+//
+void CHnMdMenuItem::CreatePropertiesL( TXmlEngElement aElement,
+                                 THnMdCommonPointers* /* aCmnPtrs */ )
+    {
+    iSpecific = !aElement.Name().Compare( KMenuItemSpecificElementName8 );
+    
+    // name
+    HBufC* name = HnConvUtils::Str8ToStrLC(
+            aElement.AttributeValueL( KName8 ) );
+    iName.Assign(name);
+    CleanupStack::Pop( name );
+
+    // position
+    TPtrC8 pos = aElement.AttributeValueL( KPositionAttrName8 );
+    TLex8 lexPosition ( pos );
+    User::LeaveIfError( lexPosition.Val( iPosition ) );
+
+    // event
+    if( aElement.AttributeValueL( KEventAttrName8 ).Length() && 
+                                            !aElement.HasChildNodes() )
+        { // there might not be the event attribute - submenues
+        TPtrC8 event = aElement.AttributeValueL( KEventAttrName8 );
+        TLex8 lex( event );
+        User::LeaveIfError( lex.Val( iEvent ) );
+        }
+    
+    // condition
+    if( aElement.AttributeValueL( KMenuConditionAttrName8 ).Length() )
+        {
+        iCondition = HnConditionFactory::NewL(  
+          aElement.AttributeNodeL( KMenuConditionAttrName8 ) );
+        }
+    }
+
+// ---------------------------------------------------------------------------
+// 
+// ---------------------------------------------------------------------------
+//
+void CHnMdMenuItem::CreateChildrenL( TXmlEngElement aElement,
+                                        THnMdCommonPointers* aCmnPtrs )
+    { 
+    RXmlEngNodeList< TXmlEngElement > children;
+    CleanupClosePushL( children );
+    aElement.GetChildElements( children );
+    TInt count = children.Count();
+
+    for ( TInt i = 0; i < count; i++ )
+        {
+        TXmlEngElement child = children.Next();
+        if ( !child.Name().Compare( KMenuItemElementName8 ) 
+        		|| !child.Name().Compare( KMenuItemSpecificElementName8 ) )
+            {
+            AppendChildItemL( CHnMdMenuItem::NewL( child, aCmnPtrs ) );
+            }
+        }
+    CleanupStack::PopAndDestroy( &children );
+    }
+
+// ---------------------------------------------------------------------------
+// ConstructL takes as an argument an item xml element. It iterates through 
+// item elements in order to find menuitems.
+// ---------------------------------------------------------------------------
+//
+void CHnMdMenuItem::ConstructL( TXmlEngElement aElement,
+                                THnMdCommonPointers* aCmnPtrs )
+    {
+    if ( !aElement.Name().Compare( KMenuItemElementName8 )
+    		|| !aElement.Name().Compare( KMenuItemSpecificElementName8 ) )
+        { // this is an ordinary menu item
+        CreatePropertiesL( aElement, aCmnPtrs );
+        CreateChildrenL( aElement, aCmnPtrs ); // in case there are subitems
+        }
+    else
+        { // this is the root level
+        CreateChildrenL( aElement, aCmnPtrs );
+        }
+    }
+
+// ---------------------------------------------------------------------------
+// 
+// ---------------------------------------------------------------------------
+//
+CHnMdMenuItem* CHnMdMenuItem::NewL( TXmlEngElement aElement,
+        THnMdCommonPointers* aCmnPtrs )
+    {
+    CHnMdMenuItem* self = CHnMdMenuItem::NewLC( aElement, aCmnPtrs );
+    CleanupStack::Pop( self );
+    return self;
+    }
+
+// ---------------------------------------------------------------------------
+// 
+// ---------------------------------------------------------------------------
+//
+CHnMdMenuItem* CHnMdMenuItem::NewLC( TXmlEngElement aElement, 
+        THnMdCommonPointers* aCmnPtrs )
+    {
+    CHnMdMenuItem* self = new( ELeave ) CHnMdMenuItem;
+    CleanupStack::PushL( self );
+    self->ConstructL( aElement, aCmnPtrs );
+    return self;
+    }
+
+// ---------------------------------------------------------------------------
+// 
+// ---------------------------------------------------------------------------
+//
+CHnMdMenuItem::CHnMdMenuItem()
+    {
+    }
+
+// ---------------------------------------------------------------------------
+// 
+// ---------------------------------------------------------------------------
+//
+CHnMdMenuItem::~CHnMdMenuItem()
+    {
+    iName.Close();
+    iChildren.ResetAndDestroy();
+    iNameValueCache.Close();
+    delete iCondition;
+    }
+
+// ---------------------------------------------------------------------------
+// 
+// ---------------------------------------------------------------------------
+//
+const TDesC& CHnMdMenuItem::NameL() 
+    {
+    iNameValueCache.Close();
+    HnStringHandler::LocaliseL( iNameValueCache, iName, NULL /*common params*/);
+    return iNameValueCache;
+    }
+
+// ---------------------------------------------------------------------------
+// 
+// ---------------------------------------------------------------------------
+//
+TBool CHnMdMenuItem::IsValidL( const CLiwGenericParamList& aQueryResults, 
+        TInt aPos )    
+    {
+    TBool ret( EFalse );
+    if( !iCondition || iCondition->ResultL( aQueryResults, aPos ) )
+        {
+        ret = ETrue;
+        }
+    return ret;
+    }
+