voiceui/vcommand/src/vcmodel.cpp
branchRCL_3
changeset 19 e36f3802f733
parent 0 bf1d17376201
equal deleted inserted replaced
18:cad71a31b7fc 19:e36f3802f733
       
     1 /*
       
     2 * Copyright (c) 2007 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:  Model class for vcommand application wrapping CVCommandHandler
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include "vcappui.h"
       
    22 #include "vcmodel.h"
       
    23 #include "vcplaybackdialog.h"
       
    24 #include "vcommanduientry.h"
       
    25 #include "vcmodelappuiinterface.h"
       
    26 
       
    27 #include "rubydebug.h"
       
    28 
       
    29 
       
    30 // ================= MEMBER FUNCTIONS =======================
       
    31 
       
    32 // -----------------------------------------------------------------------------
       
    33 // CVCModel::NewL
       
    34 // Two-phased constructor.
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 CVCModel* CVCModel::NewL( MVcModelAppUiInterface* aAppUi )
       
    38     {
       
    39     CVCModel* self = new (ELeave) CVCModel( aAppUi );
       
    40     CleanupStack::PushL( self );
       
    41     self->ConstructL();
       
    42     CleanupStack::Pop( self );
       
    43     return self;
       
    44     }
       
    45 
       
    46 // ----------------------------------------------------------------------------
       
    47 // CVCModel::CVCModel
       
    48 // C++ constructor
       
    49 // ----------------------------------------------------------------------------
       
    50 //
       
    51 CVCModel::CVCModel( MVcModelAppUiInterface* aAppUi ) : iAppUi( aAppUi )
       
    52     {   
       
    53     }
       
    54  
       
    55 // ----------------------------------------------------------------------------
       
    56 // CVCModel::ConstructL
       
    57 // Two-phased constructor
       
    58 // ----------------------------------------------------------------------------
       
    59 //
       
    60 void CVCModel::ConstructL() 
       
    61     {
       
    62     iVcHandler = CVCommandHandler::NewL( this );
       
    63     
       
    64     LoadVCommandsL();
       
    65     }
       
    66 
       
    67 // ----------------------------------------------------------------------------
       
    68 // CVCModel::~CVCModel
       
    69 // Destructor
       
    70 // ----------------------------------------------------------------------------
       
    71 //
       
    72 CVCModel::~CVCModel() 
       
    73     {
       
    74     delete iVcHandler;
       
    75     delete iListBoxVCommands;
       
    76     }
       
    77     
       
    78 // ----------------------------------------------------------------------------
       
    79 // CVCModel::GetVCommandL
       
    80 // ----------------------------------------------------------------------------
       
    81 //
       
    82 const CVCommandUiEntry& CVCModel::GetVCommandL( const TDesC& aWrittenText )
       
    83     {
       
    84     RUBY_DEBUG_BLOCKL( "CVCModel::GetVCommandL" );
       
    85     
       
    86     TInt index( KErrNotFound );
       
    87     index = FindVCommandIndexL( aWrittenText );
       
    88     User::LeaveIfError( index );
       
    89     
       
    90     return iListBoxVCommands->At( index );
       
    91     }
       
    92     
       
    93 // ----------------------------------------------------------------------------
       
    94 // CVCModel::At
       
    95 // ----------------------------------------------------------------------------
       
    96 //
       
    97 const CVCommandUiEntry& CVCModel::At( TInt aIndex ) const
       
    98     {
       
    99     // An index that is out of bounds causes a USER-130 panic.
       
   100     return iListBoxVCommands->At( aIndex );
       
   101     }
       
   102     
       
   103 // ----------------------------------------------------------------------------
       
   104 // CVCModel::At
       
   105 // ----------------------------------------------------------------------------
       
   106 //
       
   107 TInt CVCModel::Count() const
       
   108     {
       
   109     return iListBoxVCommands->Count();
       
   110     }
       
   111     
       
   112 // ----------------------------------------------------------------------------
       
   113 // CVCModel::VCommandArrayL
       
   114 // ----------------------------------------------------------------------------
       
   115 //
       
   116 CVCommandUiEntryArray* CVCModel::VCommandArrayL()
       
   117     {    
       
   118     return iListBoxVCommands->CloneL();
       
   119     }
       
   120 
       
   121 // ----------------------------------------------------------------------------
       
   122 // CVCModel::Service
       
   123 // ----------------------------------------------------------------------------
       
   124 //
       
   125 CVCommandHandler& CVCModel::Service()
       
   126     {    
       
   127     return *iVcHandler;
       
   128     }
       
   129     
       
   130 // ----------------------------------------------------------------------------
       
   131 // CVCModel::LoadVCommandsL
       
   132 // ----------------------------------------------------------------------------
       
   133 //
       
   134 void CVCModel::LoadVCommandsL()
       
   135     {
       
   136     RUBY_DEBUG_BLOCKL( "CVCModel::LoadVCommandsL" );
       
   137     
       
   138     // CVCommandHandler::ListCommandsL must be completed when exiting
       
   139     // the application or a panic might occur.
       
   140     iAppUi->StartAtomicOperationLC();
       
   141     CVCommandUiEntryArray* listBoxVCommands
       
   142         = CVCommandUiEntryArray::NewL( iVcHandler->ListCommandsL() );
       
   143         
       
   144     delete iListBoxVCommands;
       
   145     iListBoxVCommands = listBoxVCommands;
       
   146         
       
   147     CleanupStack::PopAndDestroy(); // StartAtomicOperationLC
       
   148     }
       
   149     
       
   150 // ----------------------------------------------------------------------------
       
   151 // CVCModel::iView->FindVCommandIndexL
       
   152 // ----------------------------------------------------------------------------
       
   153 //
       
   154 TInt CVCModel::FindVCommandIndexL( const TDesC& aWrittenText )
       
   155     {
       
   156     RUBY_DEBUG_BLOCKL( "CVCModel::FindVCommandIndexL" );
       
   157     
       
   158     for( TInt i = 0; i < iListBoxVCommands->Count(); i++ ) 
       
   159         {
       
   160         if( aWrittenText == iListBoxVCommands->At( i ).WrittenText() )
       
   161             {
       
   162             return i;
       
   163             }
       
   164         }
       
   165     
       
   166     return KErrNotFound;
       
   167     }
       
   168 
       
   169 // ----------------------------------------------------------------------------
       
   170 // CVCModel::HasCommandL
       
   171 // ----------------------------------------------------------------------------
       
   172 //
       
   173 TBool CVCModel::HasCommandL( const TDesC& aWrittenText )
       
   174     {
       
   175     return FindVCommandIndexL( aWrittenText ) != KErrNotFound;
       
   176     }
       
   177 
       
   178 // ----------------------------------------------------------------------------
       
   179 // CVCModel::SetNewSpokenTextL
       
   180 // ----------------------------------------------------------------------------
       
   181 //
       
   182 void CVCModel::SetNewSpokenTextL( const TDesC& aWrittenText,
       
   183                                   const TDesC& aNewSpokenText ) 
       
   184     {
       
   185     RUBY_DEBUG_BLOCKL( "CVCModel::UpdateVCommandL" );
       
   186     
       
   187     iAppUi->StartAtomicOperationLC();
       
   188     
       
   189     TInt index( KErrNotFound );
       
   190     index = FindVCommandIndexL( aWrittenText );
       
   191     
       
   192     User::LeaveIfError( index );
       
   193     
       
   194     const CVCommand& oldCommand = iListBoxVCommands->At( index ).Command();
       
   195 
       
   196     CVCCommandUi* updatedCommandUi( NULL );
       
   197     CVCFolderInfo* folderInfo
       
   198         = CVCFolderInfo::NewL( oldCommand.CommandUi().FolderInfo() );
       
   199     CleanupStack::PushL( folderInfo );
       
   200     updatedCommandUi = CVCCommandUi::NewL( oldCommand.CommandUi().WrittenText(), 
       
   201                                            *folderInfo,
       
   202                                            oldCommand.CommandUi().Modifiable(),
       
   203                                            oldCommand.CommandUi().Tooltip(), 
       
   204                                            oldCommand.CommandUi().IconUid(),
       
   205                                            aNewSpokenText,
       
   206                                            oldCommand.CommandUi().ConfirmationNeeded() );
       
   207     CleanupStack::PopAndDestroy( folderInfo );
       
   208     CleanupStack::PushL( updatedCommandUi );
       
   209 
       
   210     CVCommand* updatedCommand( NULL );
       
   211     updatedCommand = CVCommand::NewL( oldCommand.SpokenText(),
       
   212                                       oldCommand.Runnable(),
       
   213                                       *updatedCommandUi );
       
   214 
       
   215     CleanupStack::PopAndDestroy( updatedCommandUi );
       
   216     CleanupStack::PushL( updatedCommand );
       
   217     iVcHandler->AddCommandL( *updatedCommand );
       
   218 
       
   219     iVcHandler->RemoveCommandL( oldCommand );
       
   220 
       
   221     CleanupStack::PopAndDestroy( updatedCommand ); 
       
   222 
       
   223     LoadVCommandsL();
       
   224     
       
   225     CleanupStack::PopAndDestroy(); // StartAtomicOperationLC
       
   226     }
       
   227     
       
   228 // ----------------------------------------------------------------------------
       
   229 // CVCModel::CommandSetChanged
       
   230 // ----------------------------------------------------------------------------
       
   231 //
       
   232 void CVCModel::CommandSetChanged()
       
   233     {
       
   234     iAppUi->CommandSetChanged();
       
   235     }
       
   236     
       
   237 // End of File