menufw/hierarchynavigator/hnpresentationmodel/src/hneventhandler.cpp
changeset 0 f72a12da539e
child 9 f966699dea19
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:  event handler class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <liwservicehandler.h>
       
    20 #include "hneventhandler.h"
       
    21 #include "hnmdmodel.h"
       
    22 #include "hnglobals.h"
       
    23 #include "hnconvutils.h"
       
    24 #include "hnliwutils.h"
       
    25 #include "hnmdbasekey.h"
       
    26 #include "hncontrollerinterface.h"
       
    27 #include "hnactionmodel.h"
       
    28 #include "hnservicehandler.h"
       
    29 #include "menudebug.h"
       
    30 
       
    31 // ============================ MEMBER FUNCTIONS =============================
       
    32 
       
    33 
       
    34 // ---------------------------------------------------------------------------
       
    35 // Safe constructor. Initializes refrerece to the Meta Data Model in which 
       
    36 // the event-to-action mappings are stored.
       
    37 // ---------------------------------------------------------------------------
       
    38 //
       
    39 CHnEventHandler::CHnEventHandler( MHnMdModelEventObserver& aModelObserver,
       
    40         MHnControllerInterface& aController ):
       
    41         iEventObserver( aModelObserver), iControllerInterface( aController )
       
    42     {
       
    43     }
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // 
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 CHnEventHandler::~CHnEventHandler()
       
    50     {
       
    51     delete iServiceHandler;
       
    52     }
       
    53 
       
    54 // ---------------------------------------------------------------------------
       
    55 // 
       
    56 // ---------------------------------------------------------------------------
       
    57 //
       
    58 CHnEventHandler* CHnEventHandler::NewLC( 
       
    59                                       MHnMdModelEventObserver& aModelObserver,
       
    60                                       MHnControllerInterface& aController )
       
    61     {
       
    62     CHnEventHandler* self =
       
    63         new (ELeave)CHnEventHandler( aModelObserver, aController );
       
    64     CleanupStack::PushL(self);
       
    65     self->ConstructL();
       
    66     return self;
       
    67     }
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 // 
       
    71 // ---------------------------------------------------------------------------
       
    72 //
       
    73 CHnEventHandler* CHnEventHandler::NewL( 
       
    74                                     MHnMdModelEventObserver& aModelObserver,
       
    75                                     MHnControllerInterface& aController )
       
    76     {
       
    77     CHnEventHandler* self=CHnEventHandler::NewLC( aModelObserver, 
       
    78                                                   aController );
       
    79     CleanupStack::Pop(self); 
       
    80     return self;
       
    81     }
       
    82 
       
    83 // ---------------------------------------------------------------------------
       
    84 // 
       
    85 // ---------------------------------------------------------------------------
       
    86 //
       
    87 void CHnEventHandler::ConstructL()
       
    88     {
       
    89     }
       
    90 
       
    91 // ---------------------------------------------------------------------------
       
    92 // 
       
    93 // ---------------------------------------------------------------------------
       
    94 //
       
    95 
       
    96 TInt CHnEventHandler::ExecuteStandardActionL( CHnActionModel* aActionModel )
       
    97     {
       
    98     delete iServiceHandler;
       
    99     iServiceHandler = NULL;
       
   100     iServiceHandler = CHnServiceHandler::NewL(
       
   101             aActionModel->Service(),
       
   102             aActionModel->Interface(),
       
   103             aActionModel->CommandName(),
       
   104             aActionModel->ServiceMode(),
       
   105             aActionModel->ConstructorLC(), 
       
   106             aActionModel->CommandLC() );
       
   107 
       
   108     CleanupStack::Pop( 2 );
       
   109     TInt res = iServiceHandler->ExecuteL( this, 0 ); 
       
   110     return res;
       
   111     }
       
   112 
       
   113 // ---------------------------------------------------------------------------
       
   114 // 
       
   115 // ---------------------------------------------------------------------------
       
   116 //
       
   117 TInt CHnEventHandler::ExtractUidFromActionL( const TDesC8& aInterface, 
       
   118         TUid& aUid )
       
   119     {
       
   120     DEBUG16(("_MM_: CHnEventHandler::ExtractUidFromActionL UIext - uid %S",
       
   121                 &aInterface ));
       
   122   
       
   123     TLex8 lex( aInterface );
       
   124     lex.Inc( 2 );
       
   125     return lex.Val( (TUint32 &) aUid.iUid, EHex );
       
   126     }
       
   127     
       
   128 
       
   129 // ---------------------------------------------------------------------------
       
   130 // 
       
   131 // ---------------------------------------------------------------------------
       
   132 //
       
   133 TInt CHnEventHandler::ExecuteInternalActionL( CHnActionModel* aActionModel )
       
   134     {
       
   135     TInt ret(KErrNotFound);
       
   136     CLiwGenericParamList* params = aActionModel->CommandLC();
       
   137     if ( aActionModel->CommandName() == KServiceOpenSuite )
       
   138         {
       
   139         ret = iEventObserver.HandleModelEventL( KNewSuiteLoadedMdEvent(), 
       
   140                 *params );
       
   141         }
       
   142     else if ( aActionModel->CommandName() == KServiceSwitchWidget )
       
   143         {
       
   144         ret = iEventObserver.HandleModelEventL( KSwitchWidgetMdEvent(), 
       
   145                 *params );
       
   146         }
       
   147     else if ( aActionModel->CommandName() == KServiceStartEditMode )
       
   148         {
       
   149         ret = iEventObserver.HandleModelEventL( KStartEditModeMdEvent(), 
       
   150                 *params );
       
   151         }
       
   152     else if ( aActionModel->CommandName() == KServiceStopEditMode )
       
   153         {
       
   154         ret = iEventObserver.HandleModelEventL( KStopEditModeMdEvent(), 
       
   155                 *params );
       
   156         }
       
   157     else if ( aActionModel->CommandName() == KServiceBack )
       
   158         {
       
   159         ret = iEventObserver.HandleModelEventL( KBackMdEvent(), 
       
   160                 *params );
       
   161         }
       
   162     else if ( aActionModel->CommandName() == KSetFocus )
       
   163         {
       
   164         ret = iEventObserver.HandleModelEventL( KSetFocusEvent(), 
       
   165                 *params );
       
   166         }
       
   167 
       
   168     CleanupStack::PopAndDestroy( params );
       
   169     return ret;
       
   170     }
       
   171 
       
   172 // ---------------------------------------------------------------------------
       
   173 // 
       
   174 // ---------------------------------------------------------------------------
       
   175 //
       
   176 TInt CHnEventHandler::ExecuteExtensionManagerActionL(
       
   177         CHnActionModel* aActionModel )
       
   178     {
       
   179     TUid uid;
       
   180     TInt err = ExtractUidFromActionL( aActionModel->Interface(), uid );
       
   181     
       
   182     if ( KErrNone == err )
       
   183         {
       
   184         HBufC* cmd = HnConvUtils::Str8ToStrFastLC( aActionModel->CommandName() );
       
   185         CLiwGenericParamList* command = aActionModel->CommandLC();
       
   186         err = iControllerInterface.ExecuteExtensionActionL( uid, *cmd, command );        
       
   187         CleanupStack::PopAndDestroy( command );
       
   188         CleanupStack::PopAndDestroy( cmd );
       
   189         }
       
   190     
       
   191     return err;
       
   192     }
       
   193 
       
   194 // ---------------------------------------------------------------------------
       
   195 // 
       
   196 // ---------------------------------------------------------------------------
       
   197 //
       
   198 EXPORT_C TInt CHnEventHandler::ExecuteActionL( CHnActionModel* aActionModel )
       
   199     {
       
   200     ASSERT( aActionModel );
       
   201     TInt err( KErrNone );
       
   202     
       
   203     if( aActionModel->Service() == KServiceMultimediaMenu )
       
   204         {
       
   205         if ( aActionModel->Interface().Length() == 0 )
       
   206             {
       
   207             err = ExecuteInternalActionL( aActionModel );
       
   208             }
       
   209         else
       
   210             {
       
   211             err = ExecuteExtensionManagerActionL( aActionModel );
       
   212             }
       
   213         }
       
   214     else
       
   215         {
       
   216         err = ExecuteStandardActionL( aActionModel );
       
   217         }
       
   218     
       
   219     return err;
       
   220     }
       
   221 
       
   222 // -----------------------------------------------------------------------------
       
   223 //
       
   224 // -----------------------------------------------------------------------------
       
   225 TInt CHnEventHandler::HandleNotifyL( TInt /*aCmdId*/, TInt /*aEventId*/,
       
   226         CLiwGenericParamList& /*aEventParamList*/,
       
   227         const CLiwGenericParamList& /*aInParamList*/ )
       
   228     {
       
   229     return KErrNone;
       
   230     }