voiceui/vcommand/src/vcplaybackdialog.cpp
changeset 13 57b735022c18
parent 1 b13cd05eeb2f
equal deleted inserted replaced
1:b13cd05eeb2f 13:57b735022c18
     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 CVCPlaybackDialog
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 
       
    22 #include <StringLoader.h>
       
    23 #include <aknnotewrappers.h>
       
    24 #include <aknsoundsystem.h>
       
    25 #include <aknappui.h>
       
    26 #include <avkon.hrh>
       
    27 #include <vcommandapi.h>
       
    28 #include "vcplaybackdialog.h"
       
    29 #include "vcmodel.h"
       
    30 #include "rubydebug.h"
       
    31 
       
    32 
       
    33 // ============================ MEMBER FUNCTIONS ===============================
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CVCPlaybackDialog::CVCPlaybackDialog
       
    37 // C++ default constructor can NOT contain any code, that
       
    38 // might leave.
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CVCPlaybackDialog::CVCPlaybackDialog( CVCommandHandler& aService,
       
    42                                       const CVCommandUiEntry& aCommand ) : 
       
    43                                       CAknProgressDialog( NULL ),
       
    44                                       iService( aService ),
       
    45                                       iCommand( aCommand )
       
    46     {
       
    47     iTModel.iFinalValue = KVoiceTagRecordLength;
       
    48     iTModel.iHundreths = KInterval;
       
    49     iTModel.iIncrement = KVoiceTagIncrement;
       
    50     iTModel.iRunning = EFalse;
       
    51     iVisibilityDelayOff = ETrue;
       
    52     }
       
    53 
       
    54 
       
    55 // Destructor
       
    56 CVCPlaybackDialog::~CVCPlaybackDialog()
       
    57     {
       
    58     if (iProgressBarTimer)
       
    59         {
       
    60         iProgressBarTimer->Cancel();
       
    61         delete iProgressBarTimer;
       
    62         }
       
    63     if (iProgressInfo)
       
    64         {
       
    65         iProgressInfo = NULL;
       
    66         }
       
    67     }
       
    68 
       
    69 
       
    70 // ---------------------------------------------------------
       
    71 // CVCPlaybackDialog::PreLayoutDynInitL
       
    72 // ---------------------------------------------------------
       
    73 //
       
    74 void CVCPlaybackDialog::PreLayoutDynInitL()
       
    75     {
       
    76     RUBY_DEBUG_BLOCKL( "CVCPlaybackDialog::PreLayoutDynInitL" );
       
    77     
       
    78     HBufC* text = StringLoader::LoadLC( R_QTN_VC_PLAYING );
       
    79     SetTextL( *text );
       
    80     CleanupStack::PopAndDestroy( text );
       
    81 
       
    82     ButtonGroupContainer().SetCommandSetL( R_SOFTKEYS_QUIT );   
       
    83     }
       
    84 
       
    85 
       
    86 // ---------------------------------------------------------
       
    87 // CVCPlaybackDialog::PostLayoutDynInitL
       
    88 // ---------------------------------------------------------
       
    89 //
       
    90 void CVCPlaybackDialog::PostLayoutDynInitL()
       
    91     {
       
    92     RUBY_DEBUG_BLOCKL( "CVCPlaybackDialog::PostLayoutDynInitL" );
       
    93     
       
    94     // FIrst check if a user edited command exists
       
    95     if( iCommand.AlternativeSpokenText().Length() > 0 )
       
    96         {
       
    97         iCommand.PlayAlternativeSpokenTextL( iService, *this );
       
    98         }
       
    99     else
       
   100         {
       
   101         iCommand.PlaySpokenTextL( iService, *this );        
       
   102         }
       
   103     }
       
   104 
       
   105 
       
   106 // ---------------------------------------------------------
       
   107 // CVCPlaybackDialog::OkToExitL
       
   108 // ---------------------------------------------------------
       
   109 //
       
   110 TBool CVCPlaybackDialog::OkToExitL( TInt aButtonId )
       
   111     {
       
   112     RUBY_DEBUG_BLOCKL( "CVCPlaybackDialog::OkToExitL" );
       
   113     
       
   114     // Finished playing
       
   115     if ( iExitWhenCalledBack )
       
   116         {
       
   117         return ETrue;
       
   118         }
       
   119 
       
   120     if ( ( iTickCount < 1 ) && ( !iExitFlag ) )
       
   121         {
       
   122         return EFalse;
       
   123         }
       
   124 
       
   125     // Check what button was pressed
       
   126     switch ( aButtonId )
       
   127         {
       
   128         case EAknSoftkeyOk:
       
   129         break;
       
   130 
       
   131         case EKeyPhoneEnd:
       
   132         case EKeyApplication:
       
   133         case EAknSoftkeyQuit:
       
   134             {
       
   135             iOkToExit = ETrue;
       
   136             
       
   137             if ( iExitFlag )
       
   138             	{
       
   139             	iCommand.CancelPlaybackL( iService );
       
   140             	}
       
   141         	
       
   142         	break;
       
   143             }
       
   144             
       
   145         case EVCommandSoftKeyQuit:
       
   146             {
       
   147             iOkToExit = ETrue;
       
   148 
       
   149             iCommand.CancelPlaybackL( iService );
       
   150             
       
   151             break;
       
   152             }
       
   153 
       
   154         default:
       
   155         	iOkToExit = EFalse;  
       
   156         break;
       
   157         }
       
   158 
       
   159     return iOkToExit;
       
   160     }
       
   161 
       
   162 
       
   163 // ---------------------------------------------------------
       
   164 // CVCPlaybackDialog::OfferKeyEventL
       
   165 // ---------------------------------------------------------
       
   166 //
       
   167 TKeyResponse CVCPlaybackDialog::OfferKeyEventL( const TKeyEvent& aKeyEvent,
       
   168                                                 TEventCode aType )
       
   169     {
       
   170     RUBY_DEBUG_BLOCKL( "CVCPlaybackDialog::OfferKeyEventL" );
       
   171     
       
   172     // Only react to red and application key
       
   173     if ( aType == EEventKey )
       
   174         {             
       
   175         if ( aKeyEvent.iCode == EKeyApplication )
       
   176             {
       
   177             iExitFlag = ETrue;
       
   178             TryExitL( EKeyApplication );
       
   179             return EKeyWasConsumed;
       
   180             }
       
   181         else if ( aKeyEvent.iCode == EKeyPhoneEnd )
       
   182             {
       
   183             iExitFlag = ETrue;
       
   184             TryExitL( EKeyPhoneEnd );
       
   185             return EKeyWasConsumed;
       
   186             }
       
   187         }
       
   188     
       
   189     return EKeyWasConsumed;
       
   190     }
       
   191 
       
   192 
       
   193 // ---------------------------------------------------------
       
   194 // CVCPlaybackDialog::StartTimerL
       
   195 // ---------------------------------------------------------
       
   196 //
       
   197 void CVCPlaybackDialog::StartTimerL()
       
   198    {
       
   199    RUBY_DEBUG_BLOCKL( "CVCPlaybackDialog::StartTimerL" );
       
   200    
       
   201    iTickCount=0;
       
   202    iProgressBarTimer = CPeriodic::NewL( CActive::EPriorityStandard );
       
   203    TTimeIntervalMicroSeconds32 delay( KDelay );
       
   204    TTimeIntervalMicroSeconds32 interval( KMicroSecondsInterval*iTModel.iHundreths );
       
   205    iProgressBarTimer->Start( delay,interval, TCallBack( OnTick, this ) );
       
   206    }
       
   207 
       
   208 // ---------------------------------------------------------
       
   209 // CVCPlaybackDialog::StopTimer
       
   210 // ---------------------------------------------------------
       
   211 //
       
   212 void CVCPlaybackDialog::StopTimer()
       
   213     {
       
   214     if ( iProgressBarTimer )
       
   215         {
       
   216         iProgressBarTimer->Cancel();
       
   217         delete iProgressBarTimer;
       
   218         iProgressBarTimer = NULL;
       
   219         }
       
   220     }
       
   221 
       
   222 // ---------------------------------------------------------
       
   223 // CVCPlaybackDialog::OnTick
       
   224 // ---------------------------------------------------------
       
   225 //
       
   226 TInt CVCPlaybackDialog::OnTick( TAny* aObject )
       
   227     { 
       
   228     STATIC_CAST( CVCPlaybackDialog*, aObject )->DoTick();
       
   229     return 1; // magic
       
   230     }
       
   231 
       
   232 // ---------------------------------------------------------
       
   233 // CVCPlaybackDialog::DoTick
       
   234 // ---------------------------------------------------------
       
   235 //
       
   236 void CVCPlaybackDialog::DoTick()
       
   237     {
       
   238     if ( iTickCount != iTModel.iFinalValue+1 )
       
   239         {
       
   240         iProgressInfo->IncrementAndDraw( iTModel.iIncrement );
       
   241         iTickCount++;
       
   242         }
       
   243 
       
   244     if (iExitFlag) 
       
   245         {
       
   246         RUBY_DEBUG0( "CVCPlaybackDialog::DoTick: Exit due to iExitFlag" );
       
   247         StopTimer();
       
   248         }
       
   249     }
       
   250 
       
   251 
       
   252 // ---------------------------------------------------------
       
   253 // CVCPlaybackDialog::DoHandlePlayErrorL
       
   254 // ---------------------------------------------------------
       
   255 //
       
   256 void CVCPlaybackDialog::DoHandlePlayErrorL( TNssPlayResult aResult )
       
   257     {
       
   258     RUBY_DEBUG1( "CVCPlaybackDialog::DoHandlePlayErrorL: [%d]", aResult );
       
   259     HandlePlayComplete( aResult );
       
   260     }
       
   261 
       
   262 
       
   263 // ---------------------------------------------------------
       
   264 // CVCPlaybackDialog::HandlePlayStarted
       
   265 // ---------------------------------------------------------
       
   266 //
       
   267 void CVCPlaybackDialog::HandlePlayStarted(
       
   268     TTimeIntervalMicroSeconds32 aDuration )
       
   269     {
       
   270     TRAP_IGNORE( DoHandlePlayStartedL( aDuration ) );
       
   271     }
       
   272 
       
   273 // ---------------------------------------------------------
       
   274 // CVCPlaybackDialog::DoHandlePlayStartedL
       
   275 // ---------------------------------------------------------
       
   276 //
       
   277 void CVCPlaybackDialog::DoHandlePlayStartedL(
       
   278     TTimeIntervalMicroSeconds32 aDuration )
       
   279     {
       
   280     RUBY_DEBUG_BLOCKL( "CVCPlaybackDialog::DoHandlePlayStartedL" );
       
   281     
       
   282     iTModel.iFinalValue = aDuration.Int()/KMicroSecondsInterval;
       
   283     iProgressInfo = GetProgressInfoL();
       
   284     iProgressInfo->SetFinalValue( iTModel.iFinalValue );
       
   285     StartTimerL();
       
   286     }
       
   287 
       
   288 
       
   289 // ---------------------------------------------------------
       
   290 // CVCPlaybackDialog::HandlePlayComplete
       
   291 // ---------------------------------------------------------
       
   292 //
       
   293 #ifdef _DEBUG
       
   294 void CVCPlaybackDialog::HandlePlayComplete( TNssPlayResult aErrorCode )
       
   295 #else
       
   296 void CVCPlaybackDialog::HandlePlayComplete( TNssPlayResult /*aErrorCode*/ )
       
   297 #endif
       
   298     {
       
   299     RUBY_DEBUG1( "CVCPlaybackDialog::HandlePlayComplete: [%d]", aErrorCode );
       
   300     iExitWhenCalledBack = ETrue;
       
   301     StopTimer();
       
   302     TRAP_IGNORE( TryExitL( EAknSoftkeyOk) );
       
   303     }
       
   304 
       
   305 
       
   306 // ---------------------------------------------------------
       
   307 // CVCPlaybackDialog::DisplayErrorNoteL
       
   308 // ---------------------------------------------------------
       
   309 //
       
   310 void CVCPlaybackDialog::DisplayErrorNoteL()
       
   311     {
       
   312     RUBY_DEBUG_BLOCKL( "CVCPlaybackDialog::DisplayErrorNoteL" );
       
   313     
       
   314     iExitFlag = ETrue;
       
   315     iOkToExit = ETrue; 
       
   316     HBufC* text = StringLoader::LoadLC( R_TEXT_VOICE_SYSTEM_ERROR );
       
   317     CAknErrorNote* dlg = new (ELeave) CAknErrorNote( ETrue );
       
   318     dlg->ExecuteLD( *text );
       
   319     CleanupStack::PopAndDestroy( text );
       
   320     }
       
   321 
       
   322 
       
   323 //  End of File