omads/omadsappui/AspSyncUtil/src/AspSchedule.cpp
branchRCL_3
changeset 52 4f0867e42d62
parent 0 dab8a81a92de
equal deleted inserted replaced
51:8e7494275d3a 52:4f0867e42d62
       
     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 // INCLUDE FILES
       
    21 
       
    22 #include "AspSchedule.h"
       
    23 #include "AspUtil.h"
       
    24 #include "AspDialogUtil.h"
       
    25 #include "AspDebug.h"
       
    26 #include "AspProfile.h"
       
    27 #include "AspLogDialog.h"
       
    28 #include "AspAutoSyncHandler.h"
       
    29 
       
    30 #include "schinfo.h" // TScheduleEntryInfo2
       
    31 #include <s32mem.h>  // RDesWriteStream
       
    32 #include <s32file.h> // RFileReadStream
       
    33 #include <bautils.h> // BaflUtils
       
    34 #include <centralrepository.h>  // CRepository
       
    35 #include <rconnmon.h>
       
    36 #include <SyncMLClientDS.h>
       
    37 
       
    38 
       
    39 
       
    40 /*******************************************************************************
       
    41  * class CAspSchedule
       
    42  *******************************************************************************/
       
    43 
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CAspSchedule::NewL
       
    47 //
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 CAspSchedule* CAspSchedule::NewL()
       
    51     {
       
    52     CAspSchedule* self = new (ELeave) CAspSchedule();
       
    53     CleanupStack::PushL(self);
       
    54     self->ConstructL();
       
    55     CleanupStack::Pop(self);
       
    56 
       
    57     return(self);
       
    58     }
       
    59 
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // CAspSchedule::NewLC
       
    63 //
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 CAspSchedule* CAspSchedule::NewLC()
       
    67     {
       
    68     CAspSchedule* self = new (ELeave) CAspSchedule();
       
    69     CleanupStack::PushL(self);
       
    70     self->ConstructL();
       
    71 
       
    72     return(self);
       
    73     }
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // CAspSchedule::CAspSchedule
       
    77 // 
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 CAspSchedule::CAspSchedule()
       
    81 	{
       
    82 	iSettingChanged = EFalse;
       
    83 	iSyncSessionOpen = EFalse;
       
    84     }
       
    85 
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // CAspSchedule::ConstructL
       
    89 //
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 void CAspSchedule::ConstructL()
       
    93     {
       
    94     InternalizeL();
       
    95 	
       
    96 	if(iAutoSyncProfileId == KErrNotFound)
       
    97 		{
       
    98 		CreateAutoSyncProfileL();
       
    99 		}
       
   100 	
       
   101 		
       
   102     } 
       
   103 
       
   104 
       
   105 // ----------------------------------------------------------------------------
       
   106 // Destructor
       
   107 //
       
   108 // ----------------------------------------------------------------------------
       
   109 //
       
   110 CAspSchedule::~CAspSchedule()
       
   111     {
       
   112     iList.Close();
       
   113 	CloseSyncSession();
       
   114     }
       
   115 
       
   116 
       
   117 // ----------------------------------------------------------------------------
       
   118 // InitializeL
       
   119 //
       
   120 // ----------------------------------------------------------------------------
       
   121 //
       
   122 void CAspSchedule::InitializeL()
       
   123     {
       
   124     
       
   125     FLOG( _L("CAspSchedule::InitializeL START") );
       
   126     iError          = KErrNone;
       
   127     iProfileId      = KErrNotFound;
       
   128     iRoamingAllowed = EFalse;
       
   129 	iDailySyncEnabled = EFalse;
       
   130 	iPeakSyncEnabled = EFalse;
       
   131 	iOffPeakSyncEnabled = EFalse;
       
   132 	
       
   133 
       
   134 	iContentFlags = 0xFF;
       
   135 	iSyncFrequency          = EIntervalManual;
       
   136 	iSyncPeakSchedule       = EIntervalManual;
       
   137     iSyncOffPeakSchedule    = EIntervalManual;
       
   138 
       
   139     iPeakScheduleHandle = KErrNotFound;
       
   140 	iOffPeakScheduleHandle = KErrNotFound;
       
   141 
       
   142 	iStartPeakTimeHr		 = KStartPeakHour;
       
   143 	iStartPeakTimeMin		 = KStartPeakMin;
       
   144 	iEndPeakTimeHr         = KEndPeakHour;
       
   145 	iEndPeakTimeMin         = KEndPeakMin;
       
   146 
       
   147 	iAutoSyncProfileId = KErrNotFound;
       
   148 	iAutoSyncScheduleTimeHr = KDefaultStartHour;
       
   149 	iAutoSyncScheduleTimeMin = 0;
       
   150 
       
   151 	SetWeekdayEnabled(EMonday,    ETrue);
       
   152    	SetWeekdayEnabled(ETuesday,   ETrue);
       
   153    	SetWeekdayEnabled(EWednesday, ETrue);
       
   154    	SetWeekdayEnabled(EThursday,  ETrue);
       
   155    	SetWeekdayEnabled(EFriday,    ETrue);
       
   156    	SetWeekdayEnabled(ESaturday,  EFalse);
       
   157    	SetWeekdayEnabled(ESunday,    EFalse);
       
   158 
       
   159 	InitializeContentsL();
       
   160 	FLOG( _L("CAspSchedule::InitializeL END") );
       
   161 
       
   162     }
       
   163 
       
   164 // ----------------------------------------------------------------------------
       
   165 // InitializeContentsL
       
   166 //
       
   167 // ----------------------------------------------------------------------------
       
   168 //
       
   169 void CAspSchedule::InitializeContentsL()
       
   170 	{
       
   171 	OpenSyncSessionL();
       
   172 	TAspParam param(EApplicationIdSync, &iSyncSession);
       
   173 	param.iMode = CAspContentList::EInitDataProviders;
       
   174 	CAspContentList* asContentList = CAspContentList::NewLC(param);		
       
   175 	
       
   176 	TInt providerCount = asContentList->ProviderCount();
       
   177 	
       
   178 	for (TInt index = 0; index < providerCount; index++)
       
   179 		{
       
   180 		TAspProviderItem& provider = asContentList->ProviderItem(index);
       
   181 			
       
   182 		if (provider.iDataProviderId == KUidNSmlAdapterEMail.iUid)
       
   183 			{
       
   184 			if (MailboxExistL())
       
   185 				{
       
   186 				SetContentEnabled(index, ETrue);
       
   187 				}
       
   188 			else
       
   189 				{
       
   190 				SetContentEnabled(index, EFalse);
       
   191 				}
       
   192 			}
       
   193 		else
       
   194 			{
       
   195 			SetContentEnabled(index, ETrue);
       
   196 			}
       
   197 		
       
   198 		}
       
   199 	CleanupStack::PopAndDestroy(asContentList);
       
   200 
       
   201 
       
   202 	}
       
   203 
       
   204 // -----------------------------------------------------------------------------
       
   205 // CAspSchedule::DoInternalizeL
       
   206 //
       
   207 // -----------------------------------------------------------------------------
       
   208 //
       
   209 void CAspSchedule::DoInternalizeL()
       
   210 	{
       
   211 	const TInt KMaxLength = 1024;
       
   212 	
       
   213     HBufC8*  hBuf = HBufC8::NewLC(KMaxLength);
       
   214     TPtr8 ptr = hBuf->Des();
       
   215     
       
   216     ReadRepositoryL(ERepositoryKeyBin, ptr);
       
   217     
       
   218     RDesReadStream stream(ptr);
       
   219     stream.PushL();
       
   220     
       
   221     InternalizeL(stream);
       
   222     
       
   223     stream.Pop();
       
   224     stream.Close();
       
   225     
       
   226     CleanupStack::PopAndDestroy(hBuf);
       
   227 	}
       
   228 
       
   229 
       
   230 // -----------------------------------------------------------------------------
       
   231 // CAspSchedule::InternalizeL
       
   232 //
       
   233 // -----------------------------------------------------------------------------
       
   234 //
       
   235 void CAspSchedule::InternalizeL()
       
   236 	{
       
   237 	FLOG( _L("CAspSchedule::InternalizeL START") );
       
   238 	TRAPD(err, DoInternalizeL());
       
   239 	
       
   240 	if (err == KErrNoMemory || err == KErrLocked || err == KErrAlreadyExists)
       
   241 		{
       
   242 		FLOG( _L("CAspSchedule::InternalizeL Error 1:  %d"),err );
       
   243 		User::Leave(err);
       
   244 		}
       
   245 		
       
   246 	else if (err != KErrNone)
       
   247 		{
       
   248 		FLOG( _L("CAspSchedule::InternalizeL Error 2:  %d"),err );
       
   249 		ResetRepositoryL();  // settings corrupted
       
   250 	    InitializeL();
       
   251 		}
       
   252 	}
       
   253 
       
   254 
       
   255 // -----------------------------------------------------------------------------
       
   256 // CAspSchedule::InternalizeL
       
   257 //
       
   258 // -----------------------------------------------------------------------------
       
   259 //
       
   260 void CAspSchedule::InternalizeL(RReadStream& aStream)
       
   261 	{
       
   262 	const TInt KAutoSyncSettingCount = 20;
       
   263 	
       
   264     iList.Reset();
       
   265     
       
   266     // total setting count
       
   267 	TInt32 count = 0;
       
   268 	
       
   269 	TRAPD(err, count = aStream.ReadInt32L());
       
   270 	
       
   271 	if (err != KErrNone && err != KErrEof)
       
   272 		{
       
   273 		User::Leave(err);
       
   274 		}
       
   275 	
       
   276 	if (count != KAutoSyncSettingCount)
       
   277 		{
       
   278 		InitializeL(); // settings not found - use defaults
       
   279 		SaveL();
       
   280 		return;
       
   281 		}
       
   282     
       
   283     
       
   284     iError                 = aStream.ReadInt32L();
       
   285     iProfileId             = aStream.ReadInt32L();
       
   286     iWeekdayFlags          = aStream.ReadInt32L();
       
   287     TInt roamingAllowed    = aStream.ReadInt32L();
       
   288 
       
   289 
       
   290 	
       
   291 	iPeakScheduleHandle = aStream.ReadInt32L();
       
   292 	iOffPeakScheduleHandle = aStream.ReadInt32L();
       
   293 	iContentFlags           = aStream.ReadInt32L();
       
   294 	iSyncPeakSchedule       = aStream.ReadInt32L();
       
   295     iSyncOffPeakSchedule    = aStream.ReadInt32L();
       
   296 	iStartPeakTimeHr		= aStream.ReadInt32L();
       
   297 	iStartPeakTimeMin		= aStream.ReadInt32L();
       
   298 	iEndPeakTimeHr          = aStream.ReadInt32L();
       
   299 	iEndPeakTimeMin         = aStream.ReadInt32L();
       
   300 	iSyncFrequency          = aStream.ReadInt32L();
       
   301 	iDailySyncEnabled 			= aStream.ReadInt32L();
       
   302 	iPeakSyncEnabled        = aStream.ReadInt32L();
       
   303 	iOffPeakSyncEnabled		= aStream.ReadInt32L();
       
   304 
       
   305 	iAutoSyncProfileId		= aStream.ReadInt32L();
       
   306 	
       
   307 	iAutoSyncScheduleTimeHr = aStream.ReadInt32L();
       
   308 	iAutoSyncScheduleTimeMin = aStream.ReadInt32L();
       
   309 	
       
   310 #ifdef _DEBUG
       
   311     LogSettings();
       
   312 #endif
       
   313 
       
   314     iRoamingAllowed = EFalse;
       
   315     if (roamingAllowed)
       
   316     	{
       
   317     	iRoamingAllowed = ETrue;
       
   318     	}
       
   319 
       
   320 	CheckEmailSelectionL();
       
   321     }   
       
   322 
       
   323 // -----------------------------------------------------------------------------
       
   324 // CAspSchedule::CheckEmailSelectionL()
       
   325 //
       
   326 // -----------------------------------------------------------------------------
       
   327 //
       
   328 void CAspSchedule::CheckEmailSelectionL()
       
   329 	{
       
   330 	TRAPD(err, OpenSyncSessionL());
       
   331 	if (err != KErrNone)
       
   332 		{
       
   333 		
       
   334 		/*OpenSynSessionL() may leave when system time is changed so that peak and off-peak syncs are
       
   335 		scheduled simulataneously.In that case also next sync time has to be updated. So a leave here should be
       
   336 		trapped and return to the time update function.	
       
   337 		*/
       
   338 		
       
   339 		FLOG( _L("Session cannot be opened now : return") );
       
   340 		return;
       
   341 		}
       
   342 	TAspParam param(EApplicationIdSync, &iSyncSession);
       
   343 	param.iMode = CAspContentList::EInitDataProviders;
       
   344 	CAspContentList* asContentList = CAspContentList::NewLC(param);		
       
   345 	
       
   346 	TInt providerCount = asContentList->ProviderCount();
       
   347 
       
   348 	TInt emailIndex = asContentList->FindProviderIndex(KUidNSmlAdapterEMail.iUid);
       
   349 					
       
   350 	if (!MailboxExistL())
       
   351 		{
       
   352 		SetContentEnabled(emailIndex, EFalse);
       
   353 		}
       
   354 	else if (!IsAutoSyncEnabled())
       
   355 		{
       
   356 		SetContentEnabled(emailIndex, ETrue);
       
   357 		}
       
   358 
       
   359 	if (iProfileId != KErrNotFound
       
   360 		 					&& !ProtocolL())
       
   361 		{
       
   362 		SetContentEnabled(emailIndex, EFalse);
       
   363 		}
       
   364 	
       
   365 	CleanupStack::PopAndDestroy(asContentList);
       
   366 
       
   367 	}
       
   368 	
       
   369 
       
   370 
       
   371 // -----------------------------------------------------------------------------
       
   372 // CAspSchedule::ExternalizeL
       
   373 //
       
   374 // -----------------------------------------------------------------------------
       
   375 //
       
   376 void CAspSchedule::ExternalizeL()
       
   377 	{
       
   378 	const TInt KMaxLength = 1024;
       
   379 	
       
   380     HBufC8*  hBuf = HBufC8::NewLC(KMaxLength);
       
   381     TPtr8 ptr = hBuf->Des();
       
   382     RDesWriteStream stream(ptr);
       
   383     stream.PushL();
       
   384     
       
   385     ExternalizeL(stream);
       
   386     
       
   387     stream.CommitL();
       
   388     stream.Pop();
       
   389     stream.Close();
       
   390     
       
   391     TRAPD (err,WriteRepositoryL(ERepositoryKeyBin, ptr));
       
   392 	User::LeaveIfError(err);
       
   393     
       
   394     CleanupStack::PopAndDestroy(hBuf);
       
   395 	}
       
   396 
       
   397 
       
   398 // -----------------------------------------------------------------------------
       
   399 // CAspSchedule::ExternalizeL
       
   400 //
       
   401 // -----------------------------------------------------------------------------
       
   402 //
       
   403 void CAspSchedule::ExternalizeL(RWriteStream& aStream)
       
   404 	{
       
   405 	const TInt KAutoSyncSettingCount = 20;
       
   406 	
       
   407         
       
   408     TInt roamingAllowed = 0;
       
   409     if (iRoamingAllowed)
       
   410     	{
       
   411     	roamingAllowed = 1;
       
   412     	}
       
   413     
       
   414    
       
   415     aStream.WriteInt32L(KAutoSyncSettingCount);
       
   416 	aStream.WriteInt32L(iError);
       
   417     aStream.WriteInt32L(iProfileId);
       
   418     aStream.WriteInt32L(iWeekdayFlags);
       
   419     aStream.WriteInt32L(roamingAllowed);
       
   420 
       
   421 	aStream.WriteInt32L(iPeakScheduleHandle);
       
   422 	aStream.WriteInt32L(iOffPeakScheduleHandle);
       
   423     aStream.WriteInt32L(iContentFlags);
       
   424 	aStream.WriteInt32L(iSyncPeakSchedule);
       
   425 	aStream.WriteInt32L(iSyncOffPeakSchedule);
       
   426 	aStream.WriteInt32L(iStartPeakTimeHr);
       
   427 	aStream.WriteInt32L(iStartPeakTimeMin);
       
   428 	aStream.WriteInt32L(iEndPeakTimeHr);
       
   429    	aStream.WriteInt32L(iEndPeakTimeMin);
       
   430 	aStream.WriteInt32L(iSyncFrequency);
       
   431 	aStream.WriteInt32L(iDailySyncEnabled);
       
   432 	aStream.WriteInt32L(iPeakSyncEnabled);
       
   433 	aStream.WriteInt32L(iOffPeakSyncEnabled);
       
   434 	aStream.WriteInt32L(iAutoSyncProfileId);
       
   435 
       
   436     aStream.WriteInt32L(iAutoSyncScheduleTimeHr);
       
   437 	aStream.WriteInt32L(iAutoSyncScheduleTimeMin);
       
   438 
       
   439 #ifdef _DEBUG
       
   440 	LogSettings();
       
   441 #endif
       
   442 
       
   443 	
       
   444 	}
       
   445 
       
   446 
       
   447 // -----------------------------------------------------------------------------
       
   448 // CAspSchedule::WriteRepositoryL
       
   449 //
       
   450 // -----------------------------------------------------------------------------
       
   451 //
       
   452 void CAspSchedule::WriteRepositoryL(TInt aKey, const TDesC8& aValue)
       
   453 	{
       
   454 	const TUid KRepositoryId = KCRUidNSmlDSApp; // 0x101F9A1D
       
   455 
       
   456     CRepository* rep = CRepository::NewLC(KRepositoryId);
       
   457     TInt err = rep->Set(aKey, aValue);
       
   458     User::LeaveIfError(err);
       
   459     
       
   460     CleanupStack::PopAndDestroy(rep);
       
   461 	}
       
   462 
       
   463 
       
   464 // -----------------------------------------------------------------------------
       
   465 // CAspSchedule::ReadRepositoryL
       
   466 //
       
   467 // -----------------------------------------------------------------------------
       
   468 //
       
   469 void CAspSchedule::ReadRepositoryL(TInt aKey, TDes8& aValue)
       
   470 	{
       
   471 	const TUid KRepositoryId = KCRUidNSmlDSApp;
       
   472 
       
   473     CRepository* rep = CRepository::NewLC(KRepositoryId);
       
   474     TInt err = rep->Get(aKey, aValue);
       
   475     User::LeaveIfError(err);
       
   476     
       
   477     CleanupStack::PopAndDestroy(rep);
       
   478 	}
       
   479 
       
   480 
       
   481 // -----------------------------------------------------------------------------
       
   482 // CAspSchedule::ResetRepositoryL
       
   483 //
       
   484 // -----------------------------------------------------------------------------
       
   485 //
       
   486 void CAspSchedule::ResetRepositoryL()
       
   487 	{
       
   488 	const TUid KRepositoryId = KCRUidNSmlDSApp;
       
   489 
       
   490     CRepository* rep = CRepository::NewLC(KRepositoryId);
       
   491     TInt err = rep->Reset();
       
   492     User::LeaveIfError(err);
       
   493     
       
   494     CleanupStack::PopAndDestroy(rep);
       
   495 	}
       
   496 
       
   497 
       
   498 // -----------------------------------------------------------------------------
       
   499 // CAspSchedule::SaveL
       
   500 //
       
   501 // -----------------------------------------------------------------------------
       
   502 //
       
   503 void CAspSchedule::SaveL()
       
   504 	{
       
   505 	ExternalizeL();
       
   506 	}
       
   507 
       
   508 // -----------------------------------------------------------------------------
       
   509 // CAspSchedule::PeakScheduleHandle
       
   510 //
       
   511 // -----------------------------------------------------------------------------
       
   512 //
       
   513 TInt CAspSchedule::PeakScheduleHandle()
       
   514 	{
       
   515 	return iPeakScheduleHandle;
       
   516 	}
       
   517 
       
   518 // -----------------------------------------------------------------------------
       
   519 // CAspSchedule::SetPeakScheduleHandle
       
   520 //
       
   521 // -----------------------------------------------------------------------------
       
   522 //
       
   523 void CAspSchedule::SetPeakScheduleHandle(TInt aScheduleHandle)
       
   524 	{
       
   525 	iPeakScheduleHandle = aScheduleHandle;
       
   526 	}
       
   527 
       
   528 
       
   529 // -----------------------------------------------------------------------------
       
   530 // CAspSchedule::SetPeakScheduleHandle
       
   531 //
       
   532 // -----------------------------------------------------------------------------
       
   533 //
       
   534 TInt CAspSchedule::OffPeakScheduleHandle()
       
   535 	{
       
   536 	return iOffPeakScheduleHandle;
       
   537 	}
       
   538 
       
   539 
       
   540 // -----------------------------------------------------------------------------
       
   541 // CAspSchedule::SetPeakScheduleHandle
       
   542 //
       
   543 // -----------------------------------------------------------------------------
       
   544 //
       
   545 void CAspSchedule::SetOffPeakScheduleHandle(TInt aScheduleHandle)
       
   546 	{
       
   547 	iOffPeakScheduleHandle = aScheduleHandle;
       
   548 	}
       
   549 
       
   550 
       
   551 // -----------------------------------------------------------------------------
       
   552 // CAspSchedule::ProfileId
       
   553 //
       
   554 // -----------------------------------------------------------------------------
       
   555 //
       
   556 TInt CAspSchedule::ProfileId()
       
   557 	{
       
   558 	return iProfileId;
       
   559 	}
       
   560 
       
   561 
       
   562 // -----------------------------------------------------------------------------
       
   563 // CAspSchedule::SetProfileId
       
   564 //
       
   565 // -----------------------------------------------------------------------------
       
   566 //
       
   567 void CAspSchedule::SetProfileId(TInt aProfileId)
       
   568 	{
       
   569 	iProfileId = aProfileId;
       
   570 	}
       
   571 
       
   572 // -----------------------------------------------------------------------------
       
   573 // CAspSchedule::DailySyncEnabled
       
   574 //
       
   575 // -----------------------------------------------------------------------------
       
   576 //
       
   577 TBool CAspSchedule::DailySyncEnabled()
       
   578 	{
       
   579 	return iDailySyncEnabled;
       
   580 	}
       
   581 
       
   582 // -----------------------------------------------------------------------------
       
   583 // CAspSchedule::SetDailySyncEnabled
       
   584 //
       
   585 // -----------------------------------------------------------------------------
       
   586 //
       
   587 void CAspSchedule::SetDailySyncEnabled(TBool aSyncEnabled)
       
   588 	{
       
   589 	iDailySyncEnabled = aSyncEnabled;
       
   590 	}
       
   591 
       
   592 
       
   593 // -----------------------------------------------------------------------------
       
   594 // CAspSchedule::PeakSyncEnabled
       
   595 //
       
   596 // -----------------------------------------------------------------------------
       
   597 //
       
   598 TBool CAspSchedule::PeakSyncEnabled()
       
   599 	{
       
   600 	return iPeakSyncEnabled;
       
   601 	}
       
   602 
       
   603 // -----------------------------------------------------------------------------
       
   604 // CAspSchedule::SetPeakSyncEnabled
       
   605 //
       
   606 // -----------------------------------------------------------------------------
       
   607 //
       
   608 void CAspSchedule::SetPeakSyncEnabled(TBool aSyncEnabled)
       
   609 	{
       
   610 	iPeakSyncEnabled = aSyncEnabled;
       
   611 	}
       
   612 // -----------------------------------------------------------------------------
       
   613 // CAspSchedule::OffPeakSyncEnabled
       
   614 //
       
   615 // -----------------------------------------------------------------------------
       
   616 //
       
   617 
       
   618 TBool CAspSchedule::OffPeakSyncEnabled()
       
   619 	{
       
   620 	return iOffPeakSyncEnabled;
       
   621 	}
       
   622 
       
   623 // -----------------------------------------------------------------------------
       
   624 // CAspSchedule::SetOffPeakSyncEnabled
       
   625 //
       
   626 // -----------------------------------------------------------------------------
       
   627 //
       
   628 void CAspSchedule::SetOffPeakSyncEnabled(TBool aSyncEnabled)
       
   629 	{
       
   630 	iOffPeakSyncEnabled = aSyncEnabled;
       
   631 	}
       
   632 
       
   633 
       
   634 // -----------------------------------------------------------------------------
       
   635 // CAspSchedule::WeekdayEnabled
       
   636 //
       
   637 // -----------------------------------------------------------------------------
       
   638 //
       
   639 TBool CAspSchedule::WeekdayEnabled(TInt aWeekday)
       
   640 	{
       
   641 	TInt dayFlag = WeekdayFlag(aWeekday);
       
   642 	
       
   643 	TFlag flag(iWeekdayFlags);
       
   644 	
       
   645 	return flag.IsOn(dayFlag);
       
   646 	}
       
   647 
       
   648 
       
   649 // -----------------------------------------------------------------------------
       
   650 // CAspSchedule::SetWeekdayEnabled
       
   651 //
       
   652 // -----------------------------------------------------------------------------
       
   653 //
       
   654 void CAspSchedule::SetWeekdayEnabled(TInt aWeekday, TInt aEnabled)
       
   655 	{
       
   656 	TInt dayFlag = WeekdayFlag(aWeekday);
       
   657 	
       
   658 	TFlag flag(iWeekdayFlags);
       
   659 	
       
   660 	if (aEnabled)
       
   661 		{
       
   662 		flag.SetOn(dayFlag);
       
   663 		}
       
   664 	else
       
   665 		{
       
   666 		flag.SetOff(dayFlag);
       
   667 		}
       
   668 	iSettingChanged = ETrue;
       
   669 	}
       
   670 
       
   671 
       
   672 // -----------------------------------------------------------------------------
       
   673 // CAspSchedule::WeekdayFlag
       
   674 //
       
   675 // -----------------------------------------------------------------------------
       
   676 //
       
   677 TInt CAspSchedule::WeekdayFlag(TInt aWeekday)
       
   678 	{
       
   679 	TInt ret = EFlagMonday;
       
   680 	
       
   681 	switch (aWeekday)
       
   682 		{
       
   683 		case EMonday:
       
   684 		    ret = EFlagMonday;
       
   685 		    break;
       
   686 		case ETuesday:
       
   687 		    ret = EFlagTuesday;
       
   688 		    break;
       
   689 		case EWednesday:
       
   690 		    ret = EFlagWednesday;
       
   691 		    break;
       
   692 		case EThursday:
       
   693 		    ret = EFlagThursday;
       
   694 		    break;
       
   695 		case EFriday:
       
   696 		    ret = EFlagFriday;
       
   697 		    break;
       
   698 		case ESaturday:
       
   699 		    ret = EFlagSaturday;
       
   700 		    break;
       
   701 		case ESunday:
       
   702 		    ret = EFlagSunday;
       
   703 		    break;
       
   704 		default:
       
   705 		    TUtil::Panic(KErrArgument);
       
   706 		    break;
       
   707 		}
       
   708 		
       
   709 	return ret;
       
   710 	}
       
   711 
       
   712 
       
   713 // -----------------------------------------------------------------------------
       
   714 // CAspSchedule::SelectedDayInfo
       
   715 //
       
   716 // -----------------------------------------------------------------------------
       
   717 //
       
   718 void CAspSchedule::SelectedDayInfo(TInt& aDayCount, TInt& aWeekday)
       
   719 	{
       
   720 	aDayCount = 0;
       
   721 
       
   722 	for (TInt i=EMonday; i<=ESunday; i++)
       
   723 		{
       
   724 		if (WeekdayEnabled(i))
       
   725 			{
       
   726 			aDayCount++;
       
   727 			aWeekday = i;
       
   728 			}
       
   729 		}
       
   730 	}
       
   731 
       
   732 // -----------------------------------------------------------------------------
       
   733 // CAspSchedule::SetContentEnabled
       
   734 //
       
   735 // -----------------------------------------------------------------------------
       
   736 //
       
   737 void CAspSchedule::SetContentEnabled(TInt aContent, TInt aEnabled)
       
   738 	{
       
   739 	TInt contentFlag = 1 << aContent;
       
   740 	TFlag flag(iContentFlags);
       
   741 	if (aEnabled)
       
   742 		{
       
   743 		flag.SetOn(contentFlag);
       
   744 		}
       
   745 	else
       
   746 		{
       
   747 		flag.SetOff(contentFlag);
       
   748 		}
       
   749 	iSettingChanged = ETrue;
       
   750 	}
       
   751 
       
   752 // -----------------------------------------------------------------------------
       
   753 // CAspSchedule::ContentEnabled
       
   754 // 
       
   755 // -----------------------------------------------------------------------------
       
   756 //
       
   757 
       
   758 TBool CAspSchedule::ContentEnabled(TInt aContent)
       
   759 	{
       
   760 	TInt contentFlag = 1 << aContent;
       
   761 	TFlag flag(iContentFlags);
       
   762 	return flag.IsOn(contentFlag);
       
   763 	}
       
   764 
       
   765 // -----------------------------------------------------------------------------
       
   766 // CAspSchedule::ContentSelectionInfo
       
   767 //
       
   768 // -----------------------------------------------------------------------------
       
   769 //
       
   770 
       
   771 void CAspSchedule::ContentSelectionInfo(TInt& aContentCnt, TInt& aContent)
       
   772 	{
       
   773 	aContentCnt = 0;
       
   774 	OpenSyncSessionL();
       
   775 	TAspParam param(EApplicationIdSync, &iSyncSession);
       
   776 	param.iMode = CAspContentList::EInitDataProviders;
       
   777 	CAspContentList* asContentList = CAspContentList::NewLC(param);		
       
   778 	
       
   779 	//contents are saved in the sorted order of data providers
       
   780 	TInt providerCount = asContentList->ProviderCount();
       
   781 	for (TInt i= 0; i < providerCount; i++)
       
   782 		{
       
   783 		if (ContentEnabled(i))
       
   784 			{
       
   785 			aContentCnt++;
       
   786 			aContent = i;
       
   787 			}
       
   788 		}
       
   789 	CleanupStack::PopAndDestroy(asContentList);
       
   790 	
       
   791 	}	
       
   792 	
       
   793 
       
   794 // -----------------------------------------------------------------------------
       
   795 // CAspSchedule::StartPeakTime
       
   796 //
       
   797 // -----------------------------------------------------------------------------
       
   798 //
       
   799 
       
   800 TTime CAspSchedule::StartPeakTime()
       
   801 	{
       
   802 	TDateTime time(0, EJanuary, 0, iStartPeakTimeHr, iStartPeakTimeMin, 0, 0);
       
   803 	TTime startTime(time);
       
   804 	return startTime;
       
   805 	}
       
   806 
       
   807 
       
   808 // -----------------------------------------------------------------------------
       
   809 // CAspSchedule::SetStartPeakTime
       
   810 //
       
   811 // -----------------------------------------------------------------------------
       
   812 //
       
   813 
       
   814 void CAspSchedule::SetStartPeakTime(TTime aStartTime)
       
   815 	{
       
   816 	TDateTime startTime  = aStartTime.DateTime();
       
   817 	if (iStartPeakTimeHr != startTime.Hour() || iStartPeakTimeMin != startTime.Minute())
       
   818 		{
       
   819 		iStartPeakTimeHr = startTime.Hour();
       
   820 		iStartPeakTimeMin = startTime.Minute();
       
   821 		iSettingChanged = ETrue;
       
   822 		}
       
   823 	}
       
   824 
       
   825 // -----------------------------------------------------------------------------
       
   826 // CAspSchedule::EndPeakTime
       
   827 //
       
   828 // -----------------------------------------------------------------------------
       
   829 //
       
   830 
       
   831 
       
   832 TTime CAspSchedule::EndPeakTime()
       
   833 	{
       
   834 	TDateTime time(0, EJanuary, 0, iEndPeakTimeHr, iEndPeakTimeMin, 0, 0);
       
   835 	TTime endTime(time);
       
   836 	return endTime;
       
   837 	}
       
   838 
       
   839 // -----------------------------------------------------------------------------
       
   840 // CAspSchedule::SetEndPeakTime
       
   841 //
       
   842 // -----------------------------------------------------------------------------
       
   843 //
       
   844 
       
   845 void CAspSchedule::SetEndPeakTime(TTime aEndTime)
       
   846 	{
       
   847 	TDateTime endTime  = aEndTime.DateTime();
       
   848 	
       
   849 	if (iEndPeakTimeHr != endTime.Hour() || iEndPeakTimeMin != endTime.Minute())
       
   850 		{
       
   851 		iEndPeakTimeHr = endTime.Hour();
       
   852 		iEndPeakTimeMin = endTime.Minute();
       
   853 		iSettingChanged = ETrue;
       
   854 		}
       
   855 	}
       
   856 
       
   857 // -----------------------------------------------------------------------------
       
   858 // CAspSchedule::SyncFrequency
       
   859 //
       
   860 // -----------------------------------------------------------------------------
       
   861 //
       
   862 
       
   863 TInt CAspSchedule::SyncFrequency()
       
   864 	{
       
   865 	return iSyncFrequency;
       
   866 	}
       
   867 
       
   868 // -----------------------------------------------------------------------------
       
   869 // CAspSchedule::SetSyncFrequency
       
   870 //
       
   871 // -----------------------------------------------------------------------------
       
   872 //
       
   873 
       
   874 void CAspSchedule::SetSyncFrequency(TInt aSchedule)
       
   875 	{
       
   876 	if (aSchedule != iSyncFrequency)
       
   877 		{
       
   878 		iSyncFrequency = aSchedule;
       
   879 		iSettingChanged = ETrue;
       
   880 		}
       
   881 	}
       
   882 
       
   883 // -----------------------------------------------------------------------------
       
   884 // CAspSchedule::SyncPeakSchedule
       
   885 //
       
   886 // -----------------------------------------------------------------------------
       
   887 //
       
   888 
       
   889 TInt CAspSchedule::SyncPeakSchedule()
       
   890 	{
       
   891 	return iSyncPeakSchedule;
       
   892 	}
       
   893 
       
   894 // -----------------------------------------------------------------------------
       
   895 // CAspSchedule::SetSyncPeakSchedule
       
   896 //
       
   897 // -----------------------------------------------------------------------------
       
   898 //
       
   899 
       
   900 void CAspSchedule::SetSyncPeakSchedule(TInt aSchedule)
       
   901 	{
       
   902 	if (aSchedule != iSyncPeakSchedule)
       
   903 		{
       
   904 		iSyncPeakSchedule = aSchedule;
       
   905 		iSettingChanged = ETrue;
       
   906 		}
       
   907 	}
       
   908 
       
   909 // -----------------------------------------------------------------------------
       
   910 // CAspSchedule::SyncOffPeakSchedule
       
   911 //
       
   912 // -----------------------------------------------------------------------------
       
   913 //
       
   914 
       
   915 TInt CAspSchedule::SyncOffPeakSchedule()
       
   916 	{
       
   917 	return iSyncOffPeakSchedule;
       
   918 	}
       
   919 
       
   920 // -----------------------------------------------------------------------------
       
   921 // CAspSchedule::SetSyncOffPeakSchedule
       
   922 //
       
   923 // -----------------------------------------------------------------------------
       
   924 //
       
   925 
       
   926 void CAspSchedule::SetSyncOffPeakSchedule(TInt aSchedule)
       
   927 	{
       
   928 	if (aSchedule != iSyncOffPeakSchedule)
       
   929 		{
       
   930 		iSyncOffPeakSchedule = aSchedule;
       
   931 		iSettingChanged = ETrue;
       
   932 		}
       
   933 	}
       
   934 
       
   935 // -----------------------------------------------------------------------------
       
   936 // CAspSchedule::AutoSyncScheduleTime
       
   937 //
       
   938 // -----------------------------------------------------------------------------
       
   939 //
       
   940 
       
   941 TTime CAspSchedule::AutoSyncScheduleTime()
       
   942 	{
       
   943 	TDateTime time(0, EJanuary, 0, iAutoSyncScheduleTimeHr, iAutoSyncScheduleTimeMin, 0, 0);
       
   944 	TTime scheduleTime(time);
       
   945 	return scheduleTime;
       
   946 	}
       
   947 
       
   948 // -----------------------------------------------------------------------------
       
   949 // CAspSchedule::SetAutoSyncScheduleTime
       
   950 //
       
   951 // -----------------------------------------------------------------------------
       
   952 //
       
   953 
       
   954 void CAspSchedule::SetAutoSyncScheduleTime(TTime aSchedule)
       
   955 	{
       
   956 	TDateTime schedule  = aSchedule.DateTime();
       
   957 	
       
   958 	//To do- check value
       
   959 	if (iAutoSyncScheduleTimeHr != schedule.Hour() || iAutoSyncScheduleTimeMin != schedule.Minute())
       
   960 		{
       
   961 		iAutoSyncScheduleTimeHr = schedule.Hour();
       
   962 		iAutoSyncScheduleTimeMin = schedule.Minute();
       
   963 		iSettingChanged = ETrue;
       
   964 		}
       
   965 	}
       
   966 
       
   967 
       
   968 // -----------------------------------------------------------------------------
       
   969 // CAspSchedule::RoamingAllowed
       
   970 //
       
   971 // -----------------------------------------------------------------------------
       
   972 //
       
   973 TBool CAspSchedule::RoamingAllowed()
       
   974 	{
       
   975 	return iRoamingAllowed;
       
   976 	}
       
   977 
       
   978 
       
   979 // -----------------------------------------------------------------------------
       
   980 // CAspSchedule::SetRoamingAllowed
       
   981 //
       
   982 // -----------------------------------------------------------------------------
       
   983 //
       
   984 void CAspSchedule::SetRoamingAllowed(TBool aRoamingAllowed)
       
   985 	{
       
   986 	iRoamingAllowed = aRoamingAllowed;
       
   987 	}
       
   988 
       
   989 
       
   990 // -----------------------------------------------------------------------------
       
   991 // CAspSchedule::Error
       
   992 //
       
   993 // -----------------------------------------------------------------------------
       
   994 //
       
   995 TInt CAspSchedule::Error()
       
   996 	{
       
   997 	return iError;
       
   998 	}
       
   999 
       
  1000 
       
  1001 // -----------------------------------------------------------------------------
       
  1002 // CAspSchedule::SetError
       
  1003 //
       
  1004 // -----------------------------------------------------------------------------
       
  1005 //
       
  1006 void CAspSchedule::SetError(TInt aError)
       
  1007 	{
       
  1008 	iError = aError;
       
  1009 	}
       
  1010 
       
  1011 
       
  1012 
       
  1013 // ----------------------------------------------------------------------------
       
  1014 // CAspSchedule::UniversalStartTime
       
  1015 //
       
  1016 // ----------------------------------------------------------------------------
       
  1017 //
       
  1018 TTime CAspSchedule::UniversalStartTime(TInt& aStartHour)
       
  1019 	{
       
  1020 	// add two hours to current universal time and 
       
  1021 	// set minutes to 0 (eg. 13:45 -> 15:00)
       
  1022     TTime time;
       
  1023     time.UniversalTime();
       
  1024  
       
  1025     TTimeIntervalHours twoHours(2);
       
  1026     time += twoHours;
       
  1027 	
       
  1028     TDateTime dateTime = time.DateTime();
       
  1029     dateTime.SetMinute(0);
       
  1030    	dateTime.SetSecond(0);
       
  1031 	dateTime.SetMicroSecond(0);
       
  1032 
       
  1033 	aStartHour = dateTime.Hour();  // return start hour to caller
       
  1034 	
       
  1035     TTime time2(dateTime);
       
  1036     return time2;
       
  1037 	}
       
  1038 
       
  1039 
       
  1040 // ----------------------------------------------------------------------------
       
  1041 // CAspSchedule::LocalStartTime
       
  1042 //
       
  1043 // ----------------------------------------------------------------------------
       
  1044 //
       
  1045 TTime CAspSchedule::LocalStartTime(TInt aStartHour)
       
  1046 	{
       
  1047 	TTime time;
       
  1048 	time.HomeTime();
       
  1049 	
       
  1050 	TDateTime dateTime = time.DateTime();
       
  1051 	dateTime.SetMinute(0);
       
  1052 	dateTime.SetSecond(0);
       
  1053 	dateTime.SetMicroSecond(0);
       
  1054 	dateTime.SetHour(aStartHour);
       
  1055 	
       
  1056 	TTime time2(dateTime); 
       
  1057 	TTime now;
       
  1058 	now.HomeTime();
       
  1059 	if (now > time2)
       
  1060 		{
       
  1061 	    TTimeIntervalDays oneDay(1);
       
  1062 	    time2 += oneDay;
       
  1063 		}
       
  1064 		
       
  1065 	return time2;
       
  1066 	}
       
  1067 
       
  1068 
       
  1069 // ----------------------------------------------------------------------------
       
  1070 // CAspSchedule::IsDaySelected
       
  1071 //
       
  1072 // ----------------------------------------------------------------------------
       
  1073 //
       
  1074 TBool CAspSchedule::IsDaySelected(TTime aTime)
       
  1075 	{
       
  1076 	TDay day = aTime.DayNoInWeek();
       
  1077 	TBool ret = WeekdayEnabled(day);
       
  1078 
       
  1079 	return ret;
       
  1080 	}
       
  1081 
       
  1082 // -----------------------------------------------------------------------------
       
  1083 // CAspSchedule::UpdateSyncScheduleL
       
  1084 // Called when any auto sync setting is changed
       
  1085 // -----------------------------------------------------------------------------
       
  1086 //
       
  1087 void CAspSchedule::UpdateSyncScheduleL()
       
  1088 	{
       
  1089 	FLOG( _L("CAspSchedule::UpdateSyncScheduleL START") );
       
  1090 	
       
  1091 	CAspSyncSchedule* schedule = CAspSyncSchedule::NewLC();
       
  1092 	
       
  1093 	TInt profileId      = ProfileId();
       
  1094 	TBool contentStatus = IsContentSelected();
       
  1095 		    
       
  1096    	if (profileId == KErrNotFound || !contentStatus)
       
  1097 		{
       
  1098 		SetDailySyncEnabled(EFalse);
       
  1099 		SetPeakSyncEnabled(EFalse);
       
  1100 		SetOffPeakSyncEnabled(EFalse);
       
  1101 		schedule->DeleteScheduleL(this);
       
  1102 		CleanupStack::PopAndDestroy(schedule);
       
  1103 		return;
       
  1104 		}
       
  1105 
       
  1106    	if (!IsAutoSyncEnabled())
       
  1107    		{
       
  1108 		//Manual Sync selected ---->Delete schedule, if exists
       
  1109 	 	 schedule->DeleteScheduleL(this);
       
  1110     	}
       
  1111    	else
       
  1112    		{
       
  1113    		if (iDailySyncEnabled)
       
  1114    			{
       
  1115 			//Daily sync enabled ,use peak scheduling with intervals more than a day
       
  1116 	  	 	schedule->DeleteScheduleL(this);
       
  1117 			SetDailySyncEnabled(ETrue);
       
  1118 			schedule->CreatePeakScheduleL(this);
       
  1119 			}
       
  1120   		else
       
  1121    			{
       
  1122    		 	if (iPeakSyncEnabled != 0 && iOffPeakSyncEnabled ==0)
       
  1123   				{
       
  1124   				//Only peak sync enabled
       
  1125 	  	 		schedule->DeleteScheduleL(this);
       
  1126 				SetPeakSyncEnabled(ETrue);
       
  1127 				schedule->CreatePeakScheduleL(this);
       
  1128 				}
       
  1129    			else if (iPeakSyncEnabled == 0 && iOffPeakSyncEnabled !=0)
       
  1130   				{			
       
  1131   				//Only peak sync enabled
       
  1132 	  			schedule->DeleteScheduleL(this);
       
  1133 				SetOffPeakSyncEnabled(ETrue);
       
  1134 				schedule->CreateOffPeakScheduleL(this);
       
  1135 				}
       
  1136    			else if (iPeakSyncEnabled && iOffPeakSyncEnabled)
       
  1137     			{
       
  1138       			schedule->DeleteScheduleL(this);
       
  1139 				SetPeakSyncEnabled(ETrue);
       
  1140 				SetOffPeakSyncEnabled(ETrue);
       
  1141 				schedule->CreatePeakScheduleL(this);
       
  1142       			schedule->CreateOffPeakScheduleL(this);
       
  1143 				}   
       
  1144    			}
       
  1145    		}
       
  1146 
       
  1147   	
       
  1148     	CleanupStack::PopAndDestroy(schedule);
       
  1149     
       
  1150 #ifdef _DEBUG
       
  1151     
       
  1152     CAspSyncSchedule* s = CAspSyncSchedule::NewLC();
       
  1153     FLOG( _L("") );
       
  1154     LogScheduleL();
       
  1155     FLOG( _L("") );
       
  1156     s->LogSchedule(this);
       
  1157     FLOG( _L("") );
       
  1158     CleanupStack::PopAndDestroy(s);
       
  1159     
       
  1160 #endif  //    _DEBUG 
       
  1161     
       
  1162     FLOG( _L("CAspSchedule::UpdateSyncScheduleL END") );
       
  1163 	}
       
  1164 
       
  1165 
       
  1166 
       
  1167 // -----------------------------------------------------------------------------
       
  1168 // CAspSchedule::UpdateSyncSchedule
       
  1169 //
       
  1170 // -----------------------------------------------------------------------------
       
  1171 //
       
  1172 void CAspSchedule::UpdateSyncSchedule()
       
  1173 	{
       
  1174 	TRAPD(err, UpdateSyncScheduleL());
       
  1175 	
       
  1176 	if (err != KErrNone)
       
  1177 		{
       
  1178 		FLOG( _L("### CAspSchedule::UpdateSyncScheduleL failed (err=%d) ###"), err );
       
  1179 		}
       
  1180 	}
       
  1181 
       
  1182 // -----------------------------------------------------------------------------
       
  1183 // CAspSchedule::GetStartTimeL
       
  1184 // -Get next auto sync start time ,peak/off-peak whichever is earlier and enabled
       
  1185 // -----------------------------------------------------------------------------
       
  1186 //
       
  1187 void CAspSchedule::GetStartTimeL(TTime& aTime, TBool aHomeTime)
       
  1188 	{
       
  1189 
       
  1190 	CAspSyncSchedule* s = CAspSyncSchedule::NewLC();
       
  1191 
       
  1192 	if (iDailySyncEnabled)
       
  1193 		{
       
  1194 		s->GetPeakStartTimeL(this, aTime, aHomeTime);
       
  1195 		}
       
  1196 	else if (iPeakSyncEnabled != 0 && iOffPeakSyncEnabled ==0)
       
  1197 		{
       
  1198 		s->GetPeakStartTimeL(this, aTime, aHomeTime);
       
  1199 		}
       
  1200 	else if (iPeakSyncEnabled == 0 && iOffPeakSyncEnabled !=0)
       
  1201 		{
       
  1202 		s->GetOffPeakStartTimeL(this, aTime, aHomeTime);
       
  1203 		}
       
  1204 	else //peak & off-peak schedules enabled
       
  1205 		{
       
  1206 		TTime peakStart;
       
  1207 		TTime offPeakStart;
       
  1208 		
       
  1209 		s->GetPeakStartTimeL(this, peakStart, aHomeTime);
       
  1210 		s->GetOffPeakStartTimeL(this, offPeakStart, aHomeTime);
       
  1211 
       
  1212 		if (peakStart < offPeakStart)
       
  1213 			{
       
  1214 			aTime = peakStart;
       
  1215 			}
       
  1216 		else
       
  1217 			{
       
  1218 			aTime = offPeakStart;
       
  1219 			}
       
  1220 		}
       
  1221     CleanupStack::PopAndDestroy(s);
       
  1222 	}
       
  1223 
       
  1224 // -----------------------------------------------------------------------------
       
  1225 // CAspSchedule::CanSynchronizeL
       
  1226 // Check primary auto sync settings
       
  1227 // -----------------------------------------------------------------------------
       
  1228 //
       
  1229 TBool CAspSchedule::CanSynchronizeL()
       
  1230 	{
       
  1231 	if (iProfileId == KErrNotFound && iAutoSyncProfileId == KErrNotFound)
       
  1232 		{
       
  1233         FLOG( _L("CAspSchedule::CanSynchronizeL Failed :CP1") );
       
  1234 		return EFalse;
       
  1235 		}
       
  1236 	OpenSyncSessionL();
       
  1237 	TAspParam param(EApplicationIdSync, &iSyncSession);
       
  1238 	CAspProfile* profile = CAspProfile::NewLC(param);
       
  1239 
       
  1240 	TRAPD (err, profile->OpenL(iProfileId, CAspProfile::EOpenRead, 
       
  1241 	                           CAspProfile::EBaseProperties));
       
  1242 	if (err == KErrNotFound)
       
  1243 		{
       
  1244 		SetProfileId(KErrNotFound);
       
  1245 		if (iAutoSyncProfileId != KErrNotFound)
       
  1246 			{
       
  1247 			TRAPD (err1, profile->OpenL(iAutoSyncProfileId, CAspProfile::EOpenRead, 
       
  1248 	                           CAspProfile::EBaseProperties));
       
  1249 			if (err1 == KErrNotFound)
       
  1250 				{
       
  1251 				SetAutoSyncProfileId(KErrNotFound);
       
  1252 				}
       
  1253 			}		
       
  1254 		UpdateSyncSchedule();
       
  1255 		SaveL();
       
  1256 		CleanupStack::PopAndDestroy(profile);
       
  1257 		FLOG( _L("CAspSchedule::CanSynchronizeL Failed :CP2") );
       
  1258 		return EFalse;
       
  1259 		}
       
  1260 	CleanupStack::PopAndDestroy(profile);
       
  1261 
       
  1262 	if (!IsContentSelected())
       
  1263 		{
       
  1264 		UpdateSyncSchedule();
       
  1265 		SaveL();
       
  1266 		FLOG( _L("CAspSchedule::CanSynchronizeL Failed :CP3") );
       
  1267 		return EFalse;
       
  1268 		}
       
  1269 	
       
  1270 	if (!IsAutoSyncEnabled())
       
  1271 		{
       
  1272         FLOG( _L("CAspSchedule::CanSynchronizeL Failed :CP4") );
       
  1273 		return EFalse;
       
  1274 		}
       
  1275 	
       
  1276 	return ETrue;
       
  1277 	}
       
  1278 
       
  1279 // -----------------------------------------------------------------------------
       
  1280 // CAspSchedule::IsValidPeakScheduleL
       
  1281 // Check if current time is peak
       
  1282 // -----------------------------------------------------------------------------
       
  1283 //
       
  1284 TInt CAspSchedule::IsValidPeakScheduleL()
       
  1285 	{
       
  1286 	//convert all time values to same day and comapre
       
  1287 	const TInt KPositive = 1;
       
  1288 	const TInt KZero = 0;
       
  1289 	const TInt KNegative = -1;
       
  1290 
       
  1291 	TTime startPeak = StartPeakTime();
       
  1292 	TTime endPeak   = EndPeakTime();
       
  1293 	
       
  1294 	TInt retVal = 0;
       
  1295 	TTime now;
       
  1296 	now.HomeTime();
       
  1297 	
       
  1298 	if (!WeekdayEnabled(now.DayNoInWeek()))
       
  1299 		{
       
  1300 		retVal = KPositive; 
       
  1301 		return retVal;
       
  1302 		}
       
  1303 
       
  1304 	TDateTime timenow = now.DateTime();
       
  1305 	TDateTime date = startPeak.DateTime();
       
  1306 	TInt nowHr  = timenow.Hour();
       
  1307 	TInt nowMin = timenow.Minute();
       
  1308 	TInt day    = date.Day();
       
  1309 
       
  1310     TDateTime time(0, EJanuary, day, nowHr, nowMin, 0, 0);
       
  1311 	TTime curTime(time);
       
  1312 	
       
  1313 	if ( curTime >= startPeak && curTime < endPeak)
       
  1314 		{
       
  1315 		retVal =  KZero; //In peak period
       
  1316 		}
       
  1317 	else if (curTime < startPeak)
       
  1318 		{
       
  1319 		retVal = KPositive;
       
  1320 		}
       
  1321 	else if (curTime > endPeak)
       
  1322 		{
       
  1323 		retVal = KNegative;
       
  1324 		}
       
  1325     
       
  1326     return retVal;
       
  1327 	
       
  1328 	}
       
  1329 
       
  1330 // -----------------------------------------------------------------------------
       
  1331 // CAspSchedule::IsValidOffPeakScheduleL
       
  1332 // Check if the current time off-peak
       
  1333 // -----------------------------------------------------------------------------
       
  1334 //
       
  1335 
       
  1336 TInt CAspSchedule::IsValidOffPeakScheduleL()
       
  1337 	{
       
  1338 	//convert all time values to same day and comapre
       
  1339 	const TInt KPositive = 1;
       
  1340 	const TInt KZero = 0;
       
  1341 		
       
  1342 	TTime startOffPeak = EndPeakTime()+ (TTimeIntervalMinutes)1;
       
  1343 	TTime endOffPeak   = StartPeakTime() + (TTimeIntervalDays)1 -(TTimeIntervalMinutes)1 ;
       
  1344 	TInt retVal = 0;
       
  1345 	TTime now;
       
  1346 	now.HomeTime();
       
  1347 
       
  1348 	if (!WeekdayEnabled(now.DayNoInWeek()))
       
  1349 		{
       
  1350 		retVal = KZero; 
       
  1351 		return retVal;
       
  1352 		}
       
  1353 
       
  1354 	TDateTime timenow = now.DateTime();
       
  1355 	TDateTime date = startOffPeak.DateTime();
       
  1356 	TInt nowHr  = timenow.Hour();
       
  1357 	TInt nowMin = timenow.Minute();
       
  1358 	TInt day    = date.Day();
       
  1359 
       
  1360     TDateTime time(0, EJanuary, day, nowHr, nowMin, 0, 0);
       
  1361 	TTime curTime(time);
       
  1362 	
       
  1363 	if (curTime < StartPeakTime() || (curTime >= startOffPeak && curTime < endOffPeak ))
       
  1364 		{
       
  1365 		retVal = KZero; 
       
  1366 		}
       
  1367 	else if (curTime < startOffPeak)
       
  1368 		{
       
  1369 		retVal = KPositive;		
       
  1370 		}
       
  1371 	
       
  1372 	return retVal;
       
  1373 	}
       
  1374 
       
  1375 // -----------------------------------------------------------------------------
       
  1376 // CAspSchedule::IsValidNextPeakScheduleL
       
  1377 // -Add sync interval to current time and checks if the next schedule will be in peak period.
       
  1378 // -otherwise sync can be postponed until next peak start
       
  1379 // -----------------------------------------------------------------------------
       
  1380 //
       
  1381 TBool CAspSchedule::IsValidNextPeakScheduleL()
       
  1382 	{
       
  1383 	//convert all time vakues to same day and compare
       
  1384 	TTime startPeak = StartPeakTime();
       
  1385 	TTime endPeak   = EndPeakTime();
       
  1386 	
       
  1387 	TTime now;
       
  1388 	now.HomeTime();
       
  1389 
       
  1390 	CAspSyncSchedule* syncSchedule = CAspSyncSchedule::NewLC();
       
  1391 	TInt interval = SyncPeakSchedule();
       
  1392     TIntervalType intervalType = syncSchedule->IntervalType(interval);
       
  1393   	
       
  1394 	TInt intervalVal = syncSchedule->Interval(interval);
       
  1395 
       
  1396 	if (interval == EInterval15Mins
       
  1397 				|| interval == EInterval30Mins)
       
  1398 		{
       
  1399 		now = now + (TTimeIntervalMinutes)intervalVal;
       
  1400 		}
       
  1401 	else if (intervalType == EHourly)
       
  1402 		{
       
  1403 		now = now + (TTimeIntervalHours)intervalVal;
       
  1404 		}
       
  1405 		
       
  1406 	CleanupStack::PopAndDestroy(syncSchedule);	
       
  1407 	if (!WeekdayEnabled(now.DayNoInWeek()))
       
  1408 		{
       
  1409 		return EFalse;
       
  1410 		}
       
  1411 	TDateTime timenow = now.DateTime();
       
  1412 	TDateTime date = startPeak.DateTime();
       
  1413 	TInt nowHr  = timenow.Hour();
       
  1414 	TInt nowMin = timenow.Minute();
       
  1415 	TInt day    = date.Day();
       
  1416 
       
  1417     TDateTime time(0, EJanuary, day, nowHr, nowMin, 0, 0);
       
  1418 	TTime nextPeakSync(time);
       
  1419 	
       
  1420 	if ( nextPeakSync >= startPeak && nextPeakSync < endPeak)
       
  1421 		{
       
  1422 		return ETrue; //In peak period
       
  1423 		}
       
  1424 
       
  1425 	return EFalse;
       
  1426 	}
       
  1427 
       
  1428 // -----------------------------------------------------------------------------
       
  1429 // CAspSchedule::IsValidNextOffPeakScheduleL
       
  1430 // -Add sync interval to current time and checks if the next schedule will be in off-peak period.
       
  1431 // -otherwise sync can be postponed until next off-peak start
       
  1432 // -----------------------------------------------------------------------------
       
  1433 //
       
  1434 TBool CAspSchedule::IsValidNextOffPeakScheduleL()
       
  1435 	{
       
  1436 
       
  1437     TTime startOffPeak = EndPeakTime()+ (TTimeIntervalMinutes)1;
       
  1438 	TTime endOffPeak   = StartPeakTime() + (TTimeIntervalDays)1 -(TTimeIntervalMinutes)1 ;
       
  1439 	
       
  1440 	TTime now;
       
  1441 	now.HomeTime();
       
  1442 
       
  1443 	CAspSyncSchedule* syncSchedule = CAspSyncSchedule::NewLC();
       
  1444 	TInt interval = SyncOffPeakSchedule();
       
  1445     TIntervalType intervalType = syncSchedule->IntervalType(interval);
       
  1446   	
       
  1447 	TInt intervalVal = syncSchedule->Interval(interval);
       
  1448 
       
  1449 	if (interval == EInterval15Mins
       
  1450 				|| interval == EInterval30Mins)
       
  1451 		{
       
  1452 		now = now + (TTimeIntervalMinutes)intervalVal;
       
  1453 		}
       
  1454 	else if (intervalType == EHourly)
       
  1455 		{
       
  1456 		now = now + (TTimeIntervalHours)intervalVal;
       
  1457 		}
       
  1458 		
       
  1459 	CleanupStack::PopAndDestroy(syncSchedule);
       
  1460 
       
  1461 	if (!WeekdayEnabled(now.DayNoInWeek()))
       
  1462 		{
       
  1463 		return ETrue;
       
  1464 		}
       
  1465 	
       
  1466 	TDateTime timenow = now.DateTime();
       
  1467 	TDateTime date = startOffPeak.DateTime();
       
  1468 	TInt nowHr  = timenow.Hour();
       
  1469 	TInt nowMin = timenow.Minute();
       
  1470 	TInt day    = date.Day();
       
  1471 
       
  1472     TDateTime time(0, EJanuary, day, nowHr, nowMin, 0, 0);
       
  1473 	TTime nextOffPeakSync(time);
       
  1474 
       
  1475 	if (nextOffPeakSync < StartPeakTime() || (nextOffPeakSync >= startOffPeak && nextOffPeakSync < endOffPeak ))
       
  1476 		{
       
  1477 		return ETrue; //in off-peak period
       
  1478 		}
       
  1479 	return EFalse;
       
  1480 	}
       
  1481 
       
  1482 
       
  1483 // -----------------------------------------------------------------------------
       
  1484 // CAspSchedule::CreateAutoSyncProfileL
       
  1485 // -Creates a hidden profile that is used for auto sync.
       
  1486 // -It is created when auto sync is used for first time
       
  1487 // -----------------------------------------------------------------------------
       
  1488 //
       
  1489 
       
  1490 void CAspSchedule::CreateAutoSyncProfileL()
       
  1491 	{
       
  1492 	if (iAutoSyncProfileId != KErrNotFound)
       
  1493 		{
       
  1494 		return;			
       
  1495 		}
       
  1496 	OpenSyncSessionL();
       
  1497 
       
  1498 	TBuf<KBufSize> aBufName(KAutoSyncProfileName);
       
  1499 	
       
  1500 	TAspParam param(EApplicationIdSync, &iSyncSession);
       
  1501 	CAspProfile* profile = CAspProfile::NewLC(param);
       
  1502 
       
  1503 	profile->CreateL(CAspProfile::EAllProperties);
       
  1504 	CAspProfile::SetDefaultValuesL(profile);
       
  1505 	profile->SetNameL(aBufName);
       
  1506 	profile->SetSASyncStateL(ESmlDisableSync);
       
  1507 	profile->SaveL();
       
  1508 	
       
  1509 	iAutoSyncProfileId = profile->ProfileId();
       
  1510 	SaveL();
       
  1511 	
       
  1512 	CleanupStack::PopAndDestroy(profile);
       
  1513 	
       
  1514 	
       
  1515 	}
       
  1516 
       
  1517 // -----------------------------------------------------------------------------
       
  1518 // CAspSchedule::AutoSyncProfileId
       
  1519 // -----------------------------------------------------------------------------
       
  1520 //
       
  1521 
       
  1522 TInt CAspSchedule::AutoSyncProfileId()
       
  1523 	{
       
  1524 	return iAutoSyncProfileId;
       
  1525 	}
       
  1526 
       
  1527 // -----------------------------------------------------------------------------
       
  1528 // CAspSchedule::SetAutoSyncProfileId
       
  1529 // -----------------------------------------------------------------------------
       
  1530 //
       
  1531 
       
  1532 void CAspSchedule::SetAutoSyncProfileId(TInt aProfileId)
       
  1533 	{
       
  1534 	iAutoSyncProfileId = aProfileId;
       
  1535 	}
       
  1536 
       
  1537 
       
  1538 // -----------------------------------------------------------------------------
       
  1539 // CAspSchedule::CopyAutoSyncContentsL
       
  1540 // -Copy contents selected in Automatic sync settings view to the profiles content list
       
  1541 // -----------------------------------------------------------------------------
       
  1542 //
       
  1543 
       
  1544 void CAspSchedule::CopyAutoSyncContentsL()
       
  1545 	{
       
  1546 	FLOG( _L("CAspSchedule::CopyAutoSyncContentsL START") );
       
  1547 	if (iAutoSyncProfileId == KErrNotFound)
       
  1548 		{
       
  1549 		return;
       
  1550 		}
       
  1551 	OpenSyncSessionL();
       
  1552 	TAspParam param(EApplicationIdSync, &iSyncSession);
       
  1553 	
       
  1554 	param.iMode = CAspContentList::EInitDataProviders;
       
  1555 	CAspContentList* asContentList = CAspContentList::NewLC(param);		
       
  1556 	
       
  1557 	CAspProfile* profile = CAspProfile::NewLC(param);
       
  1558 
       
  1559 	TRAPD (err, profile->OpenL(iAutoSyncProfileId, CAspProfile::EOpenReadWrite, 
       
  1560 	                           CAspProfile::EAllProperties));
       
  1561 	User::LeaveIfError(err);
       
  1562 
       
  1563 	asContentList->SetProfile(profile);
       
  1564 	asContentList->InitAllTasksL();
       
  1565 		
       
  1566 	TBool aEnabled;
       
  1567 	
       
  1568 	TInt providerCount = asContentList->ProviderCount();
       
  1569 		
       
  1570 	for (TInt i= 0; i < providerCount; i++)
       
  1571 		{
       
  1572 		if(ContentEnabled(i))
       
  1573 			{
       
  1574 			aEnabled = ETrue;
       
  1575 			}
       
  1576 		else
       
  1577 			{
       
  1578 			aEnabled = EFalse;
       
  1579 			}
       
  1580 		TAspProviderItem& provider = asContentList->ProviderItem(i);	
       
  1581 		if (provider.iDataProviderId != KErrNotFound)
       
  1582 			{
       
  1583 			asContentList->ModifyTaskIncludedL(provider.iDataProviderId, aEnabled, KNullDesC);
       
  1584 			}
       
  1585 		}
       
  1586 	CleanupStack::PopAndDestroy(profile);
       
  1587 	CleanupStack::PopAndDestroy(asContentList);
       
  1588 	FLOG( _L("CAspSchedule::CopyAutoSyncContentsL END") );
       
  1589      
       
  1590 	}
       
  1591 
       
  1592 // -----------------------------------------------------------------------------
       
  1593 // CAspSchedule::UpdateProfileSettingsL
       
  1594 // -Copy latest settings from profile selected for sync to auto sync profile.
       
  1595 // -Called before every scheduled sync to get updated settings
       
  1596 // -Also called when any settings changed
       
  1597 // -----------------------------------------------------------------------------
       
  1598 //
       
  1599 
       
  1600 void CAspSchedule::UpdateProfileSettingsL()
       
  1601 	{
       
  1602 	FLOG( _L("CAspSchedule::UpdateProfileSettingsL START") );
       
  1603 	if (iProfileId == KErrNotFound || iAutoSyncProfileId == KErrNotFound)
       
  1604 		{
       
  1605 		return;
       
  1606 		}
       
  1607 	OpenSyncSessionL();
       
  1608 	TAspParam param(EApplicationIdSync, &iSyncSession);
       
  1609 
       
  1610 	param.iMode = CAspContentList::EInitDataProviders;
       
  1611 			
       
  1612 	CAspContentList* asContentList = CAspContentList::NewL(param);
       
  1613 	CleanupStack::PushL(asContentList);
       
  1614 	CAspContentList* contentList = CAspContentList::NewL(param);
       
  1615 	CleanupStack::PushL(contentList);
       
  1616 	
       
  1617     CAspProfile* selectedProfile = CAspProfile::NewLC(param);
       
  1618     selectedProfile->OpenL(iProfileId, CAspProfile::EOpenRead, CAspProfile::EAllProperties);
       
  1619 
       
  1620 	CAspProfile* autosyncProfile = CAspProfile::NewLC(param);
       
  1621 	autosyncProfile->OpenL(iAutoSyncProfileId, CAspProfile::EOpenReadWrite, CAspProfile::EAllProperties);
       
  1622 
       
  1623 	autosyncProfile->CopyValuesL(selectedProfile);
       
  1624 	autosyncProfile->SetSASyncStateL(ESmlDisableSync);
       
  1625 	autosyncProfile->SaveL();
       
  1626 
       
  1627     //Copy database names.
       
  1628     contentList->SetProfile(selectedProfile);
       
  1629 	contentList->InitAllTasksL();
       
  1630 	
       
  1631 	TBuf<KBufSize> aLocalDatabase;
       
  1632 	TBuf<KBufSize> aRemoteDatabase;
       
  1633 	TInt aSyncDirection;
       
  1634 	TBool aTaskEnabled;
       
  1635 	
       
  1636 	asContentList->SetProfile(autosyncProfile);
       
  1637 	asContentList->InitAllTasksL();
       
  1638 	
       
  1639 	TInt providerCount = asContentList->ProviderCount();
       
  1640 	
       
  1641  	for (TInt i= 0; i < providerCount; i++)
       
  1642 		{
       
  1643 		TAspProviderItem& provider = asContentList->ProviderItem(i);
       
  1644 			
       
  1645 		contentList->ReadTaskL(provider.iDataProviderId, aLocalDatabase, aRemoteDatabase,
       
  1646 		                    aTaskEnabled, aSyncDirection);
       
  1647 		
       
  1648 		
       
  1649 		if(ContentEnabled(i))
       
  1650 			{
       
  1651 			aTaskEnabled = ETrue;
       
  1652 			}
       
  1653 		else
       
  1654 			{
       
  1655 			aTaskEnabled = EFalse;
       
  1656 			}
       
  1657 
       
  1658 		if (provider.iDataProviderId == KUidNSmlAdapterEMail.iUid)
       
  1659 			{
       
  1660 			if (!MailboxExistL())
       
  1661 				{
       
  1662 				continue;
       
  1663 				}
       
  1664 			RSyncMLDataProvider provider;
       
  1665 			TInt err;
       
  1666 			TRAP(err, provider.OpenL(iSyncSession, KUidNSmlAdapterEMail.iUid));
       
  1667 			aLocalDatabase = provider.DefaultDataStoreName();
       
  1668 			}
       
  1669 		
       
  1670 		if (aTaskEnabled)
       
  1671 			{		
       
  1672 			TBuf<KBufSize> asLocaldb;
       
  1673 			TBuf<KBufSize> asRemotedb;
       
  1674 			TBool asTask;
       
  1675 			TInt asDirection;
       
  1676 		
       
  1677 			asContentList->ReadTaskL(provider.iDataProviderId,asLocaldb,asRemotedb,
       
  1678 													asTask,asDirection);
       
  1679 													
       
  1680 		    if (asLocaldb != aLocalDatabase || asRemotedb != aRemoteDatabase ||
       
  1681 		    					asTask != aTaskEnabled || asDirection != aSyncDirection )
       
  1682 		    	{
       
  1683 		    	TRAPD(err,	asContentList->CreateTaskL(provider.iDataProviderId, aLocalDatabase, aRemoteDatabase,
       
  1684 	                              aTaskEnabled, aSyncDirection));
       
  1685 		    	User::LeaveIfError(err);
       
  1686 		    	}
       
  1687 			}
       
  1688 	
       
  1689 		}
       
  1690 	CleanupStack::PopAndDestroy(autosyncProfile);
       
  1691 	CleanupStack::PopAndDestroy(selectedProfile);
       
  1692 	
       
  1693 	CleanupStack::PopAndDestroy(contentList);
       
  1694 	CleanupStack::PopAndDestroy(asContentList);
       
  1695 	FLOG( _L("CAspSchedule::UpdateProfileSettingsL END") );
       
  1696 	
       
  1697    }
       
  1698 
       
  1699 // -----------------------------------------------------------------------------
       
  1700 // CAspSchedule::UpdatePeakSchedule
       
  1701 // -----------------------------------------------------------------------------
       
  1702 //
       
  1703 void CAspSchedule::UpdatePeakScheduleL()
       
  1704 	{
       
  1705 	//Today's peak time ended ,postpone the peak scheduling until tomorrow peak start time
       
  1706 	CAspSyncSchedule* syncSchedule = CAspSyncSchedule::NewLC();
       
  1707     TIntervalType intervalType = syncSchedule->IntervalType(SyncPeakSchedule());
       
  1708     if(intervalType == EDaily )
       
  1709     	{
       
  1710 		CleanupStack::PopAndDestroy(syncSchedule);
       
  1711 		return;
       
  1712 		}
       
  1713 	syncSchedule->UpdatePeakScheduleL(this);
       
  1714 	CleanupStack::PopAndDestroy(syncSchedule);		
       
  1715 
       
  1716     }
       
  1717 // -----------------------------------------------------------------------------
       
  1718 // CAspSchedule::UpdateOffPeakSchedule
       
  1719 // -----------------------------------------------------------------------------
       
  1720 //
       
  1721 
       
  1722 void CAspSchedule::UpdateOffPeakScheduleL()
       
  1723 	{
       
  1724 	//postpone the off-peak scheduling until tomorrow off-peak start time
       
  1725 	CAspSyncSchedule* syncSchedule = CAspSyncSchedule::NewLC();
       
  1726     TIntervalType intervalType = syncSchedule->IntervalType(SyncOffPeakSchedule());
       
  1727     if (intervalType == EDaily )
       
  1728     	{
       
  1729 		CleanupStack::PopAndDestroy(syncSchedule);
       
  1730 		return;
       
  1731 		}
       
  1732 	syncSchedule->UpdateOffPeakScheduleL(this);
       
  1733 	CleanupStack::PopAndDestroy(syncSchedule);		
       
  1734 
       
  1735     }
       
  1736 
       
  1737 // -----------------------------------------------------------------------------
       
  1738 // CAspSchedule::EnableSchedule
       
  1739 // -----------------------------------------------------------------------------
       
  1740 //
       
  1741 void CAspSchedule::EnableScheduleL()
       
  1742 	{
       
  1743 	if ( iPeakScheduleHandle == KErrNotFound && iOffPeakScheduleHandle == KErrNotFound)
       
  1744 		{
       
  1745 		return;
       
  1746 		}
       
  1747 	CAspSyncSchedule* syncSchedule = CAspSyncSchedule::NewLC();
       
  1748 	syncSchedule->EnableSchedule(this);
       
  1749 	CleanupStack::PopAndDestroy(syncSchedule);		
       
  1750 	}
       
  1751 
       
  1752 // -----------------------------------------------------------------------------
       
  1753 // CAspSchedule::UpdateOffPeakSchedule
       
  1754 // -----------------------------------------------------------------------------
       
  1755 //
       
  1756 TIntervalType CAspSchedule::IntervalType(TInt aInterval)
       
  1757 	{
       
  1758 	if (aInterval == EInterval24hours
       
  1759 			  || aInterval == EInterval2days
       
  1760 			  || aInterval == EInterval4days
       
  1761 			  || aInterval == EInterval7days
       
  1762 			  || aInterval == EInterval14days
       
  1763 			  || aInterval == EInterval30days)
       
  1764 		{
       
  1765 		return EDaily;
       
  1766 		}
       
  1767 		
       
  1768 	return EHourly;
       
  1769 	}
       
  1770 
       
  1771 // ----------------------------------------------------------------------------
       
  1772 // CAspSchedule::MailboxExistL()
       
  1773 // Return ETrue if any mail box exists, EFlase otherwise
       
  1774 // ----------------------------------------------------------------------------
       
  1775 //
       
  1776 TBool CAspSchedule::MailboxExistL()
       
  1777 	{
       
  1778 	OpenSyncSessionL();
       
  1779 	TBool mailboxExist = EFalse;
       
  1780 	TAspParam param(EApplicationIdSync, &iSyncSession);
       
  1781 	param.iMode = CAspContentList::EInitDataProviders;
       
  1782 	CAspContentList* contentList = CAspContentList::NewL(param);
       
  1783 	CleanupStack::PushL(contentList);
       
  1784 	// get email syncml mailboxes
       
  1785    	CDesCArray* localDataStores = new (ELeave) CDesCArrayFlat(KDefaultArraySize);
       
  1786 	CleanupStack::PushL(localDataStores);
       
  1787 	contentList->GetLocalDatabaseList(KUidNSmlAdapterEMail.iUid, localDataStores);
       
  1788 
       
  1789     if (localDataStores->Count() > 0)
       
  1790    		{
       
  1791    		mailboxExist = ETrue;
       
  1792    		}
       
  1793 
       
  1794 	CleanupStack::PopAndDestroy(localDataStores);
       
  1795 	CleanupStack::PopAndDestroy(contentList);
       
  1796 
       
  1797 	return mailboxExist;
       
  1798 	}
       
  1799 
       
  1800 
       
  1801 // ----------------------------------------------------------------------------
       
  1802 // CAspSchedule::ProtocolL()
       
  1803 // Return server protocol version 
       
  1804 // ----------------------------------------------------------------------------
       
  1805 //
       
  1806 TInt CAspSchedule::ProtocolL()
       
  1807 	{
       
  1808 	OpenSyncSessionL();
       
  1809 	TAspParam param(EApplicationIdSync, &iSyncSession);
       
  1810 	CAspProfile* profile = CAspProfile::NewLC(param);
       
  1811 	profile->OpenL(iProfileId, CAspProfile::EOpenRead,
       
  1812                                          CAspProfile::EBaseProperties);
       
  1813 	TInt protocol = profile->ProtocolVersion();
       
  1814 	CleanupStack::PopAndDestroy(profile);
       
  1815 	return protocol;
       
  1816 	}
       
  1817 
       
  1818 
       
  1819 // ----------------------------------------------------------------------------
       
  1820 // CAspSchedule::IsAutoSyncEnabled()
       
  1821 // Return ETrue if autosync enable ,EFalse otherwise 
       
  1822 // ----------------------------------------------------------------------------
       
  1823 //
       
  1824 TBool CAspSchedule::IsAutoSyncEnabled()
       
  1825 	{
       
  1826 	if (iDailySyncEnabled || iPeakSyncEnabled || iOffPeakSyncEnabled)
       
  1827 		{
       
  1828 		return ETrue;
       
  1829 		}
       
  1830 	return EFalse;
       
  1831 	}
       
  1832 
       
  1833 
       
  1834 // -----------------------------------------------------------------------------
       
  1835 // CAspSchedule::OpenSyncSessionL
       
  1836 // -----------------------------------------------------------------------------
       
  1837 //
       
  1838 
       
  1839 void CAspSchedule::OpenSyncSessionL()
       
  1840 	{
       
  1841 	if (!iSyncSessionOpen)
       
  1842 		{
       
  1843         TRAPD(err, iSyncSession.OpenL());
       
  1844         
       
  1845         if (err != KErrNone)
       
  1846         	{
       
  1847         	FLOG( _L("### CAspSchedule: RSyncMLSession::OpenL failed (%d) ###"), err );
       
  1848         	User::Leave(err);
       
  1849         	}
       
  1850 
       
  1851 		iSyncSessionOpen = ETrue;
       
  1852 		}
       
  1853     }
       
  1854 
       
  1855 // -----------------------------------------------------------------------------
       
  1856 // CAspSchedule::CloseSyncSession
       
  1857 // -----------------------------------------------------------------------------
       
  1858 //
       
  1859 
       
  1860 void CAspSchedule::CloseSyncSession()
       
  1861 	{
       
  1862 	if (iSyncSessionOpen)
       
  1863 		{
       
  1864 		iSyncSession.Close();
       
  1865 		iSyncSessionOpen = EFalse;
       
  1866 		}
       
  1867     }
       
  1868 
       
  1869 
       
  1870 // -----------------------------------------------------------------------------
       
  1871 // CAspSchedule::CheckMandatoryData
       
  1872 // 
       
  1873 // -----------------------------------------------------------------------------
       
  1874 //
       
  1875 TInt CAspSchedule::CheckMandatoryDataL(TInt& count,TInt& firstItem)
       
  1876 	{
       
  1877 	FLOG( _L("CAspSchedule::CheckMandatoryDataL START") );
       
  1878 	OpenSyncSessionL();
       
  1879     TAspParam param(EApplicationIdSync, &iSyncSession);
       
  1880 
       
  1881     CAspProfile* profile = CAspProfile::NewLC(param);
       
  1882     profile->OpenL(iProfileId, CAspProfile::EOpenRead, CAspProfile::EAllProperties);
       
  1883     
       
  1884 	param.iProfile = profile;
       
  1885 	param.iMode = CAspContentList::EInitAll;
       
  1886 	CAspContentList* list = CAspContentList::NewLC(param);
       
  1887 
       
  1888    	TInt index = 0;
       
  1889 	count = 0;
       
  1890 	firstItem = 0;
       
  1891 	
       
  1892 	TInt providerCount = list->ProviderCount();
       
  1893 	
       
  1894 	for (TInt i= 0; i < providerCount; i++)
       
  1895 		{
       
  1896 		if (ContentEnabled(i))
       
  1897 			{
       
  1898 			FLOG( _L("Content Id : %d"),i );
       
  1899 			TAspProviderItem& provider = list->ProviderItem(i);	
       
  1900 			index = list->FindTaskIndexForProvider(provider.iDataProviderId);
       
  1901 			if (index == KErrNotFound )
       
  1902 				{
       
  1903 				FLOG( _L("Index not found , Id : %d"),i );
       
  1904 				count++;
       
  1905 				if(count == 1)
       
  1906 					{
       
  1907 					firstItem = i;
       
  1908 					}
       
  1909 				continue;
       
  1910 				}
       
  1911 			TAspTaskItem& task = list->TaskItem(index);
       
  1912 			if (provider.iDataProviderId == KUidNSmlAdapterEMail.iUid)
       
  1913 				{
       
  1914 				if(!task.iRemoteDatabaseDefined || !task.iLocalDatabaseDefined)
       
  1915 					{
       
  1916 					count++;
       
  1917 					if(count == 1)
       
  1918 						{
       
  1919 						firstItem = i;
       
  1920 						}
       
  1921 					}
       
  1922 				}
       
  1923 			else
       
  1924 				{
       
  1925 				if (!task.iRemoteDatabaseDefined)
       
  1926 					{
       
  1927 					count++;
       
  1928 					if(count == 1)
       
  1929 						{
       
  1930 						firstItem = i;
       
  1931 						}
       
  1932 					}
       
  1933 				}
       
  1934 			}
       
  1935 			}
       
  1936 		
       
  1937 	CleanupStack::PopAndDestroy(list);
       
  1938 	CleanupStack::PopAndDestroy(profile);
       
  1939 	
       
  1940 	if (count)
       
  1941 		{
       
  1942 		return EFalse;
       
  1943 		}
       
  1944 
       
  1945 	FLOG( _L("CAspSchedule::CheckMandatoryDataL END") );
       
  1946 	return ETrue;
       
  1947 
       
  1948    }
       
  1949 
       
  1950 
       
  1951 // -----------------------------------------------------------------------------
       
  1952 // CAspSchedule::ShowAutoSyncLogL
       
  1953 //
       
  1954 // -----------------------------------------------------------------------------
       
  1955 //
       
  1956 void CAspSchedule::ShowAutoSyncLogL()
       
  1957 	{
       
  1958 	FLOG( _L("CAspSchedule::ShowAutoSyncLogL START") );
       
  1959 	OpenSyncSessionL();
       
  1960     TAspParam param(EApplicationIdSync, &iSyncSession);
       
  1961 	param.iProfileId = iProfileId;
       
  1962 
       
  1963 	CAspProfile* asProfile = CAspProfile::NewLC(param);
       
  1964 	asProfile->OpenL(iAutoSyncProfileId, CAspProfile::EOpenRead, CAspProfile::EAllProperties);
       
  1965 	
       
  1966 	CAspProfile* profile = CAspProfile::NewLC(param);
       
  1967 	profile->OpenL(iProfileId, CAspProfile::EOpenRead, CAspProfile::EAllProperties);
       
  1968 
       
  1969 	if (asProfile->LastSync() > profile->LastSync())
       
  1970 		{
       
  1971 		param.iProfileId = iAutoSyncProfileId;
       
  1972 		}
       
  1973 	CleanupStack::PopAndDestroy(profile);
       
  1974 	CleanupStack::PopAndDestroy(asProfile);
       
  1975 	
       
  1976     CAspLogDialog* dialog = CAspLogDialog::NewL(param);
       
  1977     CleanupStack::PushL(dialog);
       
  1978         
       
  1979     dialog->ShowDialogL();
       
  1980         
       
  1981     CleanupStack::PopAndDestroy(dialog);
       
  1982 	FLOG( _L("CAspSchedule::ShowAutoSyncLogL END") );
       
  1983 	}
       
  1984 
       
  1985 
       
  1986 // -----------------------------------------------------------------------------
       
  1987 // CAspSchedule::UpdateServerIdL
       
  1988 // Do server id modifications so that SAN selectes correct profile instead of hidden
       
  1989 // auto sync profile.
       
  1990 // -----------------------------------------------------------------------------
       
  1991 //
       
  1992 void CAspSchedule::UpdateServerIdL()
       
  1993 	{
       
  1994 	FLOG( _L("CAspSchedule::ClearAutoSyncProfileServerL START") );
       
  1995 	OpenSyncSessionL();
       
  1996 	TAspParam param(EApplicationIdSync, &iSyncSession);
       
  1997 		
       
  1998 	CAspProfile* asprofile = CAspProfile::NewLC(param);
       
  1999 	TRAPD (err, asprofile->OpenL(iAutoSyncProfileId, CAspProfile::EOpenReadWrite, 
       
  2000 	                           CAspProfile::EAllProperties));
       
  2001 	User::LeaveIfError(err);
       
  2002 
       
  2003 	CAspProfile* profile = CAspProfile::NewLC(param);
       
  2004 	TRAPD (err1, profile->OpenL(iProfileId, CAspProfile::EOpenReadWrite, 
       
  2005 	                           CAspProfile::EAllProperties));
       
  2006 	User::LeaveIfError(err1);
       
  2007 
       
  2008 	asprofile->GetServerId(iBuf);
       
  2009 	profile->SetServerIdL(iBuf);
       
  2010 	asprofile->SetServerIdL(KNullDesC);
       
  2011 	profile->SaveL();
       
  2012 	asprofile->SaveL();
       
  2013 	
       
  2014 	CleanupStack::PopAndDestroy(profile);
       
  2015 	CleanupStack::PopAndDestroy(asprofile);
       
  2016 	FLOG( _L("CAspSchedule::ClearAutoSyncProfileServerL END") );
       
  2017 	}
       
  2018 // -----------------------------------------------------------------------------
       
  2019 // CAspSchedule::IsContentSelected
       
  2020 //
       
  2021 // -----------------------------------------------------------------------------
       
  2022 //
       
  2023 TBool CAspSchedule::IsContentSelected()
       
  2024 	{
       
  2025 	TInt selectedContentCnt = 0;
       
  2026 	TInt selectedContentIndex = 0;
       
  2027 	
       
  2028 	ContentSelectionInfo(selectedContentCnt, selectedContentIndex);
       
  2029 	if (selectedContentCnt)
       
  2030 		{
       
  2031 		return ETrue;
       
  2032 		}
       
  2033 	return EFalse;
       
  2034 	}
       
  2035 
       
  2036 
       
  2037 #ifdef _DEBUG
       
  2038 
       
  2039 void CAspSchedule::LogSettings()
       
  2040 	{
       
  2041 	FLOG( _L("iProfileId   %d"),iProfileId);
       
  2042 	FLOG( _L("iPeakScheduleHandle   %d"),iPeakScheduleHandle);
       
  2043 	FLOG( _L("iOffPeakScheduleHandle   %d"),iOffPeakScheduleHandle);
       
  2044    	FLOG( _L("iStartPeakTimeHr   %d"),iStartPeakTimeHr);
       
  2045 	FLOG( _L("iStartPeakTimeMin   %d"),iStartPeakTimeMin);
       
  2046 	FLOG( _L("iEndPeakTimeHr   %d"),iEndPeakTimeHr);
       
  2047 	FLOG( _L("iEndPeakTimeMin   %d"),iEndPeakTimeMin);
       
  2048 	FLOG( _L("iSyncPeakSchedule   %d"),iSyncPeakSchedule);
       
  2049 	FLOG( _L("iSyncOffPeakSchedule   %d"),iSyncOffPeakSchedule);
       
  2050 	FLOG( _L("iDailySyncEnabled   %d"),iDailySyncEnabled);
       
  2051 	FLOG( _L("iPeakSyncEnabled   %d"),iPeakSyncEnabled);
       
  2052 	FLOG( _L("iOffPeakSyncEnabled   %d"),iOffPeakSyncEnabled);
       
  2053     FLOG( _L("iAutoSyncProfileId   %d"),iAutoSyncProfileId);
       
  2054     FLOG( _L("iAutoSyncScheduleTimeHr   %d"),iAutoSyncScheduleTimeHr);
       
  2055     FLOG( _L("iAutoSyncScheduleTimeMin   %d"),iAutoSyncScheduleTimeMin);
       
  2056 	
       
  2057 	
       
  2058 	}
       
  2059 
       
  2060 
       
  2061 
       
  2062 // -----------------------------------------------------------------------------
       
  2063 // CAspSchedule::LogScheduleL
       
  2064 // 
       
  2065 // -----------------------------------------------------------------------------
       
  2066 //
       
  2067 void CAspSchedule::LogScheduleL()
       
  2068 	{
       
  2069 	TBuf<128> buf; TBuf<128> buf2;
       
  2070 	
       
  2071 	FLOG( _L("---- automatic sync settings ----") );
       
  2072 	
       
  2073 	TTime time;
       
  2074 	time.HomeTime();
       
  2075     TUtil::GetDateTimeTextL(buf, time);
       
  2076     buf2.Format(_L("current time: %S"), &buf);
       
  2077     FLOG(buf2);
       
  2078     
       
  2079     if (PeakSyncEnabled())
       
  2080     	{
       
  2081     	buf = _L("Peak sync enabled");
       
  2082     	}
       
  2083    
       
  2084     FLOG(buf);
       
  2085 
       
  2086 	if (OffPeakSyncEnabled())
       
  2087     	{
       
  2088     	buf = _L("Off-Peak sync enabled");
       
  2089     	}
       
  2090     FLOG(buf);
       
  2091 	 
       
  2092     TInt id = ProfileId();
       
  2093     FLOG(_L("profile id: %d"), id);
       
  2094     
       
  2095     LogSyncInterval();
       
  2096     LogSyncDays();
       
  2097 
       
  2098 #if 0   
       
  2099     if (RoamingAllowed())
       
  2100     	{
       
  2101     	buf = _L("roaming allowed: yes");
       
  2102     	}
       
  2103     else
       
  2104     	{
       
  2105     	buf = _L("roaming allowed: no");
       
  2106        	}
       
  2107     FLOG(buf);
       
  2108 #endif
       
  2109     FLOG( _L("---- automatic sync settings ----") );
       
  2110     }
       
  2111 
       
  2112 
       
  2113 // -----------------------------------------------------------------------------
       
  2114 // CAspSchedule::LogSyncDays
       
  2115 // 
       
  2116 // -----------------------------------------------------------------------------
       
  2117 //
       
  2118 void CAspSchedule::LogSyncDays()
       
  2119 	{
       
  2120 	TBuf<128> buf; TBuf<128> buf2;
       
  2121 	
       
  2122 	buf = KNullDesC;
       
  2123 	
       
  2124 	if (WeekdayEnabled(EMonday))
       
  2125     	{
       
  2126     	buf.Append(_L("monday "));
       
  2127     	}
       
  2128 	if (WeekdayEnabled(ETuesday))
       
  2129     	{
       
  2130     	buf.Append(_L("tuesday "));
       
  2131     	}
       
  2132 	if (WeekdayEnabled(EWednesday))
       
  2133     	{
       
  2134     	buf.Append(_L("wednesday "));
       
  2135     	}
       
  2136 	if (WeekdayEnabled(EThursday))
       
  2137     	{
       
  2138     	buf.Append(_L("thursday "));
       
  2139     	}
       
  2140 	if (WeekdayEnabled(EFriday))
       
  2141     	{
       
  2142     	buf.Append(_L("friday "));
       
  2143     	}
       
  2144 	if (WeekdayEnabled(ESaturday))
       
  2145     	{
       
  2146     	buf.Append(_L("saturday "));
       
  2147     	}
       
  2148 	if (WeekdayEnabled(ESunday))
       
  2149     	{
       
  2150     	buf.Append(_L("sunday "));
       
  2151     	}
       
  2152 	if (buf.Length() == 0)
       
  2153     	{
       
  2154     	buf.Append(_L("none"));
       
  2155     	}
       
  2156 
       
  2157     buf2.Format(_L("sync days: %S"), &buf);
       
  2158     FLOG(buf2);
       
  2159     }
       
  2160 
       
  2161 
       
  2162 // -----------------------------------------------------------------------------
       
  2163 // CAspSchedule::LogSyncInterval
       
  2164 // 
       
  2165 // -----------------------------------------------------------------------------
       
  2166 //
       
  2167 void CAspSchedule::LogSyncInterval()
       
  2168 	{
       
  2169 	TBuf<128> buf; TBuf<128> buf2;
       
  2170 	
       
  2171 	switch (iSyncPeakSchedule)
       
  2172 		{
       
  2173 		case CAspSchedule::EIntervalManual:
       
  2174 		    buf = _L("Manual");
       
  2175 		    break;
       
  2176 		case CAspSchedule::EInterval15Mins:
       
  2177 		    buf = _L("15 minutes");
       
  2178 		    break;
       
  2179 		case CAspSchedule::EInterval30Mins:
       
  2180 		    buf = _L("30 minutes");
       
  2181 		    break;
       
  2182 		case CAspSchedule::EInterval1hour:
       
  2183 		    buf = _L("1 hour");
       
  2184 		    break;
       
  2185 		case CAspSchedule::EInterval2hours:
       
  2186 		    buf = _L("2 hours");
       
  2187 		    break;
       
  2188 		case CAspSchedule::EInterval4hours:
       
  2189 		    buf = _L("4 hours");
       
  2190 		    break;
       
  2191 		case CAspSchedule::EInterval8hours:
       
  2192 		    buf = _L("8 hours");
       
  2193 		    break;
       
  2194 		case CAspSchedule::EInterval12hours:
       
  2195 		    buf = _L("12 hours");
       
  2196 		    break;
       
  2197 		case CAspSchedule::EInterval24hours:
       
  2198 		    buf = _L("24 hours");
       
  2199 		    break;
       
  2200 		case CAspSchedule::EInterval2days:
       
  2201 		    buf = _L("2 days");
       
  2202 		    break;
       
  2203 		case CAspSchedule::EInterval4days:
       
  2204 		    buf = _L("4 days");
       
  2205 		    break;
       
  2206 		case CAspSchedule::EInterval7days:
       
  2207 		    buf = _L("7 days");
       
  2208 		    break;
       
  2209 		case CAspSchedule::EInterval14days:
       
  2210 		    buf = _L("14 days");
       
  2211 		    break;
       
  2212 		case CAspSchedule::EInterval30days:
       
  2213 		    buf = _L("30 days");
       
  2214 		    break;
       
  2215 		default:
       
  2216 		    buf = _L("unknown sync interval");
       
  2217 		    break;
       
  2218 		}
       
  2219 		
       
  2220     buf2.Format(_L("sync interval: %S"), &buf);
       
  2221     FLOG(buf2);
       
  2222     }
       
  2223 
       
  2224 #endif  // _DEBUG
       
  2225 
       
  2226 
       
  2227 #ifdef _DEBUG
       
  2228 
       
  2229 
       
  2230 // ----------------------------------------------------------------------------
       
  2231 // CAspSchedule::PrintTimeL
       
  2232 //
       
  2233 // ----------------------------------------------------------------------------
       
  2234 //
       
  2235 void CAspSchedule::PrintTimeL(TTime aTime)
       
  2236 	{
       
  2237 	TBuf<128> buf;
       
  2238 	TUtil::GetDateTimeTextL(buf, aTime);
       
  2239 	TDialogUtil::ShowInformationQueryL(buf);
       
  2240 	}
       
  2241 
       
  2242 
       
  2243 // -----------------------------------------------------------------------------
       
  2244 // CAspSchedule::TestL
       
  2245 //
       
  2246 // -----------------------------------------------------------------------------
       
  2247 //
       
  2248 void CAspSchedule::TestL()
       
  2249 	{
       
  2250 	TRAPD(err, DoTestL());
       
  2251 	
       
  2252 	if (err != KErrNone)
       
  2253 		{
       
  2254 	    TBuf<KBufSize> buf;
       
  2255         buf.Format(_L("TestL failed (%d)"), err);
       
  2256         TDialogUtil::ShowErrorNoteL(buf);
       
  2257 		}
       
  2258 	}
       
  2259 
       
  2260 
       
  2261 // -----------------------------------------------------------------------------
       
  2262 // CAspSchedule::DoTestL
       
  2263 //
       
  2264 // -----------------------------------------------------------------------------
       
  2265 //
       
  2266 void CAspSchedule::DoTestL()
       
  2267 	{
       
  2268 	const TInt KTestCount = 500;
       
  2269 	
       
  2270     TInt err = KErrNone;
       
  2271     
       
  2272     ResetRepositoryL();
       
  2273     
       
  2274     CAspSchedule* s = NULL;
       
  2275     TInt count = 0;
       
  2276     for (; count<KTestCount; count++)
       
  2277     	{
       
  2278         TRAP(err, InternalizeL());
       
  2279         if (err != KErrNone)
       
  2280         	{
       
  2281         	User::Leave(err);
       
  2282         	}
       
  2283         
       
  2284         if (s)
       
  2285         	{
       
  2286       		CompareValues(s);
       
  2287         	CleanupStack::PopAndDestroy(s);
       
  2288         	s = NULL;
       
  2289         	}
       
  2290 
       
  2291         TRAP(err, UpdateValuesL(count));
       
  2292         if (err != KErrNone)
       
  2293         	{
       
  2294         	User::Leave(err);
       
  2295         	}
       
  2296         
       
  2297         s = CreateCopyLC();
       
  2298         	
       
  2299         TRAP(err, ExternalizeL());
       
  2300         if (err != KErrNone)
       
  2301         	{
       
  2302         	User::Leave(err);
       
  2303         	}
       
  2304      	}
       
  2305     	
       
  2306     if (s)
       
  2307     	{
       
  2308     	CleanupStack::PopAndDestroy(s);
       
  2309     	}
       
  2310     	
       
  2311     TBuf<KBufSize> buf;
       
  2312     buf.Format(_L("centrep test ok (%d)"), count);
       
  2313     TDialogUtil::ShowErrorNoteL(buf);
       
  2314     
       
  2315     	
       
  2316 	return;
       
  2317 	}
       
  2318 
       
  2319 
       
  2320 // ----------------------------------------------------------------------------
       
  2321 // UpdateValuesL
       
  2322 //
       
  2323 // ----------------------------------------------------------------------------
       
  2324 //
       
  2325 void CAspSchedule::UpdateValuesL(TInt aCount)
       
  2326     {
       
  2327     TInt num = 100 * aCount;
       
  2328     TBool isEven = aCount % 2;
       
  2329     
       
  2330     iPeakScheduleHandle = num+1;
       
  2331 	iOffPeakScheduleHandle = num +1;
       
  2332   
       
  2333     iError          = num+3;
       
  2334     
       
  2335     iPeakSyncEnabled = isEven;
       
  2336 	iOffPeakSyncEnabled = isEven;
       
  2337     iProfileId = num+4;
       
  2338     
       
  2339     iRoamingAllowed = isEven;
       
  2340     
       
  2341 	if (isEven)
       
  2342     	{
       
  2343     	SetWeekdayEnabled(EMonday, ETrue);
       
  2344     	SetWeekdayEnabled(ETuesday, ETrue);
       
  2345     	SetWeekdayEnabled(EWednesday, ETrue);
       
  2346     	SetWeekdayEnabled(EThursday, ETrue);
       
  2347     	SetWeekdayEnabled(EFriday, ETrue);
       
  2348     	SetWeekdayEnabled(ESaturday, EFalse);
       
  2349     	SetWeekdayEnabled(ESunday, EFalse);
       
  2350     	}
       
  2351     else
       
  2352     	{
       
  2353     	SetWeekdayEnabled(EMonday, EFalse);
       
  2354     	SetWeekdayEnabled(ETuesday, EFalse);
       
  2355     	SetWeekdayEnabled(EWednesday, EFalse);
       
  2356     	SetWeekdayEnabled(EThursday, EFalse);
       
  2357     	SetWeekdayEnabled(EFriday, EFalse);
       
  2358     	SetWeekdayEnabled(ESaturday, ETrue);
       
  2359     	SetWeekdayEnabled(ESunday, ETrue);
       
  2360     	}
       
  2361     }
       
  2362 
       
  2363 
       
  2364 // ----------------------------------------------------------------------------
       
  2365 // CreateCopyLC
       
  2366 //
       
  2367 // ----------------------------------------------------------------------------
       
  2368 //
       
  2369 CAspSchedule* CAspSchedule::CreateCopyLC()
       
  2370     {
       
  2371     CAspSchedule* s = CAspSchedule::NewL();
       
  2372     CleanupStack::PushL(s);
       
  2373     
       
  2374     s->iPeakScheduleHandle = iPeakScheduleHandle;
       
  2375 	s->iOffPeakScheduleHandle = iOffPeakScheduleHandle;
       
  2376     s->iError = iError;
       
  2377     s->SetProfileId(ProfileId());
       
  2378     s->SetPeakSyncEnabled(PeakSyncEnabled());
       
  2379     s->SetRoamingAllowed(RoamingAllowed());
       
  2380     
       
  2381     
       
  2382     TBool enabled = EFalse;
       
  2383     if (WeekdayEnabled(EMonday))
       
  2384     	{
       
  2385         enabled = ETrue;    	
       
  2386     	}
       
  2387     s->SetWeekdayEnabled(EMonday, enabled);    	
       
  2388     	
       
  2389     enabled = EFalse;
       
  2390     if (WeekdayEnabled(ETuesday))
       
  2391     	{
       
  2392         enabled = ETrue;    	
       
  2393     	}
       
  2394     s->SetWeekdayEnabled(ETuesday, enabled);    	
       
  2395     
       
  2396     enabled = EFalse;
       
  2397     if (WeekdayEnabled(EWednesday))
       
  2398     	{
       
  2399         enabled = ETrue;    	
       
  2400     	}
       
  2401     s->SetWeekdayEnabled(EWednesday, enabled);    	
       
  2402     
       
  2403     enabled = EFalse;
       
  2404     if (WeekdayEnabled(EThursday))
       
  2405     	{
       
  2406         enabled = ETrue;    	
       
  2407     	}
       
  2408     s->SetWeekdayEnabled(EThursday, enabled);    	
       
  2409     
       
  2410     enabled = EFalse;
       
  2411     if (WeekdayEnabled(EFriday))
       
  2412     	{
       
  2413         enabled = ETrue;    	
       
  2414     	}
       
  2415     s->SetWeekdayEnabled(EFriday, enabled);
       
  2416     
       
  2417     enabled = EFalse;
       
  2418     if (WeekdayEnabled(ESaturday))
       
  2419     	{
       
  2420         enabled = ETrue;    	
       
  2421     	}
       
  2422     s->SetWeekdayEnabled(ESaturday, enabled);    	
       
  2423     
       
  2424     enabled = EFalse;
       
  2425     if (WeekdayEnabled(ESunday))
       
  2426     	{
       
  2427         enabled = ETrue;    	
       
  2428     	}
       
  2429     s->SetWeekdayEnabled(ESunday, enabled);
       
  2430     
       
  2431     return s;
       
  2432     }
       
  2433 
       
  2434 
       
  2435 // ----------------------------------------------------------------------------
       
  2436 // CompareValues
       
  2437 //
       
  2438 // ----------------------------------------------------------------------------
       
  2439 //
       
  2440 void CAspSchedule::CompareValues(CAspSchedule* aSchedule)
       
  2441     {
       
  2442     CAspSchedule* s = aSchedule;
       
  2443     
       
  2444     AssertEqual(s->PeakScheduleHandle(), PeakScheduleHandle());
       
  2445     AssertEqual(s->OffPeakScheduleHandle(), OffPeakScheduleHandle());
       
  2446     AssertEqual(s->Error(), Error());
       
  2447     AssertEqual(s->ProfileId(), ProfileId());
       
  2448 
       
  2449 	AssertEqual(s->PeakSyncEnabled(), PeakSyncEnabled());
       
  2450 	AssertEqual(s->OffPeakSyncEnabled(), OffPeakSyncEnabled());
       
  2451    
       
  2452     AssertEqual(s->RoamingAllowed(), RoamingAllowed());
       
  2453     
       
  2454     AssertEqual(s->iWeekdayFlags, iWeekdayFlags);    
       
  2455   
       
  2456     AssertEqual(s->WeekdayEnabled(EMonday), WeekdayEnabled(EMonday));
       
  2457     AssertEqual(s->WeekdayEnabled(ETuesday), WeekdayEnabled(ETuesday));
       
  2458     AssertEqual(s->WeekdayEnabled(EWednesday), WeekdayEnabled(EWednesday));
       
  2459     AssertEqual(s->WeekdayEnabled(EThursday), WeekdayEnabled(EThursday));
       
  2460     AssertEqual(s->WeekdayEnabled(EFriday), WeekdayEnabled(EFriday));
       
  2461     AssertEqual(s->WeekdayEnabled(ESaturday), WeekdayEnabled(ESaturday));
       
  2462     AssertEqual(s->WeekdayEnabled(ESunday), WeekdayEnabled(ESunday));
       
  2463     }
       
  2464 
       
  2465 
       
  2466 // ----------------------------------------------------------------------------
       
  2467 // AssertEqual
       
  2468 //
       
  2469 // ----------------------------------------------------------------------------
       
  2470 //
       
  2471 void CAspSchedule::AssertEqual(TInt aValue1, TInt aValue2)
       
  2472     {
       
  2473     __ASSERT_DEBUG(aValue1 == aValue2, TUtil::Panic(KErrArgument));
       
  2474     }
       
  2475 
       
  2476 #endif  // _DEBUG
       
  2477 
       
  2478 
       
  2479 
       
  2480 // End of file
       
  2481