srsf/vcommandmanager/src/vcmanagerbackupobserver.cpp
branchRCL_3
changeset 19 e36f3802f733
parent 0 bf1d17376201
equal deleted inserted replaced
18:cad71a31b7fc 19:e36f3802f733
       
     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:  Watches changes of the PC-Suite data sync state
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "vcmanagerbackupobserver.h"
       
    20 #include "rubydebug.h"
       
    21 
       
    22 #include "srsfprivatecrkeys.h"
       
    23 
       
    24 #include <sbdefs.h>
       
    25 #include <centralrepository.h>
       
    26 
       
    27 // CONSTANTS
       
    28 
       
    29 static const TInt KUndefinedLanguage = -1;
       
    30 
       
    31 /**
       
    32  @todo generalize the common parts of this class, CVCommandManagerBackupObserver
       
    33        and CNssVasBackupObserver from VAS API
       
    34        At the moment the code is copy-pasted and duplicated
       
    35 */
       
    36 
       
    37 // ---------------------------------------------------------
       
    38 // CVCommandManagerBackupObserver::NewL
       
    39 // ---------------------------------------------------------
       
    40 //
       
    41 CVCommandManagerBackupObserver* CVCommandManagerBackupObserver::NewL()
       
    42     {
       
    43     CVCommandManagerBackupObserver* self = new (ELeave) CVCommandManagerBackupObserver();
       
    44     CleanupStack::PushL( self );
       
    45     self->ConstructL();
       
    46     CleanupStack::Pop( self );
       
    47     return self;
       
    48     }
       
    49     
       
    50 // ---------------------------------------------------------
       
    51 // CVCommandManagerBackupObserver::CVCommandManagerBackupObserver
       
    52 // C++ constructor can NOT contain any code, that might leave.
       
    53 // ---------------------------------------------------------
       
    54 //
       
    55 CVCommandManagerBackupObserver::CVCommandManagerBackupObserver()
       
    56  : CActive( CActive::EPriorityHigh ), iRestoreStarted( EFalse )
       
    57     {
       
    58     // Nothing
       
    59     }
       
    60     
       
    61 // ---------------------------------------------------------
       
    62 // CVCommandManagerBackupObserver::ConstructL
       
    63 // C++ constructor can NOT contain any code, that might leave.
       
    64 // ---------------------------------------------------------
       
    65 //
       
    66 void CVCommandManagerBackupObserver::ConstructL() 
       
    67     {
       
    68     RUBY_DEBUG_BLOCK( "CVCommandManagerBackupObserver::ConstructL" );
       
    69     User::LeaveIfError( iProperty.Attach( KUidSystemCategory, conn::KUidBackupRestoreKey ) );
       
    70        
       
    71     // initial subscription and process current property value
       
    72     iProperty.Subscribe( iStatus );
       
    73     
       
    74     CActiveScheduler::Add( this ); 
       
    75     SetActive();   
       
    76     }
       
    77     
       
    78 // ---------------------------------------------------------
       
    79 // CVCommandManagerBackupObserver::~CVCommandManagerBackupObserver
       
    80 // ---------------------------------------------------------
       
    81 //
       
    82 CVCommandManagerBackupObserver::~CVCommandManagerBackupObserver()
       
    83     {
       
    84     Cancel();
       
    85     iProperty.Close();
       
    86     }
       
    87     
       
    88 // ---------------------------------------------------------
       
    89 // CNssVasBackupObserver::DoCancel
       
    90 // Cancel listening now
       
    91 // ---------------------------------------------------------
       
    92 //    
       
    93 void CVCommandManagerBackupObserver::DoCancel() 
       
    94     {
       
    95     iProperty.Cancel();
       
    96     }
       
    97 
       
    98 // ---------------------------------------------------------
       
    99 // CVCommandManagerBackupObserver::RunL
       
   100 // Is called, when property changed
       
   101 // ---------------------------------------------------------
       
   102 //
       
   103 void CVCommandManagerBackupObserver::RunL()
       
   104     {
       
   105     RUBY_DEBUG_BLOCK( "CVCommandManagerBackupObserver::RunL" );
       
   106     
       
   107     if( iStatus != KErrNone ) 
       
   108         {
       
   109         // At least report the error
       
   110         RUBY_ERROR1( "CVCommandManagerBackupObserver::RunL - iStatus is [%d]", iStatus.Int() );
       
   111         }
       
   112         
       
   113     // resubscribe before processing new value to prevent missing updates
       
   114     // even if some error happened
       
   115     iProperty.Subscribe( iStatus );
       
   116     SetActive();
       
   117     // property updated, get new value
       
   118 	TInt backupFlag;
       
   119 	User::LeaveIfError( iProperty.Get( backupFlag ) );
       
   120 	switch ( backupFlag & conn::KBURPartTypeMask )
       
   121 	    {
       
   122 	    case conn::EBURNormal:
       
   123 	        RUBY_DEBUG0( "CVCommandManagerBackupObserver::RunL - Backup/restore ended" );
       
   124 	        SetVoiceCommandRetrainingL();
       
   125 	        iRestoreStarted = EFalse;
       
   126 	        break;
       
   127 	        
       
   128 	    case conn::EBURBackupFull:
       
   129 	    case conn::EBURBackupPartial:
       
   130 	        RUBY_DEBUG0( "CVCommandManagerBackupObserver::RunL - Backup started" );
       
   131             iRestoreStarted = EFalse;
       
   132 	        break;
       
   133 	    
       
   134 	    case conn::EBURRestoreFull:
       
   135 	    case conn::EBURRestorePartial:
       
   136 	        RUBY_DEBUG0( "CVCommandManagerBackupObserver::RunL - Restore started" );
       
   137             iRestoreStarted = ETrue;
       
   138 	        break;
       
   139 	        
       
   140 	    case conn::EBURUnset:
       
   141 	    default:
       
   142 	        RUBY_ERROR1( "CVCommandManagerBackupObserver::RunL - Backup flag unknown %h ", backupFlag );
       
   143 	    }
       
   144     }
       
   145 
       
   146 // ---------------------------------------------------------
       
   147 // CVCommandManagerBackupObserver::SetVoiceCommandRetrainingL
       
   148 // Enables voice command retraining
       
   149 // ---------------------------------------------------------
       
   150 //    
       
   151 void CVCommandManagerBackupObserver::SetVoiceCommandRetrainingL()
       
   152     {
       
   153     RUBY_DEBUG_BLOCK( "CVCommandManagerBackupObserver::SetVoiceCommandRetrainingL" );
       
   154     
       
   155     if ( iRestoreStarted )
       
   156         {
       
   157         CRepository* client = CRepository::NewLC( KCRUidSRSFSettings );
       
   158         User::LeaveIfError( client->Set( KSRSFUiLanguage, KUndefinedLanguage ) );
       
   159         CleanupStack::PopAndDestroy( client );
       
   160         }
       
   161     }
       
   162 
       
   163 //  End of File