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