menufw/hierarchynavigator/hnpresentationmodel/src/hnactionmodel.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:  action presentation model
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <liwcommon.h>
       
    20 #include "hnsuitemodelcontainer.h"
       
    21 #include "hnactionmodel.h"
       
    22 #include "hnmdbasekey.h"
       
    23 #include "hnmdmodel.h"
       
    24 #include "hneventhandler.h"
       
    25 #include "hnhelper.inl"
       
    26 
       
    27 using namespace LIW;
       
    28 
       
    29 // ============================ MEMBER FUNCTIONS =============================
       
    30 
       
    31 // ---------------------------------------------------------------------------
       
    32 // 
       
    33 // ---------------------------------------------------------------------------
       
    34 //
       
    35 EXPORT_C CHnActionModel* CHnActionModel::NewL()
       
    36     {
       
    37     CHnActionModel* self = new( ELeave ) CHnActionModel();
       
    38     CleanupStack::PushL( self );
       
    39     self->ConstructL();
       
    40     CleanupStack::Pop( self );
       
    41     return self;
       
    42     }
       
    43     
       
    44 // ---------------------------------------------------------------------------
       
    45 // 
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 CHnActionModel::~CHnActionModel()
       
    49     {
       
    50     delete iConstructor;
       
    51     delete iCommand;
       
    52     
       
    53     iService.Close();
       
    54     iInterface.Close();
       
    55     iCommandName.Close();
       
    56     
       
    57     }
       
    58     
       
    59 // ---------------------------------------------------------------------------
       
    60 // 
       
    61 // ---------------------------------------------------------------------------
       
    62 //  
       
    63 void CHnActionModel::ConstructL()
       
    64     {
       
    65     
       
    66     }
       
    67 
       
    68 // ---------------------------------------------------------------------------
       
    69 // 
       
    70 // ---------------------------------------------------------------------------
       
    71 EXPORT_C CLiwGenericParamList*  CHnActionModel::ConstructorLC()
       
    72     {
       
    73     CLiwGenericParamList* constructor = CLiwGenericParamList::NewL();
       
    74     CleanupStack::PushL( constructor );
       
    75     if ( iConstructor )
       
    76         {
       
    77         iConstructor->ToGenericParamListL( *constructor );
       
    78         }
       
    79     return constructor;
       
    80     }
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // 
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 EXPORT_C const TDesC8& CHnActionModel::Service() const
       
    87     {
       
    88     return iService;
       
    89     }
       
    90         
       
    91 // ---------------------------------------------------------------------------
       
    92 // 
       
    93 // ---------------------------------------------------------------------------
       
    94 //
       
    95 EXPORT_C CLiwGenericParamList* CHnActionModel::CommandLC() const
       
    96     {
       
    97     CLiwGenericParamList* command = CLiwGenericParamList::NewL();
       
    98     CleanupStack::PushL( command );
       
    99     if ( iCommand )
       
   100         {
       
   101         iCommand->ToGenericParamListL( *command );        
       
   102         }
       
   103     return command;
       
   104     }
       
   105 
       
   106 
       
   107         
       
   108 // ---------------------------------------------------------------------------
       
   109 // 
       
   110 // ---------------------------------------------------------------------------
       
   111 //
       
   112 EXPORT_C const TDesC8& CHnActionModel::Interface() const
       
   113     {
       
   114     return iInterface;
       
   115     }
       
   116 
       
   117 // ---------------------------------------------------------------------------
       
   118 // 
       
   119 // ---------------------------------------------------------------------------
       
   120 //
       
   121 EXPORT_C void CHnActionModel::SetConstructorL( CHnMdBaseKey* aData )
       
   122     {
       
   123     delete iConstructor;
       
   124     iConstructor = aData;
       
   125     }
       
   126 
       
   127 // ---------------------------------------------------------------------------
       
   128 // 
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 EXPORT_C void CHnActionModel::SetServiceL( const TDesC8& aSrevice )
       
   132     {
       
   133     iService.Close();
       
   134     iService.CreateL( aSrevice );
       
   135     }
       
   136         
       
   137 // ---------------------------------------------------------------------------
       
   138 // 
       
   139 // ---------------------------------------------------------------------------
       
   140 //
       
   141 EXPORT_C void CHnActionModel::SetCommand( CHnMdBaseKey* aCommand )
       
   142     {
       
   143     delete iCommand;
       
   144     iCommand = aCommand;
       
   145     }
       
   146 
       
   147 // ---------------------------------------------------------------------------
       
   148 // 
       
   149 // ---------------------------------------------------------------------------
       
   150 //
       
   151 EXPORT_C void CHnActionModel::SetInterfaceL( const TDesC8& aInterface )
       
   152     {
       
   153     iInterface.Close();
       
   154     iInterface.CreateL( aInterface );
       
   155     }
       
   156 
       
   157 // ---------------------------------------------------------------------------
       
   158 // 
       
   159 // ---------------------------------------------------------------------------
       
   160 //
       
   161 EXPORT_C void CHnActionModel::SetCommandNameL( const TDesC8& aCommandName )
       
   162     {
       
   163     iCommandName.Close();
       
   164     iCommandName.CreateL( aCommandName );
       
   165     }
       
   166 
       
   167 
       
   168 // ---------------------------------------------------------------------------
       
   169 // 
       
   170 // ---------------------------------------------------------------------------
       
   171 //
       
   172 EXPORT_C void CHnActionModel::SetServiceModeL( const TServiceMode aMode )
       
   173     {
       
   174     iMode = aMode;
       
   175     }
       
   176 
       
   177 // ---------------------------------------------------------------------------
       
   178 // 
       
   179 // ---------------------------------------------------------------------------
       
   180 //
       
   181 EXPORT_C const TDesC8& CHnActionModel::CommandName() const
       
   182 {
       
   183     return iCommandName;
       
   184 }
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 // 
       
   188 // ---------------------------------------------------------------------------
       
   189 //
       
   190 EXPORT_C TServiceMode CHnActionModel::ServiceMode() const
       
   191 {
       
   192     return iMode;
       
   193 }
       
   194 
       
   195 // ---------------------------------------------------------------------------
       
   196 // 
       
   197 // ---------------------------------------------------------------------------
       
   198 //
       
   199 CHnActionModel::CHnActionModel()
       
   200     {
       
   201     
       
   202     }
       
   203 
       
   204 // ---------------------------------------------------------------------------
       
   205 // 
       
   206 // ---------------------------------------------------------------------------
       
   207 //
       
   208 CHnActionModel* CHnActionModel::ConcretizeL( const CHnActionModel & aActionModel,
       
   209         CLiwGenericParamList* aGenericParamList )
       
   210     {
       
   211     CHnActionModel* newInstance = CHnActionModel::NewL();
       
   212     CleanupStack::PushL( newInstance );
       
   213     
       
   214     newInstance->iService.CreateL( aActionModel.Service() );
       
   215     newInstance->iInterface.CreateL( aActionModel.Interface() );
       
   216     newInstance->iCommandName.CreateL( aActionModel.CommandName() );
       
   217     newInstance->iMode = aActionModel.iMode;
       
   218     
       
   219     if ( aActionModel.iCommand )
       
   220         {
       
   221         if ( aGenericParamList )
       
   222             {
       
   223             newInstance->iCommand = aActionModel.iCommand->EvaluateLC( *aGenericParamList );
       
   224             }
       
   225         else
       
   226             {
       
   227             newInstance->iCommand = aActionModel.iCommand->CopyLC();
       
   228             }
       
   229         CleanupStack::Pop( newInstance->iCommand );
       
   230         }
       
   231     
       
   232     if (  aActionModel.iConstructor )
       
   233         {
       
   234         if ( aGenericParamList )
       
   235             {
       
   236             newInstance->iConstructor = aActionModel.iConstructor->EvaluateLC( *aGenericParamList );
       
   237             }
       
   238         else
       
   239             {
       
   240             newInstance->iConstructor = aActionModel.iConstructor->CopyLC();
       
   241             }
       
   242         CleanupStack::Pop( newInstance->iConstructor );
       
   243         }
       
   244 
       
   245     CleanupStack::Pop( newInstance );
       
   246     return newInstance;
       
   247     }
       
   248 
       
   249 // ---------------------------------------------------------------------------
       
   250 // 
       
   251 // ------------------ ---------------------------------------------------------
       
   252 //
       
   253 TInt CHnActionModel::ExecuteL( CHnEventHandler & aEventHandler, 
       
   254         CLiwGenericParamList *aExecutionParams )
       
   255 {
       
   256     CHnActionModel* actionModel = ConcretizeL( *this, aExecutionParams );
       
   257     CleanupStack::PushL( actionModel );
       
   258     TRAPD( err, aEventHandler.ExecuteActionL( actionModel ) );
       
   259     // forward KErrNoMemory error to most outer TRAP.
       
   260     if ( KErrNoMemory == err || KErrDiskFull == err )
       
   261         {
       
   262         User::Leave( err );
       
   263         }
       
   264     CleanupStack::PopAndDestroy( actionModel );
       
   265     return err;
       
   266 }
       
   267 
       
   268 
       
   269