omadm/omadmappui/src/NSmlDMSyncHandler.cpp
changeset 0 3ce708148e4d
child 8 0a8136f75056
equal deleted inserted replaced
-1:000000000000 0:3ce708148e4d
       
     1 /*
       
     2 * Copyright (c) 2005 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 DM UI component
       
    15 * 	This is part of omadmappui.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDES
       
    21 #include <NSmlDMSync.rsg>
       
    22 #include <aknnotewrappers.h>
       
    23 #include <AknWaitDialog.h>
       
    24 #include <textresolver.h>   // for CTextResolver
       
    25 #include <StringLoader.h>
       
    26 #include <e32property.h>
       
    27 
       
    28 #include <data_caging_path_literals.hrh>  // for resource and bitmap directories
       
    29 #include <SyncMLErr.h>      // sync error codes
       
    30 
       
    31 
       
    32 #include <AknsUtils.h>
       
    33 #include <DevManInternalCRKeys.h>
       
    34 #include <centralrepository.h>
       
    35 
       
    36 #include "NSmlDMSyncDocument.h"
       
    37 #include "NSmlDMSyncHandler.h"
       
    38 #include "NSmlDMAuthQueryDlg.h"
       
    39 #include "NSmlDMSyncState.h"
       
    40 #include "NSmlDMSyncDebug.h"
       
    41 #include "NSmlDMSyncDialog.h"
       
    42 #include "nsmldmsyncinternalpskeys.h"
       
    43 
       
    44 #include <nsmldmsync.mbg>
       
    45 #include <featmgr.h>
       
    46 #ifdef __SCALABLE_ICONS
       
    47 _LIT( KBitmapFileName,  "z:nsmldmsync.mif" );
       
    48 #else
       
    49 _LIT( KBitmapFileName,  "z:nsmldmsync.mbm" );
       
    50 #endif
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CNSmlDMSyncHandler::NewL
       
    54 //
       
    55 // Two-phased constructor.
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 CNSmlDMSyncHandler* CNSmlDMSyncHandler::NewL( RSyncMLSession* aSyncSession,
       
    59                                               CNSmlDMSyncAppEngine* aAppEngine,
       
    60                                               CNSmlDMSyncDocument* aSyncDocument )
       
    61     {
       
    62 	FLOG( "CNSmlDMSyncHandler::NewL()" );
       
    63 
       
    64     CNSmlDMSyncHandler* self =
       
    65         new (ELeave) CNSmlDMSyncHandler( aSyncSession,
       
    66                                          aAppEngine,
       
    67                                          aSyncDocument );
       
    68 	CleanupStack::PushL(self);
       
    69 	self->ConstructL();
       
    70 	CleanupStack::Pop(self);
       
    71     return self;
       
    72     }
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // Destructor.
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 CNSmlDMSyncHandler::~CNSmlDMSyncHandler()
       
    79     {
       
    80     FLOG( "CNSmlDMSyncHandler::~CNSmlDMSyncHandler()" );
       
    81 
       
    82     
       
    83     if ( iFotaProgressDialog )
       
    84 		{
       
    85 	    TRAP_IGNORE( iFotaProgressDialog->CancelProgressDialogL() );
       
    86 	    delete iFotaProgressDialog;
       
    87 		}		            
       
    88 
       
    89 
       
    90 	if ( iProgressDialog )
       
    91 		{
       
    92 	    TRAP_IGNORE( iProgressDialog->CancelProgressDialogL() );
       
    93 	    delete iProgressDialog;
       
    94 		}
       
    95 	delete iState;
       
    96 	delete iActiveCaller;
       
    97 
       
    98 	if ( iSyncRunning )
       
    99 	    {
       
   100 	    TRAP_IGNORE( iSyncJob.StopL() );
       
   101         iSyncJob.Close();
       
   102 	    }
       
   103 	  FeatureManager::UnInitializeLib();
       
   104 	FLOG( "CNSmlDMSyncHandler::~CNSmlDMSyncHandler() completed" );
       
   105     }
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // CNSmlDMSyncHandler::ConstructL
       
   109 // Symbian 2nd phase constructor can leave.
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 void CNSmlDMSyncHandler::ConstructL( void )
       
   113     {
       
   114     FLOG( "CNSmlDMSyncHandler::ConstructL" );
       
   115    FeatureManager::InitializeLibL();   
       
   116 	iState = CNSmlDMSyncState::NewL();
       
   117 	iActiveCaller = CNSmlDMActiveCaller::NewL(this);
       
   118 	iServerAlertedSync = EFalse;
       
   119 	iSyncRunning = EFalse;
       
   120 	iSyncError = KErrNone;
       
   121 	
       
   122 	iCheckUpdate = EFalse;
       
   123 	
       
   124     }
       
   125 
       
   126 // -----------------------------------------------------------------------------
       
   127 // CNSmlDMSyncHandler::CNSmlDMSyncHandler
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 CNSmlDMSyncHandler::CNSmlDMSyncHandler( RSyncMLSession* aSyncSession,
       
   131                                         CNSmlDMSyncAppEngine* aAppEngine,
       
   132                                         CNSmlDMSyncDocument* aSyncDocument ) 
       
   133     : iSyncSession( aSyncSession ),
       
   134     iSyncAppEngine( aAppEngine ),
       
   135     iSyncDocument( aSyncDocument ),iFotaProgressLaunched(EFalse)
       
   136 	{
       
   137 	}
       
   138 
       
   139 // -----------------------------------------------------------------------------
       
   140 // CNSmlDMSyncHandler::HandleDialogEventL
       
   141 // -----------------------------------------------------------------------------
       
   142 //
       
   143 void CNSmlDMSyncHandler::HandleDialogEventL( TInt aButtonId )
       
   144     {
       
   145     FLOG( "CNSmlDMSyncHandler::HandleDialogEventL" );
       
   146     
       
   147 	if ( aButtonId == EEikBidCancel )
       
   148 		{
       
   149 		FLOG( "CNSmlDMSyncHandler::HandleDialogEventL cancelling" );
       
   150 		if ( SyncRunning() )
       
   151 			{
       
   152 	        TInt err = RProperty::Set( KPSUidNSmlDMSyncApp,
       
   153 				KDmJobCancel, KErrCancel );
       
   154 	        FTRACE( FPrint(
       
   155 	              _L("CNSmlDMSyncHandler::CancelSynchronizeL() KDmJobCancel = -3, err = %d"),
       
   156 	                			err ) );
       
   157 			FLOG( "CNSmlDMSyncHandler::HandleDialogEventL cancelling stop job" );
       
   158 			TRAP_IGNORE( iSyncJob.StopL() );
       
   159 		    
       
   160 		    State()->SetSyncPhase( CNSmlDMSyncState::EPhaseCanceling );
       
   161 	        UpdateDialogL();
       
   162 			}
       
   163 		}
       
   164     FLOG( "CNSmlDMSyncHandler::HandleDialogEventL() completed" );
       
   165     }
       
   166 
       
   167 // -----------------------------------------------------------------------------
       
   168 // CNSmlDMSyncHandler::SynchronizeL
       
   169 // -----------------------------------------------------------------------------
       
   170 //
       
   171 void CNSmlDMSyncHandler::SynchronizeL( TDesC& aServerName,
       
   172                                        const TInt aProfileId,
       
   173                                        const TInt aJobId,
       
   174                                        const TInt aConnectionBearer,
       
   175                                        const TBool aUseFotaProgressNote )
       
   176 	{
       
   177 	FLOG( "CNSmlDMSyncHandler::SynchronizeL Server alert" );
       
   178 	
       
   179 	iServerName = aServerName;
       
   180 	iConnectionBearer = aConnectionBearer;
       
   181     iProfileId = aProfileId;
       
   182     iJobId = aJobId;
       
   183     iUseFotaProgressNote = aUseFotaProgressNote;
       
   184     
       
   185     iSyncJob.OpenL( Session(), iJobId );
       
   186     iSyncJobId = iSyncJob.Identifier();
       
   187     FTRACE( FPrint( _L(
       
   188 	    "[OMADM]\tCNSmlDMSyncHandler::SynchronizeL--server alert, iSyncJobId = %d" ),
       
   189 	     iSyncJobId ) ); 
       
   190 	  //SAN Support
       
   191 	  iServerAlertedSync = ETrue;  
       
   192 	  _LIT_SECURITY_POLICY_S0( KWritePolicy, KUidSmlSyncApp.iUid );
       
   193         _LIT_SECURITY_POLICY_C1( KReadPolicy, ECapabilityReadDeviceData );
       
   194         RProperty::Define( KPSUidNSmlDMSyncApp,
       
   195                            KNSmlDMSyncUiInitiatedJobKey,
       
   196                            RProperty::EInt,
       
   197                            KReadPolicy,
       
   198                            KWritePolicy ); 
       
   199     RProperty::Set( KPSUidNSmlDMSyncApp,
       
   200                     KNSmlDMSyncUiInitiatedJobKey,
       
   201                     iSyncJobId );                       
       
   202 	  //SAN Support
       
   203     SynchronizeL();
       
   204 	}
       
   205 	
       
   206 // -----------------------------------------------------------------------------
       
   207 // CNSmlDMSyncHandler::SynchronizeL
       
   208 // -----------------------------------------------------------------------------
       
   209 //
       
   210 void CNSmlDMSyncHandler::SynchronizeL( TDesC& aServerName,
       
   211                                        const TInt aProfileId,
       
   212                                        const TInt aConnectionBearer,
       
   213                                        const TBool aUseFotaProgressNote )
       
   214     {
       
   215     FLOG( "CNSmlDMSyncHandler::SynchronizeL" );
       
   216 
       
   217     iServerName = aServerName;
       
   218     iConnectionBearer = aConnectionBearer;
       
   219     iProfileId = aProfileId;
       
   220     iUseFotaProgressNote = aUseFotaProgressNote;
       
   221 
       
   222     iSyncJob.CreateL( Session(), iProfileId );
       
   223     iSyncJobId = iSyncJob.Identifier();
       
   224     SynchronizeL();
       
   225     
       
   226     TInt dummyValue;
       
   227     TInt err = RProperty::Get( KPSUidNSmlDMSyncApp,
       
   228                                KNSmlDMSyncUiInitiatedJobKey,
       
   229                                dummyValue );
       
   230     if ( err == KErrNotFound )
       
   231         {
       
   232         _LIT_SECURITY_POLICY_S0( KWritePolicy, KUidSmlSyncApp.iUid );
       
   233         _LIT_SECURITY_POLICY_C1( KReadPolicy, ECapabilityReadDeviceData );
       
   234         RProperty::Define( KPSUidNSmlDMSyncApp,
       
   235                            KNSmlDMSyncUiInitiatedJobKey,
       
   236                            RProperty::EInt,
       
   237                            KReadPolicy,
       
   238                            KWritePolicy );
       
   239         }
       
   240     FTRACE( FPrint( _L(
       
   241 	    "[OMADM]\tCNSmlDMSyncHandler::SynchronizeL--UI initiated, iSyncJobId = %d" ),
       
   242 	     iSyncJobId ) );    
       
   243     RProperty::Set( KPSUidNSmlDMSyncApp,
       
   244                     KNSmlDMSyncUiInitiatedJobKey,
       
   245                     iSyncJobId );
       
   246 	}
       
   247 	
       
   248 // -----------------------------------------------------------------------------
       
   249 // CNSmlDMSyncHandler::SynchronizeL
       
   250 // -----------------------------------------------------------------------------
       
   251 //
       
   252 void CNSmlDMSyncHandler::SynchronizeL()
       
   253 	{
       
   254 	FLOG( "CNSmlDMSyncHandler::SynchronizeL" );
       
   255 	
       
   256 	TInt err = KErrNone;
       
   257 	
       
   258 	// for MSyncMLEventObserver events
       
   259 	TRAP( err, Session().RequestEventL(*this) );
       
   260 	if ( err != KErrNone )
       
   261 		{
       
   262 		iSyncJob.StopL();
       
   263 		iSyncJob.Close();
       
   264 		User::Leave(err);
       
   265 		}
       
   266     
       
   267     // for MSyncMLProgressObserver events
       
   268     TRAP( err, Session().RequestProgressL(*this) );
       
   269 	if ( err != KErrNone )
       
   270 		{
       
   271 		Session().CancelEvent();
       
   272 		iSyncJob.StopL();
       
   273 		iSyncJob.Close();
       
   274 		User::Leave( err );
       
   275 		}
       
   276 	
       
   277 	State()->SetSyncPhase( CNSmlDMSyncState::EPhaseConnecting );
       
   278 	TInt IsDMBusy = EFalse;   //IAD: Making DM Idle
       
   279 	TInt r2=RProperty::Get(KUidSmlSyncApp,KDMIdle,IsDMBusy);
       
   280 	if (IsDMBusy)
       
   281 	   iNotinFotaView = 1;    //Not in fota view 
       
   282 	else
       
   283 	   iNotinFotaView = 0;    //already busy because in other view
       
   284 	IsDMBusy =ETrue; 
       
   285   r2=RProperty::Set(KUidSmlSyncApp,KDMIdle,IsDMBusy);	   
       
   286 	
       
   287 	TRAP( err, ShowProgressDialogL() );
       
   288 	if ( err != KErrNone )
       
   289 		{
       
   290 		Session().CancelEvent();
       
   291 		Session().CancelProgress();
       
   292 		iSyncJob.StopL();
       
   293 		iSyncJob.Close();
       
   294 		User::Leave( err );
       
   295 		}
       
   296 	FLOG( "CNSmlDMSyncHandler::SynchronizeL Sync is running" );
       
   297 
       
   298     iSyncDocument->MarkFwUpdChangesStartL();
       
   299 	
       
   300 	iSyncRunning = ETrue;
       
   301 	iSyncError = KErrNone;
       
   302 	}
       
   303 
       
   304 // -----------------------------------------------------------------------------
       
   305 // CNSmlDMSyncHandler::SynchronizeCompletedL
       
   306 // -----------------------------------------------------------------------------
       
   307 //
       
   308 void CNSmlDMSyncHandler::SynchronizeCompletedL( TInt aError )
       
   309 	{
       
   310     FTRACE( FPrint(
       
   311         _L("[OMADM]\t CNSmlDMSyncHandler::SynchronizeCompletedL(), aError = %d"),
       
   312         aError ) );
       
   313 	
       
   314 	if ( !SyncRunning() )
       
   315 		{
       
   316 		FLOG( "CNSmlDMSyncHandler::SynchronizeCompletedL already completed" );
       
   317 		return;  // sync has already completed
       
   318 		}
       
   319 		
       
   320     iSyncJob.Close();
       
   321     
       
   322      FTRACE( FPrint( _L(
       
   323 	    "[OMADM]\tCNSmlDMSyncHandler::SynchronizecompletedL, iSyncJobId = %d" ),
       
   324 	     KNSmlDMNoUserInitiatedJob ) );
       
   325     // Error code can be ignored.
       
   326     RProperty::Set( KPSUidNSmlDMSyncApp,
       
   327                     KNSmlDMSyncUiInitiatedJobKey,
       
   328                     KNSmlDMNoUserInitiatedJob );
       
   329 	
       
   330 	iSyncRunning = EFalse;
       
   331 	iSyncError = aError;
       
   332 
       
   333     
       
   334     iCheckUpdate = EFalse;
       
   335     
       
   336     
       
   337 	// close progress dialog
       
   338 	if ( iProgressDialog )
       
   339         {
       
   340         FLOG( "CNSmlDMSyncHandler::SynchronizeCompletedL close dialog" ); 
       
   341         iProgressDialog->CancelProgressDialogL();
       
   342         delete iProgressDialog;
       
   343         iProgressDialog = NULL;
       
   344         }
       
   345 
       
   346     
       
   347     if (  iFotaProgressDialog )
       
   348         {
       
   349         __ASSERT_ALWAYS( iSyncDocument, TUtil::Panic( KErrGeneral ) );
       
   350         
       
   351         iFotaProgressDialog->CancelProgressDialogL();
       
   352         TInt configFlags( EGenericSession );
       
   353         //TInt SetGenValue(0);
       
   354         CRepository* centrep = NULL;
       
   355         TRAPD( err, centrep = CRepository::NewL( KCRUidDeviceManagementInternalKeys ) );
       
   356         if ( centrep )
       
   357             {
       
   358             if( err == KErrNone )
       
   359              {
       
   360             centrep->Get( KDevManSessionType, configFlags );
       
   361              }
       
   362             delete centrep;
       
   363             } 
       
   364         /*if ( err != KErrNone ) 
       
   365             {
       
   366             User::Leave( err );
       
   367             }
       
   368         else
       
   369             {
       
   370             
       
   371             centrep->Set( KDevManSessionType, SetGenValue );
       
   372             }      
       
   373         if(centrep)    
       
   374            {
       
   375            delete centrep;
       
   376            }*/
       
   377         delete iFotaProgressDialog;
       
   378         iFotaProgressDialog = NULL;
       
   379         // configFlags=2 for FOTA Package not downloaded case ,1- successful download
       
   380         if ( !iSyncDocument->FwUpdStatesChangedL() && (aError == KErrNone) 
       
   381         				&& configFlags == EFotaPkgNotFound )
       
   382             {
       
   383             FLOG( "[OMADM]\t CNSmlDMSyncHandler::SynchronizeCompletedL(): No changes in FW Update states." );
       
   384             
       
   385             HBufC* stringHolder =
       
   386                 StringLoader::LoadLC( R_QTN_FOTA_NO_NEW_UPDATES );
       
   387 
       
   388             CAknInformationNote* infoNote =
       
   389                 new (ELeave) CAknInformationNote;
       
   390 
       
   391             infoNote->SetTimeout( CAknNoteDialog::ELongTimeout );
       
   392             
       
   393             // We are not interested in the result.
       
   394             infoNote->ExecuteLD( *stringHolder );
       
   395             CleanupStack::PopAndDestroy( stringHolder );
       
   396             }
       
   397         }  
       
   398       
       
   399 
       
   400 	iUseFotaProgressNote = EFalse;
       
   401     iSyncJob.Close();
       
   402     
       
   403 	// handle error in HandleActiveCallL (when active caller completes)
       
   404 	iActiveCaller->Start( aError );
       
   405 
       
   406 	FLOG( "CNSmlDMSyncHandler::SynchronizeCompletedL() completed" );
       
   407 	}
       
   408 
       
   409 // -----------------------------------------------------------------------------
       
   410 // CNSmlDMSyncHandler::OnSyncMLSessionEvent
       
   411 // -----------------------------------------------------------------------------
       
   412 //
       
   413 void CNSmlDMSyncHandler::OnSyncMLSessionEvent( TEvent aEvent,
       
   414                                                TInt aIdentifier,
       
   415                                                TInt aError,
       
   416                                                TInt /*aAdditionalData*/ )
       
   417 	{
       
   418 	FTRACE( FPrint( _L(
       
   419 	    "[OMADM]\tCNSmlDMSyncHandler::OnSyncMLSessionEvent(), aEvent = %d, aIdentifier = %d, aError = %d" ),
       
   420 	    aEvent, aIdentifier, aError ) );
       
   421 	
       
   422 
       
   423 	if ( aEvent == EJobStop
       
   424 	    || aEvent == EJobStartFailed
       
   425 	    || aEvent == EJobRejected )
       
   426 		{
       
   427     	FTRACE( FPrint( _L(
       
   428     	    "[OMADM]\tCNSmlDMSyncHandler::OnSyncMLSessionEvent(), iSyncJobId = %d" ),
       
   429     	    iSyncJobId ) );
       
   430     	    
       
   431     	 
       
   432     	TInt value =EFalse; 
       
   433     	TInt r=RProperty::Get( KPSUidNSmlDMSyncApp, KFotaDLStatus, value );	  
       
   434     	FTRACE( FPrint(
       
   435 					_L("KFotaDLStatus = %d"),r ) );  
       
   436 					
       
   437     	if(!iNotinFotaView && value != 1 )    
       
   438         r =  RProperty::Set( KPSUidNSmlDMSyncApp,
       
   439 				 			KDMIdle, KErrNone ); 
       
   440 									
       
   441 							
       
   442 							
       
   443 							
       
   444 							
       
   445 		if ( iSyncJobId == aIdentifier )
       
   446 			{
       
   447 			FLOG( "CNSmlDMSyncHandler::OnSyncMLSessionEvent EJobStop close" );
       
   448 			//For holding the DM Job session successful / error for future purpose
       
   449 			TInt err =  RProperty::Set( KPSUidNSmlDMSyncApp,
       
   450 							KDmJobCancel, KErrNone );   
       
   451 			FTRACE( FPrint(
       
   452 					_L("KDmJobCancel setting in OnSyncMLSessionEvent err = %d"),err ) );
       
   453             TRAP_IGNORE( SynchronizeCompletedL( aError ) );
       
   454 			}
       
   455 		}
       
   456     FLOG( "[OMADM]\tCNSmlDMSyncHandler::OnSyncMLSessionEvent() completed" );
       
   457     }
       
   458 
       
   459 // -----------------------------------------------------------------------------
       
   460 // CNSmlDMSyncHandler::OnSyncMLSyncError
       
   461 // -----------------------------------------------------------------------------
       
   462 //
       
   463 void CNSmlDMSyncHandler::OnSyncMLSyncError( TErrorLevel aErrorLevel,
       
   464                                             TInt aError,
       
   465                                             TInt /*aTaskId*/,
       
   466                                             TInt /*aInfo1*/,
       
   467                                             TInt /*aInfo2*/)
       
   468 	{
       
   469 	FTRACE( FPrint( _L(
       
   470 	    "[OMADM]\tCNSmlDMSyncHandler::OnSyncMLSyncError(), aErrorLevel = %d, aError = %d"),
       
   471 	    aErrorLevel, aError ) );
       
   472 	
       
   473 	if ( aErrorLevel == ESmlFatalError )
       
   474 		{
       
   475         TRAP_IGNORE( SynchronizeCompletedL( aError ) );
       
   476 		}
       
   477     FLOG( "[OMADM]\tCNSmlDMSyncHandler::OnSyncMLSyncError() completed" );
       
   478 	}
       
   479 
       
   480 // -----------------------------------------------------------------------------
       
   481 // CNSmlDMSyncHandler::OnSyncMLSyncProgress
       
   482 // -----------------------------------------------------------------------------
       
   483 //
       
   484 void CNSmlDMSyncHandler::OnSyncMLSyncProgress( TStatus aStatus,
       
   485                                                TInt /*aInfo1*/,
       
   486                                                TInt /*aInfo2*/ )
       
   487 	{
       
   488 	FTRACE( RDebug::Print(
       
   489 	          _L("CNSmlDMSyncHandler::OnSyncMLSyncProgress (%d)"), aStatus ) );
       
   490 	
       
   491 	switch (aStatus)
       
   492 		{
       
   493 		case ESmlConnecting:
       
   494 		    State()->SetSyncPhase( CNSmlDMSyncState::EPhaseConnecting );
       
   495 		    break;
       
   496 		case ESmlConnected:
       
   497 		    break;
       
   498 		case ESmlLoggingOn:
       
   499 		    break;
       
   500 		case ESmlLoggedOn:
       
   501 		    State()->SetSyncPhase( CNSmlDMSyncState::EPhaseSynchronizing );
       
   502 		    break;
       
   503 		case ESmlDisconnected:
       
   504 		    State()->SetSyncPhase( CNSmlDMSyncState::EPhaseDisconnecting );
       
   505 		    break;
       
   506 		case ESmlCompleted:
       
   507 		    State()->SetSyncPhase( CNSmlDMSyncState::EPhaseDisconnecting );
       
   508 		    break;
       
   509 		case ESmlProcessingServerCommands:
       
   510 		    State()->SetSyncPhase( CNSmlDMSyncState::EPhaseSending );
       
   511 		    break;
       
   512 		case ESmlReceivingServerCommands:
       
   513 		    State()->SetSyncPhase( CNSmlDMSyncState::EPhaseReceiving );
       
   514 		    break;
       
   515 		
       
   516 		case ESmlSendingModificationsToServer:
       
   517 		    {
       
   518 		    if( iFotaProgressDialog && iCheckUpdate == EFalse )
       
   519 		    {
       
   520 		    State()->SetSyncPhase( CNSmlDMSyncState::EPhaseFinal );	
       
   521 		    }
       
   522 		    
       
   523 		    break;
       
   524 		    }
       
   525 		
       
   526 		default:
       
   527 		    break;
       
   528 		}
       
   529     TRAP_IGNORE( UpdateDialogL() );
       
   530 	}
       
   531 
       
   532 // -----------------------------------------------------------------------------
       
   533 // CNSmlDMSyncHandler::OnSyncMLDataSyncModifications
       
   534 // -----------------------------------------------------------------------------
       
   535 //
       
   536 void CNSmlDMSyncHandler::OnSyncMLDataSyncModifications( TInt /*aTaskId*/,
       
   537                    const TSyncMLDataSyncModifications& /*aClientModifications*/,
       
   538                    const TSyncMLDataSyncModifications& /*aServerModifications*/ )
       
   539     {
       
   540     FLOG( "CNSmlDMSyncHandler::OnSyncMLDataSyncModifications" );
       
   541 
       
   542     }
       
   543 
       
   544 // -----------------------------------------------------------------------------
       
   545 // CNSmlDMSyncHandler::GetStatusDialogTextL
       
   546 // -----------------------------------------------------------------------------
       
   547 //
       
   548 void CNSmlDMSyncHandler::GetStatusDialogTextL( TDes& aBuffer )
       
   549     {
       
   550     FLOG( "CNSmlDMSyncHandler::GetStatusDialogTextL()" );
       
   551     
       
   552 	aBuffer = KNullDesC;
       
   553 	TInt phase = State()->SyncPhase();
       
   554 
       
   555     switch ( phase )
       
   556         {
       
   557         case CNSmlDMSyncState::EPhaseConnecting:
       
   558             {
       
   559             ReadL( aBuffer, R_SYNCSTATUS_SYNC_CONN );  // "Connecting"
       
   560             break;
       
   561             }
       
   562         case CNSmlDMSyncState::EPhaseSynchronizing:
       
   563             {
       
   564             if(iProgressDialog)
       
   565             ReadL( aBuffer, R_SYNCSTATUS_SYNC_SEND ); // "Synchronizing"
       
   566             
       
   567             else if(iFotaProgressDialog ) 
       
   568             ReadL( aBuffer, R_QTN_FOTA_WAIT_CHECKING_UPDATE );
       
   569             
       
   570             break;
       
   571             }
       
   572         case CNSmlDMSyncState::EPhaseDisconnecting:
       
   573             {
       
   574      
       
   575             TInt configFlags( EGenericSession );
       
   576             CRepository* centrep = NULL;
       
   577             TRAPD( err, centrep = CRepository::NewL( KCRUidDeviceManagementInternalKeys ) );
       
   578             if ( centrep )
       
   579                 {
       
   580                 centrep->Get( KDevManSessionType, configFlags );
       
   581                 delete centrep;
       
   582                 }
       
   583             if ( err != KErrNone ) 
       
   584                 {
       
   585                 User::Leave( err );
       
   586                 }
       
   587             if( iFotaProgressDialog &&  configFlags == EGenericSession )
       
   588                {
       
   589                ReadL( aBuffer, R_SYNCSTATUS_SYNC_DISC );  // "Disconnecting"
       
   590                }
       
   591             else if( iProgressDialog )
       
   592                {
       
   593                ReadL( aBuffer, R_SYNCSTATUS_SYNC_DISC );  // "Disconnecting"
       
   594                }
       
   595              
       
   596             break;
       
   597             }
       
   598         case CNSmlDMSyncState::EPhaseCanceling:
       
   599             {
       
   600             ReadL( aBuffer, R_SYNCSTATUS_CANC );  // "Canceling"
       
   601             break;
       
   602             }
       
   603         case CNSmlDMSyncState::EPhaseSending:   // ReadProgressText handles both
       
   604         case CNSmlDMSyncState::EPhaseReceiving: // cases.
       
   605             {
       
   606 
       
   607             if( iProgressDialog )
       
   608                {
       
   609             	ReadProgressTextL( aBuffer, State()->Content(), State()->Progress(),
       
   610                                State()->TotalProgress(), phase );
       
   611                }
       
   612             TInt configFlags( EGenericSession );
       
   613             CRepository* centrep = NULL;
       
   614             TRAPD( err, centrep = CRepository::NewL( KCRUidDeviceManagementInternalKeys ) );
       
   615             if( centrep )
       
   616                 {
       
   617                 centrep->Get( KDevManSessionType, configFlags );
       
   618                 delete centrep;
       
   619                 }
       
   620             if( err != KErrNone ) 
       
   621                {
       
   622                User::Leave( err );
       
   623                }
       
   624             if( iFotaProgressDialog && iCheckUpdate && !iFotaProgressLaunched )
       
   625                {
       
   626                ReadProgressTextL( aBuffer, State()->Content(), State()->Progress(),
       
   627                                State()->TotalProgress(), phase );
       
   628                TFileName bitmapName;
       
   629                TParse parse;
       
   630     	       parse.Set(KBitmapFileName, &KDC_APP_BITMAP_DIR, NULL);
       
   631     	       TUtil::StrCopy(bitmapName, parse.FullName());
       
   632 	           CEikImage* image = iFotaProgressDialog->CreateImageLC(KAknsIIDQgnNoteSml,bitmapName,
       
   633 		                                                EMbmNsmldmsyncQgn_note_sml,
       
   634 		                                              EMbmNsmldmsyncQgn_note_sml_mask);
       
   635 	           iFotaProgressDialog->SetImageL(image);
       
   636                CleanupStack::Pop(image);
       
   637                }
       
   638              
       
   639             break;
       
   640             }
       
   641          
       
   642          case CNSmlDMSyncState::EPhaseFinal:
       
   643             {
       
   644             iCheckUpdate = ETrue;
       
   645             ReadL( aBuffer, R_QTN_FOTA_WAIT_CHECKING_UPDATE );  // "Check for update
       
   646             TFileName bitmapName;
       
   647        	    TParse parse;
       
   648     	    parse.Set(KBitmapFileName, &KDC_APP_BITMAP_DIR, NULL);
       
   649     	    TUtil::StrCopy(bitmapName, parse.FullName());
       
   650 	        CEikImage* image = iFotaProgressDialog->CreateImageLC(KAknsIIDQgnMenuDm,bitmapName,
       
   651 		                                               EMbmNsmldmsyncQgn_menu_dm,
       
   652 		                                         EMbmNsmldmsyncQgn_menu_dm_mask);
       
   653 	        iFotaProgressDialog->SetImageL(image);
       
   654             CleanupStack::Pop(image);
       
   655             break;
       
   656             }
       
   657          
       
   658         default:
       
   659             {
       
   660             break;
       
   661             }
       
   662         }
       
   663     FLOG( "CNSmlDMSyncHandler::GetStatusDialogTextL() completed" );
       
   664     }
       
   665 
       
   666 // -----------------------------------------------------------------------------
       
   667 // CNSmlDMSyncHandler::UpdateDialogL
       
   668 // -----------------------------------------------------------------------------
       
   669 //
       
   670 void CNSmlDMSyncHandler::UpdateDialogL()
       
   671 	{
       
   672 	FLOG( "CNSmlDMSyncHandler::UpdateDialogL()" );
       
   673 	
       
   674 	if ( iProgressDialog )
       
   675 	    {
       
   676 	    FLOG( "CNSmlDMSyncHandler::UpdateDialogL(): dialog exists update" );
       
   677     	TBuf<KBufSize256> stringHolder;
       
   678     	
       
   679     	TInt phase = State()->SyncPhase();
       
   680     	
       
   681         GetStatusDialogTextL( stringHolder );
       
   682         if ( stringHolder.Compare( KNullDesC ) != 0 ) // If correct text found
       
   683             {
       
   684             Dialog()->UpdateTextL( stringHolder );
       
   685             }
       
   686     	
       
   687     	if ( phase == CNSmlDMSyncState::EPhaseSending ||
       
   688     	     phase == CNSmlDMSyncState::EPhaseReceiving )
       
   689     		{
       
   690     		if (State()->Progress() == 1)
       
   691     			{
       
   692     			if ( State()->ProgressKnown() )
       
   693     				{
       
   694 	    			Dialog()->CancelAnimation();
       
   695     	    		Dialog()->SetFinalProgress(State()->TotalProgress());
       
   696          	    	Dialog()->SetProgress(State()->Progress());
       
   697     				}
       
   698     			else
       
   699     				{
       
   700         			Dialog()->SetFinalProgress(0);
       
   701 	    	        Dialog()->StartAnimationL();
       
   702     				}
       
   703     			}
       
   704     		else if ( State()->ProgressKnown() )
       
   705     			{
       
   706     			Dialog()->SetProgress( State()->Progress() );
       
   707     			}
       
   708     		}
       
   709 	    }
       
   710 	 
       
   711 	 else if( iFotaProgressDialog )   
       
   712 	 {
       
   713 	 FLOG( "CNSmlDMSyncHandler::UpdateDialogL(): fota dialog" );
       
   714      TBuf<KBufSize256> stringHolder;	
       
   715      TInt phase = State()->SyncPhase();	
       
   716      GetStatusDialogTextL( stringHolder );
       
   717      if ( stringHolder.Compare( KNullDesC ) != 0 ) // If correct text found
       
   718          {
       
   719          iFotaProgressDialog->UpdateTextL( stringHolder );
       
   720          }
       
   721     	
       
   722      if ( phase == CNSmlDMSyncState::EPhaseSending ||
       
   723     	     phase == CNSmlDMSyncState::EPhaseReceiving )
       
   724     	 {
       
   725     		if (State()->Progress() == 1)
       
   726     			{
       
   727     			if ( State()->ProgressKnown() )
       
   728     				{
       
   729 	    			iFotaProgressDialog->CancelAnimation();
       
   730     	    	    iFotaProgressDialog->SetFinalProgress(State()->TotalProgress());
       
   731          	    	iFotaProgressDialog->SetProgress(State()->Progress());
       
   732     				}
       
   733     			else
       
   734     				{
       
   735         			iFotaProgressDialog->SetFinalProgress(0);
       
   736 	    	        iFotaProgressDialog->StartAnimationL();
       
   737     				}
       
   738     			}
       
   739     		else if ( State()->ProgressKnown() )
       
   740     			{
       
   741     			iFotaProgressDialog->SetProgress( State()->Progress() );
       
   742     			}
       
   743     	 }
       
   744 	 }
       
   745 	 
       
   746 	FLOG( "CNSmlDMSyncHandler::UpdateDialogL() completed" );
       
   747 	}
       
   748 
       
   749 
       
   750 // -----------------------------------------------------------------------------
       
   751 // CNSmlDMSyncHandler::HandleActiveCallL
       
   752 // -----------------------------------------------------------------------------
       
   753 //
       
   754 void CNSmlDMSyncHandler::HandleActiveCallL()
       
   755 	{
       
   756     FLOG( "CNSmlDMSyncHandler::HandleActiveCallL" );
       
   757     
       
   758     // HandleSyncErrorL will set this to true if
       
   759     // sync will be retried.
       
   760     iRetrySync = EFalse;
       
   761 
       
   762 	if ( (iSyncError != KErrNone) && (iSyncError != KErrCancel) )
       
   763 		{
       
   764 		TRAP_IGNORE( HandleSyncErrorL() );
       
   765 		}
       
   766 	if ( iRetrySync == EFalse )
       
   767 		{
       
   768 	    // Inform parent that sync is done.
       
   769 	    iSyncAppEngine->SyncCompleted( ENSmlSyncComplete );		
       
   770 		}
       
   771 	}
       
   772 
       
   773 // -----------------------------------------------------------------------------
       
   774 // CNSmlDMSyncHandler::HandleSyncErrorL
       
   775 // -----------------------------------------------------------------------------
       
   776 //
       
   777 void CNSmlDMSyncHandler::HandleSyncErrorL()
       
   778 	{
       
   779 	FLOG( "CNSmlDMSyncHandler::HandleSyncErrorL" );
       
   780 	
       
   781 	if ( iSyncError != KDMErr )
       
   782 		{
       
   783     	GetErrorText( iBuf, iSyncError, iConnectionBearer );
       
   784     	CAknErrorNote* queryDialog = new (ELeave) CAknErrorNote(ETrue);
       
   785     	if( iSyncDocument->SANSupport() && iSyncDocument->SilentSession() )
       
   786     	   {
       
   787     	    queryDialog->SetTone(CAknErrorNote::ENoTone);    	
       
   788     	   }
       
   789         queryDialog->ExecuteLD( iBuf );
       
   790 		}
       
   791 	if ( ( iSyncError == SyncMLError::KErrAuthenticationFailure ) ||
       
   792 	    ( iSyncError == SyncMLError::KErrTransportAuthenticationFailure ) )
       
   793         {
       
   794         TBool httpQuery( iSyncError == SyncMLError::KErrTransportAuthenticationFailure );
       
   795         
       
   796 	    FLOG( "CNSmlDMSyncHandler::HandleSyncErrorL ask username" );
       
   797 
       
   798 	    CNSmlDMMultiQuery* dlg = CNSmlDMMultiQuery::NewL( iSyncAppEngine,
       
   799 	                                                      iProfileId,
       
   800 	                                                      httpQuery );
       
   801 	    if ( dlg->ExecuteLD( R_NSMLDM_AUTHDIALOG ) )
       
   802 		    {
       
   803 		    // ok
       
   804 		    FLOG( "CNSmlDMSyncHandler::HandleSyncErrorL ask username ok retry sync" );
       
   805 		    iRetrySync = ETrue;
       
   806             // We have already closed job so create a new.
       
   807           	iSyncJob.CreateL( Session(), iProfileId );
       
   808           	iSyncJobId = iSyncJob.Identifier();
       
   809 		    SynchronizeL();
       
   810 		    }
       
   811 	    else
       
   812 		    {
       
   813 		    FLOG( "CNSmlDMSyncHandler::HandleSyncErrorL ask username cancel" );
       
   814 		    }
       
   815         }
       
   816     }
       
   817 
       
   818 // -----------------------------------------------------------------------------
       
   819 // CNSmlDMSyncHandler::GetErrorTextL
       
   820 // -----------------------------------------------------------------------------
       
   821 //
       
   822 void CNSmlDMSyncHandler::GetErrorText( TDes& aErrorText,
       
   823                                        TInt aErrorCode,
       
   824                                        TInt aTransport )
       
   825 	{
       
   826     FTRACE( RDebug::Print(
       
   827           _L("CNSmlDMSyncHandler::GetErrorText Errorcode (%d)"), aErrorCode) );
       
   828     
       
   829     aErrorText = KNullDesC();
       
   830    
       
   831     TInt id = R_QTN_DM_LOG_ERR_SYSTEMERROR;  // "System Error"
       
   832    
       
   833 	switch ( aErrorCode )
       
   834 		{
       
   835 		case SyncMLError::KErrTransportAuthenticationFailure:
       
   836 			{
       
   837 			if ( aTransport == EAspBearerInternet )
       
   838 				{
       
   839 				// "Http authentication failed"
       
   840 				id = R_QTN_NSML_LOG_ERR_CLIENTAUTH;  
       
   841 				}
       
   842 			else
       
   843 				{
       
   844 				// "Invalid user name or password"
       
   845 				id = R_QTN_DM_LOG_ERR_CLIENTAUTH;
       
   846 				}
       
   847 		    break;
       
   848 			}
       
   849 		
       
   850 		case SyncMLError::KErrAuthenticationFailure:
       
   851 			{
       
   852 			// "Invalid user name or password"
       
   853 			id = R_QTN_DM_LOG_ERR_CLIENTAUTH;
       
   854 		    break;
       
   855 			}	
       
   856 
       
   857 		case KErrServerBusy:
       
   858 		    {
       
   859 		    // "Synchronisation server was busy"
       
   860 		    id = R_QTN_DM_LOG_ERR_SERVERBUSY;
       
   861 		    break;
       
   862 		    }
       
   863 		    
       
   864 		case SyncMLError::KErrServerDatabaseNotFound:
       
   865 		    {
       
   866 		    // "Invalid remote database"
       
   867 		    id = R_QTN_DM_LOG_ERR_SESSIONABORT;
       
   868 		    break;
       
   869 		    }
       
   870 
       
   871 		case SyncMLError::KErrConnectionError:
       
   872 		    {
       
   873 		    // "Server is not responding"
       
   874 		    id = R_QTN_DM_LOG_ERR_SERVERNOTRESPONDING;
       
   875 		    break;
       
   876 		    }
       
   877 		    
       
   878 		case SyncMLError::KErrTransportSvrNoUri:
       
   879 		    {
       
   880 		    // "Invalid host address"
       
   881 		    id = R_QTN_DM_LOG_ERR_URIINVALID;
       
   882 		    break;
       
   883 		    }
       
   884 		case SyncMLError::KErrTransportDisconnected:
       
   885 		{
       
   886 			id = R_QTN_DM_LOG_ERR_TIMEDOUT;
       
   887 			break;
       
   888 		}
       
   889 		
       
   890 		case SyncMLError::KErrTransportRequest:
       
   891 		case SyncMLError::KErrTransportHeader:
       
   892 		case SyncMLError::KErrTransportSvrError:
       
   893 		case SyncMLError::KErrCannotCommunicateWithServer:
       
   894 		    {
       
   895 		    // "Error in communication"
       
   896 		    id = R_QTN_DM_LOG_ERR_COMM;
       
   897 		    break;
       
   898 		    }
       
   899 		    
       
   900 		case SyncMLError::KErrVerDTDMissing:
       
   901 		case SyncMLError::KErrProtoMissing:
       
   902 		case SyncMLError::KErrVersionDTDNotSupported:
       
   903 		case SyncMLError::KErrProtoNotSupported:
       
   904 		    {
       
   905 		    // "Unsupported SyncML software version in server"
       
   906 		    id = R_QTN_DM_LOG_ERR_VERSIONNOTSUPPORTED;  
       
   907 		    break;
       
   908 		    }
       
   909        
       
   910 		case SyncMLError::KErrSessionIdNotValid:
       
   911 		case SyncMLError::KErrMappingInfoMissing:
       
   912 		case SyncMLError::KErrMappingInfoNotAcked:
       
   913 		case SyncMLError::KErrStatusCommandForCommandNotSent:
       
   914 		case SyncMLError::KErrStatusCommandNotTheSame:
       
   915 		case SyncMLError::KErrMissingStatusCommands:
       
   916 		case SyncMLError::KErrFailedToAddRecord:
       
   917 		case SyncMLError::KErrFailedToReplaceRecord:
       
   918 		case SyncMLError::KErrFailedToDeleteRecord:
       
   919 		case SyncMLError::KErrXmlParsingError:
       
   920 		case SyncMLError::KErrReferenceToolkitError:
       
   921 		case SyncMLError::KErrObjectTooLargeToSendToServer:
       
   922 		case SyncMLError::KErrFailedToGetRecord:
       
   923 		case SyncMLError::KErrUserInteractionFailed:
       
   924 		case SyncMLError::KErrStatusSizeMismatch:
       
   925 		case SyncMLError::KErrFailedToCloseDatabase:
       
   926 		case SyncMLError::KErrDatabaseAdapterIndexError:
       
   927 		case SyncMLError::KErrClientDatabaseNotFound:
       
   928 		    {
       
   929 		    // "Error in sync server"
       
   930 	   	    id = R_QTN_DM_LOG_ERR_SERVERERROR;
       
   931 		    break;
       
   932 		    }
       
   933 		case SyncMLError::KErrPhoneOnOfflineMode:
       
   934 		    {
       
   935 		    // "Phone in offline"
       
   936 	   	    id = R_QTN_DM_LOG_ERR_OFFLINE;
       
   937 		    break;	        
       
   938 		    }
       
   939 
       
   940 		case SyncMLError::KErrInvalidCredentials:
       
   941 		    {
       
   942 		    // Server authentication failed
       
   943 	   	    id = R_QTN_DM_LOG_ERR_SERVERTAUTH;
       
   944 		    break;	        
       
   945 		    }
       
   946 	        
       
   947 		//TARM Enabled build Server profile Cert not stored or invalid    
       
   948         case SyncMLError::KErrInvalidCert:
       
   949 	      {
       
   950 	      	if(FeatureManager::FeatureSupported(KFeatureIdSapPolicyManagement))
       
   951 	      	{
       
   952 	      	id =  R_QTN_DM_ERROR_UNTRUSTED_CERT ;
       
   953 	      	}
       
   954 	      	break;
       
   955 	      }
       
   956         default:
       
   957             {
       
   958             if ( ( aErrorCode == KErrDiskFull ) ||
       
   959                  ( aErrorCode == KErrNoMemory ) )
       
   960                 {
       
   961                 TRAPD( retVal, SetErrorMessageL( aErrorCode, aErrorText ) );
       
   962                 if ( retVal == KErrNone )
       
   963                     {
       
   964                     return;
       
   965                     }
       
   966                 }
       
   967             // "System Error"
       
   968             id = R_QTN_DM_LOG_ERR_SYSTEMERROR;
       
   969 		    break;
       
   970             }
       
   971 		}
       
   972 		
       
   973 	TRAP_IGNORE( ReadL( aErrorText, id ) );
       
   974 	}
       
   975 	
       
   976 // -----------------------------------------------------------------------------
       
   977 // CNSmlDMSyncHandler::ShowProgressDialogL
       
   978 // -----------------------------------------------------------------------------
       
   979 //
       
   980 void CNSmlDMSyncHandler::ShowProgressDialogL( )
       
   981 	{
       
   982 	FLOG( "CNSmlDMSyncHandler::ShowProgressDialogL" );
       
   983 	
       
   984 	delete iProgressDialog;
       
   985 	iProgressDialog = NULL;
       
   986 	
       
   987 	if ( iUseFotaProgressNote )
       
   988 	    {
       
   989       
       
   990         iFotaProgressDialog = CNSmlDMProgressDialog::NewL( this );
       
   991         iFotaProgressLaunched = ETrue;
       
   992         TBuf<KBufSize> buf;
       
   993     	GetStatusDialogTextL( buf );
       
   994        	TFileName bitmapName;
       
   995        	TParse parse;
       
   996     	parse.Set(KBitmapFileName, &KDC_APP_BITMAP_DIR, NULL);
       
   997     	TUtil::StrCopy(bitmapName, parse.FullName());
       
   998     	
       
   999 	    if ( iServerAlertedSync )
       
  1000 		    {
       
  1001 		     iFotaProgressDialog->LaunchProgressDialogL(
       
  1002                                     buf,
       
  1003 		                            KAknsIIDQgnNoteSml,
       
  1004 		                            bitmapName,
       
  1005 		                            EMbmNsmldmsyncQgn_note_sml_server,
       
  1006 		                            EMbmNsmldmsyncQgn_note_sml_server_mask );		                            
       
  1007 		    }
       
  1008 	    else
       
  1009 		    {
       
  1010 		    iFotaProgressDialog->LaunchProgressDialogL( 
       
  1011 		                            buf,
       
  1012 		                            KAknsIIDQgnNoteSml,
       
  1013 		                            bitmapName,
       
  1014 		                            EMbmNsmldmsyncQgn_note_sml,
       
  1015 		                            EMbmNsmldmsyncQgn_note_sml_mask );
       
  1016     		}
       
  1017 	    iFotaProgressLaunched = EFalse;
       
  1018 		UpdateDialogL();
       
  1019         
       
  1020 	    }
       
  1021     else
       
  1022         {
       
  1023     	iProgressDialog = CNSmlDMProgressDialog::NewL( this );
       
  1024 
       
  1025     	TBuf<KBufSize> buf;
       
  1026     	GetStatusDialogTextL( buf );
       
  1027 
       
  1028        	TFileName bitmapName;
       
  1029        	TParse parse;
       
  1030     	parse.Set(KBitmapFileName, &KDC_APP_BITMAP_DIR, NULL);
       
  1031     	TUtil::StrCopy(bitmapName, parse.FullName());
       
  1032     	
       
  1033 	if ( iServerAlertedSync )
       
  1034 		{
       
  1035 		iProgressDialog->LaunchProgressDialogL(
       
  1036                                     buf,
       
  1037 		                            KAknsIIDQgnNoteSml,
       
  1038 		                            bitmapName,
       
  1039 		                            EMbmNsmldmsyncQgn_note_sml_server,
       
  1040 		                            EMbmNsmldmsyncQgn_note_sml_server_mask );		                            
       
  1041 		}
       
  1042 	else
       
  1043 		{
       
  1044 		iProgressDialog->LaunchProgressDialogL( 
       
  1045 		                            buf,
       
  1046 		                            KAknsIIDQgnNoteSml,
       
  1047 		                            bitmapName,
       
  1048 		                            EMbmNsmldmsyncQgn_note_sml,
       
  1049 		                            EMbmNsmldmsyncQgn_note_sml_mask );
       
  1050     		}
       
  1051 		UpdateDialogL();
       
  1052         }
       
  1053         
       
  1054 	FLOG( "CNSmlDMSyncHandler::ShowProgressDialogL() completed" );
       
  1055 	}
       
  1056 
       
  1057 // -----------------------------------------------------------------------------
       
  1058 // CNSmlDMSyncHandler::HideProgressDialogL
       
  1059 // -----------------------------------------------------------------------------
       
  1060 //
       
  1061 void CNSmlDMSyncHandler::HideProgressDialogL()
       
  1062     {
       
  1063     FLOG( "CNSmlDMSyncHandler::HideProgressDialogL" );
       
  1064 
       
  1065 
       
  1066     if ( iFotaProgressDialog )
       
  1067 		{
       
  1068 		FLOG( "CNSmlDMSyncHandler::HideProgressDialogL dialog exists hide it" );
       
  1069 	    iFotaProgressDialog->CancelProgressDialogL();
       
  1070 	    delete iFotaProgressDialog;
       
  1071 	    iFotaProgressDialog = NULL;
       
  1072 		}
       
  1073     
       
  1074 	if ( iProgressDialog )
       
  1075 		{
       
  1076 		FLOG( "CNSmlDMSyncHandler::HideProgressDialogL dialog exists hide it" );
       
  1077 	    iProgressDialog->CancelProgressDialogL();
       
  1078 	    delete iProgressDialog;
       
  1079 	    iProgressDialog = NULL;
       
  1080 		}
       
  1081     }
       
  1082 
       
  1083 // -----------------------------------------------------------------------------
       
  1084 // CNSmlDMSyncHandler::SetErrorMessageL
       
  1085 // 
       
  1086 // Set synchronisation error message text.
       
  1087 // -----------------------------------------------------------------------------
       
  1088 //
       
  1089 void CNSmlDMSyncHandler::SetErrorMessageL(TInt aError, TDes& aMsg)
       
  1090 	{
       
  1091 	FLOG( "CNSmlDMSyncHandler::SetErrorMessageL" );
       
  1092 	
       
  1093 	CTextResolver* textResolver = CTextResolver::NewLC(); 
       
  1094 	
       
  1095     aMsg.Append( textResolver->ResolveErrorString( aError,
       
  1096 	                                         CTextResolver::ECtxNoCtx ) );
       
  1097 
       
  1098 	CleanupStack::PopAndDestroy( textResolver );
       
  1099 
       
  1100 	TBuf<KBufSize> buf;
       
  1101     ReadL( buf, R_SML_APP_TITLE );
       
  1102 	TUtil::StrInsert( aMsg, buf );
       
  1103 	}
       
  1104 
       
  1105 // -----------------------------------------------------------------------------
       
  1106 // CNSmlDMSyncHandler::Session
       
  1107 // -----------------------------------------------------------------------------
       
  1108 //
       
  1109 RSyncMLSession& CNSmlDMSyncHandler::Session()
       
  1110 	{
       
  1111 	__ASSERT_DEBUG(iSyncSession, TUtil::Panic(KErrGeneral));
       
  1112 	
       
  1113 	return *iSyncSession;
       
  1114 	}
       
  1115 
       
  1116 // -----------------------------------------------------------------------------
       
  1117 // CNSmlDMSyncHandler::Dialog
       
  1118 // -----------------------------------------------------------------------------
       
  1119 //
       
  1120 CNSmlDMProgressDialog* CNSmlDMSyncHandler::Dialog()
       
  1121 	{
       
  1122 	__ASSERT_DEBUG(iProgressDialog, TUtil::Panic(KErrGeneral));
       
  1123 
       
  1124 	return iProgressDialog;
       
  1125 	}
       
  1126 
       
  1127 
       
  1128 // -----------------------------------------------------------------------------
       
  1129 // CNSmlDMSyncHandler::SyncRunning
       
  1130 // -----------------------------------------------------------------------------
       
  1131 //
       
  1132 TBool CNSmlDMSyncHandler::SyncRunning()
       
  1133 	{
       
  1134 	FTRACE( RDebug::Print(
       
  1135 	          _L("CNSmlDMSyncHandler::SyncRunning status (%d)"), iSyncRunning ) );
       
  1136 	          
       
  1137 	return iSyncRunning;
       
  1138 	}
       
  1139 
       
  1140 // -----------------------------------------------------------------------------
       
  1141 // CNSmlDMSyncHandler::State
       
  1142 // -----------------------------------------------------------------------------
       
  1143 //
       
  1144 CNSmlDMSyncState* CNSmlDMSyncHandler::State()
       
  1145 	{
       
  1146 	__ASSERT_DEBUG(iState, TUtil::Panic(KErrGeneral));
       
  1147 
       
  1148 	return iState;
       
  1149 	}
       
  1150 	
       
  1151 // -----------------------------------------------------------------------------
       
  1152 // CNSmlDMSyncHandler::ReadL
       
  1153 // -----------------------------------------------------------------------------
       
  1154 //	
       
  1155 void CNSmlDMSyncHandler::ReadL( TDes& aText, TInt aResourceId )
       
  1156     {
       
  1157     FLOG( "CNSmlDMSyncHandler::ReadL" );
       
  1158     
       
  1159     HBufC* buf = StringLoader::LoadLC( aResourceId );
       
  1160     TUtil::StrCopy( aText, *buf );
       
  1161     CleanupStack::PopAndDestroy( buf );
       
  1162     }
       
  1163     
       
  1164 // -----------------------------------------------------------------------------
       
  1165 // CNSmlDMSyncHandler::ReadProgressTextL
       
  1166 // -----------------------------------------------------------------------------
       
  1167 //	
       
  1168 void CNSmlDMSyncHandler::ReadProgressTextL( TDes& aText,
       
  1169                                             const TDesC& /*aContent*/,
       
  1170                                             TInt /*aCurrent*/,
       
  1171                                             TInt aFinal,
       
  1172                                             TInt aPhase )
       
  1173 	{
       
  1174 	FLOG( "CNSmlDMSyncHandler::ReadProgressTextL" );
       
  1175 	
       
  1176 	aText = KNullDesC;
       
  1177 
       
  1178 	HBufC* buf = NULL;
       
  1179     
       
  1180     TBool send = EFalse;
       
  1181     if ( aPhase == CNSmlDMSyncState::EPhaseSending )
       
  1182     	{
       
  1183     	send = ETrue;
       
  1184     	}
       
  1185 	if ( send && aFinal == -1 )
       
  1186 		{
       
  1187 	    buf = StringLoader::LoadLC( R_SYNCSTATUS_SYNC_SEND, iServerName );
       
  1188 		}
       
  1189 	if ( send && aFinal >= 0 )
       
  1190 		{
       
  1191 		buf = StringLoader::LoadLC( R_SYNCSTATUS_SYNC_SEND, iServerName );	
       
  1192 		}
       
  1193 	if ( !send && aFinal == -1 )
       
  1194 		{
       
  1195 	    buf = StringLoader::LoadLC( R_SYNCSTATUS_SYNC_RECV, iServerName );
       
  1196 		}
       
  1197 	if ( !send && aFinal >= 0 ) 
       
  1198 		{
       
  1199 	    buf = StringLoader::LoadLC( R_SYNCSTATUS_SYNC_RECV, iServerName );	
       
  1200 		}
       
  1201 
       
  1202 	if ( buf )
       
  1203 		{
       
  1204 	    TUtil::StrCopy( aText, *buf );
       
  1205 	    CleanupStack::PopAndDestroy( buf );
       
  1206 		}
       
  1207 	}
       
  1208 	
       
  1209 // -----------------------------------------------------------------------------
       
  1210 // CNSmlDMSyncHandler::CancelSynchronizeL
       
  1211 // -----------------------------------------------------------------------------
       
  1212 //		
       
  1213 void CNSmlDMSyncHandler::CancelSynchronizeL()
       
  1214     {
       
  1215     FLOG( "CNSmlDMSyncHandler::CancelSynchronizeL" );
       
  1216     
       
  1217     if ( iSyncRunning )
       
  1218         {
       
  1219         iSyncJob.StopL();
       
  1220         TInt err = RProperty::Set( KPSUidNSmlDMSyncApp,
       
  1221         			KDmJobCancel, KErrCancel);
       
  1222         FTRACE( FPrint(
       
  1223             _L( "CNSmlDMSyncHandler::CancelSynchronizeL() KDmJobCancel=-3, err = %d" ),
       
  1224                 err ) );
       
  1225         SynchronizeCompletedL( KErrCancel );
       
  1226         }
       
  1227     }
       
  1228 
       
  1229 // -----------------------------------------------------------------------------
       
  1230 // CNSmlDMSyncHandler::DialogDismissedL
       
  1231 // -----------------------------------------------------------------------------
       
  1232 //		
       
  1233 void CNSmlDMSyncHandler::DialogDismissedL( TInt aButtonId )
       
  1234     {
       
  1235     FTRACE( FPrint(
       
  1236         _L( "CNSmlDMSyncHandler::DialogDismissedL(), aButtonId = %d" ),
       
  1237         aButtonId ) );
       
  1238     
       
  1239     HandleDialogEventL( aButtonId );
       
  1240     
       
  1241     FLOG( "CNSmlDMSyncHandler::DialogDismissedL() completed" );
       
  1242     }
       
  1243 
       
  1244 // End of File