voiceui/voiceuivoicerecognition/src/vuictutorial.cpp
changeset 0 bf1d17376201
child 17 8ce15fced3a6
equal deleted inserted replaced
-1:000000000000 0:bf1d17376201
       
     1 /*
       
     2 * Copyright (c) 2006-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:  Handles tutorial mode resources and dialog showing
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include <avkon.rsg>
       
    22 #include <avkon.hrh>
       
    23 #include <centralrepository.h>
       
    24 #include <vcommanddomaincrkeys.h>
       
    25 
       
    26 #include <vuivoicerecognition.rsg>
       
    27 
       
    28 #include "vuivoicerecognition.hrh"
       
    29 
       
    30 #include "vuictutorial.h"
       
    31 #include "vuictutorialmessagedialog.h"
       
    32 
       
    33 #include "rubydebug.h"
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CTutorial::InstanceL
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 CTutorial* CTutorial::NewL()
       
    40     {
       
    41     CTutorial* self = new ( ELeave ) CTutorial();
       
    42     CleanupStack::PushL( self ); 
       
    43     self->ConstructL(); 
       
    44     CleanupStack::Pop( self ); 
       
    45     return self; 
       
    46     }
       
    47     
       
    48 // Destructor       
       
    49 CTutorial::~CTutorial()
       
    50     {
       
    51     RUBY_DEBUG0( "CTutorial::~CTutorial START" );
       
    52     
       
    53     // Save tutorial mode settings before exiting
       
    54     TRAP_IGNORE( SaveSettingsL() );
       
    55     
       
    56     DestroyMessage();
       
    57     
       
    58     RUBY_DEBUG0( "CTutorial::~CTutorial EXIT" );
       
    59     }
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // CTutorial::CreateMessageL
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 void CTutorial::CreateMessageL()
       
    66     {
       
    67     RUBY_DEBUG_BLOCK( "CTutorial::CreateMessageL" );
       
    68     
       
    69     if ( iDlg )
       
    70         {
       
    71         User::Leave( KErrAlreadyExists );
       
    72         }
       
    73        
       
    74     iDlg = CTutorialMessageDialog::NewL();
       
    75     }
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // CTutorial::CreateAndShowMessageL
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 TInt CTutorial::CreateAndShowMessageL()
       
    82     {
       
    83     RUBY_DEBUG_BLOCK( "CTutorial::CreateAndShowMessageL" );
       
    84     
       
    85     CreateMessageL();
       
    86     return ShowMessageL();
       
    87     }
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // CTutorial::ShowMessageL
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 TInt CTutorial::ShowMessageL( TBool aDeviceLockMode )
       
    94     {
       
    95     RUBY_DEBUG_BLOCK( "CTutorial::ShowMessageL" );
       
    96     
       
    97     TInt returnValue = KErrGeneral;    
       
    98     
       
    99     switch( iState )
       
   100         {
       
   101         case EIntroState:
       
   102             
       
   103             if ( IsTutorialModeEnabled() && iTutorialMode )
       
   104                 {
       
   105                 iState = ECommandState;
       
   106                 returnValue = iDlg->ShowMessageDialogL( R_MESSAGE_QUERY,
       
   107                                                         R_TEXT_SIND_TUTORIAL_PAGE_INTRO_TITLE,
       
   108                                                         R_TEXT_SIND_TUTORIAL_PAGE_INTRO_TEXT_UP,
       
   109                                                         R_TEXT_SIND_TUTORIAL_PAGE_INTRO_TEXT_DOWN,
       
   110                                                         R_SOFTKEYS_NEXT_CANCEL__NEXT );
       
   111                 }
       
   112             else if ( IsTutorialModeEnabled() && !aDeviceLockMode )
       
   113                 {
       
   114                 iState = ETryState;
       
   115                 returnValue = iDlg->ShowMessageDialogL( R_MESSAGE_QUERY,
       
   116                                                         R_TEXT_SIND_TUTORIAL_PAGE_INTRO_TITLE,
       
   117                                                         R_TEXT_SIND_TUTORIAL_FIRST_TIME_TEXT_UP,
       
   118                                                         R_TEXT_SIND_TUTORIAL_FIRST_TIME_TEXT_DOWN,
       
   119                                                         R_SOFTKEYS_ACTIVATE_CANCEL__ACTIVATE,
       
   120                                                         SecondaryDisplay::ECmdShowFirstTimeActivationQuery );
       
   121                 if ( returnValue == EVoiceInfoSoftKeyActivate )
       
   122                     {
       
   123                     DisableFirstTimeMode();
       
   124                     }
       
   125                 }
       
   126             else 
       
   127                 {
       
   128                 iState = ETryState;
       
   129                 }
       
   130             break;
       
   131             
       
   132         case ECommandState:
       
   133             
       
   134             iState = EDialState;
       
   135             returnValue = iDlg->ShowMessageDialogL( R_MESSAGE_QUERY,
       
   136                                                     R_TEXT_SIND_TUTORIAL_PAGE_COMMAND_TITLE,
       
   137                                                     R_TEXT_SIND_TUTORIAL_PAGE_COMMAND_TEXT_UP,
       
   138                                                     R_TEXT_SIND_TUTORIAL_PAGE_COMMAND_TEXT_DOWN,
       
   139                                                     R_SOFTKEYS_NEXT_CANCEL__NEXT );
       
   140             break;
       
   141             
       
   142         case EDialState:
       
   143             
       
   144             iState = EOtherState;
       
   145             returnValue = iDlg->ShowMessageDialogL( R_MESSAGE_QUERY,
       
   146                                                     R_TEXT_SIND_TUTORIAL_PAGE_DIAL_TITLE,
       
   147                                                     R_TEXT_SIND_TUTORIAL_PAGE_DIAL_TEXT_UP,
       
   148                                                     R_TEXT_SIND_TUTORIAL_PAGE_DIAL_TEXT_DOWN,
       
   149                                                     R_SOFTKEYS_NEXT_CANCEL__NEXT );
       
   150             break;
       
   151 
       
   152         case EOtherState:
       
   153             
       
   154             iState = ETryState;
       
   155             returnValue = iDlg->ShowMessageDialogL( R_MESSAGE_QUERY,
       
   156                                                     R_TEXT_SIND_TUTORIAL_PAGE_OTHER_TITLE,
       
   157                                                     R_TEXT_SIND_TUTORIAL_PAGE_OTHER_TEXT_UP,
       
   158                                                     R_TEXT_SIND_TUTORIAL_PAGE_OTHER_TEXT_DOWN,
       
   159                                                     R_SOFTKEYS_NEXT_CANCEL__NEXT );
       
   160             break;
       
   161 
       
   162         case ETryState:
       
   163             
       
   164             iState = EBestState;
       
   165             if ( IsTutorialModeEnabled() && !aDeviceLockMode )
       
   166                 {
       
   167                 returnValue = iDlg->ShowMessageDialogL( R_MESSAGE_QUERY,
       
   168                                                         R_TEXT_SIND_TUTORIAL_PAGE_TRY_TITLE,
       
   169                                                         R_TEXT_SIND_TUTORIAL_PAGE_TRY_TEXT_UP,
       
   170                                                         R_TEXT_SIND_TUTORIAL_PAGE_TRY_TEXT_DOWN,
       
   171                                                         R_SOFTKEYS_ACTIVATE_CANCEL__ACTIVATE );
       
   172                 }
       
   173             break;
       
   174 
       
   175         case EBestState:
       
   176             
       
   177             iState = EActivationState;
       
   178             if ( IsTutorialModeEnabled() && !aDeviceLockMode )
       
   179                 {
       
   180                 returnValue = iDlg->ShowMessageDialogL( R_MESSAGE_QUERY,
       
   181                                                         R_TEXT_SIND_TUTORIAL_PAGE_BEST_TITLE,
       
   182                                                         R_TEXT_SIND_TUTORIAL_PAGE_BEST_TEXT_UP,
       
   183                                                         R_TEXT_SIND_TUTORIAL_PAGE_BEST_TEXT_DOWN,
       
   184                                                         R_SOFTKEYS_NEXT_CANCEL__NEXT );
       
   185                 }
       
   186             break;
       
   187 
       
   188         case EActivationState:
       
   189             
       
   190             iState = EFinishedState;
       
   191             if ( IsTutorialModeEnabled() && !aDeviceLockMode )
       
   192                 {
       
   193                 returnValue = iDlg->ShowMessageDialogL( R_MESSAGE_QUERY,
       
   194                                                         R_TEXT_SIND_TUTORIAL_PAGE_ACTIVATION_TITLE,
       
   195                                                         R_TEXT_SIND_TUTORIAL_PAGE_ACTIVATION_TEXT,
       
   196                                                         KErrNone,
       
   197                                                         R_AVKON_SOFTKEYS_QUIT );
       
   198                 }
       
   199             break;
       
   200 
       
   201         case EErrorState:
       
   202             
       
   203             iState = EFinishedState;
       
   204             if ( IsTutorialModeEnabled() && !aDeviceLockMode )
       
   205                 {
       
   206                 returnValue = iDlg->ShowMessageDialogL( R_MESSAGE_QUERY,
       
   207                                                         R_TEXT_SIND_TUTORIAL_PAGE_ERROR_TITLE,
       
   208                                                         R_TEXT_SIND_TUTORIAL_PAGE_ERROR_TEXT_UP,
       
   209                                                         R_TEXT_SIND_TUTORIAL_PAGE_ERROR_TEXT_DOWN,
       
   210                                                         R_SOFTKEYS_NEXT_CANCEL__NEXT );
       
   211                 if ( returnValue == EVoiceInfoSoftKeyNext )
       
   212                     {
       
   213                     iState = ETryState;
       
   214                     }
       
   215                 }
       
   216             break;
       
   217             
       
   218         default:
       
   219             returnValue = KErrCancel;
       
   220             break;
       
   221         }
       
   222         
       
   223         if ( returnValue == EVoiceInfoSoftKeyCancel || returnValue == EAknSoftkeyQuit )
       
   224             {
       
   225             iTutorialMode = EFalse;
       
   226             returnValue = KErrCancel;
       
   227             }
       
   228         else if ( returnValue == KErrNone )
       
   229             {
       
   230             // Return general error because dialog has been canceled without any keypress
       
   231             returnValue = KErrGeneral;
       
   232             }
       
   233         else if ( returnValue != KErrCancel )
       
   234             {
       
   235             returnValue = KErrNone;
       
   236             }
       
   237         
       
   238     return returnValue;
       
   239     }
       
   240 
       
   241 // -----------------------------------------------------------------------------
       
   242 // CTutorial::DestroyMessage
       
   243 // -----------------------------------------------------------------------------
       
   244 //
       
   245 void CTutorial::DestroyMessage()
       
   246     {
       
   247     RUBY_DEBUG0( "CTutorial::DestroyMessage START" );
       
   248     
       
   249     if ( iDlg )
       
   250         {
       
   251         delete iDlg;
       
   252         iDlg = NULL;
       
   253         }
       
   254     
       
   255     RUBY_DEBUG0( "CTutorial::DestroyMessage EXIT" );    
       
   256     }
       
   257 
       
   258 // -----------------------------------------------------------------------------
       
   259 // CTutorial::GetTutorialState
       
   260 // -----------------------------------------------------------------------------
       
   261 //
       
   262 CTutorial::TTutorialState CTutorial::GetTutorialState()
       
   263     {
       
   264     RUBY_DEBUG0( "CTutorial::GetTutorialState" );
       
   265     return iState;
       
   266     }
       
   267 
       
   268 // -----------------------------------------------------------------------------
       
   269 // CTutorial::ShowError
       
   270 // -----------------------------------------------------------------------------
       
   271 //
       
   272 void CTutorial::ErrorState()
       
   273     {
       
   274     RUBY_DEBUG0( "CTutorial::ErrorState" );
       
   275     iState = EErrorState;
       
   276     }
       
   277 
       
   278 // -----------------------------------------------------------------------------
       
   279 // CTutorial::IsTutorialModeEnabled
       
   280 // -----------------------------------------------------------------------------
       
   281 //
       
   282 TBool CTutorial::IsTutorialModeEnabled()
       
   283     {
       
   284     RUBY_DEBUG0( "CTutorial::IsTutorialModeEnabled" );
       
   285     return iTutorialMode || iFirstTimeMode;
       
   286     }
       
   287 
       
   288 // -----------------------------------------------------------------------------
       
   289 // CTutorial::DisableTutorialMode
       
   290 // -----------------------------------------------------------------------------
       
   291 //
       
   292 void CTutorial::DisableFirstTimeMode()
       
   293     {
       
   294     RUBY_DEBUG0( "CTutorial::DisableFirstTimeMode" );
       
   295     if ( !iTutorialMode )
       
   296         {
       
   297         iFirstTimeMode = EFalse;
       
   298         
       
   299         TRAP_IGNORE( SaveSettingsL() );
       
   300         }    
       
   301     }
       
   302 
       
   303 // -----------------------------------------------------------------------------
       
   304 // CTutorial::CTutorial
       
   305 // C++ default constructor can NOT contain any code, that
       
   306 // might leave.
       
   307 // -----------------------------------------------------------------------------
       
   308 //
       
   309 CTutorial::CTutorial()
       
   310  : iTutorialMode( EFalse ), iFirstTimeMode( EFalse ), iState( EIntroState )
       
   311     {
       
   312     // Nothing
       
   313     }
       
   314 
       
   315 // -----------------------------------------------------------------------------
       
   316 // CTutorialMessageDialog::ConstructL
       
   317 // Symbian 2nd phase constructor can leave.
       
   318 // -----------------------------------------------------------------------------
       
   319 //
       
   320 void CTutorial::ConstructL()
       
   321     {
       
   322     RUBY_DEBUG_BLOCK( "CTutorial::ConstructL" );
       
   323     
       
   324     LoadSettingsL();
       
   325     }
       
   326 
       
   327 // ---------------------------------------------------------------------------
       
   328 // CTutorial::LoadSettingsL
       
   329 // ---------------------------------------------------------------------------
       
   330 //
       
   331 void CTutorial::LoadSettingsL()
       
   332     {
       
   333     RUBY_DEBUG_BLOCK( "CTutorial::LoadSettingsL" );
       
   334     
       
   335     CRepository* client = CRepository::NewLC( KCRUidVCommandSettings );
       
   336     
       
   337     User::LeaveIfError( client->Get( KVuiDemoFirstTime,
       
   338                                      iFirstTimeMode ) );
       
   339     
       
   340     User::LeaveIfError( client->Get( KVuiDemoMode,
       
   341                                      iTutorialMode ) );
       
   342 
       
   343     CleanupStack::PopAndDestroy( client );
       
   344     }
       
   345 
       
   346 // ---------------------------------------------------------------------------
       
   347 // CTutorial::SaveSettingsL
       
   348 // ---------------------------------------------------------------------------
       
   349 //
       
   350 void CTutorial::SaveSettingsL()
       
   351     {
       
   352     RUBY_DEBUG_BLOCK( "CTutorial::SaveSettingsL" );
       
   353     
       
   354     CRepository* client = CRepository::NewLC( KCRUidVCommandSettings );
       
   355 
       
   356     User::LeaveIfError( client->Set( KVuiDemoFirstTime,
       
   357                                      iFirstTimeMode ) );
       
   358                         
       
   359     User::LeaveIfError( client->Set( KVuiDemoMode,
       
   360                                      EFalse ) );
       
   361 
       
   362     CleanupStack::PopAndDestroy( client );
       
   363     }
       
   364 
       
   365 // End of File
       
   366