voiceui/vcommand/src/vcgenericcontainer.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:  Container class for vcommand app
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include <StringLoader.h> 
       
    22 #include <avkon.hrh>
       
    23 #include <aknlists.h>
       
    24 #include <eikclbd.h>
       
    25 #include <aknkeys.h>
       
    26 #include <fbs.h>
       
    27 #include <eiklbd.h>
       
    28 #include <eiklbx.h>
       
    29 #include <eikclbd.h>
       
    30 #include <eiklbi.h>
       
    31 #include <aknlists.h> 
       
    32 #include <aknPopup.h>
       
    33 #include <akntitle.h>
       
    34 #include <eikspane.h>
       
    35 #include <aknlistquerydialog.h>
       
    36 #include <sysutil.h>
       
    37 #include <apgcli.h>
       
    38 #include <featmgr.h>
       
    39 #include <AknsUtils.h>
       
    40 #include <s32strm.h>
       
    41 #include <f32file.h>
       
    42 #include <s32file.h>
       
    43 #include <AknUtils.h>
       
    44 #include <apgcli.h>
       
    45 #include <collate.h>
       
    46 
       
    47 #include <vcommand.rsg>
       
    48 #include <vcommand.mbg>
       
    49 #include "vcgenericcontainer.h"
       
    50 #include "vcgenericview.h"
       
    51 #include "vcommanduientry.h"
       
    52 #include "uiarraysgenerator.h"
       
    53 #include "vctextquerydialog.h"
       
    54 #include "vcdoublelargestylelistbox.h"
       
    55 
       
    56 #include "vcommand.hrh"
       
    57 #include "vcappui.h"
       
    58 #include "rubydebug.h"
       
    59 
       
    60 
       
    61 // CONSTANTS
       
    62 const TChar KTabulator = '\t';
       
    63 const TInt KArrayGranularity( 12 );
       
    64 // Show tooltip for four seconds
       
    65 const TInt KPopupVisibilityTime = 4000;
       
    66 _LIT( KLocReplace, "%U" );
       
    67 // Bytes that should be free in the disk drive in addition to critical level 
       
    68 // before voice command editing is allowed (10k)
       
    69 const TInt KEditDiskUsage = 10240;
       
    70 
       
    71 // ================= MEMBER FUNCTIONS =======================
       
    72 
       
    73 
       
    74 // ----------------------------------------------------------------------------
       
    75 // C++ constructor
       
    76 // ----------------------------------------------------------------------------
       
    77 CVCGenericContainer::CVCGenericContainer( CEikMenuBar* aMenuBar,
       
    78                                           CVCModel& aModel,
       
    79                                           CVCGenericView& aView ):
       
    80     iMenuBar( aMenuBar ), iView( aView ), iModel( aModel )
       
    81     { 
       
    82     }
       
    83 
       
    84 
       
    85 // ----------------------------------------------------------------------------
       
    86 // CVCGenericContainer::ConstructL
       
    87 // ----------------------------------------------------------------------------
       
    88 //
       
    89 void CVCGenericContainer::ConstructL( const TRect& aRect ) 
       
    90     {
       
    91     RUBY_DEBUG_BLOCKL( "CVCGenericContainer::ConstructL" );
       
    92     
       
    93     SetTitlePaneL( R_VC_MAIN_VIEW_TITLE );
       
    94     CreateWindowL();
       
    95 
       
    96     iPopupController = CAknInfoPopupNoteController::NewL();
       
    97     iPopupController->SetTimePopupInView( KPopupVisibilityTime );
       
    98     
       
    99     ConstructListBoxL();
       
   100 
       
   101     SetRect( aRect );
       
   102     SetObserver( this );
       
   103     ActivateL();
       
   104     } 
       
   105 
       
   106 
       
   107 // ----------------------------------------------------------------------------
       
   108 // CVCGenericContainer::~CVCGenericContainer
       
   109 // ----------------------------------------------------------------------------
       
   110 //
       
   111 CVCGenericContainer::~CVCGenericContainer() 
       
   112     {
       
   113 	delete iFolderTitles;
       
   114 	iItemIsFolder.Close();
       
   115 	delete iPopupController;
       
   116     
       
   117     if ( iListBox )
       
   118         {
       
   119         static_cast<CVCDoubleLargeStyleListBox*>( iListBox )->AddScrollBarObserver( NULL );
       
   120         }
       
   121     delete iListBox; 
       
   122     }
       
   123 
       
   124 
       
   125 // ----------------------------------------------------------------------------
       
   126 // CVCGenericContainer::SetTitlePaneL
       
   127 // ----------------------------------------------------------------------------
       
   128 //
       
   129 void CVCGenericContainer::SetTitlePaneL(TInt aResourceId) const 
       
   130     {
       
   131     RUBY_DEBUG_BLOCKL( "CVCGenericContainer::SetTitlePaneL" );
       
   132     
       
   133     // Set up status pane
       
   134     CEikStatusPane* statusPane =
       
   135         ( static_cast<CAknAppUi*> ( iCoeEnv->AppUi() ) )->StatusPane();
       
   136     CAknTitlePane* title = 
       
   137         static_cast<CAknTitlePane*>( statusPane->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) );
       
   138 
       
   139     TResourceReader rReader;
       
   140     iCoeEnv->CreateResourceReaderLC( rReader, aResourceId );
       
   141     title->SetFromResourceL( rReader );
       
   142     
       
   143     // Set title for folder views
       
   144     if( iView.FolderTitle() != KNullDesC() )
       
   145         {
       
   146         title->SetTextL( iView.FolderTitle() );
       
   147         }
       
   148     
       
   149     CleanupStack::PopAndDestroy(); // rReader
       
   150     }
       
   151 
       
   152 
       
   153 // ----------------------------------------------------------------------------
       
   154 // CVCGenericContainer::OfferKeyEventL
       
   155 // ----------------------------------------------------------------------------
       
   156 //
       
   157 TKeyResponse CVCGenericContainer::OfferKeyEventL( const TKeyEvent& aKeyEvent, 
       
   158                                                   TEventCode aType ) 
       
   159     {
       
   160     RUBY_DEBUG_BLOCKL( "CVCGenericContainer::OfferKeyEventL" );
       
   161     
       
   162     if( iHandlingKeyPressInProgress )
       
   163         {
       
   164         return EKeyWasConsumed;
       
   165         }
       
   166      
       
   167     // Special case when for some reason vcommand database is empty.
       
   168     // Only exiting is allowed
       
   169     if( ListBoxCount() <= 0 && aKeyEvent.iCode != EKeyCBA2 ) 
       
   170         {
       
   171         return EKeyWasConsumed;
       
   172         }
       
   173      
       
   174     SetHandlingKeyPressInProgress( ETrue );
       
   175     TKeyResponse retval( EKeyWasConsumed );
       
   176     TBool isFolder = IsItemFolderL( CurrentSelection() );
       
   177         
       
   178     switch ( aKeyEvent.iCode ) 
       
   179         {
       
   180         case EKeyBackspace: // C - key. Deletes an application
       
   181             {
       
   182             if ( iView.MenuBar()->ItemSpecificCommandsEnabled() )
       
   183                 {
       
   184                 TDesC* secondRow = GetSecondRowNameLC( CurrentSelection() );
       
   185                 if( !isFolder && secondRow->Length() > 0 ) 
       
   186                     {
       
   187                     SetHandlingKeyPressInProgress( EFalse );
       
   188                     iView.HandleCommandL( EVCCmdDelete );    
       
   189                     }
       
   190                 else 
       
   191                     {
       
   192                     SetHandlingKeyPressInProgress( EFalse );
       
   193                     iView.HandleCommandL( EVCCmdRemove );
       
   194                     }
       
   195                 CleanupStack::PopAndDestroy( secondRow );
       
   196                 }
       
   197             break;  
       
   198             }
       
   199 
       
   200         case EKeyUpArrow: 
       
   201         case EKeyDownArrow: 
       
   202             {
       
   203             retval = iListBox->OfferKeyEventL( aKeyEvent, aType );
       
   204             TRAP_IGNORE(
       
   205                 ShowTooltipL( CurrentSelection() );
       
   206                 iView.SetMiddleSoftkeyLabelL( CurrentSelection() ) );
       
   207             break;
       
   208             }
       
   209             
       
   210         case EKeyCBA2:
       
   211             {
       
   212             if( iView.FolderTitle() == KNullDesC() ) 
       
   213                 {
       
   214                 iView.HandleCommandL( EAknSoftkeyExit );
       
   215                 }
       
   216             }
       
   217         
       
   218         default: 
       
   219             {
       
   220             retval = iListBox->OfferKeyEventL( aKeyEvent, aType );
       
   221             break;
       
   222             }
       
   223         } 
       
   224         
       
   225     SetHandlingKeyPressInProgress( EFalse );
       
   226     return retval;
       
   227     }
       
   228 
       
   229 
       
   230 // ----------------------------------------------------------------------------
       
   231 // CVCGenericContainer::IsItemFolderL
       
   232 // ----------------------------------------------------------------------------
       
   233 //
       
   234 TBool CVCGenericContainer::IsItemFolderL( TInt aListBoxIndex ) const 
       
   235     {
       
   236     RUBY_DEBUG_BLOCKL( "CVCGenericContainer::IsItemFolderL" );
       
   237                   
       
   238     if( aListBoxIndex >= 0 && aListBoxIndex < iItemIsFolder.Count() )
       
   239         {
       
   240         return iItemIsFolder[aListBoxIndex];
       
   241         }
       
   242     else
       
   243         {
       
   244         return false;
       
   245         }
       
   246     }
       
   247 
       
   248 
       
   249 // ----------------------------------------------------------------------------
       
   250 // CVCGenericContainer::ConstructListBoxL
       
   251 // ----------------------------------------------------------------------------
       
   252 //
       
   253 void CVCGenericContainer::ConstructListBoxL() 
       
   254     {
       
   255     RUBY_DEBUG_BLOCKL( "CVCGenericContainer::ConstructListBoxL" );
       
   256     
       
   257     CVCAppUi* appUi = static_cast<CVCAppUi*>( iEikonEnv->AppUi() );
       
   258         
       
   259     iListBox = CVCDoubleLargeStyleListBox::NewL();
       
   260     iListBox->SetContainerWindowL( *this ); // set's iListBox to be contained in this container
       
   261     
       
   262     iListBox->ConstructL( this, EAknListBoxSelectionList );
       
   263     iListBox->ItemDrawer()->FormattedCellData()->EnableMarqueeL( ETrue );
       
   264     // Ownership not transferred
       
   265     iItemArray = 
       
   266         static_cast<CDesC16ArrayFlat*>( iListBox->Model()->ItemTextArray() );
       
   267     
       
   268     // Folder title array    
       
   269     iFolderTitles = new (ELeave) CDesC16ArrayFlat( KArrayGranularity );
       
   270         
       
   271     // Populates the listbox
       
   272     PopulateListBoxL();
       
   273     
       
   274     CEikFormattedCellListBox* listbox = static_cast<CEikFormattedCellListBox*>( iListBox );
       
   275     
       
   276     // Set listbox observer
       
   277     listbox->SetListBoxObserver( this );
       
   278     
       
   279     static_cast<CVCDoubleLargeStyleListBox*>( iListBox )->AddScrollBarObserver( this );
       
   280     }
       
   281 
       
   282 
       
   283 // ----------------------------------------------------------------------------
       
   284 // CVCGenericContainer::PopulateListBoxL
       
   285 // ----------------------------------------------------------------------------
       
   286 //
       
   287 void CVCGenericContainer::PopulateListBoxL() 
       
   288     {
       
   289     RUBY_DEBUG_BLOCKL( "CVCGenericContainer::PopulateListBoxL" );
       
   290     
       
   291     CAknIconArray* icons = new ( ELeave ) CAknIconArray( KArrayGranularity );
       
   292     CleanupStack::PushL( icons );
       
   293     
       
   294     CUiArraysGenerator* generator = CUiArraysGenerator::NewLC();
       
   295     generator->FillArraysL( iModel, iView.FolderTitle(), *icons, *iFolderTitles, 
       
   296                             iItemIsFolder, *iItemArray );
       
   297     
       
   298     CleanupStack::PopAndDestroy( generator );
       
   299 
       
   300     CEikFormattedCellListBox* listbox = static_cast<CEikFormattedCellListBox*>( iListBox );
       
   301     // Takes ownership of icons
       
   302     listbox->ItemDrawer()->ColumnData()->SetIconArray( icons );
       
   303     CleanupStack::Pop( icons );
       
   304 
       
   305     iListBox->CreateScrollBarFrameL( ETrue );
       
   306     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff, 
       
   307                                                          CEikScrollBarFrame::EAuto );
       
   308     }
       
   309 
       
   310 
       
   311 // ----------------------------------------------------------------------------
       
   312 // CVCGenericContainer::SortItemListL
       
   313 // Insertion sort implementation
       
   314 // ----------------------------------------------------------------------------
       
   315 //
       
   316 void CVCGenericContainer::SortItemListL() 
       
   317     {
       
   318     RUBY_DEBUG_BLOCKL( "CVCGenericContainer::SortItemListL" );
       
   319     
       
   320     // Case insentitive comparing
       
   321     TCollationMethod cm = *Mem::CollationMethodByIndex( 0 ); // Default collation method
       
   322     cm.iFlags |= TCollationMethod::EFoldCase;
       
   323     
       
   324     TInt i( 1 );
       
   325     while( i < iItemArray->Count() )
       
   326         {
       
   327         TDesC* strToCompare = GetFirstRowNameLC( i );
       
   328         TBool isFolder = IsItemFolderL( i );
       
   329         
       
   330         TDesC* firstRow( NULL );
       
   331         TInt j = i - 1;
       
   332         // Previous item is greater than strToCompare or previous is not a
       
   333         // folder and current item is
       
   334         while( j >= 0 &&
       
   335                ( (firstRow = GetFirstRowNameLC( j ))->CompareC( *strToCompare, 0, &cm ) > 0 || 
       
   336                isFolder && !IsItemFolderL( j ) ) ) 
       
   337             {
       
   338             CleanupStack::PopAndDestroy( firstRow );
       
   339             // Pointers are expected to be on the cleanup stack if they are non-null
       
   340             firstRow = NULL;
       
   341             if( !isFolder && IsItemFolderL( j ) ) // folders are first on the list
       
   342                 {
       
   343                 break;
       
   344                 }
       
   345             j--;
       
   346             }
       
   347         // Pointers popped and destroyed are nullified, so non-null pointers
       
   348         // are still on the cleanup stack
       
   349         if( firstRow )
       
   350             {
       
   351             CleanupStack::PopAndDestroy( firstRow );
       
   352             }
       
   353         j++; // the last index which satisfied the conditions
       
   354         
       
   355         if( j < i ) 
       
   356             {
       
   357             iItemArray->InsertL( j, iListBox->Model()->ItemText( i ) );
       
   358             iItemArray->Delete( i + 1 );
       
   359             
       
   360             // No need to sort iItemIsFolder. Folders are in the beginning
       
   361             // and other items are in the end. This hasn't changed.
       
   362             }
       
   363 
       
   364         i++;
       
   365         CleanupStack::PopAndDestroy( strToCompare );
       
   366         }
       
   367     }
       
   368 
       
   369 
       
   370 // ----------------------------------------------------------------------------
       
   371 // CVCGenericContainer::HandleListBoxEventL
       
   372 // ----------------------------------------------------------------------------
       
   373 //
       
   374 void CVCGenericContainer::HandleListBoxEventL( CEikListBox* /*aListBox*/,
       
   375                                                TListBoxEvent aEventType ) 
       
   376     {
       
   377     RUBY_DEBUG_BLOCKL( "CVCGenericView::HandleListBoxEventL" );
       
   378     
       
   379     switch ( aEventType ) 
       
   380         {
       
   381         case EEventEnterKeyPressed:
       
   382         case EEventItemSingleClicked: 
       
   383             {
       
   384             if( IsItemFolderL( CurrentSelection() ) ) 
       
   385                 {
       
   386                 SetHandlingKeyPressInProgress( EFalse );
       
   387                 iView.HandleCommandL( EVCCmdOpen );
       
   388                 }
       
   389             else
       
   390                 {
       
   391                 SetHandlingKeyPressInProgress( EFalse );
       
   392                 iView.HandleCommandL( EVCCmdPlayback );
       
   393                 ShowTooltipL( CurrentSelection() );
       
   394                 }
       
   395             break;
       
   396             }
       
   397             
       
   398         default:
       
   399             {
       
   400             ShowTooltipL( -1 );
       
   401             }
       
   402         
       
   403         break;
       
   404         }
       
   405     }
       
   406 
       
   407 
       
   408 // ----------------------------------------------------------------------------
       
   409 //  CVCGenericContainer::HandleScrollEventL
       
   410 // ----------------------------------------------------------------------------
       
   411 void CVCGenericContainer::HandleScrollEventL( CEikScrollBar* /*aScrollBar*/,
       
   412                                               TEikScrollEvent /*aEventType*/ )
       
   413     {
       
   414     RUBY_DEBUG_BLOCKL( "CVCGenericView::HandleScrollEventL" );
       
   415     
       
   416     ShowTooltipL( -1 );
       
   417     }
       
   418 
       
   419 
       
   420 // ----------------------------------------------------------------------------
       
   421 //  CVCGenericContainer::DeleteVoiceCommandL
       
   422 // ----------------------------------------------------------------------------
       
   423 void CVCGenericContainer::DeleteVCommandL() 
       
   424     {
       
   425     RUBY_DEBUG_BLOCKL( "CVCGenericContainer::DeleteVCommandL" );
       
   426     
       
   427     // Get corresponding CVCommand-object
       
   428     TDesC* firstRow = GetFirstRowNameLC( CurrentSelection() );
       
   429     
       
   430     const CVCommandUiEntry& vcommand = iModel.GetVCommandL( *firstRow );
       
   431     CleanupStack::PopAndDestroy( firstRow );
       
   432     
       
   433     TDesC* secondRow = GetSecondRowNameLC( CurrentSelection() );
       
   434     
       
   435     // Show "cannot delete" note if the voice command is not user edited
       
   436     if ( secondRow->Length() <= 0 ||
       
   437         ( vcommand.UserText() == KNullDesC() &&
       
   438           vcommand.WrittenText() != vcommand.SpokenText() ) )
       
   439         {
       
   440         CleanupStack::PopAndDestroy( secondRow );
       
   441         return iView.DoHandleCommandL( EVCCmdRemove );    
       
   442         }
       
   443     else
       
   444         {        
       
   445         HBufC* stringholder = StringLoader::LoadL( R_QTN_VC_DELETE_COMMAND, *secondRow, iEikonEnv );
       
   446         CleanupStack::PushL( stringholder );
       
   447         
       
   448         CAknQueryDialog* dlg = CAknQueryDialog::NewL( CAknQueryDialog::EConfirmationTone );
       
   449          
       
   450         if ( dlg->ExecuteLD( R_REMOVE_APPLICATION_DIALOG, *stringholder ) ) // not cancelled: ret != 0
       
   451             {
       
   452             UpdateTextL( CurrentSelection(), KNullDesC(), *secondRow );
       
   453             }
       
   454         
       
   455         CleanupStack::PopAndDestroy( stringholder );
       
   456         CleanupStack::PopAndDestroy( secondRow );
       
   457         }
       
   458     }
       
   459 
       
   460 
       
   461 // ----------------------------------------------------------------------------
       
   462 //  CVCGenericContainer::ShowTooltipL
       
   463 // ----------------------------------------------------------------------------
       
   464 void CVCGenericContainer::ShowTooltipL( TInt aItemIndex ) 
       
   465     {
       
   466     RUBY_DEBUG_BLOCKL( "CVCGenericContainer::ShowTooltipL" );
       
   467     
       
   468     if( aItemIndex >= 0 && aItemIndex < iItemArray->Count() &&
       
   469         !IsItemFolderL( aItemIndex ) )
       
   470         {
       
   471         TDesC* firstRow = GetFirstRowNameLC( CurrentSelection() );
       
   472         
       
   473         const CVCommandUiEntry& vcommand = iModel.GetVCommandL( *firstRow );
       
   474         
       
   475         CleanupStack::PopAndDestroy( firstRow );
       
   476 
       
   477         TName ttText = vcommand.Tooltip();
       
   478         
       
   479         const TDesC& writtenText = vcommand.WrittenText();
       
   480         TDesC* spokenText = vcommand.AlternativeSpokenText().AllocLC();
       
   481         // Command is not user edited
       
   482         if( *spokenText == KNullDesC() )
       
   483             {
       
   484             CleanupStack::PopAndDestroy( spokenText );
       
   485             spokenText = vcommand.SpokenText().AllocLC();
       
   486             }
       
   487             
       
   488         TName ttText2;    
       
   489         if( ttText.Find( KLocReplace ) != KErrNotFound )
       
   490             {
       
   491             // Replace %U with the vc api spoken text
       
   492             StringLoader::Format( ttText2, ttText, -1, *spokenText );
       
   493             ttText.Copy( ttText2 );
       
   494             }
       
   495         else
       
   496             {
       
   497             // Replace %0U with the vc api spoken text
       
   498             StringLoader::Format( ttText2, ttText, 0, *spokenText );
       
   499             // Replace %1U with the vc api written text
       
   500             StringLoader::Format( ttText, ttText2, 1, writtenText );            
       
   501             }
       
   502             
       
   503         iPopupController->SetTextL( ttText );
       
   504         iPopupController->RestoreDefaultPosition();
       
   505         iPopupController->ShowInfoPopupNote();
       
   506         
       
   507         CleanupStack::PopAndDestroy( spokenText );
       
   508         }
       
   509     else 
       
   510         {
       
   511         iPopupController->HideInfoPopupNote();
       
   512         }
       
   513     }
       
   514     
       
   515 
       
   516 // ----------------------------------------------------------------------------
       
   517 // CVCGenericContainer::IsHandlingKeyPressInProgress
       
   518 // ----------------------------------------------------------------------------
       
   519 //                   
       
   520 TBool CVCGenericContainer::IsHandlingKeyPressInProgress()
       
   521     {
       
   522     return iHandlingKeyPressInProgress;
       
   523     }
       
   524 
       
   525 
       
   526 // ----------------------------------------------------------------------------
       
   527 // CVCGenericContainer::SetHandlingKeyPressInProgress
       
   528 // ----------------------------------------------------------------------------
       
   529 //                           
       
   530 void CVCGenericContainer::SetHandlingKeyPressInProgress( TBool aValue )
       
   531     {
       
   532     iHandlingKeyPressInProgress = aValue;
       
   533     }
       
   534 
       
   535 
       
   536 // ----------------------------------------------------------------------------
       
   537 // CVCGenericContainer::CountComponentControls
       
   538 // ----------------------------------------------------------------------------
       
   539 //
       
   540 TInt CVCGenericContainer::CountComponentControls() const 
       
   541     {
       
   542     return 1; // return nbr of controls inside this container
       
   543     }
       
   544     
       
   545 
       
   546 // ----------------------------------------------------------------------------
       
   547 // CVCGenericContainer::HandleControlEventL(
       
   548 //     (CCoeControl* aControl,TCoeEvent aEventType)
       
   549 // ----------------------------------------------------------------------------
       
   550 //
       
   551 void CVCGenericContainer::HandleControlEventL( CCoeControl* /*aControl*/, 
       
   552                                                    TCoeEvent /*aEventType*/ )    
       
   553     {
       
   554     // Do nothing
       
   555     }
       
   556 
       
   557 
       
   558 // ----------------------------------------------------------------------------
       
   559 // CVCGenericContainer::ShowEditTextL()
       
   560 // Gets the application name from listbox and extracts it.
       
   561 // ----------------------------------------------------------------------------
       
   562 //
       
   563 void CVCGenericContainer::ShowEditTextL()
       
   564     {
       
   565     RUBY_DEBUG_BLOCKL( "CVCGenericContainer::ShowEditTextL" );
       
   566     
       
   567     if( !CheckCriticalLevelL() )
       
   568         {
       
   569         TBuf<KMaxEditableTextLength> voiceCmd;
       
   570         TInt index = CurrentSelection();
       
   571         TDesC* secondRow = GetSecondRowNameLC( index );
       
   572         
       
   573         // 
       
   574         if( secondRow->Length() <= 0 ) 
       
   575             {
       
   576             TDesC* firstRow = GetFirstRowNameLC( index );
       
   577             const CVCommand* orgCommand = &iModel.GetVCommandL( *firstRow ).Command();
       
   578             voiceCmd.Append( orgCommand->SpokenText() );
       
   579             CleanupStack::PopAndDestroy( firstRow );
       
   580             }
       
   581         else 
       
   582             {
       
   583             voiceCmd.Append( *secondRow );
       
   584             }
       
   585 
       
   586         CleanupStack::PopAndDestroy( secondRow );
       
   587 
       
   588         TBuf<KMaxEditableTextLength> spokenText;
       
   589         spokenText.Copy( voiceCmd );
       
   590         
       
   591         // Save the currently selected command
       
   592         TDesC* firstRow = GetFirstRowNameLC( index );
       
   593         const CVCommand* orgCommand = &iModel.GetVCommandL( *firstRow ).Command();
       
   594         CleanupStack::PopAndDestroy( firstRow );
       
   595         
       
   596         CVCommand* command = CVCommand::NewL( *orgCommand );
       
   597         CleanupStack::PushL( command );            
       
   598 
       
   599         // Create the data query dialog        
       
   600         CVCTextQueryDialog* dlg = CVCTextQueryDialog::NewL( voiceCmd );
       
   601         // Enable T9
       
   602         dlg->SetPredictiveTextInputPermitted( ETrue );
       
   603 
       
   604         TBool res;
       
   605         // Check whether Japanese is in use
       
   606         if ( FeatureManager::FeatureSupported( KFeatureIdJapanese )
       
   607              && User::Language() == ELangJapanese )
       
   608             {
       
   609             res = ( dlg->ExecuteLD( R_VC_DATA_QUERY_JAPANESE ) == EAknSoftkeyOk );
       
   610             }
       
   611         else
       
   612             {
       
   613             res = ( dlg->ExecuteLD( R_VC_DATA_QUERY ) == EAknSoftkeyOk );
       
   614             }
       
   615         dlg = NULL;
       
   616         
       
   617         // User didn't cancel and the index is still in correct range
       
   618         if ( res && index < iItemArray->Count() )
       
   619             {
       
   620             // Get current command
       
   621             firstRow = GetFirstRowNameLC( index );
       
   622             const CVCommand* currentCommand = &iModel.GetVCommandL( *firstRow ).Command();
       
   623             CleanupStack::PopAndDestroy( firstRow );
       
   624             
       
   625             // If only whitespace was given, TrimAll modifies the name into an empty string
       
   626             voiceCmd.TrimAll();
       
   627             
       
   628             if ( voiceCmd.Length() )
       
   629                 {
       
   630                 // The selected command is the same and the name was changed
       
   631                 if ( *command == *currentCommand && spokenText != voiceCmd )
       
   632                     {
       
   633                     if( !CheckNameValidityL( voiceCmd ) ) // New name base was valid. Exit from query
       
   634                         {
       
   635                         UpdateTextL( index, voiceCmd, spokenText );
       
   636                         }
       
   637                     else
       
   638                         {
       
   639                         ShowEditTextL(); // Query is shown again
       
   640                         }
       
   641                     }
       
   642                 }
       
   643             else
       
   644                 {
       
   645                 // Remove command if possible since the inserted string was empty
       
   646                 TDesC* secondRow = GetSecondRowNameLC( index );                
       
   647                 if( !IsItemFolderL( index ) && secondRow->Length() > 0 ) 
       
   648                     {
       
   649                     SetHandlingKeyPressInProgress( EFalse );
       
   650                     iView.HandleCommandL( EVCCmdDelete );    
       
   651                     }
       
   652                 CleanupStack::PopAndDestroy( secondRow );
       
   653                 }
       
   654             }
       
   655         CleanupStack::PopAndDestroy( command );
       
   656         }
       
   657     }
       
   658 
       
   659 // ----------------------------------------------------------------------------
       
   660 // CVCGenericContainer::CheckCriticalLevelL
       
   661 // Checks for CL disk space
       
   662 // ----------------------------------------------------------------------------
       
   663 //
       
   664 TBool CVCGenericContainer::CheckCriticalLevelL()
       
   665     {
       
   666     RFs session = iCoeEnv->FsSession();
       
   667     TBool noMemory = SysUtil::FFSSpaceBelowCriticalLevelL( &session, KEditDiskUsage );
       
   668    
       
   669     if ( noMemory )
       
   670         {
       
   671         CAknQueryDialog* dlg = CAknQueryDialog::NewL( CAknQueryDialog::ENoTone );
       
   672         dlg->ExecuteLD( R_NOT_ENOUGH_MEMORY_DIALOG );
       
   673         }
       
   674         
       
   675     return noMemory;
       
   676     }
       
   677 
       
   678 // ----------------------------------------------------------------------------
       
   679 // CVCGenericContainer::UpdateTextL
       
   680 // Sets the new application name to the list
       
   681 // ----------------------------------------------------------------------------
       
   682 //
       
   683 void CVCGenericContainer::UpdateTextL( TInt aIndex, const TDesC& aNewName,
       
   684                                        const TDesC& aOldName ) 
       
   685     {
       
   686     RUBY_DEBUG_BLOCKL( "CVCGenericContainer::UpdateTextL" );
       
   687     
       
   688     TDesC* firstRow = GetFirstRowNameLC( aIndex );
       
   689     
       
   690     if( iModel.GetVCommandL( *firstRow ).UserText() != aNewName )
       
   691         {
       
   692         TPtrC itemText = iListBox->Model()->ItemText( aIndex );
       
   693         TInt tabIndex = itemText.Locate( KTabulator );
       
   694         
       
   695         TBuf<KVCMaxNameSize> applicationName;
       
   696         
       
   697         applicationName.Append( itemText.Left( tabIndex ) );
       
   698         applicationName.Append( KTabulator );
       
   699         
       
   700         applicationName.Append( *firstRow );
       
   701     	applicationName.Append( KTabulator );
       
   702         
       
   703         // Add user edited text to second line
       
   704     	if( aNewName.Size() > 0 ) 
       
   705     	    {
       
   706             applicationName.Append( aNewName );
       
   707     	    }
       
   708     	    
       
   709     	CVCAppUi* appUi = static_cast <CVCAppUi*> ( iEikonEnv->AppUi() );
       
   710     	
       
   711     	HBufC* stringholder;
       
   712         // We are removing the edited command
       
   713         if( aNewName == KNullDesC() )
       
   714             {
       
   715             stringholder = StringLoader::LoadL( R_QTN_VC_WAIT_NOTE_REMOVING, aOldName, iEikonEnv );
       
   716             CleanupStack::PushL( stringholder );
       
   717             appUi->ShowWaitNoteL( *stringholder );
       
   718             }
       
   719         // We are modifying a command
       
   720         else
       
   721             {
       
   722             stringholder = StringLoader::LoadLC( R_QTN_VC_WAIT_NOTE_CREATING_COMMAND, iEikonEnv );
       
   723             appUi->ShowWaitNoteL( *stringholder );
       
   724             }
       
   725         
       
   726         // Update extra text field for VCommand
       
   727         TRAPD( error, iModel.SetNewSpokenTextL( *firstRow, aNewName ) );
       
   728         // Untrainable text
       
   729         if( error == KErrArgument || error == KErrGeneral )
       
   730             {
       
   731             appUi->DeleteWaitNoteL();
       
   732             
       
   733             appUi->ShowErrorNoteL( R_QTN_VC_ERROR_NOTE_INVALID_TEXT );
       
   734             
       
   735             ShowEditTextL();
       
   736             }
       
   737         else
       
   738             {
       
   739             appUi->DeleteWaitNoteL();
       
   740             User::LeaveIfError( error );
       
   741             
       
   742             // Update listbox
       
   743             iItemArray->Delete( aIndex );
       
   744             iItemArray->InsertL( aIndex, applicationName );    
       
   745             
       
   746             iListBox->HandleItemAdditionL();
       
   747     
       
   748             }
       
   749                 
       
   750         CleanupStack::PopAndDestroy( stringholder );
       
   751         }
       
   752     
       
   753     CleanupStack::PopAndDestroy( firstRow );
       
   754     }
       
   755 
       
   756 
       
   757 // ----------------------------------------------------------------------------
       
   758 // CVCGenericContainer::CurrentSelection
       
   759 // ----------------------------------------------------------------------------
       
   760 //
       
   761 TInt CVCGenericContainer::CurrentSelection() const 
       
   762     {   
       
   763     return iListBox->CurrentItemIndex();
       
   764     }
       
   765 
       
   766 
       
   767 // ----------------------------------------------------------------------------
       
   768 // CVCGenericContainer::SetCurrentSelection
       
   769 // ----------------------------------------------------------------------------
       
   770 //
       
   771 void CVCGenericContainer::SetCurrentSelection( TInt aIndex )
       
   772     {   
       
   773     if ( aIndex >= 0 && aIndex < iItemArray->Count() )
       
   774         {
       
   775         iListBox->SetCurrentItemIndexAndDraw( aIndex );
       
   776         }
       
   777     else if ( iItemArray->Count() > 0 )
       
   778         {
       
   779         iListBox->SetCurrentItemIndexAndDraw( 0 );
       
   780         }
       
   781     }
       
   782 
       
   783 
       
   784 // ----------------------------------------------------------------------------
       
   785 // CVCGenericContainer::SizeChanged
       
   786 // ----------------------------------------------------------------------------
       
   787 //
       
   788 void CVCGenericContainer::SizeChanged() 
       
   789     {
       
   790     if( iListBox ) 
       
   791         {
       
   792         iListBox->SetRect( Rect() );
       
   793         }
       
   794     }
       
   795 
       
   796 
       
   797 // ----------------------------------------------------------------------------
       
   798 // CVCGenericContainer::FocusChanged
       
   799 // ----------------------------------------------------------------------------
       
   800 //
       
   801 void CVCGenericContainer::FocusChanged( TDrawNow aDrawNow ) 
       
   802     {
       
   803     if( iListBox ) 
       
   804         {
       
   805         iListBox->SetFocus( IsFocused(), aDrawNow );
       
   806         }
       
   807     }
       
   808     
       
   809 
       
   810 // ----------------------------------------------------------------------------
       
   811 // CVCGenericContainer::ComponentControl
       
   812 // ----------------------------------------------------------------------------
       
   813 //
       
   814 CCoeControl* CVCGenericContainer::ComponentControl( TInt /*aIndex*/ ) const 
       
   815     {
       
   816     return iListBox;
       
   817     }
       
   818 
       
   819 
       
   820 // --------------------------------------------------------------------------- 
       
   821 // CVCGenericContainer::GetHelpContext
       
   822 // Gives the help context to be displayed
       
   823 // ----------------------------------------------------------------------------
       
   824 //
       
   825 void CVCGenericContainer::GetHelpContext( TCoeHelpContext& aContext ) const 
       
   826     {
       
   827     aContext.iMajor = KUidHelp;
       
   828     if ( iView.Id() == KUidVCMainView )
       
   829         {
       
   830         aContext.iContext = KHLP_VC_SIND_MAIN;
       
   831         }
       
   832     else
       
   833         {
       
   834         aContext.iContext = KHLP_VC_SIND_FOLDER;
       
   835         }
       
   836     }
       
   837 
       
   838 
       
   839 // ----------------------------------------------------------------------------
       
   840 // CVCGenericContainer::CheckNameValidityL
       
   841 // ----------------------------------------------------------------------------
       
   842 //
       
   843 TBool CVCGenericContainer::CheckNameValidityL( const TDesC& aName ) 
       
   844     {
       
   845     RUBY_DEBUG_BLOCKL( "CVCGenericContainer::CheckNameValidityL" );
       
   846     
       
   847     TBool nameFound = EFalse;
       
   848     CVCAppUi* appUi = static_cast < CVCAppUi* > ( iEikonEnv->AppUi() );
       
   849 
       
   850     for( TInt i( 0 ); i < iModel.Count(); i++ ) 
       
   851         {        
       
   852         if( aName.Compare( iModel.At( i ).WrittenText() ) == 0 ||
       
   853             aName.Compare( iModel.At( i ).SpokenText() ) == 0 ) 
       
   854             {
       
   855             nameFound = ETrue;
       
   856             break;
       
   857             }
       
   858             
       
   859         if( aName.Compare( KNullDesC() ) != 0 &&
       
   860             aName.Compare( iModel.At( i ).UserText() ) == 0 )
       
   861             {
       
   862             nameFound = ETrue;
       
   863             break;
       
   864             }
       
   865         }
       
   866 
       
   867     if( nameFound ) 
       
   868         {    
       
   869         appUi->NameAlreadyInUseNoteL( aName );
       
   870         }
       
   871 
       
   872     return nameFound;
       
   873     }
       
   874 
       
   875 
       
   876 // ----------------------------------------------------------------------------
       
   877 // CVCGenericContainer::GetFirstRowNameLCC
       
   878 // ----------------------------------------------------------------------------
       
   879 //
       
   880 TDesC* CVCGenericContainer::GetFirstRowNameLC( TInt aIndex ) const
       
   881     {    
       
   882     TBuf<KVCMaxNameSize> name;
       
   883     name.Zero();
       
   884 
       
   885     // Get the application name
       
   886     TPtrC first = iListBox->Model()->ItemText( aIndex );
       
   887     
       
   888     // Locate the first tab char
       
   889     TInt index = first.Locate( KTabulator );
       
   890     
       
   891     // delete the icon from the beginning and get the name
       
   892     TPtrC second = first.Right( first.Length() - index - 1 );
       
   893 
       
   894     // check if the name has more tab chars in it
       
   895     index = second.Locate( KTabulator );
       
   896 
       
   897     if( index == second.Length()-1 || index == KErrNotFound ) 
       
   898         {
       
   899         name.Append( second );
       
   900         AknTextUtils::StripCharacters( name, KAknStripListControlChars );
       
   901         }
       
   902     else 
       
   903         {
       
   904         TInt reverse = second.LocateReverse( KTabulator );
       
   905         
       
   906         if( index == reverse ) 
       
   907             {
       
   908         
       
   909             TPtrC third = second.Left( index );
       
   910             name.Append( third );
       
   911             AknTextUtils::StripCharacters( name, KAknStripListControlChars );
       
   912             }
       
   913         }
       
   914 
       
   915     return name.AllocLC();
       
   916     }
       
   917 
       
   918 
       
   919 // ----------------------------------------------------------------------------
       
   920 // CVCGenericContainer::GetSecondRowNameLC
       
   921 // ----------------------------------------------------------------------------
       
   922 //
       
   923 TDesC* CVCGenericContainer::GetSecondRowNameLC( TInt aIndex ) const
       
   924     {    
       
   925     TBuf<KVCMaxNameSize> secondRow;
       
   926     
       
   927     TPtrC temp = iListBox->Model()->ItemText( aIndex );
       
   928     
       
   929     TPtrC text = temp.Right( temp.Length() - 2 );
       
   930     TInt foundTab = text.Locate( KTabulator );
       
   931 
       
   932     if( foundTab != KErrNotFound ) 
       
   933         {
       
   934         TInt index = text.LocateReverse( KTabulator );
       
   935         secondRow.Append( text.Right( text.Length() - index - 1 ) );
       
   936         AknTextUtils::StripCharacters( secondRow, KAknStripListControlChars );
       
   937         }
       
   938     return secondRow.AllocLC();
       
   939     }
       
   940 
       
   941 
       
   942 // ----------------------------------------------------------------------------
       
   943 // CVCGenericContainer::GetFolderTitle
       
   944 // ----------------------------------------------------------------------------
       
   945 //    
       
   946 TPtrC CVCGenericContainer::GetFolderTitle( TInt aIndex )
       
   947     {
       
   948     return (*iFolderTitles)[aIndex];
       
   949     }
       
   950 
       
   951 
       
   952 
       
   953 // ----------------------------------------------------------------------------
       
   954 // CVCGenericContainer::ListBoxSize
       
   955 // ----------------------------------------------------------------------------
       
   956 //
       
   957 TInt CVCGenericContainer::ListBoxCount() const
       
   958     {
       
   959     if( !iListBox ) 
       
   960         {
       
   961         return 0;
       
   962         }
       
   963     return iItemArray->Count();
       
   964     }
       
   965 
       
   966 
       
   967 // ----------------------------------------------------------------------------
       
   968 // CVCGenericContainer::HandleResourceChange
       
   969 // ----------------------------------------------------------------------------
       
   970 //
       
   971 void CVCGenericContainer::HandleResourceChangeL( TInt aType ) 
       
   972     {
       
   973     RUBY_DEBUG_BLOCKL( "CVCGenericContainer::HandleResourceChangeL" );
       
   974     
       
   975     CCoeControl::HandleResourceChange( aType );        
       
   976     }
       
   977 
       
   978 
       
   979 // ----------------------------------------------------------------------------
       
   980 // CVCGenericContainer::RefreshListboxL
       
   981 // ----------------------------------------------------------------------------
       
   982 //
       
   983 void CVCGenericContainer::RefreshListboxL( CVCommandUiEntryArray& oldCommands,
       
   984                                            CVCommandUiEntryArray& newCommands )
       
   985     {
       
   986     RUBY_DEBUG_BLOCKL( "CVCGenericContainer::RefreshListboxL" );
       
   987     
       
   988     TInt currentIndex = CurrentSelection();
       
   989     
       
   990     RArray<CVCommandUiEntry> commands = FindCommandsToBeAddedL( oldCommands,
       
   991                                                          newCommands );
       
   992     CleanupClosePushL( commands );
       
   993     AddCommandsL( commands );
       
   994     CleanupStack::PopAndDestroy();
       
   995         
       
   996     commands = FindCommandsToBeRemovedL( oldCommands, newCommands );
       
   997     CleanupClosePushL( commands );
       
   998     RemoveCommands( commands );                                  
       
   999     CleanupStack::PopAndDestroy( &commands );
       
  1000 
       
  1001     // Owned by listbox
       
  1002     CAknIconArray* icons = (CAknIconArray*) iListBox->ItemDrawer()->ColumnData()->IconArray();
       
  1003 
       
  1004     CUiArraysGenerator* generator = CUiArraysGenerator::NewLC();
       
  1005     generator->UpdateFolderArraysL( iModel, iView.FolderTitle(), *icons,
       
  1006                                     *iFolderTitles, iItemIsFolder, *iItemArray );
       
  1007     
       
  1008     CleanupStack::PopAndDestroy( generator );
       
  1009     
       
  1010     iListBox->HandleItemAdditionL();
       
  1011     iListBox->HandleItemRemovalL();
       
  1012     
       
  1013     SortItemListL();
       
  1014     
       
  1015     if ( currentIndex >= iItemArray->Count() )
       
  1016         {
       
  1017         if (iItemArray->Count() > 0)
       
  1018             {       
       
  1019             SetCurrentSelection( iItemArray->Count() - 1 );
       
  1020             }
       
  1021         else
       
  1022             {
       
  1023             // group has been renamed (ui language change) -> go back to main menu
       
  1024             iView.DoHandleCommandL( EAknSoftkeyBack );
       
  1025             }
       
  1026         }
       
  1027     }
       
  1028 
       
  1029 
       
  1030 // ----------------------------------------------------------------------------
       
  1031 // CVCGenericContainer::FindCommandLsToBeAddedL
       
  1032 // ----------------------------------------------------------------------------
       
  1033 //
       
  1034 RArray<CVCommandUiEntry> CVCGenericContainer::FindCommandsToBeAddedL(
       
  1035     CVCommandUiEntryArray& oldCommands, CVCommandUiEntryArray& newCommands )
       
  1036     {
       
  1037     RArray<CVCommandUiEntry> addedCmds;
       
  1038     CleanupClosePushL( addedCmds );
       
  1039     
       
  1040     // Compare items in newCommands with the items in oldCommands and see
       
  1041     // which are not found. These should be added to the listbox.
       
  1042     for( TInt i( 0 ); i < newCommands.Count(); i++ )
       
  1043         {
       
  1044         const CVCommandUiEntry& cmd = newCommands[i];
       
  1045         TBool found( EFalse );
       
  1046         
       
  1047         for( TInt j( 0 ); j < oldCommands.Count(); j++ )
       
  1048             {
       
  1049             const CVCommandUiEntry& compareCmd = oldCommands[j];
       
  1050                         
       
  1051             if( cmd == compareCmd )
       
  1052                 {
       
  1053                 found = ETrue;
       
  1054                 break;
       
  1055                 }
       
  1056             }
       
  1057             
       
  1058         if( !found )
       
  1059             {
       
  1060             addedCmds.AppendL( cmd );
       
  1061             }
       
  1062         }
       
  1063         
       
  1064     CleanupStack::Pop();
       
  1065     return addedCmds;
       
  1066     }
       
  1067 
       
  1068 
       
  1069 // ----------------------------------------------------------------------------
       
  1070 // CVCGenericContainer::AddCommandsL
       
  1071 // ----------------------------------------------------------------------------
       
  1072 //
       
  1073 void CVCGenericContainer::AddCommandsL( RArray<CVCommandUiEntry>& aCommands )
       
  1074     {
       
  1075     CEikFormattedCellListBox* listbox
       
  1076         = static_cast<CEikFormattedCellListBox*>( iListBox );
       
  1077     CAknIconArray* icons
       
  1078         = static_cast<CAknIconArray*>(listbox->ItemDrawer()->ColumnData()->IconArray());
       
  1079     
       
  1080     // Update the listbox and the icon array
       
  1081     for( TInt i( 0 ); i < aCommands.Count(); i++ )
       
  1082         {
       
  1083         CVCommandUiEntry& cmd = aCommands[i];
       
  1084         
       
  1085         // Check the folder
       
  1086         if( cmd.FolderTitle() == iView.FolderTitle() )
       
  1087             {
       
  1088             icons->AppendL( cmd.IconLC() );
       
  1089             CleanupStack::Pop(); // IconLC
       
  1090             
       
  1091             CVCommandUiEntry& cmd = aCommands[i];
       
  1092             
       
  1093             // Append to the end
       
  1094             iItemArray->AppendL( *CreateListboxItemLC( icons->Count()-1, // Last index
       
  1095                                                        cmd.WrittenText(),
       
  1096                                                        KNullDesC() ) );
       
  1097             CleanupStack::PopAndDestroy(); // CreateListboxItemLC
       
  1098             
       
  1099             iItemIsFolder.Append( EFalse );
       
  1100             }
       
  1101         }
       
  1102     }
       
  1103 
       
  1104 
       
  1105 // ----------------------------------------------------------------------------
       
  1106 // CVCGenericContainer::FindCommandLsToBeRemovedL
       
  1107 // ----------------------------------------------------------------------------
       
  1108 //
       
  1109 RArray<CVCommandUiEntry> CVCGenericContainer::FindCommandsToBeRemovedL(
       
  1110     CVCommandUiEntryArray& oldCommands, CVCommandUiEntryArray& newCommands )
       
  1111     {
       
  1112     RArray<CVCommandUiEntry> removedCmds;
       
  1113     CleanupClosePushL( removedCmds );
       
  1114         
       
  1115     // Compare items in oldCommands with the items in newCommands and see
       
  1116     // which are not found. These should be removed from the listbox.
       
  1117     for( TInt i( 0 ); i < oldCommands.Count(); i++ )
       
  1118         {
       
  1119         const CVCommandUiEntry& cmd = oldCommands[i];
       
  1120         TBool found( EFalse );
       
  1121         
       
  1122         for( TInt j( 0 ); j < newCommands.Count(); j++ )
       
  1123             {
       
  1124             const CVCommandUiEntry& compareCmd = newCommands[j];
       
  1125                         
       
  1126             if( cmd == compareCmd )
       
  1127                 {
       
  1128                 found = ETrue;
       
  1129                 break;
       
  1130                 }
       
  1131             }
       
  1132             
       
  1133         if( !found )
       
  1134             {
       
  1135             removedCmds.AppendL( cmd );
       
  1136             }
       
  1137         }
       
  1138 
       
  1139     CleanupStack::Pop();
       
  1140     return removedCmds;
       
  1141     }
       
  1142 
       
  1143 
       
  1144 // ----------------------------------------------------------------------------
       
  1145 // CVCGenericContainer::RemoveCommands
       
  1146 // ----------------------------------------------------------------------------
       
  1147 //
       
  1148 void CVCGenericContainer::RemoveCommands( RArray<CVCommandUiEntry>& aCommands )
       
  1149     {
       
  1150     CEikFormattedCellListBox* listbox
       
  1151         = static_cast<CEikFormattedCellListBox*>( iListBox );
       
  1152     CAknIconArray* icons
       
  1153         = static_cast<CAknIconArray*>(listbox->ItemDrawer()->ColumnData()->IconArray());
       
  1154     
       
  1155     // Update the listbox
       
  1156     for( TInt i( 0 ); i < aCommands.Count(); i++ )
       
  1157         {
       
  1158         CVCommandUiEntry& cmd = aCommands[i];
       
  1159         
       
  1160         // Check the folder
       
  1161         if( cmd.FolderTitle() == iView.FolderTitle() )
       
  1162             {
       
  1163             for( TInt j( 0 ); j < iItemArray->Count(); j++ )
       
  1164                 {
       
  1165                 TPtrC16 item = (*iItemArray)[j];
       
  1166                 
       
  1167                 // Written text is unique. When changing a spoken text we 
       
  1168                 // check that the new spoken text is not a written text
       
  1169                 // for any command. That is why it is enough to search for
       
  1170                 // the written text in the item here
       
  1171                 if( item.Find( cmd.WrittenText() ) != KErrNotFound )
       
  1172                     {
       
  1173                     iItemArray->Delete( j );
       
  1174                     iItemArray->Compress();
       
  1175                     }
       
  1176                 }
       
  1177                 
       
  1178             // Icon array now has excess items, but that is no problem.
       
  1179             // It is more efficient to leave the icons as they are.
       
  1180             }
       
  1181         }
       
  1182     }
       
  1183     
       
  1184 
       
  1185 // ----------------------------------------------------------------------------
       
  1186 // CVCGenericContainer::SearchItemArrayL
       
  1187 // ----------------------------------------------------------------------------
       
  1188 //
       
  1189 TInt CVCGenericContainer::SearchItemArrayL( const TDesC& aText  )
       
  1190     {
       
  1191     TInt ret( KErrNotFound );
       
  1192     
       
  1193     for( TInt i( 0 ); i < iItemArray->Count(); i++ )
       
  1194         {
       
  1195         if( (*iItemArray)[i].Find( aText ) != KErrNotFound )
       
  1196             {
       
  1197             ret = i;
       
  1198             break;
       
  1199             }
       
  1200         }
       
  1201     return ret;
       
  1202     }
       
  1203 
       
  1204 // ----------------------------------------------------------------------------
       
  1205 // CVCGenericContainer::CreateListboxItem
       
  1206 // ----------------------------------------------------------------------------
       
  1207 //  
       
  1208 TDesC* CVCGenericContainer::CreateListboxItemLC( TInt aIconArrayIndex,
       
  1209                                                const TDesC& aFirstRow,
       
  1210                                                const TDesC& aSecondRow )
       
  1211     {
       
  1212     TBuf<KVCMaxNameSize> name;
       
  1213     name.AppendNum( aIconArrayIndex );
       
  1214     name.Append( KTabulator );
       
  1215     name.Append( aFirstRow );
       
  1216     name.Append( KTabulator );
       
  1217     name.Append( aSecondRow );
       
  1218     
       
  1219     return name.AllocLC();
       
  1220     }
       
  1221 
       
  1222 
       
  1223 // End of File
       
  1224