omads/omadsappui/AspSyncUtil/src/AspSyncHandler.cpp
changeset 19 2691f6aa1921
parent 4 e6e896426eac
child 20 e1de7d03f843
equal deleted inserted replaced
4:e6e896426eac 19:2691f6aa1921
     1 /*
       
     2 * Copyright (c) 2002-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:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDES
       
    21 #include "AspSyncHandler.h"
       
    22 #include "AspDebug.h"
       
    23 #include "AspSettingDialog.h"
       
    24 
       
    25 #include <aspsyncutil.mbg>  // for progress dialog bitmap enumerations
       
    26 
       
    27 #include <SyncMLErr.h>  // sync error codes
       
    28 
       
    29 #include <ecom/ecom.h>
       
    30 #include <ecom/implementationinformation.h>
       
    31 #include <rconnmon.h>
       
    32 #include <e32std.h> //For TRequestStatus
       
    33 #include "CPreSyncPlugin.h"
       
    34 #include "AspPreSyncPluginInterface.h"
       
    35 
       
    36 
       
    37 
       
    38 /******************************************************************************
       
    39  * class TAspSyncParam
       
    40  ******************************************************************************/
       
    41 
       
    42 
       
    43 // -------------------------------------------------------------------------------
       
    44 // TAspSyncParam::TAspSyncParam
       
    45 //
       
    46 // -------------------------------------------------------------------------------
       
    47 //
       
    48 TAspSyncParam::TAspSyncParam(TInt aApplicationId)
       
    49  : iApplicationId(aApplicationId), iProfileId(KErrNotFound), iJobId(KErrNotFound),
       
    50    iTaskId(KErrNotFound), iSyncDirection(KErrNotFound), iDialogMode(EModeDialogNoWait)
       
    51 	 {
       
    52 	 }
       
    53 
       
    54 
       
    55 
       
    56 /******************************************************************************
       
    57  * class CAspSyncHandler
       
    58  ******************************************************************************/
       
    59 
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // CAspSyncHandler::NewL
       
    63 //
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 CAspSyncHandler* CAspSyncHandler::NewL(const TAspParam& aParam)
       
    67     {
       
    68     FLOG( _L("CAspSyncHandler::NewL START") );
       
    69 
       
    70     CAspSyncHandler* self = new (ELeave) CAspSyncHandler(aParam);
       
    71 	CleanupStack::PushL(self);
       
    72 	self->ConstructL();
       
    73 	CleanupStack::Pop(self);
       
    74 
       
    75     FLOG( _L("CAspSyncHandler::NewL END") );
       
    76     return self;
       
    77     }
       
    78 
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // Destructor
       
    82 //
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 CAspSyncHandler::~CAspSyncHandler()
       
    86     {
       
    87     FLOG( _L("CAspSyncHandler::~CAspSyncHandler START") );
       
    88     
       
    89     delete iProgressDialog;
       
    90 	delete iState;
       
    91 	delete iResHandler;
       
    92 	delete iActiveCaller;
       
    93 	delete iTextResolver;
       
    94 	
       
    95 	delete iContentList;
       
    96 	
       
    97     if (iWait && iWait->IsStarted())
       
    98         {
       
    99         iWait->AsyncStop();
       
   100         }
       
   101 	delete iWait;
       
   102 	
       
   103 	
       
   104 	CloseSyncSession();
       
   105 	
       
   106 	FLOG( _L("CAspSyncHandler::~CAspSyncHandler END") );
       
   107     }
       
   108 
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // CAspSyncHandler::ConstructL
       
   112 //
       
   113 // -----------------------------------------------------------------------------
       
   114 //
       
   115 void CAspSyncHandler::ConstructL()
       
   116     {
       
   117 	FLOG( _L("CAspSyncHandler::ConstructL START") );
       
   118 	
       
   119 	iState = CAspState::NewL();
       
   120 
       
   121 	iActiveCaller = CAspActiveCaller::NewL(this);
       
   122 	iTextResolver = CTextResolver::NewL();
       
   123 	
       
   124 	iServerAlertSync = EFalse;
       
   125 	iSyncRunning = EFalse;
       
   126 	iSyncError = KErrNone;
       
   127 	iCurrentSyncJobId = KErrNotFound;
       
   128 	iSyncSessionOpen = EFalse;
       
   129 	
       
   130 	iWait = new (ELeave) CActiveSchedulerWait();
       
   131 	
       
   132 	FLOG( _L("CAspSyncHandler::ConstructL END") );
       
   133     }
       
   134 
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 // CAspSyncHandler::CAspSyncHandler
       
   138 //
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 CAspSyncHandler::CAspSyncHandler(const TAspParam& /*aParam*/)
       
   142 	{
       
   143 	}
       
   144 
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 // CAspSyncHandler::SetObserver
       
   148 //
       
   149 // -----------------------------------------------------------------------------
       
   150 //
       
   151 void CAspSyncHandler::SetObserver(MAspSyncObserver* aObserver)
       
   152 	{
       
   153 	iSyncObserver = aObserver;
       
   154 	}
       
   155 
       
   156 
       
   157 // -----------------------------------------------------------------------------
       
   158 // CAspSyncHandler::HandleDialogEventL (from MAspProgressDialogObserver)
       
   159 //
       
   160 // 
       
   161 // Canceling sequence after user presses "Cancel":
       
   162 //
       
   163 // 1. framework calls CAspProgressDialog2::OkToExitL
       
   164 // 2. OkToExitL calls CAspProgressDialog::DialogDismissedL
       
   165 // 3. DialogDismissedL calls CAspSyncHandler::HandleDialogEventL
       
   166 // 4. HandleDialogEventL cancels sync (RSyncMLDataSyncJob::StopL)
       
   167 //    and updates progress dialog text ("Cancelling")
       
   168 // 5. MSyncMLEventObserver::EJobStop arrives (asynchronously)
       
   169 //    and CAspProgressDialog is closed
       
   170 //
       
   171 // -----------------------------------------------------------------------------
       
   172 //
       
   173 void CAspSyncHandler::HandleDialogEventL(TInt aButtonId)
       
   174     {
       
   175     FLOG( _L("CAspSyncHandler::HandleDialogEventL START") );
       
   176     
       
   177     TBool syncRunning = SyncRunning();
       
   178     
       
   179 	//  close handling (eg. end key)
       
   180 	if (aButtonId == EKeyPhoneEnd && syncRunning)
       
   181 		{
       
   182 		TRAPD(err, iSyncJob.StopL());
       
   183 
       
   184 		if (err != KErrNone)
       
   185 			{
       
   186 			FLOG( _L("### RSyncMLDataSyncJob::StopL failed (%d) ###"), err );
       
   187 			}
       
   188 
       
   189 	    iSyncJob.Close(); // this can be done when job has not been opened
       
   190 
       
   191 	    CloseSyncSession();
       
   192 
       
   193 		iSyncRunning = EFalse;
       
   194 		
       
   195 	 	if (iIsSynchronousOperation && iWait->IsStarted())
       
   196 		    {
       
   197 	        iWait->AsyncStop();
       
   198 		    }
       
   199 
       
   200 		
       
   201 		FLOG( _L("CAspSyncHandler::HandleDialogEventL: end key handling done") );
       
   202 		FLOG( _L("CAspSyncHandler::HandleDialogEventL END") );
       
   203 		return;
       
   204 		}
       
   205 		
       
   206 	// cancel key handling
       
   207 	if (aButtonId == EEikBidCancel && syncRunning)
       
   208 		{
       
   209 		if (iStopEventReceived)
       
   210 			{
       
   211 			CompleteWithDelay(KErrNone);
       
   212         	FLOG( _L("### EJobStop already received ###") );
       
   213         	FLOG( _L("CAspSyncHandler::HandleDialogEventL END") );
       
   214 	        return;
       
   215 			}
       
   216 			
       
   217 		TInt jobId = CAspProfile::CurrentJob(&iSyncSession);
       
   218        	if (jobId != iCurrentSyncJobId)
       
   219 	        {
       
   220 	        CompleteWithDelay(KErrNotFound);
       
   221 
       
   222 	        FLOG( _L("### job conflict (%d/%d) ###"), iCurrentSyncJobId, jobId );
       
   223         	FLOG( _L("CAspSyncHandler::HandleDialogEventL END") );
       
   224 	        return;
       
   225 	        }
       
   226 
       
   227 		TRAPD(err, iSyncJob.StopL());
       
   228        	if (err != KErrNone)
       
   229 	        {
       
   230 	        CompleteWithDelay(err);
       
   231 
       
   232 	        FLOG( _L("### RSyncMLDataSyncJob::StopL failed (%d) ###"), err );
       
   233         	FLOG( _L("CAspSyncHandler::HandleDialogEventL END") );
       
   234 	        return;
       
   235 	        }
       
   236 		    
       
   237 	    State()->SetSyncPhase(CAspState::EPhaseCanceling);
       
   238         UpdateDialog();
       
   239         
       
   240         FLOG( _L("CAspSyncHandler::HandleDialogEventL: cancel key handling done") );
       
   241 		}
       
   242 		
       
   243 	FLOG( _L("CAspSyncHandler::HandleDialogEventL END") );
       
   244     }
       
   245 
       
   246 
       
   247 TBool CAspSyncHandler::IsRoamingL()
       
   248     {
       
   249     RConnectionMonitor conMon;
       
   250     
       
   251     conMon.ConnectL();
       
   252 
       
   253     TRequestStatus status;
       
   254     TInt registrationStatus(0);
       
   255 
       
   256     //check network status
       
   257     conMon.GetIntAttribute(EBearerIdGSM, 0, KNetworkRegistration, 
       
   258                             registrationStatus, status);
       
   259 
       
   260     User::WaitForRequest(status);
       
   261     conMon.Close();
       
   262     
       
   263     if (registrationStatus == ENetworkRegistrationRoaming)
       
   264         {
       
   265         return ETrue;   
       
   266         }
       
   267         
       
   268     return EFalse;
       
   269     }
       
   270 
       
   271 // -----------------------------------------------------------------------------
       
   272 // CAspSyncHandler::ReadRepositoryL
       
   273 //
       
   274 // -----------------------------------------------------------------------------
       
   275 //
       
   276 void CAspSyncHandler::ReadRepositoryL(TInt aKey, TInt& aValue)
       
   277     {
       
   278     CRepository* rep = CRepository::NewLC(KCRUidNSmlDSApp);
       
   279     TInt err = rep->Get(aKey, aValue);
       
   280     User::LeaveIfError(err);
       
   281     
       
   282     CleanupStack::PopAndDestroy(rep);
       
   283     }
       
   284 
       
   285 TInt CAspSyncHandler::BearerTypeL(TInt aProfileId)
       
   286     {    
       
   287     TInt BearerType = KErrNotFound;
       
   288     
       
   289     // sync session
       
   290     RSyncMLSession syncSession;
       
   291     syncSession.OpenL();
       
   292     CleanupClosePushL( syncSession );
       
   293 
       
   294     RSyncMLDataSyncProfile syncProfile;
       
   295     syncProfile.OpenL( syncSession, aProfileId, ESmlOpenRead );
       
   296     CleanupClosePushL( syncProfile );
       
   297     
       
   298     // Check if always ask is selected as accesspoint
       
   299     RSyncMLConnection connection;
       
   300 
       
   301     TInt err = KErrNone;
       
   302     RArray<TSmlTransportId> arr;
       
   303     
       
   304     TRAP(err, syncProfile.ListConnectionsL(arr));
       
   305     if (err != KErrNone)
       
   306         {
       
   307         syncProfile.Close();
       
   308         CleanupStack::Pop( &syncProfile );
       
   309         return KErrNotFound; 
       
   310         }
       
   311     if (arr.Count() == 0)
       
   312         {
       
   313         syncProfile.Close();
       
   314         CleanupStack::Pop( &syncProfile );
       
   315         arr.Close();  
       
   316         return KErrNotFound; // no connection
       
   317         }
       
   318             
       
   319     TInt transportId = arr[0];
       
   320     arr.Close();
       
   321         
       
   322     TRAP(err, connection.OpenL( syncProfile, transportId ) );
       
   323     CleanupClosePushL( connection );
       
   324 
       
   325     if ( err == KErrNone )
       
   326         {
       
   327         TInt id = connection.Identifier();
       
   328         if (id == KUidNSmlMediumTypeInternet.iUid)
       
   329             {
       
   330             BearerType = EAspBearerInternet;
       
   331             }
       
   332         else if (id == KUidNSmlMediumTypeBluetooth.iUid)
       
   333             {
       
   334             BearerType = EAspBearerBlueTooth;
       
   335             }
       
   336         else if (id == KUidNSmlMediumTypeUSB.iUid)
       
   337             {
       
   338             BearerType = EAspBearerUsb;
       
   339             }
       
   340         else if (id == KUidNSmlMediumTypeIrDA.iUid)
       
   341             {
       
   342             BearerType = EAspBearerIrda;
       
   343             }
       
   344         }
       
   345 
       
   346     connection.Close();
       
   347     CleanupStack::Pop( &connection );
       
   348     
       
   349     syncProfile.Close();
       
   350     CleanupStack::Pop( &syncProfile );
       
   351             
       
   352     syncSession.Close();
       
   353     CleanupStack::Pop( &syncSession );
       
   354     return BearerType;
       
   355     }
       
   356 // -----------------------------------------------------------------------------
       
   357 // CAspSyncHandler::SynchronizeL
       
   358 //
       
   359 // -----------------------------------------------------------------------------
       
   360 //
       
   361 void CAspSyncHandler::SynchronizeL(TAspSyncParam& aSyncParam)
       
   362 	{
       
   363 	iServerAlertSync = EFalse;
       
   364 	iSyncRunning = EFalse;
       
   365 	iCurrentSyncJobId = KErrNotFound;
       
   366 	iSyncError = KErrNone;
       
   367 	iCompleteEventReceived = EFalse;
       
   368 	iStopEventReceived = EFalse;
       
   369 	iIsSynchronousOperation = EFalse;
       
   370 	TBool bCanSync = ETrue;
       
   371 	
       
   372     TInt aValue = 0;
       
   373     ReadRepositoryL(KNSmlDSRoamingFeature, aValue);
       
   374     if(( IsRoamingL() ) && (aValue == EAspRoamingSettingFeatureEnabled))
       
   375         {
       
   376            TInt bearerType = BearerTypeL(aSyncParam.iProfileId);
       
   377            if (bearerType == EAspBearerInternet)           
       
   378             {
       
   379             CPreSyncPluginInterface* syncPluginInterface = CPreSyncPluginInterface::NewL();
       
   380             CPreSyncPlugin* syncPlugin = 
       
   381                 syncPluginInterface->InstantiateRoamingPluginLC(aSyncParam.iProfileId);
       
   382 
       
   383             if(syncPlugin->IsSupported())
       
   384                 {
       
   385                 bCanSync = syncPlugin->CanSyncL();
       
   386                 }
       
   387 
       
   388             CleanupStack::PopAndDestroy(syncPlugin);
       
   389             //syncPluginInterface->UnloadPlugIns();
       
   390             delete  syncPluginInterface;   
       
   391 
       
   392             if(!bCanSync)
       
   393                 {
       
   394                 return;
       
   395                 }
       
   396             }        
       
   397         }	
       
   398 	
       
   399 	State()->SetSyncPhase(CAspState::EPhaseConnecting);
       
   400 	State()->ResetProgress();
       
   401 	//State()->SetTotalProgress(KTotalProgress);
       
   402 	
       
   403 	TRAPD(err, DoSynchronizeL(aSyncParam));
       
   404 	
       
   405 	if (err != KErrNone)
       
   406 		{
       
   407 		SynchronizeCompleted(err);
       
   408      	return;
       
   409 		}
       
   410 	}
       
   411 
       
   412 
       
   413 // -----------------------------------------------------------------------------
       
   414 // CAspSyncHandler::DoSynchronizeL
       
   415 //
       
   416 // -----------------------------------------------------------------------------
       
   417 //
       
   418 void CAspSyncHandler::DoSynchronizeL(TAspSyncParam& aSyncParam)
       
   419 	{
       
   420 	FLOG( _L("CAspSyncHandler::DoSynchronizeL START") );
       
   421     
       
   422 	iApplicationId = aSyncParam.iApplicationId;
       
   423 	iProfileId = aSyncParam.iProfileId;
       
   424 	if (aSyncParam.iDialogMode == EModeDialogWait)
       
   425 		{
       
   426 		iIsSynchronousOperation = ETrue; // email 3.2 needs synchronous syncing
       
   427 		}
       
   428 
       
   429 	
       
   430 	ShowProgressDialogL();
       
   431     OpenSyncSessionL();
       
   432     CreateContentListL();
       
   433     
       
   434     iSyncSession.RequestEventL(*this);     // for MSyncMLEventObserver events
       
   435     iSyncSession.RequestProgressL(*this);  // for MSyncMLProgressObserver events
       
   436     
       
   437  	if (aSyncParam.iTaskId != KErrNotFound && iProfileId != KErrNotFound)
       
   438 		{
       
   439 		RArray<TSmlTaskId> arr(1);
       
   440 		CleanupClosePushL(arr);
       
   441 		User::LeaveIfError(arr.Append(aSyncParam.iTaskId));
       
   442 		if (aSyncParam.iSyncDirection != KErrNotFound)
       
   443 			{
       
   444 			TSmlSyncType syncDirection = TAspTask::SmlSyncDirection(aSyncParam.iSyncDirection);
       
   445 			iSyncJob.CreateL(iSyncSession, iProfileId, syncDirection, arr);
       
   446 			}
       
   447 		else
       
   448 			{
       
   449 			iSyncJob.CreateL(iSyncSession, iProfileId, arr);
       
   450 			}
       
   451 			
       
   452 		CleanupStack::PopAndDestroy(&arr);
       
   453 		}
       
   454 	else if (iProfileId != KErrNotFound)
       
   455 		{
       
   456 		if (aSyncParam.iSyncDirection != KErrNotFound)
       
   457 			{
       
   458 		    TSmlSyncType syncDirection = TAspTask::SmlSyncDirection(aSyncParam.iSyncDirection);
       
   459 			iSyncJob.CreateL(iSyncSession, iProfileId, syncDirection);
       
   460 			}
       
   461 		else
       
   462 			{
       
   463 		    iSyncJob.CreateL(iSyncSession, iProfileId);
       
   464 			}
       
   465 		}
       
   466 	else
       
   467 		{
       
   468 		User::Leave(KErrArgument);
       
   469 		}
       
   470 		
       
   471 	iCurrentSyncJobId = iSyncJob.Identifier();
       
   472 	iSyncRunning = ETrue;
       
   473 	
       
   474 	if (iIsSynchronousOperation)
       
   475 		{
       
   476 		iWait->Start();  // stop here until sync has completed
       
   477 		}
       
   478    
       
   479     FLOG( _L("sync job created: app=%d, profile=%d, job=%d, task=%d"), iApplicationId, iProfileId, aSyncParam.iJobId, aSyncParam.iTaskId );
       
   480     FLOG( _L("CAspSyncHandler::DoSynchronizeL END") );
       
   481 	}
       
   482 
       
   483 
       
   484 // -----------------------------------------------------------------------------
       
   485 // CAspSyncHandler::SynchronizeCompleted
       
   486 //
       
   487 // -----------------------------------------------------------------------------
       
   488 //
       
   489 void CAspSyncHandler::SynchronizeCompleted(TInt aError)
       
   490 	{
       
   491 	FLOG( _L("CAspSyncHandler::SynchronizeCompleted START") );
       
   492 	
       
   493 	iSyncRunning = EFalse;
       
   494 	
       
   495 	if (aError != KErrNone)
       
   496 		{
       
   497 		iSyncError = aError;
       
   498 		}
       
   499    	
       
   500    	iSyncJob.Close(); // this can be done when job has not been opened
       
   501    	
       
   502     TRAP_IGNORE(Dialog()->CancelProgressDialogL());
       
   503 	
       
   504 	if (iSyncError != KErrNone)
       
   505 		{
       
   506 	   	CloseSyncSession();
       
   507    		ShowErrorNote();
       
   508       	
       
   509       	FLOG( _L("### sync failed (%d) ###"), iSyncError );
       
   510 		}
       
   511 	else
       
   512 	    {
       
   513       	CloseSyncSession();
       
   514       	TRAP_IGNORE(TDialogUtil::ShowInformationNoteL(R_ASP_SYNC_COMPLETED));
       
   515 	    }
       
   516 	    
       
   517     if (iSyncObserver)
       
   518     	{
       
   519         TRAP_IGNORE(iSyncObserver->HandleSyncEventL(iSyncError, iProfileId));
       
   520     	}
       
   521     	
       
   522  	if (iIsSynchronousOperation && iWait->IsStarted())
       
   523 		{
       
   524 	    iWait->AsyncStop();
       
   525 		}
       
   526 	    	
       
   527 	FLOG( _L("CAspSyncHandler::SynchronizeCompleted END") );
       
   528 	}
       
   529 
       
   530 
       
   531 // -----------------------------------------------------------------------------
       
   532 // CAspSyncHandler::OnSyncMLSessionEvent (from MSyncMLEventObserver)
       
   533 //
       
   534 // -----------------------------------------------------------------------------
       
   535 //
       
   536 void CAspSyncHandler::OnSyncMLSessionEvent(TEvent aEvent, TInt aIdentifier, TInt aError, TInt /*aAdditionalData*/)
       
   537 	{
       
   538 	FLOG( _L("CAspSyncHandler::OnSyncMLSessionEvent START") );
       
   539 
       
   540 #ifdef _DEBUG
       
   541     LogSessionEvent(aEvent, aIdentifier, aError);
       
   542 #endif
       
   543 
       
   544     if (iCurrentSyncJobId != aIdentifier)
       
   545     	{
       
   546     	FLOG( _L("### job conflict (%d/%d) ###"), iCurrentSyncJobId, aIdentifier );
       
   547     	FLOG( _L("CAspSyncHandler::OnSyncMLSessionEvent END") );
       
   548     	return; // not our sync job
       
   549     	}
       
   550 	
       
   551 	if (aEvent == EJobStop)
       
   552 		{
       
   553 		iStopEventReceived = ETrue;
       
   554 		if (aError != KErrNone)
       
   555 			{
       
   556 			iSyncError = aError;
       
   557 			}
       
   558 	
       
   559 	    if (State()->SyncPhase() == CAspState::EPhaseCanceling)
       
   560 		    {
       
   561 		    CompleteWithDelay(aError);
       
   562 		    }
       
   563         else if (iCompleteEventReceived || iSyncError != KErrNone)
       
   564 		    {
       
   565 		    CompleteWithDelay(aError);
       
   566 		    }
       
   567 		}
       
   568     	
       
   569 	if (aEvent == EJobStartFailed || aEvent == EJobRejected)
       
   570 		{
       
   571 		CompleteWithDelay(aError);
       
   572 		}
       
   573 		
       
   574 	FLOG( _L("CAspSyncHandler::OnSyncMLSessionEvent END") );
       
   575     }
       
   576 
       
   577 
       
   578 // -----------------------------------------------------------------------------
       
   579 // CAspSyncHandler::CompleteWithDelay
       
   580 //
       
   581 // -----------------------------------------------------------------------------
       
   582 //
       
   583 void CAspSyncHandler::CompleteWithDelay(TInt aError)
       
   584 	{
       
   585 	iActiveCaller->Start(aError, 0); // call SynchronizeCompleted with delay
       
   586 	}
       
   587 
       
   588 
       
   589 // -----------------------------------------------------------------------------
       
   590 // CAspSyncHandler::OnSyncMLSyncError (from MSyncMLProgressObserver)
       
   591 //
       
   592 // -----------------------------------------------------------------------------
       
   593 //
       
   594 void CAspSyncHandler::OnSyncMLSyncError(TErrorLevel aErrorLevel, TInt aError, TInt /*aTaskId*/, TInt /*aInfo1*/, TInt /*aInfo2*/)
       
   595 	{
       
   596 	FLOG( _L("CAspSyncHandler::OnSyncMLSyncError START") );
       
   597 	
       
   598 	// just store error code - sync is terminated only in function OnSyncMLSessionEvent
       
   599 	if (aErrorLevel == ESmlFatalError)
       
   600 		{
       
   601 		iSyncError = aError;
       
   602 		}
       
   603 		
       
   604 #ifdef _DEBUG
       
   605     LogErrorEvent(aErrorLevel, aError);
       
   606 #endif
       
   607 
       
   608 	FLOG( _L("CAspSyncHandler::OnSyncMLSyncError END") );
       
   609 	}
       
   610 
       
   611 
       
   612 // -----------------------------------------------------------------------------
       
   613 // CAspSyncHandler::OnSyncMLSyncProgress (from MSyncMLProgressObserver)
       
   614 //
       
   615 // -----------------------------------------------------------------------------
       
   616 //
       
   617 void CAspSyncHandler::OnSyncMLSyncProgress(TStatus aStatus, TInt aInfo1, TInt /*aInfo2*/)
       
   618 	{
       
   619 	FLOG( _L("CAspSyncHandler::OnSyncMLSyncProgress START") );
       
   620 	
       
   621 	if (State()->SyncPhase() == CAspState::EPhaseCanceling)
       
   622 		{
       
   623 		return; // no progress dialog updating while canceling
       
   624 		}
       
   625 
       
   626 #ifdef _DEBUG
       
   627     LogProgressEvent(aStatus, aInfo1);
       
   628 #endif
       
   629 	
       
   630 	switch (aStatus)
       
   631 		{
       
   632 		case ESmlConnecting:
       
   633 		    State()->SetSyncPhase(CAspState::EPhaseConnecting);
       
   634 	        UpdateDialog();
       
   635 		    break;
       
   636 		case ESmlConnected:
       
   637 		    break;
       
   638 		case ESmlLoggingOn:
       
   639 		    break;
       
   640 		case ESmlLoggedOn:
       
   641 		    State()->SetSyncPhase(CAspState::EPhaseSynchronizing);
       
   642 		    UpdateDialog();
       
   643 		    break;
       
   644 		case ESmlDisconnected:
       
   645 		    State()->SetSyncPhase(CAspState::EPhaseDisconnecting);
       
   646 		    UpdateDialog();
       
   647 		    break;
       
   648 		case ESmlCompleted:
       
   649 		    iCompleteEventReceived = ETrue;
       
   650 		    
       
   651 			if (iStopEventReceived)
       
   652 			    {
       
   653 			    FLOG( _L("### EJobStop already received ###") );
       
   654 			    CompleteWithDelay(iSyncError);
       
   655 			    }
       
   656             else
       
   657             	{
       
   658             	State()->SetSyncPhase(CAspState::EPhaseDisconnecting);
       
   659 		        UpdateDialog();
       
   660             	}
       
   661 		    break;
       
   662 
       
   663 		case ESmlSendingModificationsToServer:
       
   664 		    State()->SetSyncPhase(CAspState::EPhaseSending);
       
   665    		    State()->ResetProgress();
       
   666 		    State()->SetTotalProgress(aInfo1); // set total sync event count
       
   667 
       
   668      	    UpdateDialog();
       
   669 		    break;
       
   670 		case ESmlReceivingModificationsFromServer:
       
   671 		    State()->SetSyncPhase(CAspState::EPhaseReceiving);
       
   672    		    State()->ResetProgress();
       
   673 		    State()->SetTotalProgress(aInfo1); // set total sync event count
       
   674 
       
   675 	        UpdateDialog();
       
   676 		    break;
       
   677 		    
       
   678 		case ESmlSendingMappingsToServer:
       
   679 		    State()->SetSyncPhase(CAspState::EPhaseSynchronizing);
       
   680 		    UpdateDialog();
       
   681 		    break;
       
   682 		
       
   683 		default:
       
   684 		    break;
       
   685 		}
       
   686 		
       
   687 	FLOG( _L("CAspSyncHandler::OnSyncMLSyncProgress END") );
       
   688 	}
       
   689 
       
   690 
       
   691 // -----------------------------------------------------------------------------
       
   692 // CAspSyncHandler::OnSyncMLDataSyncModifications (from MSyncMLProgressObserver)
       
   693 //
       
   694 // -----------------------------------------------------------------------------
       
   695 //
       
   696 void CAspSyncHandler::OnSyncMLDataSyncModifications(TInt aTaskId, 
       
   697                       const TSyncMLDataSyncModifications& aClientModifications,
       
   698                       const TSyncMLDataSyncModifications& aServerModifications)
       
   699 	{
       
   700 	
       
   701     if (!Dialog()->ProgressDialog())
       
   702     	{
       
   703     	//it is observed that some times this call back comes 
       
   704     	//just after deleting progress dialog.
       
   705     	return;
       
   706     	}
       
   707 	
       
   708 	TRAPD(err, OnSyncMLDataSyncModificationsL(aTaskId, aClientModifications, aServerModifications));
       
   709 	if (err != KErrNone)
       
   710 		{
       
   711 		FLOG( _L("### CAspSyncHandler::OnSyncMLDataSyncModificationsL failed (%d) ###"), err );
       
   712 		FLOG( _L("### CAspSyncHandler::OnSyncMLDataSyncModificationsL failed (%d) ###"), err );
       
   713 		}
       
   714 	}
       
   715 
       
   716 
       
   717 // -----------------------------------------------------------------------------
       
   718 // CAspSyncHandler::OnSyncMLDataSyncModificationsL
       
   719 //
       
   720 // -----------------------------------------------------------------------------
       
   721 //
       
   722 void CAspSyncHandler::OnSyncMLDataSyncModificationsL(TInt aTaskId,
       
   723                       const TSyncMLDataSyncModifications& aClientModifications,
       
   724                       const TSyncMLDataSyncModifications& aServerModifications)
       
   725 	{
       
   726 	FLOG( _L("CAspSyncHandler::OnSyncMLDataSyncModificationsL START") );
       
   727 	
       
   728 
       
   729 	if (State()->Progress() == 0)
       
   730 		{
       
   731 	    TInt index = iContentList->FindProviderIndexForTask(aTaskId);
       
   732 	
       
   733 	    if (index != KErrNotFound)
       
   734 		    {
       
   735 		    TAspProviderItem& item = iContentList->ProviderItem(index);
       
   736 		    HBufC* hBuf = CAspResHandler::GetContentNameLC(item.iDataProviderId,
       
   737 		                                                   item.iDisplayName);
       
   738 	        State()->SetContentL(hBuf->Des());
       
   739 
       
   740 #ifdef _DEBUG
       
   741             LogModificationEvent(aTaskId, hBuf->Des());
       
   742 #endif
       
   743 
       
   744 	        CleanupStack::PopAndDestroy(hBuf);
       
   745 		    }
       
   746 	    else
       
   747 		    {
       
   748 		    State()->SetContentL(KNullDesC);
       
   749 		    FLOG( _L("### task not found (%d) ###"), aTaskId );
       
   750 		    }
       
   751 		}
       
   752 	
       
   753 	// Set sync event count. On last OnSyncMLDataSyncModifications call it 
       
   754 	// must match total sync event count (set in OnSyncMLSyncProgress). 
       
   755 	TInt count = ProgressCount(aClientModifications, aServerModifications);
       
   756 	State()->IncreaseProgress(count);
       
   757 	
       
   758 	UpdateDialog();
       
   759 
       
   760 	
       
   761 #ifdef _DEBUG
       
   762     LogModificationEvent(aTaskId, aClientModifications, aServerModifications);
       
   763 #endif
       
   764 
       
   765 
       
   766 	FLOG( _L("CAspSyncHandler::OnSyncMLDataSyncModificationsL END") );
       
   767 	FLOG( _L(" ") );
       
   768 	}
       
   769 
       
   770 
       
   771 
       
   772 // -----------------------------------------------------------------------------
       
   773 // CAspSyncHandler::UpdateDialog
       
   774 //
       
   775 // -----------------------------------------------------------------------------
       
   776 //
       
   777 void CAspSyncHandler::UpdateDialog()
       
   778 	{
       
   779 	TRAPD(err, UpdateDialogL());
       
   780 	
       
   781 	if (err != KErrNone)
       
   782 		{
       
   783 		FLOG( _L("### CAspSyncHandler::UpdateDialogL failed (%d) ###"), err );
       
   784 		}
       
   785 	}
       
   786 
       
   787 
       
   788 // -----------------------------------------------------------------------------
       
   789 // CAspSyncHandler::UpdateDialogL
       
   790 //
       
   791 // -----------------------------------------------------------------------------
       
   792 //
       
   793 void CAspSyncHandler::UpdateDialogL()
       
   794 	{
       
   795 	if (!SyncRunning())
       
   796 		{
       
   797 		FLOG( _L("### CAspSyncHandler::UpdateDialogL: Sync not running ###") );
       
   798 		return;
       
   799 		}
       
   800 
       
   801 	TInt phase = State()->SyncPhase();
       
   802 	
       
   803 	if (phase == CAspState::EPhaseConnecting)
       
   804 		{
       
   805 		Dialog()->StartAnimationL();
       
   806 		HBufC* hBuf = ResHandlerL()->ReadLC(R_SYNCSTATUS_SYNC_CONN);  // "Connecting"
       
   807 		Dialog()->UpdateTextL(hBuf->Des());
       
   808 		CleanupStack::PopAndDestroy(hBuf);
       
   809 		}
       
   810 
       
   811 	if (phase == CAspState::EPhaseSynchronizing)
       
   812 		{
       
   813 		Dialog()->StartAnimationL();
       
   814 		HBufC* hBuf = ResHandlerL()->ReadLC(R_SYNCSTATUS_SYNC_SYNC); // "Synchronizing"
       
   815 		Dialog()->UpdateTextL(hBuf->Des());
       
   816 		CleanupStack::PopAndDestroy(hBuf);
       
   817 		}
       
   818 
       
   819 	if (phase == CAspState::EPhaseDisconnecting)
       
   820 		{
       
   821 		Dialog()->StartAnimationL();
       
   822 		HBufC* hBuf = ResHandlerL()->ReadLC(R_SYNCSTATUS_SYNC_DISC);  // "Disconnecting"
       
   823 		Dialog()->UpdateTextL(hBuf->Des());
       
   824 		CleanupStack::PopAndDestroy(hBuf);
       
   825 		}
       
   826 
       
   827 	if (phase == CAspState::EPhaseCanceling)
       
   828 		{
       
   829 		Dialog()->StartAnimationL();
       
   830 		HBufC* hBuf = ResHandlerL()->ReadLC(R_SYNCSTATUS_CANC);  // "Canceling"
       
   831 		Dialog()->UpdateTextL(hBuf->Des());
       
   832 		CleanupStack::PopAndDestroy(hBuf);
       
   833 		Dialog()->HideButtonL();
       
   834 		}
       
   835 
       
   836 //The number of Emails-Synced NOT printed if Sync is started from Sync E-mail Application
       
   837 	if (iApplicationId == EApplicationIdEmail)
       
   838 	     return;
       
   839 	
       
   840 	if (phase == CAspState::EPhaseSending || phase == CAspState::EPhaseReceiving)
       
   841 		{
       
   842 		if (State()->Progress() == 0 || State()->TotalProgress() == 0)
       
   843 			{
       
   844 			return; 
       
   845 			}
       
   846 			
       
   847 		if (State()->FirstProgress())
       
   848 			{
       
   849 			if (State()->ProgressKnown())
       
   850 				{
       
   851     			Dialog()->CancelAnimation();
       
   852 	    		Dialog()->SetFinalProgress(State()->TotalProgress());
       
   853      	    	Dialog()->SetProgress(State()->Progress());
       
   854 				}
       
   855 			else
       
   856 				{
       
   857     			Dialog()->SetFinalProgress(0);
       
   858 	    	    Dialog()->StartAnimationL();
       
   859 				}
       
   860 			}
       
   861 		else if (State()->ProgressKnown())
       
   862 			{
       
   863 			Dialog()->SetProgress(State()->Progress());
       
   864 			}
       
   865 			
       
   866 		HBufC* hBuf = ResHandlerL()->ReadProgressTextLC(State()->Content(), phase);
       
   867 		
       
   868 
       
   869 #ifdef _DEBUG
       
   870 		TBuf<KBufSize> buf1; TBuf<KBufSize> buf2;
       
   871 		buf1 = hBuf->Des();
       
   872 		buf2.Format(_L("%S\n (%d/%d)"), &buf1, State()->Progress(), State()->TotalProgress());
       
   873 		CleanupStack::PopAndDestroy(hBuf);
       
   874 		hBuf = NULL;
       
   875 		hBuf = buf2.AllocLC();
       
   876 #endif
       
   877 		
       
   878    	
       
   879     	Dialog()->UpdateTextL(hBuf->Des());
       
   880 		CleanupStack::PopAndDestroy(hBuf);
       
   881 		}
       
   882 	}
       
   883 
       
   884 
       
   885 // -----------------------------------------------------------------------------
       
   886 // CAspSyncHandler::UpdateRequired
       
   887 //
       
   888 // -----------------------------------------------------------------------------
       
   889 //
       
   890 TBool CAspSyncHandler::UpdateRequired()
       
   891 	{
       
   892     const TInt KProgressLevel_1 = 10;
       
   893     const TInt KProgressLevel_2 = 20;
       
   894     const TInt KProgressLevel_3 = 50;
       
   895     
       
   896     const TInt KProgressStep_1 = 5;
       
   897     const TInt KProgressStep_2 = 10;
       
   898     const TInt KProgressStep_3 = 20;
       
   899     
       
   900     TInt total = State()->TotalProgress();
       
   901     TInt current = State()->Progress();
       
   902     TBool firstProgress = State()->FirstProgress();
       
   903     TBool progressKnown = State()->ProgressKnown();
       
   904     
       
   905     // always show first progress
       
   906     if (firstProgress)
       
   907     	{
       
   908     	return ETrue;
       
   909     	}
       
   910     
       
   911     // handle case where total progress count is not known
       
   912     if (!progressKnown)
       
   913     	{
       
   914     	if (current <= KProgressStep_2)
       
   915     		{
       
   916     		return ETrue;
       
   917     		}
       
   918     	else if (current % KProgressStep_1 == 0)
       
   919     		{
       
   920     		return ETrue;
       
   921     		}
       
   922     		
       
   923     	return EFalse;
       
   924     	}
       
   925     
       
   926     // handle case where total progress count is known
       
   927     if (current == total)
       
   928     	{
       
   929     	return ETrue; // always show last progress
       
   930     	}
       
   931     else if (total <= KProgressLevel_1)
       
   932     	{
       
   933     	return ETrue;
       
   934     	}
       
   935     else if (total > KProgressLevel_1 && total <= KProgressLevel_2)
       
   936 		{
       
   937     	if (current % KProgressStep_1 == 0)
       
   938 			{
       
   939 			return ETrue;
       
   940 			}
       
   941 		}
       
   942     else if (total > KProgressLevel_2 && total <= KProgressLevel_3)
       
   943 		{
       
   944     	if (current % KProgressStep_2 == 0)
       
   945 			{
       
   946 			return ETrue;
       
   947 			}
       
   948 		}
       
   949     else if (total > KProgressLevel_3)
       
   950 		{
       
   951     	if (current % KProgressStep_3 == 0)
       
   952 			{
       
   953 			return ETrue;
       
   954 			}
       
   955 		}
       
   956 
       
   957 	return EFalse;
       
   958 	}
       
   959 
       
   960 
       
   961 // -----------------------------------------------------------------------------
       
   962 // CAspSyncHandler::HandleActiveCallL (from MAspActiveCallerObserver)
       
   963 //
       
   964 // -----------------------------------------------------------------------------
       
   965 //
       
   966 void CAspSyncHandler::HandleActiveCallL(TInt aCallId)
       
   967 	{
       
   968     SynchronizeCompleted(aCallId);
       
   969 	}
       
   970 
       
   971 
       
   972 // -----------------------------------------------------------------------------
       
   973 // CAspSyncHandler::ShowErrorNote
       
   974 //
       
   975 // -----------------------------------------------------------------------------
       
   976 //
       
   977 void CAspSyncHandler::ShowErrorNote()
       
   978 	{
       
   979 	if (iSyncError == KErrNone || iSyncError == KErrCancel)
       
   980 		{
       
   981 		return; // nothing to show
       
   982 		}
       
   983 
       
   984 	// show sync engine error
       
   985 	if (iSyncError <= SyncMLError::KErrSyncEngineErrorBase)
       
   986 		{
       
   987 		HBufC* hBuf = NULL;
       
   988 		hBuf = TAspSyncError::GetSmlErrorText(iSyncError, 0);
       
   989 		if (hBuf)  // hBuf can be NULL
       
   990  			{
       
   991      	   	TRAP_IGNORE(TDialogUtil::ShowErrorQueryL(hBuf->Des()));
       
   992 	     	delete hBuf;
       
   993 			}
       
   994 			
       
   995 		return;
       
   996 		}
       
   997 
       
   998     // show system error
       
   999     TPtrC errorMsg;
       
  1000     
       
  1001     errorMsg.Set(iTextResolver->ResolveErrorString(iSyncError, CTextResolver::ECtxNoCtxNoSeparator));
       
  1002 	
       
  1003 	TRAP_IGNORE(TDialogUtil::ShowErrorQueryL(errorMsg));
       
  1004     }
       
  1005 
       
  1006 // -----------------------------------------------------------------------------
       
  1007 // CAspSyncHandler::ShowProgressDialogL
       
  1008 //
       
  1009 // -----------------------------------------------------------------------------
       
  1010 //
       
  1011 void CAspSyncHandler::ShowProgressDialogL()
       
  1012 	{
       
  1013 	delete iProgressDialog;
       
  1014 	iProgressDialog = NULL;
       
  1015 	iProgressDialog = CAspProgressDialog::NewL(this);
       
  1016 	
       
  1017 	TInt resId = R_SYNCSTATUS_SYNC_CONN;
       
  1018 	if (iApplicationId == EApplicationIdEmail)
       
  1019 		{
       
  1020 		resId = R_SYNCSTATUS_SYNC_SYNC;
       
  1021 		}
       
  1022 	
       
  1023 	HBufC* hBuf = CAspResHandler::ReadLC(resId);
       
  1024 	
       
  1025 	iProgressDialog->SetApplicationId(iApplicationId);
       
  1026 	
       
  1027    	TFileName bitmapName;
       
  1028 	CAspResHandler::GetBitmapFileName(bitmapName);
       
  1029 	
       
  1030 	iProgressDialog->LaunchProgressDialogL(hBuf->Des(),
       
  1031 	                                       KAknsIIDQgnNoteSml, 
       
  1032 	                                       bitmapName,
       
  1033 	                                       EMbmAspsyncutilQgn_note_sml,
       
  1034 	                                       EMbmAspsyncutilQgn_note_sml_mask);
       
  1035 	CleanupStack::PopAndDestroy(hBuf);
       
  1036 	}
       
  1037 
       
  1038 
       
  1039 // -----------------------------------------------------------------------------
       
  1040 // CAspSyncHandler::CreateContentListL
       
  1041 //
       
  1042 // -----------------------------------------------------------------------------
       
  1043 //
       
  1044 void CAspSyncHandler::CreateContentListL()
       
  1045     {
       
  1046     TAspParam param(iApplicationId, &iSyncSession);
       
  1047 
       
  1048     CAspProfile* profile = CAspProfile::NewLC(param);
       
  1049     profile->OpenL(iProfileId, CAspProfile::EOpenRead, CAspProfile::EBaseProperties);
       
  1050     
       
  1051 	param.iProfile = profile;
       
  1052 	param.iMode = CAspContentList::EInitAll;
       
  1053 	
       
  1054 	delete iContentList;
       
  1055 	iContentList = NULL;
       
  1056 	iContentList = CAspContentList::NewL(param);
       
  1057 	
       
  1058     CleanupStack::PopAndDestroy(profile);	
       
  1059     }
       
  1060 
       
  1061 
       
  1062 // -----------------------------------------------------------------------------
       
  1063 // CAspSyncHandler::CheckLocalDatabaseL
       
  1064 //
       
  1065 // -----------------------------------------------------------------------------
       
  1066 //
       
  1067 void CAspSyncHandler::CheckLocalDatabaseL(TInt aProfileId)
       
  1068     {
       
  1069     TAspParam param(iApplicationId, &iSyncSession);
       
  1070 
       
  1071     CAspProfile* profile = CAspProfile::NewLC(param);
       
  1072     profile->OpenL(aProfileId, CAspProfile::EOpenRead, CAspProfile::EBaseProperties);
       
  1073     
       
  1074 	TInt dataProviderId = KErrNotFound;
       
  1075 	TBool databaseFound = TAspTask::CheckLocalDatabase(profile, dataProviderId);
       
  1076 	CleanupStack::PopAndDestroy(profile);
       
  1077 	
       
  1078 	if (!databaseFound)
       
  1079 		{
       
  1080 		User::Leave(SyncMLError::KErrClientDatabaseNotFound);
       
  1081 		}
       
  1082     }
       
  1083 
       
  1084 
       
  1085 
       
  1086 // -----------------------------------------------------------------------------
       
  1087 // CAspSyncHandler::Dialog
       
  1088 //
       
  1089 // -----------------------------------------------------------------------------
       
  1090 //
       
  1091 CAspProgressDialog* CAspSyncHandler::Dialog()
       
  1092 	{
       
  1093 	__ASSERT_DEBUG(iProgressDialog, TUtil::Panic(KErrGeneral));
       
  1094 
       
  1095 	return iProgressDialog;
       
  1096 	}
       
  1097 
       
  1098 
       
  1099 // -----------------------------------------------------------------------------
       
  1100 // CAspSyncHandler::State
       
  1101 //
       
  1102 // -----------------------------------------------------------------------------
       
  1103 //
       
  1104 CAspState* CAspSyncHandler::State()
       
  1105 	{
       
  1106 	__ASSERT_DEBUG(iState, TUtil::Panic(KErrGeneral));
       
  1107 
       
  1108 	return iState;
       
  1109 	}
       
  1110 
       
  1111 
       
  1112 // -----------------------------------------------------------------------------
       
  1113 // CAspSyncHandler::ResHandlerL
       
  1114 //
       
  1115 // -----------------------------------------------------------------------------
       
  1116 //
       
  1117 CAspResHandler* CAspSyncHandler::ResHandlerL()
       
  1118 	{
       
  1119 	if (!iResHandler)
       
  1120 		{
       
  1121 		iResHandler = CAspResHandler::NewL();
       
  1122 		}
       
  1123 
       
  1124 	return iResHandler;
       
  1125 	}
       
  1126 
       
  1127 
       
  1128 // -----------------------------------------------------------------------------
       
  1129 // SyncRunning
       
  1130 // 
       
  1131 // -----------------------------------------------------------------------------
       
  1132 //
       
  1133 TBool CAspSyncHandler::SyncRunning()
       
  1134 	{
       
  1135 	return iSyncRunning;
       
  1136 	}
       
  1137 
       
  1138 // -----------------------------------------------------------------------------
       
  1139 // IsServerAlertSync
       
  1140 // 
       
  1141 // -----------------------------------------------------------------------------
       
  1142 //
       
  1143 TBool CAspSyncHandler::IsServerAlertSync()
       
  1144 	{
       
  1145 	return iServerAlertSync;
       
  1146 	}
       
  1147 
       
  1148 
       
  1149 // -----------------------------------------------------------------------------
       
  1150 // OpenSyncSessionL
       
  1151 // 
       
  1152 // -----------------------------------------------------------------------------
       
  1153 //
       
  1154 void CAspSyncHandler::OpenSyncSessionL()
       
  1155 	{
       
  1156 	if (!iSyncSessionOpen)
       
  1157 		{
       
  1158         TRAPD(err, iSyncSession.OpenL());
       
  1159         
       
  1160         if (err != KErrNone)
       
  1161         	{
       
  1162         	FLOG( _L("### CAspSyncHandler: RSyncMLSession::OpenL failed (%d) ###"), err );
       
  1163         	User::Leave(err);
       
  1164         	}
       
  1165 
       
  1166 		iSyncSessionOpen = ETrue;
       
  1167 		}
       
  1168     }
       
  1169 
       
  1170 
       
  1171 // -----------------------------------------------------------------------------
       
  1172 // CloseSyncSession
       
  1173 // 
       
  1174 // -----------------------------------------------------------------------------
       
  1175 //
       
  1176 void CAspSyncHandler::CloseSyncSession()
       
  1177 	{
       
  1178 	if (iSyncSessionOpen)
       
  1179 		{
       
  1180 		iSyncSession.Close();
       
  1181 		iSyncSessionOpen = EFalse;
       
  1182 		}
       
  1183     }
       
  1184 
       
  1185 
       
  1186 // -----------------------------------------------------------------------------
       
  1187 // ProgressCount
       
  1188 // 
       
  1189 // -----------------------------------------------------------------------------
       
  1190 //
       
  1191 TInt CAspSyncHandler::ProgressCount(const TSyncMLDataSyncModifications& aC, 
       
  1192                                     const TSyncMLDataSyncModifications& aS)
       
  1193 	{
       
  1194 	TInt num1 = aC.iNumAdded + aC.iNumReplaced + aC.iNumMoved + aC.iNumDeleted + aC.iNumFailed;
       
  1195 	TInt num2 = aS.iNumAdded + aS.iNumReplaced + aS.iNumMoved + aS.iNumDeleted + aS.iNumFailed;
       
  1196 	
       
  1197 	return num1 + num2;
       
  1198 	}
       
  1199 	
       
  1200 	
       
  1201 
       
  1202 #ifdef _DEBUG
       
  1203 
       
  1204 
       
  1205 // -----------------------------------------------------------------------------
       
  1206 // LogModificationEvent
       
  1207 //
       
  1208 // -----------------------------------------------------------------------------
       
  1209 //
       
  1210 void CAspSyncHandler::LogModificationEvent(TInt aTaskId, const TSyncMLDataSyncModifications& aC, const TSyncMLDataSyncModifications& aS)
       
  1211 	{
       
  1212 	TInt num1 = State()->Progress();
       
  1213 	TInt num2 = State()->TotalProgress();
       
  1214 	
       
  1215 	if (num1 > num2 && num2 != -1)
       
  1216 		{
       
  1217 		FTRACE( RDebug::Print(_L("### syncui: task=%d, progress=%d, totalprogress=%d ###"), aTaskId, num1, num2) );
       
  1218 		FLOG(_L("### syncui: task=%d, progress=%d, totalprogress=%d ###"), aTaskId, num1, num2);
       
  1219 		}
       
  1220 	else
       
  1221 		{
       
  1222 		FTRACE( RDebug::Print(_L("syncui: task=%d, progress=%d, totalprogress=%d"), aTaskId, num1, num2) );
       
  1223 		FLOG(_L("syncui: task=%d, progress=%d, totalprogress=%d"), aTaskId, num1, num2);
       
  1224 		}
       
  1225 		
       
  1226 	num1 = aC.iNumAdded + aC.iNumReplaced + aC.iNumMoved + aC.iNumDeleted + aC.iNumFailed;
       
  1227 	num2 = aS.iNumAdded + aS.iNumReplaced + aS.iNumMoved + aS.iNumDeleted + aS.iNumFailed;
       
  1228 	
       
  1229 	if ( (num1>0 && num2>0) || (num1<0 || num2<0) || (num1==0 && num2==0) )
       
  1230 		{
       
  1231 		FLOG( _L("### parameter error ###") );
       
  1232 		}
       
  1233 		
       
  1234     FTRACE( RDebug::Print(_L("client: add=%d, rep=%d, mov=%d del=%d fai=%d"), aC.iNumAdded, aC.iNumReplaced, aC.iNumMoved, aC.iNumDeleted, aC.iNumFailed) );
       
  1235     FTRACE( RDebug::Print(_L("server: add=%d, rep=%d, mov=%d del=%d fai=%d"), aS.iNumAdded, aS.iNumReplaced, aS.iNumMoved, aS.iNumDeleted, aS.iNumFailed) );
       
  1236     
       
  1237     FLOG(_L("client: add=%d, rep=%d, mov=%d del=%d fai=%d"), aC.iNumAdded, aC.iNumReplaced, aC.iNumMoved, aC.iNumDeleted, aC.iNumFailed);
       
  1238     FLOG(_L("server: add=%d, rep=%d, mov=%d del=%d fai=%d"), aS.iNumAdded, aS.iNumReplaced, aS.iNumMoved, aS.iNumDeleted, aS.iNumFailed);
       
  1239 	}
       
  1240 
       
  1241 
       
  1242 // -----------------------------------------------------------------------------
       
  1243 // LogModificationEvent
       
  1244 //
       
  1245 // -----------------------------------------------------------------------------
       
  1246 //
       
  1247 void CAspSyncHandler::LogModificationEvent(TInt aTaskId, const TDesC& aText)
       
  1248 	{
       
  1249 	FTRACE( RDebug::Print(_L("progress = 0, task id = %d, task name ='%S'"), aTaskId, &aText) );
       
  1250 	FLOG(_L("progress = 0, task id = %d, task name ='%S'"), aTaskId, &aText);
       
  1251 	}
       
  1252 
       
  1253 
       
  1254 // -----------------------------------------------------------------------------
       
  1255 // LogSessionEvent
       
  1256 //
       
  1257 // -----------------------------------------------------------------------------
       
  1258 //
       
  1259 void CAspSyncHandler::LogSessionEvent(TEvent& aEvent, TInt aIdentifier, TInt aError)
       
  1260 	{
       
  1261     TBuf<KBufSize> eventStr;
       
  1262     GetSyncEventText(eventStr, aEvent);
       
  1263 
       
  1264     TBuf<KBufSize> errStr;
       
  1265     TAspSyncError::GetSyncMLErrorText(errStr, aError);
       
  1266 
       
  1267 	if (aError == KErrNone)
       
  1268 		{
       
  1269 		FTRACE( RDebug::Print(_L("event='%S' err='%S' job= %d curjob= %d"), &eventStr, &errStr, aIdentifier, iCurrentSyncJobId) );
       
  1270 		FLOG(_L("event='%S' err='%S' job= %d curjob= %d"), &eventStr, &errStr, aIdentifier, iCurrentSyncJobId);
       
  1271 		}
       
  1272 	else
       
  1273 		{
       
  1274 		FTRACE( RDebug::Print(_L("### event='%S' err='%S' job= %d curjob= %d ###"), &eventStr, &errStr, aIdentifier, iCurrentSyncJobId) );
       
  1275 		FLOG(_L("### event='%S' err='%S' job= %d curjob= %d ###"), &eventStr, &errStr, aIdentifier, iCurrentSyncJobId);
       
  1276 		}
       
  1277 	}
       
  1278 	
       
  1279 
       
  1280 // -----------------------------------------------------------------------------
       
  1281 // LogProgressEvent
       
  1282 //
       
  1283 // -----------------------------------------------------------------------------
       
  1284 //
       
  1285 void CAspSyncHandler::LogProgressEvent(TStatus& aStatus, TInt aInfo1)
       
  1286 	{
       
  1287     TBuf<KBufSize> statusStr;
       
  1288     GetSyncStatusText(statusStr, aStatus);
       
  1289     FTRACE( RDebug::Print(_L("OnSyncMLSyncProgress: status = '%S' info1 = %d"), &statusStr, aInfo1) );
       
  1290     FLOG(_L("OnSyncMLSyncProgress: status = '%S' info1 = %d"), &statusStr, aInfo1);
       
  1291     
       
  1292    	TInt num1 = State()->Progress();
       
  1293    	TInt num2 = State()->TotalProgress();
       
  1294    	if (num1 != num2 && num2 != -1)
       
  1295    		{
       
  1296    		FTRACE( RDebug::Print(_L("### progress count error (%d/%d) ###"), num1, num2) );
       
  1297    		FLOG(_L("### progress count error (%d/%d) ###"), num1, num2);
       
  1298    		}
       
  1299 	}
       
  1300 	
       
  1301 	
       
  1302 // -----------------------------------------------------------------------------
       
  1303 // LogErrorEvent
       
  1304 //
       
  1305 // -----------------------------------------------------------------------------
       
  1306 //
       
  1307 void CAspSyncHandler::LogErrorEvent(TErrorLevel aErrorLevel, TInt aError)
       
  1308 	{
       
  1309     TBuf<KBufSize> errStr;
       
  1310     TAspSyncError::GetSyncMLErrorText(errStr, aError);
       
  1311     
       
  1312     if (aErrorLevel == ESmlFatalError)
       
  1313     	{
       
  1314     	FTRACE( RDebug::Print(_L("### OnSyncMLSyncError: fatalerror = %S ###"), &errStr) );
       
  1315     	FLOG(_L("### OnSyncMLSyncError: fatalerror = %S ###"), &errStr);
       
  1316     	}
       
  1317     else
       
  1318     	{
       
  1319     	FTRACE( RDebug::Print(_L("### OnSyncMLSyncError: error = %S ###"), &errStr) );
       
  1320     	FLOG(_L("### OnSyncMLSyncError: error = %S ###"), &errStr);
       
  1321     	}
       
  1322 	}
       
  1323 
       
  1324 
       
  1325 
       
  1326 // -----------------------------------------------------------------------------
       
  1327 // GetSyncStatusText
       
  1328 //
       
  1329 // -----------------------------------------------------------------------------
       
  1330 //
       
  1331 void CAspSyncHandler::GetSyncStatusText(TDes& aText, MSyncMLProgressObserver::TStatus aStatus)
       
  1332 	{
       
  1333     aText = _L("Unknown");
       
  1334     		
       
  1335 	if (aStatus == MSyncMLProgressObserver::ESmlConnecting)
       
  1336 		{
       
  1337 		aText = _L("ESmlConnecting");
       
  1338 		}
       
  1339 	if (aStatus == MSyncMLProgressObserver::ESmlConnected)
       
  1340 		{
       
  1341 		aText = _L("ESmlConnected");
       
  1342 		}
       
  1343 	if (aStatus == MSyncMLProgressObserver::ESmlLoggingOn)
       
  1344 		{
       
  1345 		aText = _L("ESmlLoggingOn");
       
  1346 		}
       
  1347 	if (aStatus == MSyncMLProgressObserver::ESmlLoggedOn)
       
  1348 		{
       
  1349 		aText = _L("ESmlLoggedOn");
       
  1350 		}
       
  1351 	if (aStatus == MSyncMLProgressObserver::ESmlDisconnected)
       
  1352 		{
       
  1353 		aText = _L("ESmlDisconnected");
       
  1354 		}
       
  1355 	if (aStatus == MSyncMLProgressObserver::ESmlCompleted)
       
  1356 		{
       
  1357 		aText = _L("ESmlCompleted");
       
  1358 		}
       
  1359 	if (aStatus == MSyncMLProgressObserver::ESmlSendingModificationsToServer)
       
  1360 		{
       
  1361 		aText = _L("ESmlSendingModificationsToServer");
       
  1362 		}
       
  1363 	if (aStatus == MSyncMLProgressObserver::ESmlReceivingModificationsFromServer)
       
  1364 		{
       
  1365 		aText = _L("ESmlReceivingModificationsFromServer");
       
  1366 		}
       
  1367 	if (aStatus == MSyncMLProgressObserver::ESmlSendingMappingsToServer)
       
  1368 		{
       
  1369 		aText = _L("ESmlSendingMappingsToServer");
       
  1370 		}
       
  1371 	}
       
  1372 
       
  1373 
       
  1374 // -----------------------------------------------------------------------------
       
  1375 // GetSyncEventText
       
  1376 //
       
  1377 // -----------------------------------------------------------------------------
       
  1378 //
       
  1379 void CAspSyncHandler::GetSyncEventText(TDes& aText, MSyncMLEventObserver::TEvent aEvent)
       
  1380 	{
       
  1381     aText = _L("Unknown");
       
  1382     		
       
  1383 	if (aEvent == MSyncMLEventObserver::EJobStart)
       
  1384 		{
       
  1385 		aText = _L("EJobStart");
       
  1386 		}
       
  1387 	if (aEvent == MSyncMLEventObserver::EJobStartFailed)
       
  1388 		{
       
  1389 		aText = _L("EJobStartFailed");
       
  1390 		}
       
  1391 	if (aEvent == MSyncMLEventObserver::EJobStop)
       
  1392 		{
       
  1393 		aText = _L("EJobStop");
       
  1394 		}
       
  1395 	if (aEvent == MSyncMLEventObserver::EJobRejected)
       
  1396 		{
       
  1397 		aText = _L("EJobRejected");
       
  1398 		}
       
  1399 	if (aEvent == MSyncMLEventObserver::EProfileCreated)
       
  1400 		{
       
  1401 		aText = _L("EProfileCreated");
       
  1402 		}
       
  1403 	if (aEvent == MSyncMLEventObserver::EProfileChanged)
       
  1404 		{
       
  1405 		aText = _L("EProfileChanged");
       
  1406 		}
       
  1407 	if (aEvent == MSyncMLEventObserver::EProfileDeleted)
       
  1408 		{
       
  1409 		aText = _L("EProfileDeleted");
       
  1410 		}
       
  1411 	if (aEvent == MSyncMLEventObserver::ETransportTimeout)
       
  1412 		{
       
  1413 		aText = _L("ETransportTimeout");
       
  1414 		}
       
  1415 	if (aEvent == MSyncMLEventObserver::EServerSuspended)
       
  1416 		{
       
  1417 		aText = _L("EServerSuspended");
       
  1418 		}
       
  1419 	if (aEvent == MSyncMLEventObserver::EServerTerminated)
       
  1420 		{
       
  1421 		aText = _L("EServerTerminated");
       
  1422 		}
       
  1423 	}
       
  1424 
       
  1425 #endif
       
  1426 
       
  1427 
       
  1428 
       
  1429 
       
  1430 
       
  1431 // End of file
       
  1432