menufw/hierarchynavigator/hnmetadatamodel/src/hnmdbutton.cpp
changeset 0 f72a12da539e
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 <e32base.h>
       
    20 #include <e32cmn.h>
       
    21 #include <xmlengelement.h> 
       
    22 #include <gulicon.h>
       
    23 #include <xmlengnodelist.h>
       
    24 #include <liwcommon.h>
       
    25 
       
    26 #include "hnmdbutton.h"
       
    27 #include "hnmdkeyfactory.h"
       
    28 #include "hnconditioninterface.h"
       
    29 #include "hnconditionfactory.h"
       
    30 #include "hnmdvalueimage.h"
       
    31 #include "hnmdvaluetext.h"
       
    32 #include "hnglobals.h"
       
    33 #include "hnattributebase.h"
       
    34 #include "hnattributeimage.h"
       
    35 #include "hnattributebase.h"
       
    36 
       
    37 // ======== MEMBER FUNCTIONS ========
       
    38 
       
    39 // ---------------------------------------------------------------------------
       
    40 // 
       
    41 // ---------------------------------------------------------------------------
       
    42 //
       
    43 CHnMdButton* CHnMdButton::NewLC( TXmlEngElement aElement,
       
    44                                             THnMdCommonPointers* aCmnPtrs )
       
    45     {
       
    46     CHnMdButton* self = new( ELeave ) CHnMdButton;
       
    47     CleanupStack::PushL( self );
       
    48     self->ConstructL( aElement, aCmnPtrs );
       
    49     return self;
       
    50     }
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // 
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 CHnMdButton::~CHnMdButton( )
       
    57     {
       
    58     delete iButtonText;
       
    59     delete iConditionDimm;
       
    60     delete iConditionAdd;
       
    61     delete iIcon;
       
    62     }
       
    63        
       
    64 // ---------------------------------------------------------------------------
       
    65 // 
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 TBool CHnMdButton::ValidateToAddL( const CLiwGenericParamList& aQueryResults, 
       
    69                                             TInt aPos )
       
    70     {
       
    71     TBool ret( EFalse );
       
    72     if( !iConditionAdd || iConditionAdd->ResultL( aQueryResults, aPos ) )
       
    73         {
       
    74         ret = ETrue;
       
    75         }
       
    76     return ret;
       
    77     }
       
    78     
       
    79 // ---------------------------------------------------------------------------
       
    80 // 
       
    81 // ---------------------------------------------------------------------------
       
    82 //
       
    83 TBool CHnMdButton::ValidateToDimmL( 
       
    84         const CLiwGenericParamList& aQueryResults, TInt aPos )
       
    85     {
       
    86     TBool ret( EFalse );
       
    87     if( iConditionDimm )
       
    88         {
       
    89         ret = iConditionDimm->ResultL( aQueryResults, aPos );
       
    90         }
       
    91     return ret;
       
    92     }
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 // 
       
    96 // ---------------------------------------------------------------------------
       
    97 //       
       
    98 TInt CHnMdButton::GetEventId() const
       
    99     {
       
   100     return iEventId;
       
   101     }    
       
   102 
       
   103 // ---------------------------------------------------------------------------
       
   104 // 
       
   105 // ---------------------------------------------------------------------------
       
   106 //       
       
   107 TInt CHnMdButton::GetIndex() const
       
   108     {
       
   109     return iIndex;
       
   110     }    
       
   111 
       
   112 // ---------------------------------------------------------------------------
       
   113 // 
       
   114 // ---------------------------------------------------------------------------
       
   115 //       
       
   116 const TPtrC CHnMdButton::EvaluateButtonTextL(
       
   117         const CLiwGenericParamList& aQueryResults, TInt aPos )
       
   118     {
       
   119     if( !iButtonText )
       
   120         {
       
   121         return KNullDesC();
       
   122         }
       
   123     
       
   124     TPtrC value;
       
   125     iButtonText->GetL( &aQueryResults, aPos, value );
       
   126     return value;
       
   127     }
       
   128        
       
   129 // ---------------------------------------------------------------------------
       
   130 // 
       
   131 // ---------------------------------------------------------------------------
       
   132 //
       
   133 CHnAttributeBase* CHnMdButton::EvaluateIconL( 
       
   134         const CLiwGenericParamList& aQueriesResultsList , TInt aPos ) const
       
   135     {
       
   136     //CGulIcon* icon = NULL;
       
   137     CHnAttributeBase* iconAttribute = NULL;
       
   138     if( iIcon )
       
   139         {
       
   140         iconAttribute =
       
   141             iIcon->CreateAttributeL( &aQueriesResultsList, aPos );
       
   142         }
       
   143     return iconAttribute;
       
   144     }
       
   145 
       
   146 // ---------------------------------------------------------------------------
       
   147 // 
       
   148 // ---------------------------------------------------------------------------
       
   149 //
       
   150 CHnMdButton::CHnMdButton() : iIndex( KErrNone )
       
   151     {
       
   152     
       
   153     }
       
   154 
       
   155 // ---------------------------------------------------------------------------
       
   156 // 
       
   157 // ---------------------------------------------------------------------------
       
   158 //
       
   159 void CHnMdButton::ConstructL( TXmlEngElement aElement,
       
   160             THnMdCommonPointers* aCmnPtrs )
       
   161     {
       
   162     // index
       
   163     if( aElement.HasAttributeL( KIndexAttrName8 ) )
       
   164         {
       
   165         TPtrC8 index = aElement.AttributeValueL( KIndexAttrName8 );
       
   166         TLex8 lexIndex( index );
       
   167         User::LeaveIfError( lexIndex.Val( iIndex ) );
       
   168         }
       
   169 
       
   170     // event
       
   171     if( aElement.HasAttributeL( KEventAttrName8 ) )
       
   172         { 
       
   173         TPtrC8 event = aElement.AttributeValueL( KEventAttrName8 );
       
   174         TLex8 lex( event );
       
   175         User::LeaveIfError( lex.Val( iEventId ) );
       
   176         }
       
   177         
       
   178     // condition
       
   179     if( aElement.HasAttributeL( KMenuConditionAttrName8 ) )
       
   180         {
       
   181         iConditionAdd = HnConditionFactory::NewL(  
       
   182                 aElement.AttributeNodeL( KMenuConditionAttrName8 ) );
       
   183         }
       
   184     
       
   185     // dimmed
       
   186     if( aElement.HasAttributeL( KMenuDimmAttrName8 ) )
       
   187         {
       
   188         iConditionDimm = HnConditionFactory::NewL(  
       
   189                 aElement.AttributeNodeL( KMenuDimmAttrName8 ) );
       
   190         }
       
   191     
       
   192     // help text
       
   193     RXmlEngNodeList< TXmlEngElement > children;
       
   194     CleanupClosePushL( children );
       
   195     aElement.GetChildElements( children );
       
   196     TInt count = children.Count();
       
   197     
       
   198     for ( TInt i = 0; i < count; i++ )
       
   199         {
       
   200         TXmlEngElement child = children.Next();
       
   201         if ( !child.Name().Compare( KTextElementItem8 ) )
       
   202             {
       
   203             iButtonText = CHnMdValueText::NewL( child, aCmnPtrs );
       
   204             }
       
   205         else if( !child.Name().Compare( KImageElementItem8 ) )
       
   206             {
       
   207             iIcon = CHnMdValueImage::NewL( child, aCmnPtrs );
       
   208             }
       
   209         }
       
   210     
       
   211     CleanupStack::PopAndDestroy( &children );
       
   212     }
       
   213