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