|
1 /* |
|
2 * Copyright (c) 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: ESMR time and date sanity checks and saving |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "emailtrace.h" |
|
20 #include <eikmfne.h> |
|
21 #include <calentry.h> |
|
22 #include <calalarm.h> |
|
23 #include <e32std.h> |
|
24 #include "cesmrannivtimevalidator.h" |
|
25 #include "cesmrglobalnote.h" |
|
26 #include "mesmrfieldstorage.h" |
|
27 #include "mesmrcalentry.h" |
|
28 |
|
29 // Unnamed namespace for local definitions |
|
30 namespace { |
|
31 |
|
32 // Definition fom max possible time |
|
33 #define KMaxTTime (TTime(TDateTime(2100, EDecember, 31-2, 23, 59, 59, 999999))) |
|
34 |
|
35 // Definition fom min possible time |
|
36 #define KMinTTime (TTime(TDateTime(1900, EJanuary, 2-1, 0, 0, 0, 0))) |
|
37 |
|
38 // Definition for max alarm duration |
|
39 #define KMaxAlarmTime TTimeIntervalDays(31) |
|
40 |
|
41 // Definition for halfday |
|
42 const TInt KNoon( 12 ); |
|
43 |
|
44 #ifdef _DEBUG |
|
45 |
|
46 // Literal for panics |
|
47 _LIT( KESMRAnnivTimeValidator, "ESMRAnnivTimeValidator" ); |
|
48 |
|
49 /** Panic code definitions */ |
|
50 enum TESMRAnnivTimeValidator |
|
51 { |
|
52 /** Start date field not set */ |
|
53 EESMRAnnivValidatorNullStartDate, |
|
54 /** Start date field not set */ |
|
55 EESMRAnnivValidatorNullAlarmTime, |
|
56 /** Start date field not set */ |
|
57 EESMRAnnivValidatorNullAlarmDate, |
|
58 /** Relative alarm called for non-relative alarm event */ |
|
59 EESMRAnnivValidatorRelativeAlarm |
|
60 }; |
|
61 |
|
62 /** |
|
63 * Raises system panic. |
|
64 * @param aPanic Panic code |
|
65 * @see TESMRRecurrentEditValidatorPanic |
|
66 */ |
|
67 void Panic( TESMRAnnivTimeValidator aPanic ) |
|
68 { |
|
69 User::Panic( KESMRAnnivTimeValidator, aPanic ); |
|
70 } |
|
71 |
|
72 #endif // _DEBUG |
|
73 |
|
74 /** |
|
75 * Sets time to editor. Time is checked and adjusted |
|
76 * between min and max before setting |
|
77 * @param aEditor Reference to time editor |
|
78 * @param aTime On return contains the set time. |
|
79 */ |
|
80 void SetTimeToEditor( |
|
81 CEikTimeEditor& aEditor, |
|
82 TTime& aTime ) |
|
83 { |
|
84 if ( aTime < KMinTTime ) |
|
85 { |
|
86 aTime = KMinTTime; |
|
87 } |
|
88 else if ( aTime > KMaxTTime ) |
|
89 { |
|
90 aTime = KMaxTTime; |
|
91 } |
|
92 |
|
93 if ( aEditor.IsVisible() ) |
|
94 { |
|
95 aEditor.SetTime( aTime ); |
|
96 } |
|
97 } |
|
98 |
|
99 /** |
|
100 * Sets date to editor. Date is checked and adjusted |
|
101 * between min and max before setting |
|
102 * @param aEditor Reference to time editor |
|
103 * @param aDate On return contains the set date. |
|
104 */ |
|
105 void SetDateToEditor( |
|
106 CEikDateEditor& aEditor, |
|
107 TTime& aDate ) |
|
108 { |
|
109 if ( aDate < KMinTTime ) |
|
110 { |
|
111 aDate = KMinTTime; |
|
112 } |
|
113 else if ( aDate > KMaxTTime ) |
|
114 { |
|
115 aDate = KMaxTTime; |
|
116 } |
|
117 |
|
118 if ( aEditor.IsVisible() ) |
|
119 { |
|
120 aEditor.SetDate( aDate ); |
|
121 } |
|
122 } |
|
123 |
|
124 /** |
|
125 * Returns the default alarm time for all day event |
|
126 * @param allday event start time |
|
127 * @return alarm time |
|
128 */ |
|
129 TTime DefaultAnniversaryAlarm( TTime& aAnnivStartTime ) |
|
130 { |
|
131 TTime defaultAlarmTime = aAnnivStartTime - TTimeIntervalHours(KNoon); |
|
132 |
|
133 if ( defaultAlarmTime < KMinTTime ) |
|
134 { |
|
135 defaultAlarmTime = KMinTTime; |
|
136 } |
|
137 return defaultAlarmTime; |
|
138 } |
|
139 |
|
140 } |
|
141 |
|
142 |
|
143 // --------------------------------------------------------------------------- |
|
144 // CESMRAnnivTimeValidator::CESMRAnnivTimeValidator() |
|
145 // --------------------------------------------------------------------------- |
|
146 // |
|
147 inline CESMRAnnivTimeValidator::CESMRAnnivTimeValidator() |
|
148 : iCurrentAnnivDate( Time::NullTTime() ), |
|
149 iCurrentAlarmTime( Time::NullTTime() ), |
|
150 iAlarmOnOff( EFalse ), |
|
151 iInitialAlarmTime( Time::NullTTime() ), |
|
152 iInitialAlarmOnOff( EFalse ), |
|
153 iInitialStartDate( Time::NullTTime() ) |
|
154 |
|
155 { |
|
156 } |
|
157 |
|
158 // --------------------------------------------------------------------------- |
|
159 // CESMRAnnivTimeValidator::~CESMRAnnivTimeValidator |
|
160 // --------------------------------------------------------------------------- |
|
161 // |
|
162 CESMRAnnivTimeValidator::~CESMRAnnivTimeValidator( ) |
|
163 { |
|
164 } |
|
165 |
|
166 // --------------------------------------------------------------------------- |
|
167 // CESMRAnnivTimeValidator::NewL |
|
168 // --------------------------------------------------------------------------- |
|
169 // |
|
170 CESMRAnnivTimeValidator* CESMRAnnivTimeValidator::NewL() |
|
171 { |
|
172 FUNC_LOG; |
|
173 CESMRAnnivTimeValidator* self = new (ELeave) CESMRAnnivTimeValidator(); |
|
174 return self; |
|
175 } |
|
176 |
|
177 // --------------------------------------------------------------------------- |
|
178 // CESMRAnnivTimeValidator::ValidateL |
|
179 // --------------------------------------------------------------------------- |
|
180 // |
|
181 MESMRFieldValidator::TESMRFieldValidatorError |
|
182 CESMRAnnivTimeValidator::ValidateL( TBool aCorrectAutomatically ) |
|
183 { |
|
184 FUNC_LOG; |
|
185 const MESMRFieldValidator::TESMRFieldValidatorError KErrorNone( |
|
186 MESMRFieldValidator::EErrorNone ); |
|
187 |
|
188 MESMRFieldValidator::TESMRFieldValidatorError error( KErrorNone ); |
|
189 |
|
190 if ( aCorrectAutomatically ) |
|
191 { |
|
192 ForceValuesL(); |
|
193 } |
|
194 else |
|
195 { |
|
196 if ( iAlarmOnOff ) |
|
197 { |
|
198 TTime start = StartTimeL(); |
|
199 TTime alarm = AlarmTimeL(); |
|
200 |
|
201 if ( start < alarm ) |
|
202 { |
|
203 TDateTime startDt = start.DateTime(); |
|
204 TDateTime alarmDt = alarm.DateTime(); |
|
205 |
|
206 // Alarm needs to be on the same day if it in future |
|
207 if ( startDt.Year() != alarmDt.Year() || |
|
208 startDt.Month() != alarmDt.Month() || |
|
209 startDt.Day() != alarmDt.Day() ) |
|
210 { |
|
211 iCurrentAlarmTime = DefaultAnniversaryAlarm( start ); |
|
212 |
|
213 SetTimeToEditor( *iAlarmTime, iCurrentAlarmTime ); |
|
214 SetDateToEditor( *iAlarmDate, iCurrentAlarmTime ); |
|
215 |
|
216 error = MESMRFieldValidator::EErrorAlarmLaterThanStart; |
|
217 } |
|
218 } |
|
219 } |
|
220 } |
|
221 return error; |
|
222 } |
|
223 |
|
224 // --------------------------------------------------------------------------- |
|
225 // CESMRAnnivTimeValidator::ReadValuesFromEntryL |
|
226 // --------------------------------------------------------------------------- |
|
227 // |
|
228 void CESMRAnnivTimeValidator::ReadValuesFromEntryL( |
|
229 MESMRCalEntry& aEntry ) |
|
230 { |
|
231 FUNC_LOG; |
|
232 if ( MESMRCalEntry::EESMRCalEntryAnniversary == aEntry.Type() ) |
|
233 { |
|
234 __ASSERT_DEBUG( iStartDate, Panic(EESMRAnnivValidatorNullStartDate) ); |
|
235 __ASSERT_DEBUG( iAlarmTime, Panic(EESMRAnnivValidatorNullAlarmTime) ); |
|
236 __ASSERT_DEBUG( iAlarmDate, Panic(EESMRAnnivValidatorNullAlarmDate) ); |
|
237 |
|
238 iEntry = &aEntry; |
|
239 CCalEntry& entry( aEntry.Entry() ); |
|
240 |
|
241 TCalTime startTime = entry.StartTimeL(); |
|
242 iCurrentAnnivDate = startTime.TimeLocalL(); |
|
243 SetDateToEditor( *iStartDate, iCurrentAnnivDate ); |
|
244 iInitialStartDate = iStartDate->Date(); |
|
245 |
|
246 CCalAlarm* alarm = entry.AlarmL(); |
|
247 CleanupStack::PushL( alarm ); |
|
248 |
|
249 if ( alarm ) |
|
250 { |
|
251 iCurrentAlarmTime = iCurrentAnnivDate - alarm->TimeOffset(); |
|
252 iAlarmOnOff = ETrue; |
|
253 iInitialAlarmOnOff = iAlarmOnOff; |
|
254 |
|
255 SetTimeToEditor( *iAlarmTime, iCurrentAlarmTime ); |
|
256 SetDateToEditor( *iAlarmDate, iCurrentAlarmTime ); |
|
257 |
|
258 iInitialAlarmTime = iAlarmTime->Time(); |
|
259 iInitialAlarmDate = iAlarmDate->Date(); |
|
260 } |
|
261 |
|
262 CleanupStack::PopAndDestroy( alarm ); |
|
263 DrawEditorsDeferred(); |
|
264 } |
|
265 } |
|
266 |
|
267 // --------------------------------------------------------------------------- |
|
268 // CESMRAnnivTimeValidator::StoreValuesToEntryL |
|
269 // --------------------------------------------------------------------------- |
|
270 // |
|
271 void CESMRAnnivTimeValidator::StoreValuesToEntryL( |
|
272 MESMRCalEntry& aEntry ) |
|
273 { |
|
274 FUNC_LOG; |
|
275 if ( MESMRCalEntry::EESMRCalEntryAnniversary == aEntry.Type() ) |
|
276 { |
|
277 PreValidateEditorContent(); |
|
278 CCalEntry& entry( aEntry.Entry() ); |
|
279 TDateTime annivEditorTime = StartTimeL(); |
|
280 |
|
281 // If entry has been modified, we will write new values to entry. |
|
282 // Otherwise entry will not be modified and thus saved |
|
283 // (ex. new entry and press only Done ) |
|
284 if( IsModifiedL( aEntry ) ) |
|
285 { |
|
286 TCalTime annivTime; |
|
287 |
|
288 // The default mode for anniversary is EFloating, |
|
289 // But some 3rd party application might have saved a different type |
|
290 // for one reason or another. In that case we are using |
|
291 // the existing value. |
|
292 if ( aEntry.IsStoredL() ) |
|
293 { |
|
294 TCalTime::TTimeMode timeMode = |
|
295 aEntry.Entry().StartTimeL().TimeMode(); |
|
296 |
|
297 switch ( timeMode ) |
|
298 { |
|
299 case TCalTime::EFixedUtc: |
|
300 { |
|
301 annivTime.SetTimeUtcL( annivEditorTime ); |
|
302 break; |
|
303 } |
|
304 case TCalTime::EFixedTimeZone: |
|
305 { |
|
306 annivTime.SetTimeLocalL( annivEditorTime ); |
|
307 break; |
|
308 } |
|
309 case TCalTime::EFloating: |
|
310 default: |
|
311 { |
|
312 annivTime.SetTimeLocalFloatingL( annivEditorTime ); |
|
313 } |
|
314 } |
|
315 } |
|
316 else |
|
317 { |
|
318 annivTime.SetTimeLocalFloatingL( annivEditorTime ); |
|
319 } |
|
320 |
|
321 entry.SetStartAndEndTimeL( annivTime, annivTime ); |
|
322 |
|
323 |
|
324 // Setting alarm only if entry needs to be saved |
|
325 if ( iAlarmOnOff ) |
|
326 { |
|
327 TTimeIntervalMinutes diff; |
|
328 |
|
329 TTime alarm = AlarmTimeL(); |
|
330 TTime editorTime = annivEditorTime; |
|
331 editorTime.MinutesFrom( alarm, diff ); |
|
332 |
|
333 CCalAlarm* alarmObject = entry.AlarmL(); |
|
334 if ( !alarmObject ) |
|
335 { |
|
336 alarmObject = CCalAlarm::NewL(); |
|
337 } |
|
338 CleanupStack::PushL( alarmObject ); |
|
339 alarmObject->SetTimeOffset( diff ); |
|
340 entry.SetAlarmL( alarmObject ); |
|
341 CleanupStack::PopAndDestroy( alarmObject ); |
|
342 alarmObject = NULL; |
|
343 } |
|
344 else |
|
345 { |
|
346 entry.SetAlarmL( NULL ); |
|
347 } |
|
348 } |
|
349 } |
|
350 } |
|
351 |
|
352 // --------------------------------------------------------------------------- |
|
353 // CESMRAnnivTimeValidator::SetStartTimeFieldL |
|
354 // --------------------------------------------------------------------------- |
|
355 // |
|
356 void CESMRAnnivTimeValidator::SetStartTimeFieldL( |
|
357 CEikTimeEditor& /*aStartTime*/ ) |
|
358 { |
|
359 FUNC_LOG; |
|
360 // No implementation for anniversary |
|
361 } |
|
362 |
|
363 // --------------------------------------------------------------------------- |
|
364 // CESMRAnnivTimeValidator::SetEndTimeFieldL |
|
365 // --------------------------------------------------------------------------- |
|
366 // |
|
367 void CESMRAnnivTimeValidator::SetEndTimeFieldL( |
|
368 CEikTimeEditor& /*aEndTime*/ ) |
|
369 { |
|
370 FUNC_LOG; |
|
371 // No implementation for anniversary |
|
372 } |
|
373 |
|
374 // --------------------------------------------------------------------------- |
|
375 // CESMRAnnivTimeValidator::SetStartDateFieldL |
|
376 // --------------------------------------------------------------------------- |
|
377 // |
|
378 void CESMRAnnivTimeValidator::SetStartDateFieldL( |
|
379 CEikDateEditor& aStartDate ) |
|
380 { |
|
381 FUNC_LOG; |
|
382 iStartDate = &aStartDate; |
|
383 |
|
384 if ( Time::NullTTime() != iCurrentAnnivDate ) |
|
385 { |
|
386 SetDateToEditor( *iStartDate, iCurrentAnnivDate ); |
|
387 } |
|
388 } |
|
389 |
|
390 // --------------------------------------------------------------------------- |
|
391 // CESMRAnnivTimeValidator::SetEndDateFieldL |
|
392 // --------------------------------------------------------------------------- |
|
393 // |
|
394 void CESMRAnnivTimeValidator::SetEndDateFieldL( |
|
395 CEikDateEditor& /*aEndDate*/ ) |
|
396 { |
|
397 FUNC_LOG; |
|
398 // No implementation for anniversary |
|
399 } |
|
400 |
|
401 // --------------------------------------------------------------------------- |
|
402 // CESMRAnnivTimeValidator::SetAlarmTimeFieldL |
|
403 // --------------------------------------------------------------------------- |
|
404 // |
|
405 void CESMRAnnivTimeValidator::SetAlarmTimeFieldL( |
|
406 CEikTimeEditor& aAlarmTime ) |
|
407 { |
|
408 FUNC_LOG; |
|
409 iAlarmTime = &aAlarmTime; |
|
410 |
|
411 if ( iAlarmOnOff ) |
|
412 { |
|
413 SetTimeToEditor( *iAlarmTime, iCurrentAlarmTime ); |
|
414 } |
|
415 } |
|
416 |
|
417 // --------------------------------------------------------------------------- |
|
418 // CESMRAnnivTimeValidator::SetAlarmDateFieldL |
|
419 // --------------------------------------------------------------------------- |
|
420 // |
|
421 void CESMRAnnivTimeValidator::SetAlarmDateFieldL( |
|
422 CEikDateEditor& aAlarmDate ) |
|
423 { |
|
424 FUNC_LOG; |
|
425 iAlarmDate = &aAlarmDate; |
|
426 |
|
427 if ( iAlarmOnOff ) |
|
428 { |
|
429 SetDateToEditor( *iAlarmDate, iCurrentAlarmTime ); |
|
430 } |
|
431 } |
|
432 |
|
433 // --------------------------------------------------------------------------- |
|
434 // CESMRAnnivTimeValidator::SetRecurrenceUntilDateFieldL |
|
435 // --------------------------------------------------------------------------- |
|
436 // |
|
437 void CESMRAnnivTimeValidator::SetRecurrenceUntilDateFieldL( |
|
438 CEikDateEditor& /*aRecurrenceUntil*/ ) |
|
439 { |
|
440 FUNC_LOG; |
|
441 // No implementation for anniversary |
|
442 } |
|
443 |
|
444 // --------------------------------------------------------------------------- |
|
445 // CESMRAnnivTimeValidator::SetAbsoluteAlarmOnOffFieldL |
|
446 // --------------------------------------------------------------------------- |
|
447 // |
|
448 void CESMRAnnivTimeValidator::SetAbsoluteAlarmOnOffFieldL( |
|
449 MMRAbsoluteAlarmController& /*aAbsoluteAlarmController*/ ) |
|
450 { |
|
451 FUNC_LOG; |
|
452 // No implementation for anniversary |
|
453 } |
|
454 |
|
455 // --------------------------------------------------------------------------- |
|
456 // CESMRAnnivTimeValidator::StartTimeChangedL |
|
457 // --------------------------------------------------------------------------- |
|
458 // |
|
459 void CESMRAnnivTimeValidator::StartTimeChangedL() |
|
460 { |
|
461 FUNC_LOG; |
|
462 StartDateChandedL(); |
|
463 } |
|
464 |
|
465 // --------------------------------------------------------------------------- |
|
466 // CESMRAnnivTimeValidator::EndTimeChangedL |
|
467 // --------------------------------------------------------------------------- |
|
468 // |
|
469 void CESMRAnnivTimeValidator::EndTimeChangedL() |
|
470 { |
|
471 FUNC_LOG; |
|
472 // No implementation for anniversary |
|
473 } |
|
474 |
|
475 // --------------------------------------------------------------------------- |
|
476 // CESMRAnnivTimeValidator::StartDateChandedL |
|
477 // --------------------------------------------------------------------------- |
|
478 // |
|
479 void CESMRAnnivTimeValidator::StartDateChandedL() |
|
480 { |
|
481 FUNC_LOG; |
|
482 PreValidateEditorContent(); |
|
483 |
|
484 TTime start = StartTimeL(); |
|
485 TTimeIntervalDays diff = start.DaysFrom( iCurrentAnnivDate ); |
|
486 iCurrentAnnivDate = start; |
|
487 SetDateToEditor( *iStartDate, iCurrentAnnivDate ); |
|
488 |
|
489 if ( iAlarmOnOff ) |
|
490 { |
|
491 TTime alarm = AlarmTimeL(); |
|
492 alarm += diff; |
|
493 |
|
494 iCurrentAlarmTime = alarm; |
|
495 |
|
496 SetTimeToEditor( *iAlarmTime, iCurrentAlarmTime ); |
|
497 SetDateToEditor( *iAlarmDate, iCurrentAlarmTime ); |
|
498 } |
|
499 |
|
500 DrawEditorsDeferred(); |
|
501 } |
|
502 |
|
503 // --------------------------------------------------------------------------- |
|
504 // CESMRAnnivTimeValidator::EndDateChangedL |
|
505 // --------------------------------------------------------------------------- |
|
506 // |
|
507 void CESMRAnnivTimeValidator::EndDateChangedL() |
|
508 { |
|
509 FUNC_LOG; |
|
510 // No implementation for anniversary |
|
511 } |
|
512 |
|
513 // --------------------------------------------------------------------------- |
|
514 // CESMRAnnivTimeValidator::AlarmTimeChangedL |
|
515 // --------------------------------------------------------------------------- |
|
516 // |
|
517 void CESMRAnnivTimeValidator::AlarmTimeChangedL() |
|
518 { |
|
519 FUNC_LOG; |
|
520 AlarmDateChangedL(); |
|
521 } |
|
522 |
|
523 // --------------------------------------------------------------------------- |
|
524 // CESMRAnnivTimeValidator::AlarmDateChangedL |
|
525 // --------------------------------------------------------------------------- |
|
526 // |
|
527 void CESMRAnnivTimeValidator::AlarmDateChangedL() |
|
528 { |
|
529 FUNC_LOG; |
|
530 TInt err( KErrNone ); |
|
531 PreValidateEditorContent(); |
|
532 |
|
533 TTime start = StartTimeL(); |
|
534 TTime alarm = AlarmTimeL(); |
|
535 |
|
536 if ( alarm > start ) |
|
537 { |
|
538 TDateTime startDt = start.DateTime(); |
|
539 TDateTime alarmDt = alarm.DateTime(); |
|
540 |
|
541 // Alarm needs to be on the same day if it in future |
|
542 if ( startDt.Year() != alarmDt.Year() || |
|
543 startDt.Month() != alarmDt.Month() || |
|
544 startDt.Day() != alarmDt.Day() ) |
|
545 { |
|
546 err = KErrArgument; |
|
547 } |
|
548 } |
|
549 |
|
550 if ( KErrNone == err ) |
|
551 { |
|
552 iCurrentAlarmTime = alarm; |
|
553 } |
|
554 |
|
555 SetTimeToEditor( *iAlarmTime, iCurrentAlarmTime ); |
|
556 SetDateToEditor( *iAlarmDate, iCurrentAlarmTime ); |
|
557 |
|
558 DrawEditorsDeferred(); |
|
559 User::LeaveIfError( err ); |
|
560 } |
|
561 |
|
562 // --------------------------------------------------------------------------- |
|
563 // CESMRAnnivTimeValidator::RelativeAlarmChangedL() |
|
564 // --------------------------------------------------------------------------- |
|
565 // |
|
566 void CESMRAnnivTimeValidator::RelativeAlarmChangedL( |
|
567 TTimeIntervalMinutes /*aCurrentAlarmTimeOffset*/, |
|
568 TBool /*aHandleAlarmChange*/, |
|
569 TBool& /*aRelativeAlarmValid*/ ) |
|
570 { |
|
571 FUNC_LOG; |
|
572 // No implementation for anniversary |
|
573 } |
|
574 |
|
575 // --------------------------------------------------------------------------- |
|
576 // CESMRAnnivTimeValidator::SetAllDayEventL |
|
577 // --------------------------------------------------------------------------- |
|
578 // |
|
579 void CESMRAnnivTimeValidator::SetAllDayEventL( |
|
580 TBool /*aAlldayEvent*/ ) |
|
581 { |
|
582 FUNC_LOG; |
|
583 // No implementation for anniversary |
|
584 } |
|
585 |
|
586 // --------------------------------------------------------------------------- |
|
587 // CESMRAnnivTimeValidator::SetAlarmOnOffL |
|
588 // --------------------------------------------------------------------------- |
|
589 // |
|
590 void CESMRAnnivTimeValidator::SetAlarmOnOffL( |
|
591 TBool aAlarmOn ) |
|
592 { |
|
593 FUNC_LOG; |
|
594 iAlarmOnOff = aAlarmOn; |
|
595 |
|
596 if ( iAlarmOnOff ) |
|
597 { |
|
598 if ( iCurrentAlarmTime == Time::NullTTime() || |
|
599 iCurrentAlarmTime > iCurrentAnnivDate ) |
|
600 { |
|
601 iCurrentAlarmTime = DefaultAnniversaryAlarm( iCurrentAnnivDate ); |
|
602 } |
|
603 |
|
604 SetTimeToEditor( *iAlarmTime, iCurrentAlarmTime ); |
|
605 SetDateToEditor( *iAlarmDate, iCurrentAlarmTime ); |
|
606 |
|
607 DrawEditorsDeferred(); |
|
608 } |
|
609 } |
|
610 |
|
611 // --------------------------------------------------------------------------- |
|
612 // CESMRAnnivTimeValidator::RecurrenceChangedL |
|
613 // --------------------------------------------------------------------------- |
|
614 // |
|
615 void CESMRAnnivTimeValidator::RecurrenceChangedL( |
|
616 TESMRRecurrenceValue /*aRecurrence*/ ) |
|
617 { |
|
618 FUNC_LOG; |
|
619 // No implementation for anniversary |
|
620 } |
|
621 |
|
622 // --------------------------------------------------------------------------- |
|
623 // CESMRAnnivTimeValidator::RecurrenceEndDateChangedL |
|
624 // --------------------------------------------------------------------------- |
|
625 // |
|
626 void CESMRAnnivTimeValidator::RecurrenceEndDateChangedL() |
|
627 { |
|
628 FUNC_LOG; |
|
629 // No implementation for anniversary |
|
630 } |
|
631 |
|
632 // --------------------------------------------------------------------------- |
|
633 // CESMRAnnivTimeValidator::IsRelativeAlarmValid |
|
634 // --------------------------------------------------------------------------- |
|
635 // |
|
636 TBool CESMRAnnivTimeValidator::IsRelativeAlarmValid( |
|
637 TTimeIntervalMinutes /*aAlarmTimeOffset*/ ) |
|
638 { |
|
639 FUNC_LOG; |
|
640 return EFalse; |
|
641 } |
|
642 |
|
643 // --------------------------------------------------------------------------- |
|
644 // CESMRAnnivTimeValidator::PreValidateEditorContent |
|
645 // --------------------------------------------------------------------------- |
|
646 // |
|
647 TInt CESMRAnnivTimeValidator::PreValidateEditorContent() |
|
648 { |
|
649 FUNC_LOG; |
|
650 TRAPD( err, PreValidateEditorContentL() ); |
|
651 return err; |
|
652 } |
|
653 |
|
654 // --------------------------------------------------------------------------- |
|
655 // CESMRAnnivTimeValidator::PreValidateEditorContentL |
|
656 // --------------------------------------------------------------------------- |
|
657 // |
|
658 void CESMRAnnivTimeValidator::PreValidateEditorContentL() |
|
659 { |
|
660 FUNC_LOG; |
|
661 if ( iStartDate && iStartDate->IsVisible() ) |
|
662 { |
|
663 iStartDate->PrepareForFocusLossL(); |
|
664 } |
|
665 |
|
666 if ( iAlarmOnOff && iAlarmTime && iAlarmTime->IsVisible() ) |
|
667 { |
|
668 iAlarmTime->PrepareForFocusLossL(); |
|
669 } |
|
670 |
|
671 if ( iAlarmOnOff && iAlarmDate && iAlarmDate->IsVisible() ) |
|
672 { |
|
673 iAlarmDate->PrepareForFocusLossL(); |
|
674 } |
|
675 } |
|
676 |
|
677 // --------------------------------------------------------------------------- |
|
678 // CESMRAnnivTimeValidator::DrawEditorsDeferred |
|
679 // --------------------------------------------------------------------------- |
|
680 // |
|
681 void CESMRAnnivTimeValidator::DrawEditorsDeferred() |
|
682 { |
|
683 FUNC_LOG; |
|
684 if ( iStartDate && iStartDate->IsVisible() ) |
|
685 { |
|
686 iStartDate->DrawDeferred(); |
|
687 } |
|
688 |
|
689 if ( iAlarmTime && iAlarmTime->IsVisible() ) |
|
690 { |
|
691 iAlarmTime->DrawDeferred(); |
|
692 } |
|
693 |
|
694 if ( iAlarmDate && iAlarmDate->IsVisible() ) |
|
695 { |
|
696 iAlarmDate->DrawDeferred(); |
|
697 } |
|
698 } |
|
699 |
|
700 // --------------------------------------------------------------------------- |
|
701 // CESMRAnnivTimeValidator::StartTimeL |
|
702 // --------------------------------------------------------------------------- |
|
703 // |
|
704 TDateTime CESMRAnnivTimeValidator::StartTimeL() |
|
705 { |
|
706 FUNC_LOG; |
|
707 return iStartDate->Date().DateTime(); |
|
708 } |
|
709 |
|
710 // --------------------------------------------------------------------------- |
|
711 // CESMRAnnivTimeValidator::AlarmTimeL |
|
712 // --------------------------------------------------------------------------- |
|
713 // |
|
714 TDateTime CESMRAnnivTimeValidator::AlarmTimeL() |
|
715 { |
|
716 FUNC_LOG; |
|
717 TDateTime alarmDateTime = iAlarmDate->Date().DateTime(); |
|
718 TDateTime alarmTime = iAlarmTime->Time().DateTime(); |
|
719 |
|
720 alarmDateTime.SetHour( alarmTime.Hour() ); |
|
721 alarmDateTime.SetMinute( alarmTime.Minute() ); |
|
722 alarmDateTime.SetSecond( alarmTime.Second() ); |
|
723 |
|
724 return alarmDateTime; |
|
725 } |
|
726 |
|
727 // --------------------------------------------------------------------------- |
|
728 // CESMRAnnivTimeValidator::ForceValuesL |
|
729 // --------------------------------------------------------------------------- |
|
730 // |
|
731 void CESMRAnnivTimeValidator::ForceValuesL() |
|
732 { |
|
733 FUNC_LOG; |
|
734 if ( iAlarmOnOff ) |
|
735 { |
|
736 TTime start = StartTimeL(); |
|
737 TTime alarm = AlarmTimeL(); |
|
738 |
|
739 // For alarm following cehcks and corrections are made: |
|
740 // - Alarm is more that 31 days before start |
|
741 // --> Alarm is adjusted to be 30,5 half days before |
|
742 // - Alarm is later than start time |
|
743 // --> Default alarm time is set for alarm |
|
744 // - Alarm occurs in past |
|
745 // --> For unsaved entries alarm is set off |
|
746 // |
|
747 TTimeIntervalDays alarmBefore = start.DaysFrom(alarm); |
|
748 if ( alarmBefore > KMaxAlarmTime ) |
|
749 { |
|
750 // Adjust alarm time to 30,5 half days earlier |
|
751 alarm = start - KMaxAlarmTime + TTimeIntervalHours(KNoon); |
|
752 } |
|
753 |
|
754 if ( alarm > start ) |
|
755 { |
|
756 // Setting alarm to default value |
|
757 alarm = DefaultAnniversaryAlarm( start ); |
|
758 } |
|
759 |
|
760 TTime currentTime; currentTime.HomeTime(); |
|
761 if ( alarm < currentTime ) |
|
762 { |
|
763 if ( !iEntry->IsStoredL() ) |
|
764 { |
|
765 // Setting alarm to default value if entry is not stored |
|
766 iAlarmOnOff = EFalse; |
|
767 } |
|
768 } |
|
769 |
|
770 SetTimeToEditor( *iAlarmTime, alarm ); |
|
771 SetDateToEditor( *iAlarmDate, alarm ); |
|
772 |
|
773 iCurrentAlarmTime = alarm; |
|
774 } |
|
775 } |
|
776 |
|
777 // --------------------------------------------------------------------------- |
|
778 // CESMRAnnivTimeValidator::IsModifiedL |
|
779 // --------------------------------------------------------------------------- |
|
780 // |
|
781 TBool CESMRAnnivTimeValidator::IsModifiedL( MESMRCalEntry& aEntry ) |
|
782 { |
|
783 // Checks if any of the editor fields have changed from the original / |
|
784 // initial values |
|
785 TBool isEdited( EFalse ); |
|
786 |
|
787 TBool isSame = aEntry.Entry().CompareL( aEntry.OriginalEntry() ); |
|
788 |
|
789 if( !isSame || |
|
790 iInitialAlarmOnOff != iAlarmOnOff || |
|
791 iStartDate->Date() != iInitialStartDate ) |
|
792 { |
|
793 isEdited = ETrue; |
|
794 } |
|
795 |
|
796 // If alarm is on, we will check alarm time and date also for changes |
|
797 if( iAlarmOnOff ) |
|
798 { |
|
799 if( iAlarmTime->Time() != iInitialAlarmTime || |
|
800 iAlarmDate->Date() != iInitialAlarmDate ) |
|
801 { |
|
802 isEdited = ETrue; |
|
803 } |
|
804 } |
|
805 |
|
806 return isEdited; |
|
807 } |
|
808 |
|
809 // EOF |