srsf/vcommandhandler/src/vcommandarray.cpp
branchRCL_3
changeset 19 e36f3802f733
parent 0 bf1d17376201
equal deleted inserted replaced
18:cad71a31b7fc 19:e36f3802f733
       
     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:  Implementation of the CVCommandRunnable class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <vcommandapi.h>
       
    21 #include "rubydebug.h"
       
    22 
       
    23 /** 
       
    24 * Constructs the non-modifiable CVCommandArray
       
    25 * @param aSource Commands to store. CVCommandArray makes
       
    26 *        copies of them
       
    27 */
       
    28 EXPORT_C CVCommandArray* CVCommandArray::NewL( const RVCommandArray& aSource )
       
    29 	{
       
    30 	RUBY_DEBUG_BLOCK( "CVCommandArray::NewL" );
       
    31 	CVCommandArray* self = new (ELeave) CVCommandArray;
       
    32 	CleanupStack::PushL( self );
       
    33 	self->ConstructL( aSource );
       
    34 	CleanupStack::Pop( self );
       
    35 	return self;
       
    36 	}
       
    37 	
       
    38 void CVCommandArray::ConstructL( const RVCommandArray& aSource )
       
    39 	{
       
    40 	RUBY_DEBUG_BLOCKL( "CVCommandArray::ConstructL" );
       
    41 	iCommands.ResetAndDestroy();
       
    42 	for( TInt j = 0; j < aSource.Count(); j++ ) 
       
    43 		{
       
    44 		CVCommand* addition = CVCommand::NewL( *aSource[j] );
       
    45 		CleanupStack::PushL( addition );
       
    46 		iCommands.AppendL( addition );
       
    47 		CleanupStack::Pop( addition );
       
    48 		}
       
    49 	}	
       
    50 
       
    51 /**
       
    52 * Destructor
       
    53 */
       
    54 EXPORT_C CVCommandArray::~CVCommandArray()
       
    55 	{
       
    56 	RUBY_DEBUG0( "CVCommandArray::~CVCommandArray start" );
       
    57 	iCommands.ResetAndDestroy();
       
    58 	RUBY_DEBUG0( "CVCommandArray::~CVCommandArray end" );
       
    59 	}
       
    60 
       
    61 /**
       
    62 * Returns the reference to the command stored in this
       
    63 * CVCommandArray
       
    64 * @param aIndex Zero-based index of the command. If aIndex is out of
       
    65 *               bounds, this method will panic with USER 130
       
    66 * @return Unmodifiable reference to CVCommand
       
    67 */
       
    68 EXPORT_C const CVCommand& CVCommandArray::At( TInt aIndex ) const
       
    69 	{
       
    70 	return *iCommands[ aIndex ];
       
    71 	}
       
    72 
       
    73 /**
       
    74 * Equivalent to the operator At
       
    75 * @see At()
       
    76 */
       
    77 EXPORT_C const CVCommand& CVCommandArray::operator[]( TInt aIndex ) const
       
    78 	{
       
    79 	return At( aIndex );
       
    80 	}
       
    81 
       
    82 /** 
       
    83 * Returns the number of commands
       
    84 */
       
    85 EXPORT_C TInt CVCommandArray::Count() const
       
    86 	{
       
    87 	return iCommands.Count();
       
    88 	}
       
    89 
       
    90 /**
       
    91 * For the compatibility with routines, requiring RVCommandArray
       
    92 * @return Unmodifiable array of pointers to VCommands
       
    93 */
       
    94 EXPORT_C const RVCommandArray& CVCommandArray::PointerArray() const
       
    95     {
       
    96     return iCommands;
       
    97     }
       
    98 
       
    99 /**
       
   100  * Figures out which commands have to untrained (removed from VCommandHandler)
       
   101  * if this command set is merged with aUpdates.
       
   102  * Merging is performed on the basis of comapring the commands' Runnable component
       
   103  * If runnables are equal, the commands are considered being equal.
       
   104  * It is useful e.g. when figuring out what to (un)train after the language change
       
   105  * 
       
   106  * @param aUpdates Set of commands to merge in. 
       
   107  * @return Set of commands to be removed from the system if the merging takes place
       
   108  */
       
   109 EXPORT_C CVCommandArray* CVCommandArray::ProduceUntrainSetByRunnablesLC( 
       
   110                             const RVCommandArray& aUpdates ) const
       
   111     {
       
   112     RVCommandArray deduction;
       
   113     CleanupClosePushL( deduction );
       
   114     for( TInt i = 0; i < Count(); i++ )
       
   115         {
       
   116         for( TInt j = 0; j < aUpdates.Count(); j++ )
       
   117             {
       
   118             if( ( At(i).Runnable() == aUpdates[j]->Runnable() ) &&
       
   119                 !( At(i).EqualNonUserChangeableData( *aUpdates[j] ) ) 
       
   120                )
       
   121                 { 
       
   122                 deduction.AppendL( &At(i) );
       
   123                 break;
       
   124                 }
       
   125             }
       
   126         }
       
   127     CVCommandArray* result = CVCommandArray::NewL( deduction );
       
   128     CleanupStack::PopAndDestroy( &deduction );
       
   129     CleanupStack::PushL( result );
       
   130     return result;
       
   131     }
       
   132     
       
   133 /**
       
   134  * Figures out which commands have to trained (removed added to the system)
       
   135  * if this command set is merged with aUpdates.
       
   136  * Merging is performed on the basis of comapring the commands' Runnable component
       
   137  * If runnables are equal, the commands are considered being equal.
       
   138  * It is useful e.g. when figuring out what to (un)train after the language change
       
   139  * 
       
   140  * @param aUpdates Set of commands to merge in. 
       
   141  * @return Set of commands to be added to the system if the merging takes place
       
   142  * @see ProduceUntrainSetByRunnables
       
   143  */
       
   144 EXPORT_C CVCommandArray* CVCommandArray::ProduceTrainSetByRunnablesLC( 
       
   145                             const RVCommandArray& aUpdates ) const
       
   146     {
       
   147     RVCommandArray addition;
       
   148     CleanupClosePushL( addition );
       
   149     for( TInt j = 0; j < aUpdates.Count(); j++ )
       
   150         {
       
   151         TBool injectedMatchesSomeTarget = EFalse;
       
   152         for( TInt i = 0; i < Count(); i++ )
       
   153             {
       
   154             if( At(i).EqualNonUserChangeableData( *aUpdates[j] ) )
       
   155                 { 
       
   156                 injectedMatchesSomeTarget = ETrue;
       
   157                 break;
       
   158                 }
       
   159             else if( At(i).Runnable() == aUpdates[j]->Runnable() &&
       
   160                      At(i).CommandUi().UserText() != KNullDesC )
       
   161                 {
       
   162                 CVCCommandUi* updatedCommandUi( NULL );
       
   163                 updatedCommandUi = CVCCommandUi::NewL( aUpdates[j]->CommandUi().WrittenText(), 
       
   164                                                        aUpdates[j]->CommandUi().FolderInfo(),
       
   165                                                        aUpdates[j]->CommandUi().Modifiable(),
       
   166                                                        aUpdates[j]->CommandUi().Tooltip(), 
       
   167                                                        aUpdates[j]->CommandUi().IconUid(),
       
   168                                                        At(i).CommandUi().UserText(),
       
   169                                                        aUpdates[j]->CommandUi().ConfirmationNeeded() );
       
   170                 CleanupStack::PushL( updatedCommandUi );
       
   171 
       
   172                 CVCommand* updatedCommand( NULL );
       
   173                 updatedCommand = CVCommand::NewL( aUpdates[j]->SpokenText(),
       
   174                                                   aUpdates[j]->Runnable(),
       
   175                                                   *updatedCommandUi );
       
   176                 CleanupStack::PushL( updatedCommand );
       
   177 
       
   178                 addition.AppendL( updatedCommand );
       
   179 
       
   180                 CleanupStack::Pop( updatedCommand );
       
   181                 CleanupStack::PopAndDestroy( updatedCommandUi );
       
   182                 
       
   183                 injectedMatchesSomeTarget = ETrue;
       
   184                 break;
       
   185                 }
       
   186             }  // for i
       
   187         if( !injectedMatchesSomeTarget )
       
   188             {
       
   189             addition.AppendL( aUpdates[j] );
       
   190             }  // if
       
   191         }  // for j
       
   192     CVCommandArray* result = CVCommandArray::NewL( addition );
       
   193     CleanupStack::PopAndDestroy( &addition );
       
   194     CleanupStack::PushL( result );
       
   195     return result;
       
   196     }
       
   197     
       
   198 //End of file