vtuis/videotelui/src/commands/cvtuicommandmanager.cpp
changeset 0 ed9695c8bcbe
equal deleted inserted replaced
-1:000000000000 0:ed9695c8bcbe
       
     1 /*
       
     2 * Copyright (c) 2006 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:  Command manager class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <cvtlogger.h>
       
    20 
       
    21 #include "cvtuicmdbase.h"
       
    22 #include "cvtuicommandmanager.h"
       
    23 #include "cvtuicommandpolicymanager.h"
       
    24 #include "cvtuiprimarycmdpolicy.h"
       
    25 #include "cvtuiexecutioncontext.h"
       
    26 #include "cvtuimenuitemdimmeraction.h"
       
    27 #include "tvtuistates.h"
       
    28 #include "mvtuicommandui.h"
       
    29 #include "cvtuicommandmodifybase.h"
       
    30 #include "cvtuicmdstatecheckaction.h"
       
    31 
       
    32 // Default array granularity.
       
    33 static const TInt KVtUiArrayGranularity = 1;
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CVtUiCommandManager::NewL
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 CVtUiCommandManager* CVtUiCommandManager::NewL( const TVtUiStates& aUiStates,
       
    40     CVtUiAppUi& aAppUi )
       
    41     {
       
    42     __VTPRINTENTER( "CmdMgr.NewL" )
       
    43     CVtUiCommandManager* self = new ( ELeave ) CVtUiCommandManager( aUiStates,
       
    44         aAppUi );
       
    45     CleanupStack::PushL( self );
       
    46     self->ConstructL();
       
    47     CleanupStack::Pop(); // self
       
    48     __VTPRINTEXIT( "CmdMgr.NewL" )
       
    49     return self;
       
    50     }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CVtUiCommandManager::~CVtUiCommandManager
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 CVtUiCommandManager::~CVtUiCommandManager()
       
    57     {
       
    58     __VTPRINTENTER( "CmdMgr.~" )
       
    59     iCommands.Reset();
       
    60     iCommandUis.Reset();
       
    61     iCommandModifiers.Reset();
       
    62     delete iExecutionContext;
       
    63     delete iCmdStateCheckAction;
       
    64     delete iCmdPolicyMgr;
       
    65     __VTPRINTEXIT( "CmdMgr.~" )
       
    66     }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CVtUiCommandManager::UiStates
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 const TVtUiStates& CVtUiCommandManager::UiStates() const
       
    73     {
       
    74     return iUiStates;
       
    75     }
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // CVtUiCommandManager::AppUi
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 const CVtUiAppUi& CVtUiCommandManager::AppUi() const
       
    82     {
       
    83     return iAppUi;
       
    84     }
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // CVtUiCommandManager::VideoTelephonyVariation
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 const TVtUiVideoTelephonyVariation&
       
    91 CVtUiCommandManager::VideoTelephonyVariation() const
       
    92     {
       
    93     return iVtVariation;
       
    94     }
       
    95 
       
    96 // -----------------------------------------------------------------------------
       
    97 // CVtUiCommandManager::HandleCommandL
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 void CVtUiCommandManager::HandleCommandL( TInt aCommandId )
       
   101     {
       
   102     TInt index( iCommands.FindInOrder( aCommandId, CVtUiCmdBase::KeyOrder() ) );
       
   103     if ( index != KErrNotFound )
       
   104         {
       
   105         iCommands[ index ]->HandleL();
       
   106         }
       
   107     /*
       
   108 
       
   109     This was commented out, because current CVtUiAppUi silently ignores
       
   110     commands that are not handled, changed this to emulate same kind of
       
   111     behaviour.
       
   112 
       
   113     else
       
   114         {
       
   115         User::Leave( KErrNotFound );
       
   116         }
       
   117     */
       
   118     }
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // CVtUiCommandManager::AddCommandUi
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 TInt CVtUiCommandManager::AddCommandUi( MVtUiCommandUi& aCommandUi )
       
   125     {
       
   126     __VTPRINTENTER( "CmdMgr.AddCommandUi" )
       
   127     TInt result( KErrAlreadyExists );
       
   128     TInt idx( iCommandUis.Find( &aCommandUi ) );
       
   129     if ( idx == KErrNotFound )
       
   130         {
       
   131         result = iCommandUis.Append( &aCommandUi );
       
   132         if ( result == KErrNone )
       
   133             {
       
   134             result = CommandUiAdded( aCommandUi );
       
   135             }
       
   136         }
       
   137     __VTPRINTEXITR( "CmdMgr.AddCommandUi %d", result )
       
   138     return result;
       
   139     }
       
   140 
       
   141 // -----------------------------------------------------------------------------
       
   142 // CVtUiCommandManager::RemoveCommandUi
       
   143 // -----------------------------------------------------------------------------
       
   144 //
       
   145 void CVtUiCommandManager::RemoveCommandUi( MVtUiCommandUi& aCommandUi )
       
   146     {
       
   147     __VTPRINTENTER( "CmdMgr.RemoveCommandUi" )
       
   148     TInt idx( iCommandUis.Find( &aCommandUi ) );
       
   149     if ( idx != KErrNotFound )
       
   150         {
       
   151         iCommandUis.Remove( idx );
       
   152         CommandUiRemoved( aCommandUi );
       
   153         }
       
   154     __VTPRINTEXIT( "CmdMgr.RemoveCommandUi" )
       
   155     }
       
   156 
       
   157 // -----------------------------------------------------------------------------
       
   158 // CVtUiCommandManager::ValidateMenuItemsL
       
   159 // -----------------------------------------------------------------------------
       
   160 //
       
   161 void CVtUiCommandManager::ValidateMenuItemsL(
       
   162     CVtUiCmdValidationActionBase& aAction )
       
   163     {
       
   164     __VTPRINTENTER( "CmdMgr.ValidateMenuItemsL" )
       
   165     iCmdPolicyMgr->ValidateMenuItemsL( aAction );
       
   166     __VTPRINTEXIT( "CmdMgr.ValidateMenuItemsL" )
       
   167     }
       
   168 
       
   169 // -----------------------------------------------------------------------------
       
   170 // CVtUiCommandManager::ValidateSoftkeyItemsL
       
   171 // -----------------------------------------------------------------------------
       
   172 //
       
   173 void CVtUiCommandManager::ValidateSoftkeyItemsL(
       
   174     CVtUiCmdValidationActionBase& aAction )
       
   175     {
       
   176     __VTPRINTENTER( "CmdMgr.ValidateSoftkeyItemsL" )
       
   177     iCmdPolicyMgr->ValidateSoftkeyItemsL( aAction );
       
   178     __VTPRINTEXIT( "CmdMgr.ValidateSoftkeyItemsL" )
       
   179     }
       
   180 
       
   181 // -----------------------------------------------------------------------------
       
   182 // CVtUiCommandManager::ValidateToolbarItemsL
       
   183 // -----------------------------------------------------------------------------
       
   184 //
       
   185 void CVtUiCommandManager::ValidateToolbarItemsL(
       
   186     CVtUiCmdValidationActionBase& aAction )
       
   187     {
       
   188     __VTPRINTENTER( "CmdMgr.ValidateToolbarItemsL" )
       
   189     iCmdPolicyMgr->ValidateToolbarItemsL( aAction );
       
   190     __VTPRINTEXIT( "CmdMgr.ValidateToolbarItemsL" )
       
   191     }
       
   192 
       
   193 // -----------------------------------------------------------------------------
       
   194 // CVtUiCommandManager::IsCommandAllowedL
       
   195 // -----------------------------------------------------------------------------
       
   196 //
       
   197 TBool CVtUiCommandManager::IsCommandAllowedL( TInt aCommandId )
       
   198     {
       
   199     __VTPRINTENTER( "CmdMgr.IsCommandAllowedL" )
       
   200     TInt index( iCommands.FindInOrder( aCommandId, CVtUiCmdBase::KeyOrder() ) );
       
   201     if ( index == KErrNotFound )
       
   202         {
       
   203         iCmdStateCheckAction->SetCommand( aCommandId );
       
   204         iCmdPolicyMgr->CustomValidateL( *iCmdStateCheckAction );
       
   205         }
       
   206     else
       
   207         {
       
   208         return iCommands[ index ]->IsEnabled();
       
   209         }
       
   210     __VTPRINTEXIT( "CmdMgr.IsCommandAllowedL" )
       
   211     return iCmdStateCheckAction->IsCommandAllowed();
       
   212     }
       
   213 
       
   214 // -----------------------------------------------------------------------------
       
   215 // CVtUiCommandManager::RegisterCommandContext
       
   216 // -----------------------------------------------------------------------------
       
   217 //
       
   218 TInt CVtUiCommandManager::RegisterCommandContext( CVtUiCmdContext& aContext )
       
   219     {
       
   220     __VTPRINTENTER( "CmdMgr.RegisterCommandContext" )
       
   221     TInt result( iCmdPolicyMgr->RegisterCommandContext( aContext ) );
       
   222     __VTPRINTEXITR( "CmdMgr.RegisterCommandContext %d", result )
       
   223     return result;
       
   224     }
       
   225 
       
   226 // -----------------------------------------------------------------------------
       
   227 // CVtUiCommandManager::UnregisterCommandContext
       
   228 // -----------------------------------------------------------------------------
       
   229 //
       
   230 void CVtUiCommandManager::UnregisterCommandContext( CVtUiCmdContext& aContext )
       
   231     {
       
   232     __VTPRINTENTER( "CmdMgr.UnregisterCommandContext" )
       
   233     iCmdPolicyMgr->UnregisterCommandContext( aContext );
       
   234     __VTPRINTEXIT( "CmdMgr.UnregisterCommandContext" )
       
   235     }
       
   236 
       
   237 // -----------------------------------------------------------------------------
       
   238 // CVtUiCommandManager::AddValidator
       
   239 // -----------------------------------------------------------------------------
       
   240 //
       
   241 TInt CVtUiCommandManager::AddValidator( CVtUiCmdValidatorBase& aValidator )
       
   242     {
       
   243     __VTPRINTENTER( "CmdMgr.AddValidator" )
       
   244     TInt result( iCmdPolicyMgr->AddValidator( aValidator ) );
       
   245     __VTPRINTEXITR( "CmdMgr.AddValidator %d", result )
       
   246     return result;
       
   247     }
       
   248 
       
   249 // -----------------------------------------------------------------------------
       
   250 // CVtUiCommandManager::RemoveValidator
       
   251 // -----------------------------------------------------------------------------
       
   252 //
       
   253 void CVtUiCommandManager::RemoveValidator(
       
   254     CVtUiCmdValidatorBase& aValidator )
       
   255     {
       
   256     __VTPRINTENTER( "CmdMgr.RemoveValidator" )
       
   257     iCmdPolicyMgr->RemoveValidator( aValidator );
       
   258     __VTPRINTEXIT( "CmdMgr.RemoveValidator" )
       
   259     }
       
   260 
       
   261 // -----------------------------------------------------------------------------
       
   262 // CVtUiCommandManager::RefreshL
       
   263 // -----------------------------------------------------------------------------
       
   264 //
       
   265 void CVtUiCommandManager::RefreshL()
       
   266     {
       
   267     __VTPRINTENTER( "CmdMgr.RefreshL" )
       
   268     for ( TInt i = iCommandUis.Count() - 1; i >= 0; i-- )
       
   269         {
       
   270         iCommandUis[ i ]->RefreshL();
       
   271         }
       
   272     __VTPRINTEXIT( "CmdMgr.RefreshL" )
       
   273     }
       
   274 
       
   275 // -----------------------------------------------------------------------------
       
   276 // CVtUiCommandManager::AddCommandModifier
       
   277 // -----------------------------------------------------------------------------
       
   278 //
       
   279 TInt CVtUiCommandManager::AddCommandModifier(
       
   280     CVtUiCommandModifyBase& aModifier )
       
   281     {
       
   282     __VTPRINTENTER( "CmdMgr.AddCommandModifier" )
       
   283     TInt result(
       
   284         iCommandModifiers.InsertInOrder( &aModifier,
       
   285             CVtUiCommandModifyBase::PriorityOrder() ) );
       
   286     if ( result == KErrNone )
       
   287         {
       
   288         result = CommandModifierAdded( aModifier );
       
   289         }
       
   290     __VTPRINTEXITR( "CmdMgr.AddCommandModifier %d", result )
       
   291     return result;
       
   292     }
       
   293 
       
   294 // -----------------------------------------------------------------------------
       
   295 // CVtUiCommandManager::RemoveCommandModifier
       
   296 // -----------------------------------------------------------------------------
       
   297 //
       
   298 void CVtUiCommandManager::RemoveCommandModifier(
       
   299     CVtUiCommandModifyBase& aModifier )
       
   300     {
       
   301     __VTPRINTENTER( "CmdMgr.RemoveCommandModifier" )
       
   302     TInt idx( iCommandModifiers.FindInOrder( &aModifier,
       
   303         CVtUiCommandModifyBase::PriorityOrder() ) );
       
   304     if ( idx != KErrNotFound )
       
   305         {
       
   306         iCommandModifiers.Remove( idx );
       
   307         CommandModifierRemoved( aModifier );
       
   308         }
       
   309     __VTPRINTEXIT( "CmdMgr.RemoveCommandModifier" )
       
   310     }
       
   311 
       
   312 // -----------------------------------------------------------------------------
       
   313 // CVtUiCommandManager::RegisterCommandL
       
   314 // -----------------------------------------------------------------------------
       
   315 //
       
   316 void CVtUiCommandManager::RegisterCommandL( CVtUiCmdBase& aCommand )
       
   317     {
       
   318     __VTPRINTENTER( "CmdMgr.RegisterCommandL" )
       
   319     iCommands.InsertInOrderL( &aCommand, CVtUiCmdBase::LinearOrder() );
       
   320     __VTPRINTEXIT( "CmdMgr.RegisterCommandL" )
       
   321     }
       
   322 
       
   323 // -----------------------------------------------------------------------------
       
   324 // CVtUiCommandManager::UnregisterCommand
       
   325 // -----------------------------------------------------------------------------
       
   326 //
       
   327 void CVtUiCommandManager::UnregisterCommand( const CVtUiCmdBase& aCommand )
       
   328     {
       
   329     __VTPRINTENTER( "CmdMgr.UnregisterCommand" )
       
   330     TInt index( iCommands.FindInOrder( &aCommand,
       
   331         CVtUiCmdBase::LinearOrder() ) );
       
   332     if ( index != KErrNotFound )
       
   333         {
       
   334         iCommands.Remove( index );
       
   335         }
       
   336     __VTPRINTEXIT( "CmdMgr.UnregisterCommand" )
       
   337     }
       
   338 
       
   339 // -----------------------------------------------------------------------------
       
   340 // CVtUiCommandManager::CVtUiCommandManager
       
   341 // -----------------------------------------------------------------------------
       
   342 //
       
   343 CVtUiCommandManager::CVtUiCommandManager( const TVtUiStates& aUiStates, 
       
   344     CVtUiAppUi& aAppUi )
       
   345 : iCommandUis( KVtUiArrayGranularity ),
       
   346   iCommandModifiers( KVtUiArrayGranularity ),
       
   347   iCommands( KVtUiArrayGranularity ),
       
   348   iUiStates( aUiStates ),
       
   349   iAppUi( aAppUi )
       
   350     {
       
   351     __VTPRINTENTER( "CmdMgr.ctor" )
       
   352     __VTPRINTEXIT( "CmdMgr.ctor" )
       
   353     }
       
   354 
       
   355 // -----------------------------------------------------------------------------
       
   356 // CVtUiCommandManager::ConstructL
       
   357 // -----------------------------------------------------------------------------
       
   358 //
       
   359 void CVtUiCommandManager::ConstructL()
       
   360     {
       
   361     __VTPRINTENTER( "CmdMgr.ConstructL" )
       
   362     iVtVariation.ReadL();
       
   363     iCmdPolicyMgr = CVtUiCommandPolicyManager::NewL( *this );
       
   364     iCmdStateCheckAction = CVtUiCmdStateCheckAction::NewL();
       
   365     iExecutionContext = CVtUiExecutionContext::NewL( *this );
       
   366     __VTPRINTEXIT( "CmdMgr.ConstructL" )
       
   367     }
       
   368 
       
   369 // -----------------------------------------------------------------------------
       
   370 // CVtUiCommandManager::CommandModifierAdded
       
   371 // -----------------------------------------------------------------------------
       
   372 //
       
   373 TInt CVtUiCommandManager::CommandModifierAdded(
       
   374     CVtUiCommandModifyBase& aModifier )
       
   375     {
       
   376     TInt error( KErrNone );
       
   377     for ( TInt i = iCommandUis.Count() - 1; !error && i >= 0; i-- )
       
   378         {
       
   379         error = iCommandUis[ i ]->AddCommandModifier( aModifier );
       
   380         }
       
   381     return error;
       
   382     }
       
   383 
       
   384 // -----------------------------------------------------------------------------
       
   385 // CVtUiCommandManager::CommandModifierRemoved
       
   386 // -----------------------------------------------------------------------------
       
   387 //
       
   388 void CVtUiCommandManager::CommandModifierRemoved(
       
   389     CVtUiCommandModifyBase& aModifier )
       
   390     {
       
   391     for ( TInt i = iCommandUis.Count() - 1; i >= 0; i-- )
       
   392         {
       
   393         iCommandUis[ i ]->RemoveCommandModifier( aModifier );
       
   394         }
       
   395     }
       
   396 
       
   397 // -----------------------------------------------------------------------------
       
   398 // CVtUiCommandManager::CommandUiAdded
       
   399 // -----------------------------------------------------------------------------
       
   400 //
       
   401 TInt CVtUiCommandManager::CommandUiAdded( MVtUiCommandUi& aCommandUi )
       
   402     {
       
   403     TInt error( KErrNone );
       
   404     for ( TInt i = iCommandModifiers.Count() - 1; !error && i >= 0; i-- )
       
   405         {
       
   406         error = aCommandUi.AddCommandModifier( *iCommandModifiers[ i ] );
       
   407         }
       
   408     return error;
       
   409     }
       
   410 
       
   411 // -----------------------------------------------------------------------------
       
   412 // CVtUiCommandManager::CommandUiRemoved
       
   413 // -----------------------------------------------------------------------------
       
   414 //
       
   415 void CVtUiCommandManager::CommandUiRemoved( MVtUiCommandUi& aCommandUi )
       
   416     {
       
   417     for ( TInt i = iCommandModifiers.Count() - 1; i >= 0; i-- )
       
   418         {
       
   419         aCommandUi.RemoveCommandModifier( *iCommandModifiers[ i ] );
       
   420         }
       
   421     }