omads/omadsappui/AspSyncUtil/inc/AspSchedule.h
branchRCL_3
changeset 52 4f0867e42d62
parent 0 dab8a81a92de
equal deleted inserted replaced
51:8e7494275d3a 52:4f0867e42d62
       
     1 /*
       
     2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: Scheduled sync implementation and setting access 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef ASPSCHEDULE_H
       
    20 #define ASPSCHEDULE_H
       
    21 
       
    22 // INCLUDES
       
    23 #include <e32base.h>
       
    24 #include <SyncMLClient.h>    // for RSyncMLSession
       
    25 #include <SyncMLObservers.h>
       
    26 
       
    27 #include "AspDefines.h"
       
    28 #include "AspUtil.h"
       
    29 
       
    30 
       
    31 // CONSTANTS
       
    32 const TInt KDefaultStartHour = 12; // 12 noon
       
    33 const TInt KStartPeakHour = 8;
       
    34 const TInt KStartPeakMin = 00;
       
    35 const TInt KEndPeakHour = 17;
       
    36 const TInt KEndPeakMin = 00;
       
    37 _LIT(KAutoSyncProfileName, "AutoSync Profile");
       
    38 
       
    39 
       
    40 // FORWARD DECLARATIONS
       
    41 class CAspProfile;
       
    42 class CAspFilterItem;
       
    43 
       
    44 
       
    45 /**
       
    46 * CAspSchedule
       
    47 *  
       
    48 */
       
    49 NONSHARABLE_CLASS (CAspSchedule) : public CBase
       
    50     {
       
    51     private:
       
    52 	enum TRepositoryKey
       
    53 		{
       
    54 	   // ERepositoryKeyInt = 1,
       
    55 	    ERepositoryKeyBin = 1
       
    56 		};
       
    57 		
       
    58     public:
       
    59 		
       
    60     enum TWeekdayFlags
       
    61         {
       
    62 	    EFlagMonday      = 0x00000001,
       
    63 	    EFlagTuesday     = 0x00000002,
       
    64 	    EFlagWednesday   = 0x00000004,
       
    65 	    EFlagThursday    = 0x00000008,
       
    66 	    EFlagFriday      = 0x00000010,
       
    67 	    EFlagSaturday    = 0x00000020,
       
    68 	    EFlagSunday      = 0x00000040
       
    69         };
       
    70 
       
    71 	enum TSyncInterval
       
    72 		{
       
    73 		EIntervalManual = 0,
       
    74 		EInterval15Mins,
       
    75 		EInterval30Mins,
       
    76 		EInterval1hour,
       
    77 		EInterval2hours,
       
    78 		EInterval4hours,
       
    79 		EInterval8hours,
       
    80 		EInterval12hours,
       
    81 		EManyTimesPerDay,
       
    82 		EInterval24hours,
       
    83 		EInterval2days,
       
    84 		EInterval4days,
       
    85 		EInterval7days,
       
    86 		EInterval14days,
       
    87 		EInterval30days
       
    88 		};
       
    89 	
       
    90   
       
    91 	public:// Constructors and destructor
       
    92 
       
    93         /**
       
    94         * Two-phased constructor.
       
    95         */
       
    96         static CAspSchedule* NewL();
       
    97         
       
    98         /**
       
    99         * Two-phased constructor.
       
   100         */
       
   101         static CAspSchedule* NewLC();
       
   102 
       
   103         /**
       
   104         * Destructor.
       
   105         */
       
   106         virtual ~CAspSchedule();
       
   107     
       
   108     private:
       
   109 
       
   110         /**
       
   111         * C++ default constructor.
       
   112         */	
       
   113         CAspSchedule();
       
   114 	
       
   115         /**
       
   116         * By default Symbian OS constructor is private.
       
   117         */
       
   118         void ConstructL();
       
   119 
       
   120 	public:
       
   121 
       
   122 		/**
       
   123         *  auto sync error
       
   124         */	
       
   125 	    TInt Error();
       
   126 	    void SetError(TInt aError);
       
   127 
       
   128 		/**
       
   129         *  Profile selected for auto sync
       
   130         */	
       
   131 	    TInt ProfileId();
       
   132 	    void SetProfileId(TInt aProfileId);
       
   133 
       
   134 		/**
       
   135         *  week day selection 
       
   136         */	
       
   137 	    TBool WeekdayEnabled(TInt aWeekday);
       
   138 	    void SetWeekdayEnabled(TInt aWeekday, TBool aEnabled);
       
   139 	    
       
   140 	    TBool RoamingAllowed();
       
   141 	    void SetRoamingAllowed(TBool aAllowed);
       
   142 	    
       
   143 	    void SelectedDayInfo(TInt& aDayCount, TInt& aWeekday);
       
   144 
       
   145 		/**
       
   146         * Save all settings using a cenrep key
       
   147         */	
       
   148         void SaveL();
       
   149 
       
   150 		/**
       
   151         * Auto sync content selection
       
   152         */	
       
   153 		void SetContentEnabled(TInt aContent, TInt aEnabled);
       
   154 	    TBool ContentEnabled(TInt aContent);
       
   155 	    void ContentSelectionInfo(TInt& aContentCnt, TInt& aContent);
       
   156 
       
   157 		/**
       
   158         * Auto sync interval
       
   159         */	
       
   160         void SetSyncFrequency(TInt aSchedule);
       
   161 		void SetSyncPeakSchedule(TInt aSchedule);
       
   162 		void SetSyncOffPeakSchedule(TInt aSchedule);
       
   163 		TInt SyncFrequency();
       
   164 		TInt SyncPeakSchedule();
       
   165 		TInt SyncOffPeakSchedule();
       
   166 
       
   167 		/**
       
   168         * Peak time definition
       
   169         */	
       
   170 		void SetStartPeakTime(TTime aStartTime);
       
   171 		void SetEndPeakTime(TTime aEndTime);
       
   172 		TTime StartPeakTime();
       
   173 		TTime EndPeakTime();
       
   174 
       
   175 		/**
       
   176         * Auto sync enabled/disabled
       
   177         */	
       
   178 		void SetDailySyncEnabled(TBool aSyncEnabled);
       
   179 		TBool DailySyncEnabled();
       
   180 		void SetPeakSyncEnabled(TBool aSyncEnabled);
       
   181 		TBool PeakSyncEnabled();
       
   182 		void SetOffPeakSyncEnabled(TBool aSyncEnabled);
       
   183 		TBool OffPeakSyncEnabled();
       
   184 
       
   185 		/**
       
   186         * Sync time for intervals >= a day
       
   187         */	
       
   188 		void SetAutoSyncScheduleTime(TTime aSchedule);
       
   189 		TTime AutoSyncScheduleTime();	
       
   190 
       
   191 		/**
       
   192         * Schedule handle returned by task scheduler during schedule creation
       
   193         */	
       
   194 		void SetPeakScheduleHandle(TInt aHandle);
       
   195 		TInt PeakScheduleHandle();
       
   196 		void SetOffPeakScheduleHandle(TInt aHandle);
       
   197 		TInt OffPeakScheduleHandle();
       
   198 
       
   199 		/**
       
   200         * A hidden profile used for auto sync.Contents are set as the content selected in auto sync settings
       
   201         *
       
   202         */	
       
   203 
       
   204 		void CreateAutoSyncProfileL();
       
   205 		TInt AutoSyncProfileId();
       
   206 		void SetAutoSyncProfileId(TInt aProfileId);
       
   207 		void CopyAutoSyncContentsL();
       
   208 		void UpdateProfileSettingsL();
       
   209 		
       
   210 		/**
       
   211         * Check validity of shedule based on current time and user defined peak time
       
   212         *
       
   213         */					
       
   214 		TInt IsValidPeakScheduleL();
       
   215 		TInt IsValidOffPeakScheduleL();
       
   216 
       
   217 		TBool IsValidNextPeakScheduleL();
       
   218 		TBool IsValidNextOffPeakScheduleL();
       
   219 
       
   220 		/**
       
   221         * Post pone schedule until next valid time
       
   222         */
       
   223 		void UpdatePeakScheduleL();
       
   224 		void UpdateOffPeakScheduleL();
       
   225 		TIntervalType IntervalType(TInt aInterval);
       
   226 
       
   227 		void EnableScheduleL();
       
   228 
       
   229 		/**
       
   230         * Check if any valid mail box exists
       
   231         */
       
   232 		TBool MailboxExistL();
       
   233 
       
   234 		/**
       
   235         * Check mandatory settings for the selected profile
       
   236         */
       
   237 		TInt CheckMandatoryDataL(TInt& count,TInt& firstItem);
       
   238 
       
   239 		/**
       
   240         * Log view opened by clicking View Details link in auto sync error note
       
   241         */
       
   242 		void ShowAutoSyncLogL();
       
   243 
       
   244 		/**
       
   245         *SyncML sever version of selected profile
       
   246         */
       
   247 		TInt ProtocolL();
       
   248 
       
   249 		/**
       
   250         *Server Id modifications so that SAN selects correct profile
       
   251         */
       
   252 		void UpdateServerIdL();
       
   253 
       
   254 		/**
       
   255         *Check if atleast one valid content selected
       
   256         */
       
   257 		TBool IsContentSelected();
       
   258 		
       
   259 		/**
       
   260         *Check if auto sync is enabled
       
   261         */
       
   262 		TBool IsAutoSyncEnabled();
       
   263 
       
   264 		/**
       
   265         *Initialize contents
       
   266         */
       
   267 		void InitializeContentsL();
       
   268 
       
   269 		
       
   270 		/**
       
   271         *Check the validity of email selection.
       
   272         */
       
   273 		void CheckEmailSelectionL();
       
   274 
       
   275 				
       
   276     public:
       
   277 
       
   278 		/**
       
   279         *Update the schedule settings with symbian task scheduler
       
   280         */
       
   281         void UpdateSyncScheduleL();
       
   282         void UpdateSyncSchedule();
       
   283         void GetStartTimeL(TTime& aTime, TBool aHomeTime);
       
   284                
       
   285       
       
   286 #ifdef _DEBUG
       
   287 		void LogSettings();
       
   288 #endif
       
   289 
       
   290 
       
   291     public:
       
   292    	    TBool CanSynchronizeL();
       
   293 		
       
   294 	private:
       
   295 	    void InitializeL();
       
   296 	
       
   297 	public:
       
   298         static TTime UniversalStartTime(TInt& aStartHour);
       
   299         static TTime LocalStartTime(TInt aStartHour);
       
   300         
       
   301 	
       
   302 	private:
       
   303 	    void InternalizeL();
       
   304 		void DoInternalizeL();
       
   305 		void InternalizeL(RReadStream& aStream);
       
   306 		void ExternalizeL();
       
   307 		void ExternalizeL(RWriteStream& aStream);
       
   308 		void WriteRepositoryL(TInt aKey, const TDesC8& aValue);
       
   309 		void ReadRepositoryL(TInt aKey, TDes8& aValue);
       
   310 		void ResetRepositoryL();
       
   311 		
       
   312 	private:
       
   313 		TInt WeekdayFlag(TInt aWeekday);
       
   314 		TBool IsDaySelected(TTime aTime);
       
   315 	
       
   316 		void OpenSyncSessionL();
       
   317 		void CloseSyncSession();
       
   318 
       
   319 		
       
   320 #ifdef _DEBUG        
       
   321 	public:
       
   322 	    void LogScheduleL();
       
   323 	    void LogSyncDays();
       
   324 	    void LogSyncInterval();	
       
   325 
       
   326 
       
   327     public:
       
   328         static void PrintTimeL(TTime aTime);
       
   329         void TestL();
       
   330         void DoTestL();
       
   331         void UpdateValuesL(TInt aCount);
       
   332         CAspSchedule* CreateCopyLC();
       
   333         void CompareValues(CAspSchedule* aSchedule);
       
   334         void AssertEqual(TInt aValue1, TInt aValue2);
       
   335 #endif
       
   336 
       
   337         	    
       
   338 		
       
   339     private:
       
   340    
       
   341          // error code
       
   342         TInt iError;
       
   343 
       
   344 		// profile id
       
   345 		TInt iProfileId;
       
   346 		
       
   347 		// selected days
       
   348 		TUint32 iWeekdayFlags;
       
   349 		
       
   350 		// start hour
       
   351 		TInt iStartHour;
       
   352 
       
   353 		// is roaming allowed
       
   354 		TBool iRoamingAllowed;
       
   355 		
       
   356 		// data provider id list
       
   357 		RArray<TInt> iList;
       
   358 		
       
   359         // long buffer for string handling 
       
   360 		TBuf<KBufSize255> iBuf;
       
   361 		
       
   362 		// have settings changed
       
   363 		TBool iSettingChanged;
       
   364 
       
   365 		//content selection flags
       
   366 		TUint32 iContentFlags;
       
   367 		
       
   368 		TInt iStartPeakTimeHr;
       
   369 		TInt iStartPeakTimeMin;
       
   370 		TInt iEndPeakTimeHr;
       
   371         TInt iEndPeakTimeMin;		
       
   372 
       
   373 		//peak interval
       
   374 		TInt iSyncPeakSchedule;
       
   375 
       
   376 		//off-peak interval
       
   377 		TInt iSyncOffPeakSchedule;
       
   378 
       
   379 		
       
   380 		TBool iPeakSyncEnabled;
       
   381 		TBool iOffPeakSyncEnabled;
       
   382 
       
   383 		//A new RSyncMLProfileBase profile is created for auto sync
       
   384 		//Selected Auto sync contents are set as the task items for this profile
       
   385 		//All the settings for this profie are copied from the profile selected by user.
       
   386 		
       
   387 		TInt iAutoSyncProfileId;
       
   388 		
       
   389         //Sync time for once a day sync
       
   390 		TInt iAutoSyncScheduleTimeHr;
       
   391 		TInt iAutoSyncScheduleTimeMin;
       
   392 
       
   393 		//schedule handles.
       
   394         TInt iPeakScheduleHandle;
       
   395 		TInt iOffPeakScheduleHandle;
       
   396 
       
   397 		// sync session
       
   398 		RSyncMLSession iSyncSession;
       
   399 
       
   400 		// is sync session open
       
   401 		TBool iSyncSessionOpen;
       
   402 
       
   403 		// Daily sync setting
       
   404 		TBool iDailySyncEnabled;
       
   405 		TInt iSyncFrequency;
       
   406 
       
   407 		
       
   408     };
       
   409 
       
   410 #endif  // ASPSCHEDULE_H
       
   411 
       
   412 // End of file