|
1 /* |
|
2 * Copyright (c) 2002-2004 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 : Class looking after alarm fields for forms. |
|
15 * |
|
16 */ |
|
17 |
|
18 // user includes |
|
19 #include "calenreminderfield.h" |
|
20 #include "CalenDefaultEditors.hrh" |
|
21 #include "calenunifiededitor.h" |
|
22 |
|
23 // system includes |
|
24 #include <AknQueryValueText.h> |
|
25 #include <AknPopupField.h> |
|
26 #include <AknUtils.h> |
|
27 #include <eikenv.h> |
|
28 #include <eikedwin.h> |
|
29 #include <eikmfne.h> |
|
30 #include <StringLoader.h> |
|
31 #include <eikdialg.h> |
|
32 #include <centralrepository.h> |
|
33 #include <calalarm.h> |
|
34 #include <calentry.h> |
|
35 #include <calrrule.h> |
|
36 #include <caltime.h> |
|
37 #include <calendateutils.h> |
|
38 #include <CalenDefaultEditorsData.rsg> |
|
39 #include <calenconstants.h> |
|
40 |
|
41 //debug |
|
42 #include "calendarui_debug.h" |
|
43 |
|
44 // ----------------------------------------------------------------------------- |
|
45 // CCalenReminderField::NewL() |
|
46 // Two-phased constructor. |
|
47 // (other items were commented in a header). |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 CCalenReminderField* CCalenReminderField::NewL( CCalenUnifiedEditor& aUnifiedEditor ) |
|
51 { |
|
52 TRACE_ENTRY_POINT; |
|
53 |
|
54 CCalenReminderField* self = |
|
55 new( ELeave ) CCalenReminderField( aUnifiedEditor ); |
|
56 CleanupStack::PushL( self ); |
|
57 self->ConstructL(); |
|
58 CleanupStack::Pop(); |
|
59 |
|
60 TRACE_EXIT_POINT; |
|
61 return self; |
|
62 } |
|
63 |
|
64 // ----------------------------------------------------------------------------- |
|
65 // CCalenReminderField::CCalenReminderField() |
|
66 // Constructor. |
|
67 // (other items were commented in a header). |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 CCalenReminderField::CCalenReminderField( CCalenUnifiedEditor& aUnifiedEditor ) |
|
71 : iUnifiedEditor( aUnifiedEditor ) |
|
72 { |
|
73 TRACE_ENTRY_POINT; |
|
74 TRACE_EXIT_POINT; |
|
75 } |
|
76 |
|
77 // ----------------------------------------------------------------------------- |
|
78 // CCalenReminderField::ConstructL() |
|
79 // Leaving construction. |
|
80 // (other items were commented in a header). |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 void CCalenReminderField::ConstructL() |
|
84 { |
|
85 TRACE_ENTRY_POINT; |
|
86 |
|
87 iIsAlarmOnOff = CCalenReminderField::EAlarmNoAlarm; |
|
88 isAllDayInitialOffsetSet = EFalse; |
|
89 |
|
90 TRACE_EXIT_POINT; |
|
91 } |
|
92 |
|
93 // ----------------------------------------------------------------------------- |
|
94 // CCalenReminderField::~CCalenReminderField() |
|
95 // Destructor. |
|
96 // (other items were commented in a header). |
|
97 // ----------------------------------------------------------------------------- |
|
98 // |
|
99 CCalenReminderField::~CCalenReminderField() |
|
100 { |
|
101 TRACE_ENTRY_POINT; |
|
102 |
|
103 TRACE_EXIT_POINT; |
|
104 } |
|
105 |
|
106 // ----------------------------------------------------------------------------- |
|
107 // CCalenReminderField::DeleteMeaninglessLinesL() |
|
108 // Remove any lines not needed by the current entry. |
|
109 // (other items were commented in a header). |
|
110 // ----------------------------------------------------------------------------- |
|
111 // |
|
112 void CCalenReminderField::DeleteMeaninglessLinesL() |
|
113 { |
|
114 TRACE_ENTRY_POINT; |
|
115 |
|
116 if ( !iUnifiedEditor.Edited().IsAlarmActivated() ) |
|
117 { |
|
118 SetAlarmDateTimeLinesDimmedL( ETrue ); |
|
119 } |
|
120 |
|
121 TRACE_EXIT_POINT; |
|
122 } |
|
123 |
|
124 // ----------------------------------------------------------------------------- |
|
125 // CCalenReminderField::SetAlarmDateTimeLinesDimmedL() |
|
126 // Delete alarm time and date items from form. |
|
127 // (other items were commented in a header). |
|
128 // ----------------------------------------------------------------------------- |
|
129 // |
|
130 void CCalenReminderField::SetAlarmDateTimeLinesDimmedL( |
|
131 const TBool& aDimmed ) |
|
132 { |
|
133 TRACE_ENTRY_POINT; |
|
134 |
|
135 CCoeControl* alarmDateCtrl = iUnifiedEditor.ControlOrNull( ECalenEditorReminderDate ); |
|
136 CCoeControl* alarmTimeCtrl = iUnifiedEditor.ControlOrNull( ECalenEditorReminderTime ); |
|
137 |
|
138 if( aDimmed ) |
|
139 { |
|
140 // Alarm Off, Delete alarm date & alarm time fields from Editor |
|
141 if( alarmTimeCtrl ) |
|
142 { |
|
143 iUnifiedEditor.DeleteLine( ECalenEditorReminderTime,EFalse ); |
|
144 } |
|
145 if( alarmDateCtrl ) |
|
146 { |
|
147 iUnifiedEditor.DeleteLine( ECalenEditorReminderDate,EFalse ); |
|
148 } |
|
149 } |
|
150 else |
|
151 { |
|
152 // Alarm On, Add alarm time & alarm date fields to Editor |
|
153 if(!alarmDateCtrl) |
|
154 { |
|
155 iUnifiedEditor.InsertFieldL( R_CALEN_EDITOR_REMINDER_TIME_ITEM, |
|
156 ECalenEditorReminderTime, ECalenEditorReminder); |
|
157 } |
|
158 if(!alarmTimeCtrl) |
|
159 { |
|
160 iUnifiedEditor.InsertFieldL( R_CALEN_EDITOR_REMINDER_DATE_ITEM, |
|
161 ECalenEditorReminderDate, ECalenEditorReminderTime); |
|
162 } |
|
163 } |
|
164 |
|
165 TRACE_EXIT_POINT; |
|
166 } |
|
167 |
|
168 // ----------------------------------------------------------------------------- |
|
169 // CCalenReminderField::HandleControlStateChangeL() |
|
170 // Called when a field is modifed. |
|
171 // (other items were commented in a header). |
|
172 // ----------------------------------------------------------------------------- |
|
173 // |
|
174 void CCalenReminderField::HandleControlStateChangeL(TInt aControlId ) |
|
175 { |
|
176 TRACE_ENTRY_POINT; |
|
177 |
|
178 switch (aControlId) |
|
179 { |
|
180 case ECalenEditorReminder: |
|
181 { |
|
182 HandleAlarmActiveFieldChangeL(); |
|
183 break; |
|
184 } |
|
185 default: |
|
186 break; |
|
187 } |
|
188 |
|
189 TRACE_EXIT_POINT; |
|
190 } |
|
191 |
|
192 // ----------------------------------------------------------------------------- |
|
193 // CCalenReminderField::NotifyChangeIsAlarmActiveL() |
|
194 // Called when an alarm field is changed. |
|
195 // (other items were commented in a header). |
|
196 // ----------------------------------------------------------------------------- |
|
197 // |
|
198 void CCalenReminderField::HandleAlarmActiveFieldChangeL( ) |
|
199 { |
|
200 TRACE_ENTRY_POINT; |
|
201 // Activate and initialize the alarm field if it is not already on |
|
202 if( IsAlarmActiveInForm() ) |
|
203 { |
|
204 if( !iUnifiedEditor.Edited().IsAlarmActivated() ) |
|
205 { |
|
206 // no more info note "Alarm Already Passed" |
|
207 // if the note is an old note and it is in past |
|
208 iUnifiedEditor.EditorDataHandler().SetDefaultAlarmDateTimeL(); |
|
209 SetAlarmDateTimeLinesDimmedL( EFalse ); |
|
210 SetDataToEditorL(); |
|
211 } |
|
212 } |
|
213 else |
|
214 { |
|
215 // Hide alarm date/time field |
|
216 iUnifiedEditor.Edited().SetAlarmOffL(); |
|
217 SetAlarmDateTimeLinesDimmedL( ETrue ); |
|
218 } |
|
219 |
|
220 iUnifiedEditor.UpdateFormL(); |
|
221 |
|
222 TRACE_EXIT_POINT; |
|
223 } |
|
224 |
|
225 // ----------------------------------------------------------------------------- |
|
226 // CCalenReminderField::UpdateAlarmDateTimeWhenStartChanged() |
|
227 // When the start time of the entry is changed, this function |
|
228 // gets called to keep the time interval between the entry start |
|
229 // and the alarm constant. |
|
230 // (other items were commented in a header). |
|
231 // ----------------------------------------------------------------------------- |
|
232 // |
|
233 void CCalenReminderField::UpdateAlarmTimeWhenStartChangedL() |
|
234 { |
|
235 TRACE_ENTRY_POINT; |
|
236 |
|
237 // Updating operation is executed only if alarm date/time field exists. |
|
238 if( iUnifiedEditor.Edited().IsAlarmActivated() ) |
|
239 { |
|
240 TTime start = iUnifiedEditor.Edited().EventDateTime(); |
|
241 TTime alarm; |
|
242 //For a new allday event when the start time is changed for the first time |
|
243 //alarm time must be updated correctly |
|
244 if(iUnifiedEditor.Edited().IsAllDayEvent() && !isAllDayInitialOffsetSet |
|
245 && iUnifiedEditor.EditorDataHandler().IsCreatingNew()) |
|
246 { |
|
247 alarm = CalenDateUtils::DefaultTime(start)+iAlarmOffset; |
|
248 isAllDayInitialOffsetSet = ETrue; |
|
249 } |
|
250 else |
|
251 { |
|
252 alarm = start + iAlarmOffset; |
|
253 } |
|
254 alarm = CalenDateUtils::LimitToValidTime( alarm ); |
|
255 iUnifiedEditor.Edited().SetAlarmDateTimeL( alarm ); |
|
256 SetDataToEditorL(); |
|
257 } |
|
258 |
|
259 TRACE_EXIT_POINT; |
|
260 } |
|
261 |
|
262 // ----------------------------------------------------------------------------- |
|
263 // CCalenReminderField::SetAlarmDateTimeField() |
|
264 // Sets the alarm date/time to the specified TTime. |
|
265 // (other items were commented in a header). |
|
266 // ----------------------------------------------------------------------------- |
|
267 // |
|
268 void CCalenReminderField::SetAlarmDateTimeField( const TTime& aTime ) |
|
269 { |
|
270 TRACE_ENTRY_POINT; |
|
271 |
|
272 iUnifiedEditor.EditorFields().SetTimeField( ECalenEditorReminderTime, aTime ); |
|
273 iUnifiedEditor.EditorFields().SetDateField( ECalenEditorReminderDate, aTime ); |
|
274 |
|
275 TRACE_EXIT_POINT; |
|
276 } |
|
277 |
|
278 // ----------------------------------------------------------------------------- |
|
279 // CCalenReminderField::HandleErrorL() |
|
280 // Handle error codes related to the alarm fields. |
|
281 // (other items were commented in a header). |
|
282 // ----------------------------------------------------------------------------- |
|
283 // |
|
284 TBool CCalenReminderField::HandleErrorL( const TInt& aError ) |
|
285 { |
|
286 TRACE_ENTRY_POINT; |
|
287 |
|
288 TBool handled = EFalse; |
|
289 switch ( aError ) |
|
290 { |
|
291 case CCalenEditorDataHandler::EFormErrAlarmTimeLaterThanNote: |
|
292 { |
|
293 TTime startDay = CalenDateUtils::BeginningOfDay( iUnifiedEditor.Edited().EventDateTime() ); |
|
294 TTime alarmDay = CalenDateUtils::BeginningOfDay( iUnifiedEditor.Edited().AlarmDateTime() ); |
|
295 |
|
296 TInt newFocusId = startDay == alarmDay ? ECalenEditorReminderTime : ECalenEditorReminderDate; |
|
297 iUnifiedEditor.TryChangeFocusToL( newFocusId ); |
|
298 handled = ETrue; |
|
299 break; |
|
300 } |
|
301 case CCalenEditorDataHandler::EFormErrAlarmDateTooManyDaysBeforeNote: |
|
302 { |
|
303 iUnifiedEditor.TryChangeFocusToL( ECalenEditorReminderDate ); |
|
304 handled = ETrue; |
|
305 break; |
|
306 } |
|
307 case CCalenEditorDataHandler::EFormErrAlarmTimePast: |
|
308 { |
|
309 TTime alarmTime = iUnifiedEditor.Edited().AlarmDateTime(); |
|
310 |
|
311 TTime now; |
|
312 now.HomeTime(); |
|
313 TInt newFocusId = ECalenEditorReminderDate; |
|
314 if( CalenDateUtils::OnSameDay( now, alarmTime ) ) |
|
315 { |
|
316 newFocusId = ECalenEditorReminderTime; |
|
317 } |
|
318 iUnifiedEditor.TryChangeFocusToL( newFocusId ); |
|
319 |
|
320 handled = ETrue; |
|
321 break; |
|
322 } |
|
323 default: |
|
324 handled = EFalse; |
|
325 break; |
|
326 } |
|
327 |
|
328 TRACE_EXIT_POINT; |
|
329 return handled; |
|
330 } |
|
331 |
|
332 // ----------------------------------------------------------------------------- |
|
333 // CCalenReminderField::PrepareForFocusTransitionL() |
|
334 // Called when focus is moved from the specified line. |
|
335 // (other items were commented in a header). |
|
336 // ----------------------------------------------------------------------------- |
|
337 // |
|
338 void CCalenReminderField::PrepareForFocusTransitionL( TInt aFocusedId ) |
|
339 { |
|
340 TRACE_ENTRY_POINT; |
|
341 |
|
342 switch( aFocusedId ) |
|
343 { |
|
344 case ECalenEditorStartDate: |
|
345 case ECalenEditorStartTime: |
|
346 { |
|
347 UpdateAlarmTimeWhenStartChangedL(); |
|
348 break; |
|
349 } |
|
350 case ECalenEditorReminderDate: |
|
351 case ECalenEditorReminderTime: |
|
352 { |
|
353 const TBool continueOnError = EFalse; |
|
354 ReadDataFromFormL( continueOnError ); |
|
355 TTime start = iUnifiedEditor.Edited().EventDateTime(); |
|
356 TTime alarm = iUnifiedEditor.Edited().AlarmDateTime(); |
|
357 User::LeaveIfError( alarm.MinutesFrom( start, iAlarmOffset ) ); |
|
358 break; |
|
359 } |
|
360 default: |
|
361 { |
|
362 break; |
|
363 } |
|
364 } |
|
365 |
|
366 TRACE_EXIT_POINT; |
|
367 } |
|
368 |
|
369 // ----------------------------------------------------------------------------- |
|
370 // CCalenReminderField::IsStartTimeInFutureL() |
|
371 // Checks to see if the current value of the alarm date/time line is in the future. |
|
372 // (other items were commented in a header). |
|
373 // ----------------------------------------------------------------------------- |
|
374 // |
|
375 TBool CCalenReminderField::IsStartTimeInFutureL() |
|
376 { |
|
377 TRACE_ENTRY_POINT; |
|
378 |
|
379 TTime currentTime; |
|
380 currentTime.HomeTime(); |
|
381 |
|
382 TTime start = iUnifiedEditor.Edited().EventDateTime(); |
|
383 |
|
384 if( iUnifiedEditor.EditorDataHandler().IsTimedEntry() ) |
|
385 { |
|
386 if( currentTime>start ) |
|
387 { |
|
388 TRACE_EXIT_POINT; |
|
389 return EFalse; |
|
390 } |
|
391 } |
|
392 else |
|
393 { |
|
394 TTime startDay = CalenDateUtils::BeginningOfDay( start ); |
|
395 TTime currentDay = CalenDateUtils::BeginningOfDay( currentTime ); |
|
396 if( currentDay>startDay ) |
|
397 { |
|
398 TRACE_EXIT_POINT; |
|
399 return EFalse; |
|
400 } |
|
401 } |
|
402 |
|
403 TRACE_EXIT_POINT; |
|
404 return ETrue; |
|
405 } |
|
406 |
|
407 // ----------------------------------------------------------------------------- |
|
408 // CCalenReminderField::IsAlarmActiveInForm() |
|
409 // Checks to see if the alarm is active. |
|
410 // (other items were commented in a header). |
|
411 // ----------------------------------------------------------------------------- |
|
412 // |
|
413 TBool CCalenReminderField::IsAlarmActiveInForm() |
|
414 { |
|
415 TRACE_ENTRY_POINT; |
|
416 |
|
417 TInt pos = iIsAlarmOnOff; |
|
418 |
|
419 TRACE_EXIT_POINT; |
|
420 return pos == CCalenReminderField::EAlarmActive; |
|
421 } |
|
422 |
|
423 // ----------------------------------------------------------------------------- |
|
424 // CCalenReminderField::SetDataToEditorL() |
|
425 // Reads data from the entry and updates the form with the appropriate values. |
|
426 // ----------------------------------------------------------------------------- |
|
427 // |
|
428 void CCalenReminderField::SetDataToEditorL() |
|
429 { |
|
430 TRACE_ENTRY_POINT; |
|
431 |
|
432 // Alarm popup choice item |
|
433 TInt pos = CCalenReminderField::EAlarmNoAlarm; |
|
434 |
|
435 if ( iUnifiedEditor.Edited().IsAlarmActivated() ) |
|
436 { |
|
437 pos = CCalenReminderField::EAlarmActive; |
|
438 |
|
439 // FIXME: How about todos with different start and end dates? |
|
440 TTime alarm = iUnifiedEditor.Edited().AlarmDateTime(); |
|
441 TTime start = iUnifiedEditor.Edited().EventDateTime(); |
|
442 |
|
443 User::LeaveIfError( alarm.MinutesFrom( start, iAlarmOffset ) ); |
|
444 SetAlarmDateTimeField( alarm ); |
|
445 } |
|
446 else |
|
447 { |
|
448 SetAlarmDateTimeLinesDimmedL( ETrue ); |
|
449 } |
|
450 |
|
451 iIsAlarmOnOff = pos; |
|
452 |
|
453 if( pos == CCalenReminderField::EAlarmActive ) |
|
454 { |
|
455 iUnifiedEditor.EditorFields().SetAlarmFieldOnOffL( ETrue ); |
|
456 } |
|
457 else |
|
458 { |
|
459 iUnifiedEditor.EditorFields().SetAlarmFieldOnOffL( EFalse ); |
|
460 } |
|
461 |
|
462 TRACE_EXIT_POINT; |
|
463 } |
|
464 |
|
465 // ----------------------------------------------------------------------------- |
|
466 // CCalenReminderField::ReadDataFromFormL() |
|
467 // Reads data from the form and updates the entry with the appropriate values. |
|
468 // ----------------------------------------------------------------------------- |
|
469 // |
|
470 void CCalenReminderField::ReadDataFromFormL( TBool aContinueOnError ) |
|
471 { |
|
472 TRACE_ENTRY_POINT; |
|
473 |
|
474 if( IsAlarmActiveInForm() ) |
|
475 { |
|
476 TTime alarm = iUnifiedEditor.Edited().AlarmDateTime(); |
|
477 TRAPD(err, alarm = AlarmDateTimeFromFormL() ); |
|
478 if(!aContinueOnError) |
|
479 { |
|
480 User::LeaveIfError( err ); |
|
481 } |
|
482 iUnifiedEditor.Edited().SetAlarmDateTimeL( alarm ); |
|
483 } |
|
484 else |
|
485 { |
|
486 iUnifiedEditor.Edited().SetAlarmOffL(); |
|
487 } |
|
488 |
|
489 TRACE_EXIT_POINT; |
|
490 } |
|
491 |
|
492 // ----------------------------------------------------------------------------- |
|
493 // CCalenReminderField::InitReminderFieldLdayoutL() |
|
494 // Updates fields just before the form is shown. |
|
495 // (other items were commented in a header). |
|
496 // ----------------------------------------------------------------------------- |
|
497 // |
|
498 void CCalenReminderField::InitReminderFieldLdayoutL() |
|
499 { |
|
500 TRACE_ENTRY_POINT; |
|
501 |
|
502 if(iUnifiedEditor.Edited().IsAlarmActivated() ) |
|
503 { |
|
504 SetAlarmDateTimeLinesDimmedL( EFalse ); |
|
505 } |
|
506 else |
|
507 { |
|
508 SetAlarmDateTimeLinesDimmedL( ETrue ); |
|
509 } |
|
510 |
|
511 TRACE_EXIT_POINT; |
|
512 } |
|
513 |
|
514 // ----------------------------------------------------------------------------- |
|
515 // CCalenReminderField::GetTimeField |
|
516 // Get the time field in touch layouts |
|
517 // ----------------------------------------------------------------------------- |
|
518 // |
|
519 TTime CCalenReminderField::GetTimeField( TInt aControlId ) |
|
520 { |
|
521 TRACE_ENTRY_POINT; |
|
522 TRACE_EXIT_POINT; |
|
523 |
|
524 return iUnifiedEditor.EditorFields().ReadTimeField( aControlId ); |
|
525 } |
|
526 |
|
527 // ----------------------------------------------------------------------------- |
|
528 // CCalenReminderField::AlarmDateTimeFromFormL() |
|
529 // Returns the current date/time value of the alarm field. |
|
530 // (other items were commented in a header). |
|
531 // ----------------------------------------------------------------------------- |
|
532 // |
|
533 TTime CCalenReminderField::AlarmDateTimeFromFormL() |
|
534 { |
|
535 TRACE_ENTRY_POINT; |
|
536 |
|
537 // get user entered date & time from the editor |
|
538 TTime alarm = CalenDateUtils::BeginningOfDay( GetTimeField( ECalenEditorReminderDate ) ); |
|
539 alarm += CalenDateUtils::TimeOfDay( GetTimeField( ECalenEditorReminderTime ) ); |
|
540 |
|
541 TRACE_EXIT_POINT; |
|
542 return alarm; |
|
543 } |
|
544 // ----------------------------------------------------------------------------- |
|
545 // CCalenReminderField::CheckAlarmActive() |
|
546 // Gets the info whether alarm on/off |
|
547 // adds & updates the alarm fields accordingly |
|
548 // (other items were commented in a header). |
|
549 // ----------------------------------------------------------------------------- |
|
550 // |
|
551 void CCalenReminderField::CheckAlarmActive( TBool aAlarmActive ) |
|
552 { |
|
553 TRACE_ENTRY_POINT; |
|
554 |
|
555 if( aAlarmActive ) |
|
556 { |
|
557 iIsAlarmOnOff = CCalenReminderField::EAlarmActive; |
|
558 } |
|
559 else |
|
560 { |
|
561 iIsAlarmOnOff = CCalenReminderField::EAlarmNoAlarm; |
|
562 } |
|
563 |
|
564 TRAP_IGNORE( HandleAlarmActiveFieldChangeL() ); |
|
565 |
|
566 TRACE_EXIT_POINT; |
|
567 } |
|
568 |
|
569 // End of File |