srsf/speechsynthesis/tsrc/testapplication/src/testappappui.cpp
changeset 0 bf1d17376201
equal deleted inserted replaced
-1:000000000000 0:bf1d17376201
       
     1 /*
       
     2 * Copyright (c) 2005-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:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "TestAppAppUi.h"
       
    21 #include "TestAppContainer.h"
       
    22 #include <TestApplication.rsg>
       
    23 #include "TestApp.hrh"
       
    24 #include <aknNoteDialog.h>
       
    25 #include <aknNoteWrappers.h>
       
    26 #include <eikmenup.h>
       
    27 #include <avkon.hrh>
       
    28 
       
    29 #include "testappengine.h"
       
    30 
       
    31 #include "rubydebug.h"
       
    32 
       
    33 // ================= MEMBER FUNCTIONS =======================
       
    34 //
       
    35 // ----------------------------------------------------------
       
    36 // CTestAppAppUi::ConstructL()
       
    37 // 
       
    38 // ----------------------------------------------------------
       
    39 //
       
    40 void CTestAppAppUi::ConstructL() 
       
    41     {
       
    42     BaseConstructL();
       
    43     
       
    44     iAppContainer = new (ELeave) CTestAppContainer;
       
    45     iAppContainer->SetMopParent(this);
       
    46     iAppContainer->ConstructL( ClientRect() );
       
    47     
       
    48     iAppEngine = CTestAppEngine::NewL( *this );
       
    49     
       
    50     AddToStackL( iAppContainer );
       
    51     }
       
    52 
       
    53 // ----------------------------------------------------
       
    54 // CTestAppAppUi::~CTestAppAppUi()
       
    55 // Destructor
       
    56 // Frees reserved resources
       
    57 // ----------------------------------------------------
       
    58 //
       
    59 CTestAppAppUi::~CTestAppAppUi()
       
    60     {
       
    61     if ( iAppContainer )
       
    62         {
       
    63         RemoveFromStack( iAppContainer );
       
    64         delete iAppContainer;
       
    65         }
       
    66         
       
    67     if ( iAppEngine )
       
    68         {
       
    69         TRAP_IGNORE( iAppEngine->DisconnectL() );
       
    70         delete iAppEngine;
       
    71         }
       
    72     }
       
    73 
       
    74 // ------------------------------------------------------------------------------
       
    75 // CTestAppAppUi::::DynInitMenuPaneL(TInt aResourceId,CEikMenuPane* aMenuPane)
       
    76 //  This function is called by the EIKON framework just before it displays
       
    77 //  a menu pane. Its default implementation is empty, and by overriding it,
       
    78 //  the application can set the state of menu items dynamically according
       
    79 //  to the state of application data.
       
    80 // ------------------------------------------------------------------------------
       
    81 //
       
    82 void CTestAppAppUi::DynInitMenuPaneL(
       
    83     TInt aResourceId, CEikMenuPane* aMenuPane )
       
    84     {
       
    85     if ( aResourceId==R_TEST_APPLICATION_MENU )
       
    86         {         
       
    87         if (iServerConnected)
       
    88             {      
       
    89             aMenuPane->SetItemDimmed( ETestAppCmdAppConnect, ETrue );
       
    90             aMenuPane->SetItemDimmed( ETestAppCmdAppDisconnect, EFalse );
       
    91             aMenuPane->SetItemDimmed( ETestAppCmdAppSayText, EFalse );
       
    92             aMenuPane->SetItemDimmed( ETestAppCmdAppSayTextToFile, EFalse );
       
    93             aMenuPane->SetItemDimmed( ETestAppCmdAppChangeVoice, EFalse );
       
    94             aMenuPane->SetItemDimmed( ETestAppCmdAppVolumeDown, EFalse );
       
    95             aMenuPane->SetItemDimmed( ETestAppCmdAppVolumeUp, EFalse );
       
    96             }
       
    97         else
       
    98             { 
       
    99             aMenuPane->SetItemDimmed( ETestAppCmdAppConnect, EFalse );
       
   100             aMenuPane->SetItemDimmed( ETestAppCmdAppDisconnect, ETrue );
       
   101             aMenuPane->SetItemDimmed( ETestAppCmdAppSayText, ETrue );
       
   102             aMenuPane->SetItemDimmed( ETestAppCmdAppSayTextToFile, ETrue );
       
   103             aMenuPane->SetItemDimmed( ETestAppCmdAppChangeVoice, ETrue );
       
   104             aMenuPane->SetItemDimmed( ETestAppCmdAppVolumeDown, ETrue );
       
   105             aMenuPane->SetItemDimmed( ETestAppCmdAppVolumeUp, ETrue );
       
   106             }
       
   107         }
       
   108     }
       
   109 
       
   110 // ----------------------------------------------------
       
   111 // CTestAppAppUi::HandleKeyEventL(
       
   112 //     const TKeyEvent& aKeyEvent,TEventCode /*aType*/)
       
   113 // ----------------------------------------------------
       
   114 //
       
   115 TKeyResponse CTestAppAppUi::HandleKeyEventL( const TKeyEvent& aKeyEvent,
       
   116                                              TEventCode aType )
       
   117     {
       
   118     TKeyResponse response( EKeyWasNotConsumed );
       
   119     
       
   120     if ( aType == EEventKey && iServerConnected )
       
   121         {
       
   122         response = EKeyWasConsumed;
       
   123         
       
   124         switch ( aKeyEvent.iCode )
       
   125             {
       
   126             case EKeyOK: 
       
   127             
       
   128                 HandleCommandL( ETestAppCmdAppSayText );
       
   129                 break;
       
   130 
       
   131             case EKeyDownArrow: 
       
   132             
       
   133                 HandleCommandL( ETestAppCmdAppChangeVoice );
       
   134                 break;
       
   135 
       
   136             case EKeyUpArrow: 
       
   137             
       
   138                 HandleCommandL( ETestAppCmdAppChangeRate );
       
   139                 break;
       
   140 
       
   141             case EKeyLeftArrow: 
       
   142             
       
   143                 HandleCommandL( ETestAppCmdAppVolumeDown );
       
   144                 break;
       
   145 
       
   146             case EKeyRightArrow: 
       
   147             
       
   148                 HandleCommandL( ETestAppCmdAppVolumeUp );
       
   149                 break;
       
   150 
       
   151             case 50: // a
       
   152                 
       
   153                 HandleCommandL( ETestAppCmdAppChangeAudioOutput );
       
   154                 break;
       
   155                 
       
   156             case 55: // p
       
   157             
       
   158                 HandleCommandL( ETestAppCmdAppPause );
       
   159                 break;
       
   160                 
       
   161             case 56: // t
       
   162             
       
   163                 HandleCommandL( ETestAppCmdAppPlay );
       
   164                 break;
       
   165                 
       
   166             case 57: // w
       
   167             
       
   168                 HandleCommandL( ETestAppCmdAppStop );
       
   169                 break;
       
   170                 
       
   171             default:
       
   172             
       
   173                 response = EKeyWasNotConsumed;
       
   174                 
       
   175             }
       
   176         }
       
   177     
       
   178     return response;
       
   179     }
       
   180 
       
   181 // ----------------------------------------------------
       
   182 // CTestAppAppUi::HandleCommandL
       
   183 // 
       
   184 // ----------------------------------------------------
       
   185 //
       
   186 void CTestAppAppUi::HandleCommandL(TInt aCommand)
       
   187     {
       
   188     TInt value( -1 );
       
   189     TVoice voice;
       
   190     
       
   191     switch ( aCommand )
       
   192         {
       
   193         case EAknSoftkeyExit:
       
   194         case EEikCmdExit:
       
   195         case EKeyPhoneEnd:
       
   196         case EKeyEscape: 
       
   197             Exit();
       
   198             break;
       
   199             
       
   200         case ETestAppCmdAppConnect:
       
   201             
       
   202             ShowNoteL( _L("Connect") );
       
   203             
       
   204             iAppEngine->ConnectL();
       
   205             iServerConnected = ETrue;            
       
   206             
       
   207             ChangeTextL( 0, _L("Server: Connected") );
       
   208             
       
   209             break;
       
   210 
       
   211         case ETestAppCmdAppDisconnect:
       
   212             
       
   213             ShowNoteL( _L("Disconnect") );
       
   214             
       
   215             iAppEngine->DisconnectL();
       
   216             iServerConnected = EFalse; 
       
   217             
       
   218             ChangeTextL( 0, _L("Server: Disconnected") ); 
       
   219             
       
   220             break;
       
   221             
       
   222         case ETestAppCmdAppSayText:
       
   223             
       
   224             ShowNoteL( _L("Say text") );
       
   225             
       
   226             iAppEngine->InitTextL();
       
   227             
       
   228             break;
       
   229             
       
   230         case ETestAppCmdAppSayTextToFile:
       
   231             
       
   232             ShowNoteL( _L("Say text to file") );
       
   233             
       
   234             iAppEngine->InitTextToFileL();
       
   235             
       
   236             break;
       
   237 
       
   238         case ETestAppCmdAppChangeVoice:
       
   239             
       
   240             voice = iAppEngine->ChangeVoiceL();
       
   241             
       
   242             ShowNoteL( voice.iVoiceName, voice.iLanguage );
       
   243             ChangeTextL( 1, voice.iVoiceName, voice.iLanguage );
       
   244             
       
   245             break;
       
   246             
       
   247         case ETestAppCmdAppVolumeDown:
       
   248             
       
   249             value = iAppEngine->VolumeDownL();
       
   250             
       
   251             ShowNoteL( _L("Volume"), value );
       
   252             ChangeTextL( 2, _L("Volume"), value );
       
   253             
       
   254             break;
       
   255             
       
   256         case ETestAppCmdAppVolumeUp:
       
   257             
       
   258             value = iAppEngine->VolumeUpL();
       
   259             
       
   260             ShowNoteL( _L("Volume"), value );
       
   261             ChangeTextL( 2, _L("Volume"), value );
       
   262             
       
   263             break;
       
   264             
       
   265         case ETestAppCmdAppChangeRate:
       
   266             
       
   267             value = iAppEngine->RateUpL();
       
   268             
       
   269             ShowNoteL( _L("Speaking rate"), value );
       
   270             ChangeTextL( 3, _L("Speking Rate"), value );
       
   271             break;
       
   272             
       
   273         case ETestAppCmdAppChangeAudioOutput:
       
   274             
       
   275             iAppEngine->ChangeAudioOutputL();
       
   276             
       
   277             ShowNoteL( _L("Audio output changed") );
       
   278             break;
       
   279             
       
   280         case ETestAppCmdAppPause:
       
   281             
       
   282             ShowNoteL( _L("Paused") );
       
   283             iAppEngine->PauseL();
       
   284             
       
   285             break;
       
   286             
       
   287         case ETestAppCmdAppPlay:
       
   288             
       
   289             ShowNoteL( _L("Play") );
       
   290             iAppEngine->PlayL();
       
   291             
       
   292             break;
       
   293 
       
   294         case ETestAppCmdAppStop:
       
   295             
       
   296             ShowNoteL( _L("Stopped") );
       
   297             
       
   298             iAppEngine->StopL();
       
   299             
       
   300             break;
       
   301             
       
   302         default:
       
   303             
       
   304             break;      
       
   305         }
       
   306     }
       
   307 
       
   308 // ----------------------------------------------------
       
   309 // CTestAppAppUi::ShowNoteL
       
   310 // 
       
   311 // ----------------------------------------------------
       
   312 //
       
   313 void CTestAppAppUi::ShowNoteL( TPtrC aText, TInt aNumber )
       
   314     {
       
   315     TBuf<64> buf( aText );
       
   316     
       
   317     if ( aNumber > -1 )
       
   318         {
       
   319         buf.Append( _L(": ") );
       
   320         buf.AppendNum( aNumber );
       
   321         }
       
   322         
       
   323     iEikonEnv->InfoMsg( buf );
       
   324     
       
   325     ChangeTextL( 5, buf.PtrZ() ); 
       
   326     }
       
   327     
       
   328 // ----------------------------------------------------
       
   329 // CTestAppAppUi::ChangeTextL
       
   330 // 
       
   331 // ----------------------------------------------------
       
   332 //
       
   333 void CTestAppAppUi::ChangeTextL( TInt aIndex, 
       
   334                                  TPtrC aText, 
       
   335                                  TInt aNumber )
       
   336     {
       
   337     TBuf<64> buf( aText );
       
   338 
       
   339     if ( aNumber != -1 )
       
   340         {
       
   341         buf.Append( _L(": ") );
       
   342         buf.AppendNum( aNumber );
       
   343         }
       
   344     
       
   345     iAppContainer->ChangeTextL( aIndex, buf );
       
   346     }
       
   347 
       
   348 // End of File