|
1 /* |
|
2 * Copyright (c) 2007-2009 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: This file implements CESMRRecurrenceInfoHandler. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 //<cmail> |
|
20 #include "emailtrace.h" |
|
21 #include "cesmrrecurrenceinfohandler.h" |
|
22 #include "esmrdef.h" |
|
23 //</cmail> |
|
24 |
|
25 #include "mesmrmeetingrequestentry.h" |
|
26 |
|
27 #include <calentry.h> |
|
28 #include <calrrule.h> |
|
29 #include <calcommon.h> |
|
30 |
|
31 /// Unnamed namespace for local definitions |
|
32 namespace { |
|
33 |
|
34 // Definition for 0 |
|
35 const TInt KZero = 0; |
|
36 |
|
37 // Definition for 1 |
|
38 const TInt KOne = 1; |
|
39 |
|
40 // Definition for 2 |
|
41 const TInt KTwo = 2; |
|
42 |
|
43 // Definition for days in week |
|
44 const TInt KDaysInWeek = 7; |
|
45 |
|
46 // Definition for days in two weeks |
|
47 const TInt KDaysInTwoWeeks = 14; |
|
48 |
|
49 // Definition for montsh in year |
|
50 const TInt KMonthsInYear = 12; |
|
51 |
|
52 /** |
|
53 * Compares two times and returns ETrue if they have same date components |
|
54 * @param aLhs Left hand side component |
|
55 * @param aRhs Right hand side component |
|
56 */ |
|
57 TBool IsSameDay( |
|
58 const TDateTime& aLhs, |
|
59 const TDateTime& aRhs ) |
|
60 { |
|
61 TBool retValue(EFalse); |
|
62 |
|
63 if ( aLhs.Day() == aRhs.Day() && |
|
64 aLhs.Month() == aRhs.Month() && |
|
65 aLhs.Year() == aRhs.Year() ) |
|
66 { |
|
67 retValue = ETrue; |
|
68 } |
|
69 |
|
70 return retValue; |
|
71 } |
|
72 |
|
73 /** |
|
74 * Checks if instance is included in exception list. |
|
75 * @param aInstanceTime Reference to instance time. |
|
76 * @param aExDateList Reference to exception list. |
|
77 */ |
|
78 TBool IsTimeIncluded( |
|
79 const TCalTime& aInstanceTime, |
|
80 const RArray<TCalTime>& aExDateList ) |
|
81 { |
|
82 FUNC_LOG; |
|
83 TBool included( EFalse ); |
|
84 TInt exceptionCount( aExDateList.Count() ); |
|
85 if ( exceptionCount ) |
|
86 { |
|
87 for (TInt i(0); (i < exceptionCount) && !included ; i++ ) |
|
88 { |
|
89 const TCalTime& exceptionTime( aExDateList[i] ); |
|
90 TDateTime exDate = exceptionTime.TimeLocalL().DateTime(); |
|
91 |
|
92 if ( aInstanceTime.TimeLocalL() == exceptionTime.TimeLocalL() ) |
|
93 { |
|
94 included = ETrue; |
|
95 } |
|
96 } |
|
97 } |
|
98 return included; |
|
99 } |
|
100 |
|
101 /** |
|
102 * Calculates time for next instance for recurrent event. |
|
103 * @param aRecurrenceValue Defines the used recurrence. |
|
104 * @param aPrevInstanceStartTime Start time of the previous instance. |
|
105 */ |
|
106 TTime TimeForNextInstaceStartTime( |
|
107 TESMRRecurrenceValue aRecurrenceValue, |
|
108 TCalTime& aPrevInstanceStartTime ) |
|
109 { |
|
110 TTime nextStartTime = aPrevInstanceStartTime.TimeLocalL(); |
|
111 |
|
112 switch ( aRecurrenceValue ) |
|
113 { |
|
114 case ERecurrenceDaily: |
|
115 { |
|
116 nextStartTime += TTimeIntervalDays( KOne ); |
|
117 } |
|
118 break; |
|
119 case ERecurrenceWeekly: |
|
120 { |
|
121 nextStartTime += TTimeIntervalDays( KDaysInWeek ); |
|
122 } |
|
123 break; |
|
124 case ERecurrenceEverySecondWeek: |
|
125 { |
|
126 nextStartTime += TTimeIntervalDays( KDaysInTwoWeeks ); |
|
127 } |
|
128 break; |
|
129 case ERecurrenceMonthly: |
|
130 { |
|
131 nextStartTime += TTimeIntervalMonths( KOne ); |
|
132 } |
|
133 break; |
|
134 case ERecurrenceYearly: |
|
135 { |
|
136 nextStartTime += TTimeIntervalYears( KOne ); |
|
137 } |
|
138 break; |
|
139 default: |
|
140 { |
|
141 nextStartTime = aPrevInstanceStartTime.TimeLocalL(); |
|
142 } |
|
143 break; |
|
144 } |
|
145 |
|
146 return nextStartTime; |
|
147 } |
|
148 |
|
149 |
|
150 void CalculateUntilForUnknownRecurrenceL( |
|
151 TTime& aUntil, |
|
152 TCalRRule& aRule ) |
|
153 { |
|
154 aUntil = aRule.Until().TimeLocalL(); |
|
155 if ( Time::NullTTime() == aUntil ) |
|
156 { |
|
157 aUntil = aRule.DtStart().TimeLocalL(); |
|
158 TInt factor( aRule.Count() * aRule.Interval() ); |
|
159 |
|
160 switch ( aRule.Type() ) |
|
161 { |
|
162 case TCalRRule::EDaily: |
|
163 { |
|
164 aUntil += TTimeIntervalDays(factor ); |
|
165 } |
|
166 break; |
|
167 case TCalRRule::EWeekly: |
|
168 { |
|
169 aUntil += TTimeIntervalDays(factor * KDaysInWeek ); |
|
170 } |
|
171 break; |
|
172 case TCalRRule::EMonthly: |
|
173 { |
|
174 aUntil += TTimeIntervalMonths(factor ); |
|
175 } |
|
176 break; |
|
177 case TCalRRule::EYearly: |
|
178 { |
|
179 aUntil += TTimeIntervalYears(factor ); |
|
180 } |
|
181 break; |
|
182 } |
|
183 } |
|
184 } |
|
185 |
|
186 } // namespace |
|
187 |
|
188 // ======== MEMBER FUNCTIONS ======== |
|
189 |
|
190 // --------------------------------------------------------------------------- |
|
191 // CESMRRecurrenceInfoHandler::CESMRRecurrenceInfoHandler |
|
192 // --------------------------------------------------------------------------- |
|
193 // |
|
194 inline CESMRRecurrenceInfoHandler::CESMRRecurrenceInfoHandler( |
|
195 CCalEntry& aEntry ) : |
|
196 iEntry( aEntry ) |
|
197 { |
|
198 FUNC_LOG; |
|
199 // Not implementation yet |
|
200 } |
|
201 |
|
202 // --------------------------------------------------------------------------- |
|
203 // CESMRRecurrenceInfoHandler::~CESMRRecurrenceInfoHandler |
|
204 // --------------------------------------------------------------------------- |
|
205 // |
|
206 EXPORT_C CESMRRecurrenceInfoHandler::~CESMRRecurrenceInfoHandler() |
|
207 { |
|
208 FUNC_LOG; |
|
209 // Not implementation yet |
|
210 } |
|
211 |
|
212 // --------------------------------------------------------------------------- |
|
213 // CESMRRecurrenceInfoHandler::NewL |
|
214 // --------------------------------------------------------------------------- |
|
215 // |
|
216 EXPORT_C CESMRRecurrenceInfoHandler* CESMRRecurrenceInfoHandler::NewL( |
|
217 CCalEntry& aEntry ) |
|
218 { |
|
219 FUNC_LOG; |
|
220 |
|
221 CESMRRecurrenceInfoHandler* self = NewLC( aEntry ); |
|
222 CleanupStack::Pop( self ); |
|
223 |
|
224 |
|
225 return self; |
|
226 } |
|
227 |
|
228 // --------------------------------------------------------------------------- |
|
229 // CESMRRecurrenceInfoHandler::NewLC |
|
230 // --------------------------------------------------------------------------- |
|
231 // |
|
232 EXPORT_C CESMRRecurrenceInfoHandler* CESMRRecurrenceInfoHandler::NewLC( |
|
233 CCalEntry& aEntry ) |
|
234 { |
|
235 FUNC_LOG; |
|
236 |
|
237 CESMRRecurrenceInfoHandler* self = |
|
238 new (ELeave) CESMRRecurrenceInfoHandler(aEntry); |
|
239 CleanupStack::PushL( self ); |
|
240 self->ConstructL(); |
|
241 |
|
242 |
|
243 return self; |
|
244 } |
|
245 |
|
246 // --------------------------------------------------------------------------- |
|
247 // CESMRRecurrenceInfoHandler::ConstructL |
|
248 // --------------------------------------------------------------------------- |
|
249 // |
|
250 void CESMRRecurrenceInfoHandler::ConstructL() |
|
251 { |
|
252 FUNC_LOG; |
|
253 // Not implementation yet |
|
254 } |
|
255 |
|
256 // --------------------------------------------------------------------------- |
|
257 // CESMRRecurrenceInfoHandler::SetRecurrenceL |
|
258 // |
|
259 // --------------------------------------------------------------------------- |
|
260 // |
|
261 EXPORT_C void CESMRRecurrenceInfoHandler::SetRecurrenceL( |
|
262 TESMRRecurrenceValue aRecurrence, |
|
263 TTime aUntil ) |
|
264 { |
|
265 FUNC_LOG; |
|
266 |
|
267 // Recurrence until time needs to be in Utc mode, because comparison in |
|
268 // NeedToSetRecurrenceL is based on UTC times |
|
269 TCalTime until; |
|
270 until.SetTimeLocalL( aUntil ); |
|
271 TTime recUntilUtc = until.TimeUtcL(); |
|
272 |
|
273 // Check input parameters |
|
274 if ( ERecurrenceNot != aRecurrence && |
|
275 Time::NullTTime() == aUntil ) |
|
276 { |
|
277 // No until parameter set --> Leave |
|
278 User::Leave( KErrArgument ); |
|
279 } |
|
280 else if ( ERecurrenceNot == aRecurrence ) |
|
281 { |
|
282 // Clear all (recurrence, exceptions) repeating properties |
|
283 iEntry.ClearRepeatingPropertiesL(); |
|
284 } |
|
285 else if ( NeedToSetRecurrenceL(aRecurrence, recUntilUtc) ) |
|
286 { |
|
287 // Calculate 'correct' until time |
|
288 // Date component is taken from input parameter and |
|
289 // time component from meeting's end time. |
|
290 TDateTime until = aUntil.DateTime(); |
|
291 TDateTime endTime = iEntry.EndTimeL().TimeLocalL().DateTime(); |
|
292 until.SetHour( endTime.Hour() ); |
|
293 until.SetMinute( endTime.Minute() ); |
|
294 until.SetSecond( endTime.Second() ); |
|
295 |
|
296 TCalTime rEndTime; |
|
297 rEndTime.SetTimeLocalL( TTime(until) ); |
|
298 |
|
299 TCalTime meetingStartTime = iEntry.StartTimeL(); |
|
300 |
|
301 TCalRRule rRule; |
|
302 rRule.SetDtStart( meetingStartTime ); |
|
303 |
|
304 // Clear recurrence properties before setting the correct one |
|
305 iEntry.ClearRepeatingPropertiesL(); |
|
306 |
|
307 switch ( aRecurrence ) |
|
308 { |
|
309 case ERecurrenceDaily: |
|
310 { |
|
311 // Set daily recurrence |
|
312 rRule.SetType( TCalRRule::EDaily ); |
|
313 |
|
314 TTimeIntervalDays daysBetween = |
|
315 rEndTime.TimeLocalL().DaysFrom( |
|
316 meetingStartTime.TimeLocalL() ); |
|
317 |
|
318 // First occurence and days between |
|
319 rRule.SetCount( daysBetween.Int() + KOne); |
|
320 rRule.SetInterval( KOne ); |
|
321 } |
|
322 break; |
|
323 |
|
324 case ERecurrenceWeekly: |
|
325 { |
|
326 // Set weekly recurrence. |
|
327 rRule.SetType( TCalRRule::EWeekly ); |
|
328 TTimeIntervalDays weeksBetween = |
|
329 rEndTime.TimeLocalL().DaysFrom( |
|
330 meetingStartTime.TimeLocalL() ); |
|
331 |
|
332 weeksBetween = weeksBetween.Int() / KDaysInWeek; |
|
333 |
|
334 RArray<TDay> dayArray; |
|
335 CleanupClosePushL( dayArray ); |
|
336 dayArray.Append( rRule.DtStart().TimeLocalL().DayNoInWeek() ); |
|
337 rRule.SetByDay( dayArray ); |
|
338 CleanupStack::PopAndDestroy( &dayArray ); |
|
339 |
|
340 // First occurence and weeks between |
|
341 rRule.SetCount( |
|
342 weeksBetween.Int() + KOne); |
|
343 rRule.SetInterval( KOne ); |
|
344 } |
|
345 break; |
|
346 |
|
347 case ERecurrenceEverySecondWeek: |
|
348 { |
|
349 // Set bi-weekly recurrence. This is weekly recurrence |
|
350 // with 2 weeks interval. |
|
351 rRule.SetType( TCalRRule::EWeekly ); |
|
352 TTimeIntervalDays fortNightBetween = |
|
353 rEndTime.TimeLocalL().DaysFrom( |
|
354 meetingStartTime.TimeLocalL() ); |
|
355 |
|
356 fortNightBetween = |
|
357 fortNightBetween.Int() / KDaysInTwoWeeks; |
|
358 |
|
359 RArray<TDay> dayArray; |
|
360 CleanupClosePushL( dayArray ); |
|
361 dayArray.Append( rRule.DtStart().TimeLocalL().DayNoInWeek() ); |
|
362 rRule.SetByDay( dayArray ); |
|
363 CleanupStack::PopAndDestroy( &dayArray ); |
|
364 |
|
365 // First occurence and fortnights between |
|
366 rRule.SetCount( |
|
367 fortNightBetween.Int() + KOne); |
|
368 rRule.SetInterval( KTwo ); |
|
369 } |
|
370 break; |
|
371 |
|
372 case ERecurrenceMonthly: |
|
373 { |
|
374 // Set monthly recurrence. |
|
375 rRule.SetType( TCalRRule::EMonthly ); |
|
376 |
|
377 RArray<TInt> dateArray; |
|
378 CleanupClosePushL( dateArray ); |
|
379 dateArray.Append( |
|
380 rRule.DtStart().TimeLocalL().DayNoInMonth() ); |
|
381 rRule.SetByMonthDay( dateArray ); |
|
382 CleanupStack::PopAndDestroy( &dateArray ); |
|
383 |
|
384 TTimeIntervalMonths monthsBetween = |
|
385 rEndTime.TimeLocalL().MonthsFrom( |
|
386 meetingStartTime.TimeLocalL() ); |
|
387 |
|
388 // First occurence and months between |
|
389 rRule.SetCount( monthsBetween.Int() + KOne); |
|
390 rRule.SetInterval( KOne ); |
|
391 } |
|
392 break; |
|
393 |
|
394 case ERecurrenceYearly: |
|
395 { |
|
396 // Set yearly recurrence. |
|
397 rRule.SetType( TCalRRule::EYearly ); |
|
398 |
|
399 TTimeIntervalYears yearsBetween = |
|
400 rEndTime.TimeLocalL().YearsFrom( |
|
401 meetingStartTime.TimeLocalL() ); |
|
402 |
|
403 // First occurence and months between |
|
404 rRule.SetCount( yearsBetween.Int() + KOne); |
|
405 rRule.SetInterval( KOne ); |
|
406 } |
|
407 default: |
|
408 break; |
|
409 } |
|
410 iEntry.SetRRuleL( rRule ); |
|
411 } |
|
412 |
|
413 } |
|
414 |
|
415 // --------------------------------------------------------------------------- |
|
416 // CESMRRecurrenceInfoHandler::GetRecurrenceL |
|
417 // |
|
418 // --------------------------------------------------------------------------- |
|
419 // |
|
420 EXPORT_C void CESMRRecurrenceInfoHandler::GetRecurrenceL( |
|
421 TESMRRecurrenceValue& aRecurrence, |
|
422 TTime& aUntil) const |
|
423 { |
|
424 FUNC_LOG; |
|
425 |
|
426 TESMRRecurrenceValue recurrenceValue(ERecurrenceNot); |
|
427 |
|
428 // Let's get RDates of the entry also to see if entry is repeating |
|
429 RArray<TCalTime> rdates; |
|
430 CleanupClosePushL( rdates ); |
|
431 iEntry.GetRDatesL( rdates ); |
|
432 |
|
433 TBool hasRdates = rdates.Count() > 0; |
|
434 |
|
435 TCalRRule rRule; |
|
436 if ( iEntry.GetRRuleL(rRule) || hasRdates ) |
|
437 { |
|
438 // Entry has recurrence |
|
439 recurrenceValue = ERecurrenceUnknown; |
|
440 |
|
441 TCalRRule::TType rType = rRule.Type(); |
|
442 TInt interval = rRule.Interval(); |
|
443 |
|
444 switch ( rType ) |
|
445 { |
|
446 case TCalRRule::EInvalid: |
|
447 { |
|
448 // Recurrence type has not yet been defined |
|
449 // --> Consider it then unknown. |
|
450 recurrenceValue = ERecurrenceUnknown; |
|
451 } |
|
452 break; |
|
453 |
|
454 case TCalRRule::EDaily: |
|
455 { |
|
456 HandleDailyRecurrenceL( recurrenceValue, rRule ); |
|
457 } |
|
458 break; |
|
459 |
|
460 case TCalRRule::EWeekly: |
|
461 { |
|
462 HandleWeeklyRecurrenceL( recurrenceValue, rRule ); |
|
463 } |
|
464 break; |
|
465 |
|
466 case TCalRRule::EMonthly: |
|
467 { |
|
468 HandleMonthlyRecurrenceL( recurrenceValue, rRule ); |
|
469 } |
|
470 break; |
|
471 |
|
472 case TCalRRule::EYearly: |
|
473 { |
|
474 // Recurrence is based on a number of years |
|
475 if ( KOne == interval) |
|
476 { |
|
477 recurrenceValue = ERecurrenceYearly; |
|
478 } |
|
479 } |
|
480 break; |
|
481 default: |
|
482 break; |
|
483 } |
|
484 |
|
485 if ( hasRdates ) |
|
486 { |
|
487 // Getting the last RDates occurance time == Until time |
|
488 aUntil = rdates[ rdates.Count() - 1 ].TimeUtcL(); |
|
489 } |
|
490 else |
|
491 { |
|
492 CalculateRecurrenceUntilDateL( |
|
493 recurrenceValue, |
|
494 aUntil, |
|
495 rRule, |
|
496 iEntry ); |
|
497 } |
|
498 } |
|
499 |
|
500 CleanupStack::PopAndDestroy( &rdates ); |
|
501 aRecurrence = recurrenceValue; |
|
502 |
|
503 } |
|
504 |
|
505 |
|
506 EXPORT_C void CESMRRecurrenceInfoHandler::RemoveInstanceL( |
|
507 TCalTime aInstanceTime ) |
|
508 { |
|
509 FUNC_LOG; |
|
510 |
|
511 RArray<TCalTime> exDateList; |
|
512 CleanupClosePushL( exDateList ); |
|
513 |
|
514 TDateTime instanceException = aInstanceTime.TimeLocalL().DateTime(); |
|
515 instanceException.SetHour( KZero ); |
|
516 instanceException.SetMinute( KZero ); |
|
517 instanceException.SetSecond( KZero ); |
|
518 instanceException.SetMicroSecond( KZero ); |
|
519 |
|
520 TCalTime exceptionTime; |
|
521 exceptionTime.SetTimeUtcL( TTime(instanceException) ); |
|
522 |
|
523 iEntry.GetExceptionDatesL( exDateList ); |
|
524 exDateList.Append( exceptionTime ); |
|
525 iEntry.SetExceptionDatesL( exDateList ); |
|
526 |
|
527 CleanupStack::PopAndDestroy( &exDateList ); |
|
528 |
|
529 } |
|
530 |
|
531 // --------------------------------------------------------------------------- |
|
532 // CESMRRecurrenceInfoHandler::AddExceptionL |
|
533 // |
|
534 // --------------------------------------------------------------------------- |
|
535 // |
|
536 EXPORT_C void CESMRRecurrenceInfoHandler::AddExceptionL( |
|
537 TCalTime aNewInstanceTime, |
|
538 TCalTime aOrginalInstanceTime ) |
|
539 { |
|
540 FUNC_LOG; |
|
541 |
|
542 // Entry's time has been modified and exception |
|
543 // needs to be added to parent entry |
|
544 RArray<TCalTime> rDateList; |
|
545 CleanupClosePushL( rDateList ); |
|
546 |
|
547 RArray<TCalTime> exDateList; |
|
548 CleanupClosePushL( exDateList ); |
|
549 |
|
550 // Only this instance is edited --> Set RRULE to entry |
|
551 iEntry.GetRDatesL( rDateList ); |
|
552 iEntry.GetExceptionDatesL( exDateList ); |
|
553 |
|
554 rDateList.Append( aNewInstanceTime ); |
|
555 exDateList.Append( aOrginalInstanceTime ); |
|
556 |
|
557 iEntry.SetRDatesL( rDateList ); |
|
558 iEntry.SetExceptionDatesL( exDateList ); |
|
559 |
|
560 CleanupStack::PopAndDestroy( &exDateList ); |
|
561 CleanupStack::PopAndDestroy( &rDateList ); |
|
562 |
|
563 } |
|
564 |
|
565 // --------------------------------------------------------------------------- |
|
566 // CESMRRecurrenceInfoHandler::CopyRecurrenceInformationToL |
|
567 // |
|
568 // --------------------------------------------------------------------------- |
|
569 // |
|
570 EXPORT_C void CESMRRecurrenceInfoHandler::CopyRecurrenceInformationToL( |
|
571 CCalEntry& aDestination ) |
|
572 { |
|
573 FUNC_LOG; |
|
574 |
|
575 aDestination.ClearRepeatingPropertiesL(); |
|
576 |
|
577 TCalRRule rrule; |
|
578 if ( iEntry.GetRRuleL(rrule) ) |
|
579 { |
|
580 aDestination.SetRRuleL( rrule ); |
|
581 |
|
582 RArray<TCalTime> rDateList; |
|
583 CleanupClosePushL( rDateList ); |
|
584 |
|
585 RArray<TCalTime> exDateList; |
|
586 CleanupClosePushL( exDateList ); |
|
587 |
|
588 iEntry.GetRDatesL( rDateList ); |
|
589 iEntry.GetExceptionDatesL( exDateList ); |
|
590 |
|
591 aDestination.SetRDatesL( rDateList ); |
|
592 aDestination.SetExceptionDatesL( exDateList ); |
|
593 |
|
594 CleanupStack::PopAndDestroy( &exDateList ); |
|
595 CleanupStack::PopAndDestroy( &rDateList ); |
|
596 } |
|
597 |
|
598 } |
|
599 |
|
600 // --------------------------------------------------------------------------- |
|
601 // CESMRRecurrenceInfoHandler::CopyRecurrenceInformationFromL |
|
602 // |
|
603 // --------------------------------------------------------------------------- |
|
604 // |
|
605 EXPORT_C void CESMRRecurrenceInfoHandler::CopyRecurrenceInformationFromL( |
|
606 const CCalEntry& aSource ) |
|
607 { |
|
608 FUNC_LOG; |
|
609 |
|
610 iEntry.ClearRepeatingPropertiesL(); |
|
611 |
|
612 TCalRRule rrule; |
|
613 if ( aSource.GetRRuleL(rrule) ) |
|
614 { |
|
615 iEntry.SetRRuleL( rrule ); |
|
616 |
|
617 RArray<TCalTime> rDateList; |
|
618 CleanupClosePushL( rDateList ); |
|
619 |
|
620 RArray<TCalTime> exDateList; |
|
621 CleanupClosePushL( exDateList ); |
|
622 |
|
623 aSource.GetRDatesL( rDateList ); |
|
624 aSource.GetExceptionDatesL( exDateList ); |
|
625 |
|
626 iEntry.SetRDatesL( rDateList ); |
|
627 iEntry.SetExceptionDatesL( exDateList ); |
|
628 |
|
629 CleanupStack::PopAndDestroy( &exDateList ); |
|
630 CleanupStack::PopAndDestroy( &rDateList ); |
|
631 } |
|
632 |
|
633 } |
|
634 |
|
635 |
|
636 // --------------------------------------------------------------------------- |
|
637 // CESMRRecurrenceInfoHandler::GetFirstInstanceTimeL |
|
638 // |
|
639 // --------------------------------------------------------------------------- |
|
640 // |
|
641 EXPORT_C void CESMRRecurrenceInfoHandler::GetFirstInstanceTimeL( |
|
642 TCalTime& aStart, |
|
643 TCalTime& aEnd ) |
|
644 { |
|
645 FUNC_LOG; |
|
646 |
|
647 TESMRRecurrenceValue recurrence( ERecurrenceNot ); |
|
648 TTime until( Time::NullTTime() ); |
|
649 GetRecurrenceL( recurrence, until ); |
|
650 |
|
651 if ( ERecurrenceNot == recurrence ) |
|
652 { |
|
653 aStart = iEntry.StartTimeL(); |
|
654 aEnd = iEntry.EndTimeL(); |
|
655 } |
|
656 else if ( ERecurrenceUnknown != recurrence ) |
|
657 { |
|
658 aStart = iEntry.StartTimeL(); |
|
659 aEnd = iEntry.EndTimeL(); |
|
660 |
|
661 TTimeIntervalMinutes diff; |
|
662 aEnd.TimeLocalL().MinutesFrom( |
|
663 aStart.TimeLocalL(), |
|
664 diff ); |
|
665 |
|
666 RArray<TCalTime> exDateList; |
|
667 CleanupClosePushL( exDateList ); |
|
668 iEntry.GetExceptionDatesL( exDateList ); |
|
669 |
|
670 TInt exceptionCount( exDateList.Count() ); |
|
671 if ( exceptionCount ) |
|
672 { |
|
673 TBool timeIncludedInExceptionList( |
|
674 IsTimeIncluded( aStart, exDateList ) ); |
|
675 |
|
676 while( timeIncludedInExceptionList ) |
|
677 { |
|
678 TTime nextInstanceTime = |
|
679 TimeForNextInstaceStartTime( |
|
680 recurrence, |
|
681 aStart ); |
|
682 |
|
683 aStart.SetTimeLocalL( nextInstanceTime); |
|
684 timeIncludedInExceptionList = |
|
685 IsTimeIncluded( aStart, exDateList ); |
|
686 } |
|
687 } |
|
688 |
|
689 TCalTime untilCalTime; |
|
690 untilCalTime.SetTimeUtcL( until ); |
|
691 |
|
692 TDateTime nextTime = aStart.TimeLocalL().DateTime(); |
|
693 TDateTime untilTime = untilCalTime.TimeLocalL().DateTime(); |
|
694 |
|
695 if ( aStart.TimeUtcL() > untilCalTime.TimeUtcL() ) |
|
696 { |
|
697 User::Leave( KErrCorrupt ); |
|
698 } |
|
699 |
|
700 TTime end = aStart.TimeLocalL() + diff; |
|
701 aEnd.SetTimeLocalL( end ); |
|
702 |
|
703 CleanupStack::PopAndDestroy( &exDateList ); |
|
704 } |
|
705 else |
|
706 { |
|
707 // Unknown recurrence type |
|
708 aStart = iEntry.StartTimeL(); |
|
709 aEnd = iEntry.EndTimeL(); |
|
710 } |
|
711 |
|
712 } |
|
713 |
|
714 // --------------------------------------------------------------------------- |
|
715 // CESMRRecurrenceInfoHandler::CalculateRecurrenceUntilDateL |
|
716 // |
|
717 // --------------------------------------------------------------------------- |
|
718 // |
|
719 void CESMRRecurrenceInfoHandler::CalculateRecurrenceUntilDateL( |
|
720 TESMRRecurrenceValue aRecurrenceType, |
|
721 TTime& aUntil, |
|
722 TCalRRule& aRule, |
|
723 const CCalEntry& aEntry ) const |
|
724 { |
|
725 FUNC_LOG; |
|
726 TCalRRule::TType rType = aRule.Type(); |
|
727 TInt count = aRule.Count(); |
|
728 TCalTime until = aRule.Until(); |
|
729 |
|
730 if ( count == KZero && |
|
731 until.TimeUtcL() == Time::NullTTime() ) |
|
732 { |
|
733 User::Leave( KErrNotFound ); |
|
734 } |
|
735 |
|
736 if ( !count ) |
|
737 { |
|
738 aUntil = until.TimeUtcL(); |
|
739 } |
|
740 else |
|
741 { |
|
742 aUntil = aEntry.StartTimeL().TimeUtcL(); |
|
743 switch( aRecurrenceType ) |
|
744 { |
|
745 case ERecurrenceDaily: |
|
746 { |
|
747 --count; |
|
748 aUntil += TTimeIntervalDays(count); |
|
749 break; |
|
750 } |
|
751 case ERecurrenceWeekly: |
|
752 { |
|
753 --count; |
|
754 aUntil += TTimeIntervalDays(count * KDaysInWeek); |
|
755 break; |
|
756 } |
|
757 case ERecurrenceEverySecondWeek: |
|
758 { |
|
759 --count; |
|
760 aUntil += TTimeIntervalDays(count * KDaysInTwoWeeks); |
|
761 break; |
|
762 } |
|
763 case ERecurrenceMonthly: |
|
764 { |
|
765 --count; |
|
766 aUntil += TTimeIntervalMonths(count); |
|
767 break; |
|
768 } |
|
769 case ERecurrenceYearly: |
|
770 { |
|
771 --count; |
|
772 aUntil += TTimeIntervalYears(count); |
|
773 break; |
|
774 } |
|
775 default: |
|
776 { |
|
777 // Check if until date can be calculated |
|
778 CalculateUntilForUnknownRecurrenceL( aUntil, aRule ); |
|
779 break; |
|
780 } |
|
781 } |
|
782 } |
|
783 } |
|
784 |
|
785 // --------------------------------------------------------------------------- |
|
786 // CESMRRecurrenceInfoHandler::HandleDailyRecurrenceL |
|
787 // --------------------------------------------------------------------------- |
|
788 // |
|
789 void CESMRRecurrenceInfoHandler::HandleDailyRecurrenceL( |
|
790 TESMRRecurrenceValue& aRecurrenceValue, |
|
791 TCalRRule& aRule ) const |
|
792 { |
|
793 FUNC_LOG; |
|
794 TInt interval( aRule.Interval() ); |
|
795 aRecurrenceValue = ERecurrenceUnknown; |
|
796 |
|
797 // Recurrence is based on a number of days |
|
798 if ( KOne == interval ) |
|
799 { |
|
800 // Recurrence occurs daily |
|
801 aRecurrenceValue = ERecurrenceDaily; |
|
802 } |
|
803 else if ( KDaysInWeek == interval) |
|
804 { |
|
805 // Interval is seven days |
|
806 // --> recurrence occurs weekly |
|
807 aRecurrenceValue = ERecurrenceWeekly; |
|
808 } |
|
809 else if ( KDaysInTwoWeeks == interval ) |
|
810 { |
|
811 // Interval is fortnight --> |
|
812 // recurrence occurs bi-weekly |
|
813 aRecurrenceValue = ERecurrenceEverySecondWeek; |
|
814 } |
|
815 } |
|
816 |
|
817 // --------------------------------------------------------------------------- |
|
818 // CESMRRecurrenceInfoHandler::HandleWeeklyRecurrenceL |
|
819 // --------------------------------------------------------------------------- |
|
820 // |
|
821 void CESMRRecurrenceInfoHandler::HandleWeeklyRecurrenceL( |
|
822 TESMRRecurrenceValue& aRecurrenceValue, |
|
823 TCalRRule& aRule ) const |
|
824 { |
|
825 FUNC_LOG; |
|
826 TInt interval( aRule.Interval() ); |
|
827 |
|
828 RArray<TDay> byDays; |
|
829 CleanupClosePushL( byDays ); |
|
830 aRule.GetByDayL(byDays); |
|
831 |
|
832 if ( byDays.Count() > KOne ) |
|
833 { |
|
834 // Entry is repeated more than once every week or |
|
835 // every second week. |
|
836 aRecurrenceValue = ERecurrenceUnknown; |
|
837 } |
|
838 else if ( KOne == interval) |
|
839 { |
|
840 aRecurrenceValue = ERecurrenceWeekly; |
|
841 } |
|
842 else if ( KTwo == interval ) |
|
843 { |
|
844 aRecurrenceValue = ERecurrenceEverySecondWeek; |
|
845 } |
|
846 |
|
847 CleanupStack::PopAndDestroy( &byDays ); |
|
848 } |
|
849 |
|
850 // --------------------------------------------------------------------------- |
|
851 // CESMRRecurrenceInfoHandler::HandleMonthlyRecurrenceL |
|
852 // --------------------------------------------------------------------------- |
|
853 // |
|
854 void CESMRRecurrenceInfoHandler::HandleMonthlyRecurrenceL( |
|
855 TESMRRecurrenceValue& aRecurrenceValue, |
|
856 TCalRRule& aRule ) const |
|
857 { |
|
858 FUNC_LOG; |
|
859 TInt interval( aRule.Interval() ); |
|
860 |
|
861 aRecurrenceValue = ERecurrenceUnknown; |
|
862 |
|
863 // Recurrence is based on a number of months |
|
864 // Recurrence is based on a number of weeks |
|
865 if ( KOne == interval) |
|
866 { |
|
867 aRecurrenceValue = ERecurrenceMonthly; |
|
868 } |
|
869 else if ( KMonthsInYear == interval ) |
|
870 { |
|
871 aRecurrenceValue = ERecurrenceYearly; |
|
872 } |
|
873 } |
|
874 |
|
875 // --------------------------------------------------------------------------- |
|
876 // CESMRRecurrenceInfoHandler::HandleYearlyRecurrenceL |
|
877 // --------------------------------------------------------------------------- |
|
878 // |
|
879 void CESMRRecurrenceInfoHandler::HandleYearlyRecurrenceL( |
|
880 TESMRRecurrenceValue& aRecurrenceValue, |
|
881 TCalRRule& aRule ) const |
|
882 { |
|
883 FUNC_LOG; |
|
884 TInt interval( aRule.Interval() ); |
|
885 |
|
886 // Recurrence is based on a number of years |
|
887 if ( KOne == interval) |
|
888 { |
|
889 aRecurrenceValue = ERecurrenceYearly; |
|
890 } |
|
891 else |
|
892 { |
|
893 aRecurrenceValue = ERecurrenceUnknown; |
|
894 } |
|
895 } |
|
896 |
|
897 // --------------------------------------------------------------------------- |
|
898 // CESMRRecurrenceInfoHandler::NeedToSetRecurrence |
|
899 // |
|
900 // --------------------------------------------------------------------------- |
|
901 // |
|
902 TBool CESMRRecurrenceInfoHandler::NeedToSetRecurrenceL( |
|
903 TESMRRecurrenceValue aRecurrence, |
|
904 TTime aUntil ) const |
|
905 { |
|
906 FUNC_LOG; |
|
907 TBool retValue(ETrue); |
|
908 |
|
909 TESMRRecurrenceValue oldRecurrence; |
|
910 TTime oldUntil; |
|
911 GetRecurrenceL( oldRecurrence, oldUntil ); |
|
912 |
|
913 if( oldRecurrence == aRecurrence && |
|
914 IsSameDay( aUntil.DateTime(), oldUntil.DateTime() ) ) |
|
915 { |
|
916 // Recurrence is not changed --> No need to set |
|
917 retValue = EFalse; |
|
918 } |
|
919 |
|
920 return retValue; |
|
921 } |
|
922 |
|
923 // EOF |
|
924 |