menufw/hierarchynavigator/hnmetadatamodel/src/hnmdeventmapping.cpp
changeset 0 f72a12da539e
child 47 7be2816dbabd
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 "hnmdeventmapping.h"
       
    20 #include "hnmdeventmappingelement.h"
       
    21 #include "hnmdevent.h"
       
    22 #include "hneventhandler.h"
       
    23 #include "hnsuitemodel.h"
       
    24 #include "hnitemmodel.h"
       
    25 #include "hnmdaction.h"
       
    26 #include "hnactionmodel.h"
       
    27 
       
    28 // ======== MEMBER FUNCTIONS ========
       
    29 
       
    30 // ---------------------------------------------------------------------------
       
    31 //
       
    32 // ---------------------------------------------------------------------------
       
    33 //
       
    34 RPointerArray<CHnMdAction> CHnMdEventMapping::GetActionsForEventId(
       
    35     TInt aEventId )
       
    36     {
       
    37     RPointerArray<CHnMdAction> emptyActions;
       
    38     CHnMdEventMappingElement* eventMappingElement = NULL;
       
    39     TBool eventIdFound( EFalse );
       
    40 
       
    41     TInt mappingCount( Count() );
       
    42 
       
    43     for ( TInt i = 0; i < mappingCount; i++ )
       
    44         {
       
    45         CHnMdEventMappingElement* eme = iMappings[i];
       
    46 
       
    47         RPointerArray<CHnMdEvent> events = eme->Events();
       
    48 
       
    49         TInt actionsCount = events.Count();
       
    50 
       
    51         for ( TInt j = 0; j < actionsCount; j++ )
       
    52             {
       
    53             CHnMdEvent* event = events[ j ];
       
    54 
       
    55             if (event->Id() == aEventId )
       
    56                 {
       
    57                 eventIdFound = ETrue;
       
    58                 break;
       
    59                 }
       
    60             }
       
    61         if ( eventIdFound )
       
    62             {
       
    63             eventMappingElement = eme;
       
    64             break;
       
    65             }
       
    66         }
       
    67 
       
    68     if ( eventIdFound )
       
    69         return eventMappingElement->Actions();
       
    70     else
       
    71         return emptyActions;  
       
    72     }
       
    73     
       
    74 // ---------------------------------------------------------------------------
       
    75 // 
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 void CHnMdEventMapping::ConstructL( TXmlEngElement aElement, THnMdCommonPointers* aCmnPtrs )
       
    79     {
       
    80     // construction...
       
    81     iCmnPtrs = aCmnPtrs;
       
    82     
       
    83     RXmlEngNodeList< TXmlEngElement > children;
       
    84     CleanupClosePushL(children);
       
    85 
       
    86     aElement.GetChildElements(children);
       
    87     TInt amount = children.Count();
       
    88 
       
    89     for (TInt i(0);i<amount;i++)
       
    90         {
       
    91         TXmlEngElement child = children.Next();
       
    92         if ( !child.Name().Compare( KEventElementName8 ) )
       
    93             {
       
    94             CHnMdEventMappingElement* eme =
       
    95                 CHnMdEventMappingElement::NewL( child );
       
    96             CleanupStack::PushL( eme );
       
    97             iMappings.AppendL( eme );
       
    98             CleanupStack::Pop( eme );
       
    99             }
       
   100         }
       
   101 
       
   102     CleanupStack::PopAndDestroy( &children );
       
   103     }
       
   104 
       
   105 // ---------------------------------------------------------------------------
       
   106 // 
       
   107 // ---------------------------------------------------------------------------
       
   108 //
       
   109 CHnMdEventMapping* CHnMdEventMapping::NewL( TXmlEngElement aElement, 
       
   110         THnMdCommonPointers* aCmnPtrs )
       
   111     {
       
   112     CHnMdEventMapping* self = CHnMdEventMapping::NewLC( aElement,
       
   113         aCmnPtrs );
       
   114     CleanupStack::Pop( self );
       
   115     return self;
       
   116     }
       
   117 
       
   118 // ---------------------------------------------------------------------------
       
   119 // 
       
   120 // ---------------------------------------------------------------------------
       
   121 //
       
   122 TInt CHnMdEventMapping::Count() const
       
   123     {
       
   124     return iMappings.Count();
       
   125     }
       
   126 
       
   127 // ---------------------------------------------------------------------------
       
   128 // 
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 CHnMdEventMapping* CHnMdEventMapping::NewLC( TXmlEngElement aElement, 
       
   132         THnMdCommonPointers* aCmnPtrs )
       
   133     {
       
   134     CHnMdEventMapping* self = new( ELeave ) CHnMdEventMapping;
       
   135     CleanupStack::PushL( self );
       
   136     self->ConstructL( aElement, aCmnPtrs );
       
   137     return self;
       
   138     }
       
   139 
       
   140 // ---------------------------------------------------------------------------
       
   141 // 
       
   142 // ---------------------------------------------------------------------------
       
   143 //
       
   144 CHnMdEventMapping::CHnMdEventMapping()
       
   145     {
       
   146     }
       
   147 
       
   148 // ---------------------------------------------------------------------------
       
   149 // 
       
   150 // ---------------------------------------------------------------------------
       
   151 //
       
   152 CHnMdEventMapping::~CHnMdEventMapping()
       
   153     {
       
   154     iMappings.ResetAndDestroy();
       
   155     }
       
   156 
       
   157 // ---------------------------------------------------------------------------
       
   158 // 
       
   159 // ---------------------------------------------------------------------------
       
   160 //
       
   161 void CHnMdEventMapping::AddActionL( 
       
   162         RHashMap<TInt,CArrayPtr<CHnActionModel> *> & aActions, 
       
   163         CHnActionModel *& aActionModel, TInt aEventId )
       
   164     {
       
   165     CArrayPtr<CHnActionModel>** actionsContainer = aActions.Find( aEventId );
       
   166     if ( !actionsContainer )
       
   167         {
       
   168         CArrayPtr<CHnActionModel>* newActionsContainer = new( 
       
   169             ELeave ) CArrayPtrFlat<CHnActionModel>( KDefaultGranularity );
       
   170         CleanupStack::PushL( newActionsContainer );
       
   171         aActions.InsertL( aEventId, newActionsContainer );
       
   172         actionsContainer = &newActionsContainer;
       
   173         CleanupStack::Pop( newActionsContainer );
       
   174         }
       
   175     ( *actionsContainer )->AppendL( aActionModel );
       
   176     }
       
   177 
       
   178 // ---------------------------------------------------------------------------
       
   179 // 
       
   180 // ---------------------------------------------------------------------------
       
   181 //
       
   182 void CHnMdEventMapping::FillActionsL( 
       
   183         RHashMap< TInt, CArrayPtr<CHnActionModel>* >& aActions,
       
   184         const CLiwGenericParamList& aQueriesResultsList, TInt aPos )
       
   185     {
       
   186     RArray< TInt > eventIds;
       
   187     CleanupClosePushL( eventIds );
       
   188     GetEventIdsL( eventIds );
       
   189     
       
   190     for ( TInt i( 0 ); i < eventIds.Count(); i++ )
       
   191         {
       
   192         RPointerArray< CHnMdAction > actions = GetActionsForEventId( 
       
   193                 eventIds[ i ] );
       
   194         for ( TInt j( 0 ); j < actions.Count(); j++ )
       
   195             {
       
   196             if ( !actions[ j ] || !actions[ j ]->IsValidL( 
       
   197                     aQueriesResultsList, aPos ) )
       
   198                 {
       
   199                 continue;
       
   200                 }
       
   201             CHnActionModel* actionModel = CHnActionModel::NewL();
       
   202             CleanupStack::PushL( actionModel );
       
   203             actions[ j ]->EvaluateL( actionModel, aQueriesResultsList, aPos );
       
   204             AddActionL( aActions, actionModel, eventIds[ i ] );
       
   205             CleanupStack::Pop( actionModel );
       
   206             }
       
   207         }
       
   208     CleanupStack::PopAndDestroy( &eventIds );
       
   209     }
       
   210 
       
   211 // ---------------------------------------------------------------------------
       
   212 // 
       
   213 // ---------------------------------------------------------------------------
       
   214 //
       
   215 void CHnMdEventMapping::GetEventIdsL( RArray< TInt >& aIds ) const
       
   216     {
       
   217     TInt mappingCount = Count();
       
   218         
       
   219     for( TInt i = 0; i < mappingCount; i++ )
       
   220         {
       
   221         CHnMdEventMappingElement* eme = iMappings[ i ];
       
   222         const RPointerArray< CHnMdEvent >& events = eme->Events();
       
   223         TInt eventsCount = events.Count();
       
   224         for ( TInt j = 0; j < eventsCount; j++ )
       
   225             {
       
   226             CHnMdEvent* event = events[ j ];
       
   227             aIds.AppendL( event->Id() );
       
   228             }
       
   229         }
       
   230     }
       
   231