|
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 : |
|
15 * |
|
16 */ |
|
17 |
|
18 // user includes |
|
19 #include "calenrepeatfield.h" |
|
20 #include "CalenDefaultEditors.hrh" |
|
21 #include "CalenDescription.h" |
|
22 #include "calennotedatautil.h" |
|
23 #include "calenentryutil.h" |
|
24 #include "CalenEditorDataHandler.h" |
|
25 |
|
26 // system includes |
|
27 #include <AknPopupField.h> |
|
28 #include <AknQueryValueText.h> |
|
29 #include <calentry.h> |
|
30 #include <calrrule.h> |
|
31 #include <calendateutils.h> |
|
32 #include <CalenDefaultEditorsData.rsg> |
|
33 |
|
34 // debug |
|
35 #include "calendarui_debug.h" |
|
36 |
|
37 //Feb 29th will be read as 28 as indexing of days starts from 0,1,2.... |
|
38 const TInt KLastDayInFebLeapYear = 28; |
|
39 |
|
40 // CONSTRUCTION AND DESTRUCTION METHODS |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // CCalenRepeatField::NewL |
|
44 // (other items were commented in a header). |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 CCalenRepeatField* CCalenRepeatField::NewL( CCalenUnifiedEditor& aUnifiedEditor ) |
|
48 { |
|
49 TRACE_ENTRY_POINT; |
|
50 |
|
51 CCalenRepeatField* self = |
|
52 new( ELeave ) CCalenRepeatField( aUnifiedEditor ); |
|
53 CleanupStack::PushL( self ); |
|
54 self->ConstructL(); |
|
55 CleanupStack::Pop(); |
|
56 |
|
57 TRACE_EXIT_POINT; |
|
58 return self; |
|
59 } |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // CCalenRepeatField::CCalenRepeatField |
|
63 // (other items were commented in a header). |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 CCalenRepeatField::CCalenRepeatField( CCalenUnifiedEditor& aUnifiedEditor ) |
|
67 : iUnifiedEditor( aUnifiedEditor ) |
|
68 { |
|
69 TRACE_ENTRY_POINT; |
|
70 TRACE_EXIT_POINT; |
|
71 } |
|
72 |
|
73 // ----------------------------------------------------------------------------- |
|
74 // CCalenRepeatField::ConstructL |
|
75 // second phase constructor |
|
76 // (other items were commented in a header). |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 void CCalenRepeatField::ConstructL() |
|
80 { |
|
81 TRACE_ENTRY_POINT; |
|
82 |
|
83 // read resource for confideitiality popup list |
|
84 iRepeatArrayText = iUnifiedEditor.ControlEnv()->ReadDesCArrayResourceL( |
|
85 R_CALEN_EDITOR_REPEAT_POPUP_ITEMS); |
|
86 |
|
87 // create textarray |
|
88 iRepeatArray = CAknQueryValueTextArray::NewL(); |
|
89 iRepeatTextValues = CAknQueryValueText::NewL(); |
|
90 iRepeatArray->SetArray(*iRepeatArrayText); |
|
91 iRepeatTextValues->SetArrayL(iRepeatArray); |
|
92 |
|
93 TRACE_EXIT_POINT; |
|
94 } |
|
95 |
|
96 // ----------------------------------------------------------------------------- |
|
97 // CCalenRepeatField::~CCalenRepeatField |
|
98 // (other items were commented in a header). |
|
99 // ----------------------------------------------------------------------------- |
|
100 // |
|
101 CCalenRepeatField::~CCalenRepeatField() |
|
102 { |
|
103 TRACE_ENTRY_POINT; |
|
104 |
|
105 delete iRepeatArrayText; |
|
106 delete iRepeatArray; |
|
107 delete iRepeatTextValues; |
|
108 |
|
109 TRACE_EXIT_POINT; |
|
110 } |
|
111 |
|
112 |
|
113 // ----------------------------------------------------------------------------- |
|
114 // CCalenRepeatField::HandleControlStateChangedL |
|
115 // (other items were commented in a header). |
|
116 // ----------------------------------------------------------------------------- |
|
117 // |
|
118 void CCalenRepeatField::HandleControlStateChangeL( TInt aControlId ) |
|
119 { |
|
120 TRACE_ENTRY_POINT; |
|
121 |
|
122 switch (aControlId) |
|
123 { |
|
124 case ECalenEditorRepeat: |
|
125 { |
|
126 NotifyChangeRepeatChoiceL(); |
|
127 break; |
|
128 } |
|
129 default: |
|
130 { |
|
131 break; |
|
132 } |
|
133 } |
|
134 |
|
135 TRACE_EXIT_POINT; |
|
136 } |
|
137 |
|
138 // ----------------------------------------------------------------------------- |
|
139 // CCalenRepeatField::HandleErrorL |
|
140 // (other items were commented in a header). |
|
141 // ----------------------------------------------------------------------------- |
|
142 // |
|
143 TBool CCalenRepeatField::HandleErrorL( const TInt& aError ) |
|
144 { |
|
145 TRACE_ENTRY_POINT; |
|
146 |
|
147 TBool handled = EFalse; |
|
148 switch ( aError ) |
|
149 { |
|
150 case CCalenEditorDataHandler::EFormErrRepeatUntilEarlierThanNote: |
|
151 { |
|
152 // ReapetUntill is earlier that note instance |
|
153 iUnifiedEditor.TryChangeFocusToL( ECalenEditorRepeatUntil ); |
|
154 handled = ETrue; |
|
155 break; |
|
156 } |
|
157 case CCalenEditorDataHandler::EFormErrStopTimeEarlierThanStartTime: |
|
158 { |
|
159 TInt newFocusId = ECalenEditorEndDate; |
|
160 |
|
161 // Stop time erarliar that satrt time of event |
|
162 if( CalenDateUtils::OnSameDay( iUnifiedEditor.Edited().StartDateTime(), |
|
163 iUnifiedEditor.Edited().EndDateTime() ) ) |
|
164 { |
|
165 newFocusId = ECalenEditorEndTime; |
|
166 } |
|
167 iUnifiedEditor.TryChangeFocusToL( newFocusId ); |
|
168 |
|
169 handled = ETrue; |
|
170 break; |
|
171 } |
|
172 case CCalenEditorDataHandler::EFormErrCancelSaveRepNoteWhenStartChange: |
|
173 { |
|
174 iUnifiedEditor.TryChangeFocusToL( ECalenEditorStartDate ); |
|
175 handled = ETrue; |
|
176 break; |
|
177 } |
|
178 default: |
|
179 { |
|
180 handled = EFalse; |
|
181 break; |
|
182 } |
|
183 } |
|
184 |
|
185 TRACE_EXIT_POINT; |
|
186 return handled; |
|
187 } |
|
188 |
|
189 // ----------------------------------------------------------------------------- |
|
190 // CCalenRepeatField::FormRepeatType |
|
191 // (other items were commented in a header). |
|
192 // ----------------------------------------------------------------------------- |
|
193 // |
|
194 TCalenRepeatIndex CCalenRepeatField::FormRepeatType() |
|
195 { |
|
196 TRACE_ENTRY_POINT; |
|
197 TRACE_EXIT_POINT; |
|
198 return static_cast<TCalenRepeatIndex>( iRepeatTextValues->CurrentValueIndex() ); |
|
199 } |
|
200 |
|
201 // ----------------------------------------------------------------------------- |
|
202 // CCalenRepeatField::FormRepeatUntilDateTimeL |
|
203 // (other items were commented in a header). |
|
204 // ----------------------------------------------------------------------------- |
|
205 // |
|
206 TTime CCalenRepeatField::FormRepeatUntilDateTimeL() |
|
207 { |
|
208 TRACE_ENTRY_POINT; |
|
209 TRACE_EXIT_POINT; |
|
210 return iUnifiedEditor.EditorFields().ReadDateField( ECalenEditorRepeatUntil ); |
|
211 } |
|
212 |
|
213 // ---------------------------------------------------- |
|
214 // CCalenMeetingForm::DeleteOtherItemFromRepeatField |
|
215 // Delete "Other" item from repeat field. |
|
216 // It MUST be called in following case. |
|
217 // 1. Default repeat value is other then "Other". |
|
218 // 2. Repeat is changed from "Other" to another value. |
|
219 // |
|
220 // If "Other" item has already been deleted, nothing is executed. |
|
221 // (other items were commented in a header). |
|
222 // ---------------------------------------------------- |
|
223 // |
|
224 void CCalenRepeatField::DeleteOtherItemFromRepeatField() |
|
225 { |
|
226 TRACE_ENTRY_POINT; |
|
227 |
|
228 TInt itemCount = iRepeatArrayText->Count(); |
|
229 |
|
230 if ( itemCount > ERepeatOther ) |
|
231 // ERepeatOther is the last item index, |
|
232 // which is zero origin. |
|
233 { |
|
234 iRepeatArrayText->Delete( ERepeatOther ); |
|
235 } |
|
236 |
|
237 TRACE_EXIT_POINT; |
|
238 } |
|
239 |
|
240 // --------------------------------------------------------- |
|
241 // CCalenRepeatField::NotifyChangeRepeatChoiceL |
|
242 // (other items were commented in a header). |
|
243 // --------------------------------------------------------- |
|
244 // |
|
245 void CCalenRepeatField::NotifyChangeRepeatChoiceL() |
|
246 { |
|
247 TRACE_ENTRY_POINT; |
|
248 |
|
249 TInt repeatType = iRepeatTextValues->CurrentValueIndex(); |
|
250 |
|
251 if ( repeatType == ERepeatNotRepeated ) |
|
252 { |
|
253 // Repeat type field value selected as 'Non repeating' |
|
254 iUnifiedEditor.Edited().SetNonRepeatingL(); |
|
255 SetRepeatUntilLineDimmedL( ETrue ); |
|
256 UpdateEndDateTimeFields(); |
|
257 } |
|
258 else |
|
259 { |
|
260 TTime start = iUnifiedEditor.Edited().StartDateTime(); |
|
261 TTime until; |
|
262 |
|
263 if ( iUnifiedEditor.Edited().IsRepeating() ) |
|
264 { |
|
265 until = iUnifiedEditor.Edited().RepeatUntilDateTime(); |
|
266 } |
|
267 else |
|
268 { |
|
269 //Fix for repeated event date change: |
|
270 TDateTime startDate = start.DateTime(); |
|
271 |
|
272 //Checking for leap year feb.29th, next year it should be 28. |
|
273 TInt untilDay; |
|
274 if(startDate.Month() == EFebruary && startDate.Day() == KLastDayInFebLeapYear) |
|
275 { |
|
276 untilDay = KLastDayInFebLeapYear - 1; |
|
277 } |
|
278 else |
|
279 { |
|
280 untilDay = startDate.Day(); |
|
281 } |
|
282 |
|
283 TDateTime repOneYear(startDate.Year()+1,startDate.Month(), untilDay, 0, 0, 0, 0); |
|
284 TTime aTime( repOneYear ); |
|
285 until = aTime; |
|
286 } |
|
287 |
|
288 iUnifiedEditor.Edited().SetRepeatingL( static_cast<TCalenRepeatIndex>( repeatType ), until ); |
|
289 SetRepeatUntilLineDimmedL( EFalse ); |
|
290 SetDataToEditorL(); |
|
291 } |
|
292 |
|
293 if ( repeatType != ERepeatOther ) |
|
294 { |
|
295 // Nothing is executed if "Other" item has already been deleted. |
|
296 DeleteOtherItemFromRepeatField(); |
|
297 } |
|
298 |
|
299 iUnifiedEditor.UpdateFormL(); |
|
300 |
|
301 TRACE_EXIT_POINT; |
|
302 } |
|
303 |
|
304 // --------------------------------------------------------- |
|
305 // CCalenRepeatField::SetRepeatUntilLineDimmedL |
|
306 // (other items were commented in a header). |
|
307 // --------------------------------------------------------- |
|
308 // |
|
309 void CCalenRepeatField::SetRepeatUntilLineDimmedL( const TBool& aDimmed ) |
|
310 { |
|
311 TRACE_ENTRY_POINT; |
|
312 |
|
313 CCoeControl* repUntilCtrl = iUnifiedEditor.ControlOrNull( ECalenEditorRepeatUntil ); |
|
314 |
|
315 if(aDimmed) |
|
316 { |
|
317 if( repUntilCtrl ) |
|
318 { |
|
319 // Delete RepeatUntil line from From |
|
320 iUnifiedEditor.DeleteLine( ECalenEditorRepeatUntil, EFalse ); |
|
321 } |
|
322 } |
|
323 else |
|
324 { |
|
325 if( !repUntilCtrl ) |
|
326 { |
|
327 // Insert RepeatUntil line to From |
|
328 iUnifiedEditor.InsertFieldL( R_CALEN_EDITOR_REPEAT_UNTIL_ITEM, |
|
329 ECalenEditorRepeatUntil, ECalenEditorRepeat ); |
|
330 } |
|
331 } |
|
332 |
|
333 TRACE_EXIT_POINT; |
|
334 } |
|
335 |
|
336 // --------------------------------------------------------- |
|
337 // CCalenRepeatField::UpdateEndDateTimeFields |
|
338 // Called when "Repeat" is updated from any repeat value |
|
339 // to "Not Repeated". |
|
340 // (other items were commented in a header). |
|
341 // --------------------------------------------------------- |
|
342 // |
|
343 void CCalenRepeatField::UpdateEndDateTimeFields() |
|
344 { |
|
345 TRACE_ENTRY_POINT; |
|
346 |
|
347 TTime end = iUnifiedEditor.Edited().EndDateTime(); |
|
348 |
|
349 if( iUnifiedEditor.HasField(ECalenEditorEndDate) ) |
|
350 { |
|
351 // Set End Date field value in Editor |
|
352 iUnifiedEditor.EditorFields().SetDateField( ECalenEditorEndDate, end, EFalse ); |
|
353 } |
|
354 if( iUnifiedEditor.HasField( ECalenEditorEndTime ) ) |
|
355 { |
|
356 // Set End Time field value in Editor |
|
357 iUnifiedEditor.EditorFields().SetTimeField( ECalenEditorEndTime, end ); |
|
358 } |
|
359 TRACE_EXIT_POINT; |
|
360 } |
|
361 |
|
362 // ----------------------------------------------------------------------------- |
|
363 // CCalenRepeatField::AskRepeatingNoteQueriesL |
|
364 // Ask the user of the repeat type when neccessary |
|
365 // (other items were commented in a header). |
|
366 // ----------------------------------------------------------------------------- |
|
367 // |
|
368 CCalenEditorDataHandler::TError CCalenRepeatField::AskRepeatingNoteQueriesL( |
|
369 CalCommon::TRecurrenceRange& aRepeatType) |
|
370 { |
|
371 TRACE_ENTRY_POINT; |
|
372 |
|
373 CCalenEditorDataHandler::TError error = CCalenEditorDataHandler::EFormErrNone; |
|
374 |
|
375 if( ShouldQueryRepeatTargetL() ) |
|
376 { |
|
377 // Query whether user want to edit This/all instanced of repeat entry. |
|
378 error = QueryRepeatTargetL( aRepeatType ); |
|
379 } |
|
380 |
|
381 TRACE_EXIT_POINT; |
|
382 return error; |
|
383 } |
|
384 |
|
385 // ----------------------------------------------------------------------------- |
|
386 // CCalenRepeatField::ShouldQueryRepeatTargetL |
|
387 // Check if the repeat query should be shown |
|
388 // (other items were commented in a header). |
|
389 // ----------------------------------------------------------------------------- |
|
390 // |
|
391 TBool CCalenRepeatField::ShouldQueryRepeatTargetL() |
|
392 { |
|
393 TRACE_ENTRY_POINT; |
|
394 |
|
395 /** |
|
396 * Show save to this/all query if: |
|
397 * Editing a repeating entry (not for child entries!!!) |
|
398 * AND |
|
399 * any of the following fields have changed: |
|
400 * subject, location, description, |
|
401 * start time, end time, (not for date changes) |
|
402 * alarm state, alarm time, alarm date |
|
403 * |
|
404 **/ |
|
405 |
|
406 if( iUnifiedEditor.IsCreatingNewEntry() || |
|
407 ! iUnifiedEditor.Original().IsRepeating() || |
|
408 ! iUnifiedEditor.Edited().IsRepeating() || |
|
409 iUnifiedEditor.EditorDataHandler().IsChildL() ) |
|
410 { |
|
411 TRACE_EXIT_POINT; |
|
412 return EFalse; |
|
413 } |
|
414 |
|
415 // This should take care of checking start date editing: |
|
416 if ( iUnifiedEditor.EditorDataHandler().IsRepeatRuleEdited() ) |
|
417 { |
|
418 TRACE_EXIT_POINT; |
|
419 return EFalse; |
|
420 } |
|
421 |
|
422 TBool isInstanceFieldEdited = |
|
423 iUnifiedEditor.EditorDataHandler().IsSummaryEdited() || |
|
424 iUnifiedEditor.EditorDataHandler().IsLocationEdited() || |
|
425 iUnifiedEditor.EditorDataHandler().IsDescriptionEdited() || |
|
426 iUnifiedEditor.EditorDataHandler().IsStartDateTimeEdited() || |
|
427 iUnifiedEditor.EditorDataHandler().IsEndDateTimeEdited() || |
|
428 iUnifiedEditor.EditorDataHandler().IsAlarmEditedL(); |
|
429 |
|
430 TRACE_EXIT_POINT; |
|
431 return isInstanceFieldEdited; |
|
432 } |
|
433 |
|
434 // ----------------------------------------------------------------------------- |
|
435 // CCalenRepeatField::QueryRepeatTargetL |
|
436 // (other items were commented in a header). |
|
437 // ----------------------------------------------------------------------------- |
|
438 // |
|
439 CCalenEditorDataHandler::TError CCalenRepeatField::QueryRepeatTargetL( |
|
440 CalCommon::TRecurrenceRange& aRepeatType ) |
|
441 { |
|
442 TRACE_ENTRY_POINT; |
|
443 |
|
444 const TBool ok = CalenNoteDataUtil::ShowRepeatTypeQueryL( aRepeatType, |
|
445 CalenNoteDataUtil::ESave ); |
|
446 |
|
447 if( !ok ) // Repeat dialog is canceled |
|
448 { |
|
449 TRACE_EXIT_POINT; |
|
450 return CCalenEditorDataHandler::EFormErrCancelChangeRepeatingNote; |
|
451 } |
|
452 |
|
453 TRACE_EXIT_POINT; |
|
454 return CCalenEditorDataHandler::EFormErrNone; |
|
455 } |
|
456 |
|
457 // ----------------------------------------------------------------------------- |
|
458 // CCalenRepeatField::ReadDataFromFormL |
|
459 // (other items were commented in a header). |
|
460 // ----------------------------------------------------------------------------- |
|
461 // |
|
462 void CCalenRepeatField::ReadDataFromFormL( TBool /*aContinueOnError*/ ) |
|
463 { |
|
464 TRACE_ENTRY_POINT; |
|
465 |
|
466 // read repeat type data from form |
|
467 TCalenRepeatIndex repeatType = FormRepeatType(); |
|
468 if ( repeatType == ERepeatNotRepeated ) |
|
469 { |
|
470 iUnifiedEditor.Edited().SetNonRepeatingL(); |
|
471 } |
|
472 else |
|
473 { |
|
474 TTime until = iUnifiedEditor.Edited().RepeatUntilDateTime(); |
|
475 until = FormRepeatUntilDateTimeL(); |
|
476 iUnifiedEditor.Edited().SetRepeatingL( repeatType, until ); |
|
477 } |
|
478 |
|
479 TRACE_EXIT_POINT; |
|
480 } |
|
481 |
|
482 // ----------------------------------------------------------------------------- |
|
483 // CCalenRepeatField::SetDataToEditorL |
|
484 // (other items were commented in a header). |
|
485 // ----------------------------------------------------------------------------- |
|
486 // |
|
487 void CCalenRepeatField::SetDataToEditorL() |
|
488 { |
|
489 TRACE_ENTRY_POINT; |
|
490 |
|
491 // Update repeat field data in Form |
|
492 TCalenRepeatIndex pos = iUnifiedEditor.Edited().RepeatType(); |
|
493 iRepeatTextValues->SetCurrentValueIndex( static_cast<TInt>( pos ) ); |
|
494 if ( iUnifiedEditor.Edited().IsRepeating() ) |
|
495 { |
|
496 // Set RepeatUntil date in Form |
|
497 TTime until = iUnifiedEditor.Edited().RepeatUntilDateTime(); |
|
498 iUnifiedEditor.EditorFields().SetDateField( ECalenEditorRepeatUntil, until ); |
|
499 } |
|
500 else |
|
501 { |
|
502 // Delete RepeatUntil line from Form |
|
503 SetRepeatUntilLineDimmedL( ETrue ); |
|
504 } |
|
505 |
|
506 TRACE_EXIT_POINT; |
|
507 } |
|
508 |
|
509 // ----------------------------------------------------------------------------- |
|
510 // CCalenRepeatField::InitRepetFieldLayoutL |
|
511 // (other items were commented in a header). |
|
512 // ----------------------------------------------------------------------------- |
|
513 // |
|
514 void CCalenRepeatField::InitRepetFieldLayoutL() |
|
515 { |
|
516 TRACE_ENTRY_POINT; |
|
517 |
|
518 CAknPopupField* pops = |
|
519 static_cast<CAknPopupField*>( iUnifiedEditor.Control( ECalenEditorRepeat ) ); |
|
520 pops->SetQueryValueL(iRepeatTextValues); |
|
521 |
|
522 if( iUnifiedEditor.Edited().RepeatType() != ERepeatOther ) |
|
523 { |
|
524 DeleteOtherItemFromRepeatField(); |
|
525 } |
|
526 |
|
527 if ( iUnifiedEditor.Edited().IsRepeating() ) |
|
528 { |
|
529 SetRepeatUntilLineDimmedL( EFalse ); |
|
530 } |
|
531 |
|
532 TRACE_EXIT_POINT; |
|
533 } |
|
534 |
|
535 // ----------------------------------------------------------------------------- |
|
536 // CCalenRepeatField::PrepareForFocusTransitionL |
|
537 // Prepare for focus change |
|
538 // ----------------------------------------------------------------------------- |
|
539 // |
|
540 void CCalenRepeatField::PrepareForFocusTransitionL( TInt aFocusedId ) |
|
541 { |
|
542 TRACE_ENTRY_POINT; |
|
543 |
|
544 switch( aFocusedId ) |
|
545 { |
|
546 case ECalenEditorRepeatUntil: |
|
547 { |
|
548 TBool continueOnError = EFalse; |
|
549 ReadDataFromFormL( continueOnError ); |
|
550 break; |
|
551 } |
|
552 default: |
|
553 { |
|
554 break; |
|
555 } |
|
556 } |
|
557 |
|
558 TRACE_EXIT_POINT; |
|
559 } |
|
560 |
|
561 // End of File |