|
1 /* |
|
2 * Copyright (c) 2006 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: CalenEditorDataHandler implements all logic of checking and |
|
15 * validating editor data |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #ifndef CALENEDITORDATAHANDLER_H |
|
21 #define CALENEDITORDATAHANDLER_H |
|
22 |
|
23 // system includes |
|
24 #include <e32base.h> |
|
25 #include <caltime.h> |
|
26 #include <calentry.h> |
|
27 #include <calinstanceview.h> |
|
28 #include <caleninstanceid.h> |
|
29 |
|
30 // user includes |
|
31 #include "calennotedatautil.h" |
|
32 |
|
33 // forward declaration |
|
34 class CCalenEntryUtil; |
|
35 class MCalenServices; |
|
36 |
|
37 /** |
|
38 * CCalenEditorDataHandler implements all logic of checking and validating editor data. |
|
39 * |
|
40 * Necessary checks and validations are specificed in UI spec. |
|
41 * CCalenEditorIt doesn't contain any dependencies to UI classes, so logic can be |
|
42 * unit-tested more easily. |
|
43 * |
|
44 * @lib CalenDefaultEditors.dll |
|
45 * @since S60 v3.0 |
|
46 */ |
|
47 class CCalenEditorDataHandler : public CBase |
|
48 { |
|
49 public: |
|
50 enum TError |
|
51 { |
|
52 EFormErrNone, |
|
53 EFormErrAlarmTimeLaterThanNote, |
|
54 EFormErrAlarmTimePast, |
|
55 EFormErrAlarmDateTooManyDaysBeforeNote, |
|
56 EFormErrRepeatUntilEarlierThanNote, |
|
57 EFormErrDurationGreaterThanRepeatInterval, |
|
58 EFormErrStopTimeEarlierThanStartTime, |
|
59 EFormErrCancelSaveRepNoteWhenStartChange, // FIXME should be removed |
|
60 EFormErrCancelChangeRepeatingNote, // FIXME should be removed |
|
61 EFormErrDbConflictEntryDeleted, |
|
62 EFormErrDbConflictEntryModified, |
|
63 EFormErrOutOfSequence, |
|
64 EFormErrOverlapsExistingInstance, |
|
65 EFormErrInstanceAlreadyExistsOnThisDay |
|
66 }; |
|
67 |
|
68 enum TAction |
|
69 { |
|
70 EActionNothing, |
|
71 EActionSave, |
|
72 EActionDelete |
|
73 }; |
|
74 public: |
|
75 /** |
|
76 * @param aEntry that is being edited. Is modified only after call to |
|
77 * WriteChangesToEntryL function. |
|
78 * @param aInstanceDateTime time of instance that is edited |
|
79 * @param aMaxTextEditorLength text editors have max length depending |
|
80 * on variant, but data in database can be longer. |
|
81 * We need this information to compare those fields correctly. |
|
82 */ |
|
83 static CCalenEditorDataHandler* NewL(CCalEntry& aEntry, |
|
84 const TCalTime& aInstanceDateTime, |
|
85 TBool aIsCreatingNew, |
|
86 TInt aMaxTextEditorLength, |
|
87 MCalenServices& aServices, |
|
88 RArray<TInt>& aCollectionIds); |
|
89 |
|
90 virtual ~CCalenEditorDataHandler(); |
|
91 |
|
92 /** |
|
93 * @brief Edited data. Data that is currently edited in form |
|
94 * @return CCalenEntryUtil, Edited entry data |
|
95 */ |
|
96 CCalenEntryUtil& Edited(); |
|
97 |
|
98 /** |
|
99 * @brief Original data. Data that was original set to form. |
|
100 * @return CCalenEntryUtil, Original entry data |
|
101 */ |
|
102 const CCalenEntryUtil& Original() const; |
|
103 |
|
104 /** |
|
105 * @brief Do not modify entry! Use WriteChangesToEntryL and access |
|
106 * entry after that. |
|
107 * @return CCalEntry |
|
108 */ |
|
109 CCalEntry& Entry(); |
|
110 |
|
111 /** |
|
112 * @brief To Return the instance date/time. |
|
113 * @return TCalTime |
|
114 */ |
|
115 const TCalTime& InstanceDateTime() const; |
|
116 |
|
117 /** |
|
118 * @brief check is child entry |
|
119 * @return ETrue if entry is child. |
|
120 */ |
|
121 TBool IsChildL() const; |
|
122 |
|
123 /** |
|
124 * @brief write all changed fields to entry |
|
125 * @param aRepeatTarget |
|
126 */ |
|
127 void WriteChangesToEntryL( CalCommon::TRecurrenceRange aRepeatTarget = CalCommon::EThisAndAll ); |
|
128 |
|
129 /** |
|
130 * @brief To deside Shoud entry be saved or deleted. Entry should be saved, |
|
131 * if it is edited. However, if subject and location fields has been |
|
132 * cleared, it should be deleted. Otherwise nothing should be done. |
|
133 */ |
|
134 TAction ShouldSaveOrDeleteOrDoNothingL(); |
|
135 |
|
136 /** |
|
137 * @brief checks if non text fields AND/OR Description field are edited |
|
138 */ |
|
139 TBool IsEditedOtherThanSubjectAndLocation(); |
|
140 |
|
141 /** |
|
142 * @brief checks if non text fields are edited |
|
143 * @return ETrue if non-text fields are edited else EFalse |
|
144 */ |
|
145 TBool NonTextFieldsEditedL(); |
|
146 |
|
147 /** |
|
148 * @brief checks if text fields are edited |
|
149 * @return ETrue if text fields are edited else EFalse |
|
150 */ |
|
151 TBool TextFieldsEdited(); |
|
152 |
|
153 /** |
|
154 * @brief compares data to original data and checks if any field is edited. |
|
155 * @return ETrue if entry data edited, else EFalse |
|
156 */ |
|
157 TBool IsEditedL(); |
|
158 |
|
159 /** |
|
160 * @brief checks data for errors and returns enumeration that describes error |
|
161 * type. These checks are specified in UI spec under |
|
162 * chapter 4.7.7.2.1 Checking Fields Before Saving, and are used when user |
|
163 * presses 'Done' and tries to save entry. |
|
164 * |
|
165 * Called either when repeat type has not yet been chosen (S60 3.1 and prior) |
|
166 * or when editing EThisAndAll. |
|
167 */ |
|
168 TError CheckErrorsForThisAndAllL(); |
|
169 |
|
170 /** |
|
171 * @brief checks data for errors and returns enumeration |
|
172 * that describes error type. These checks are specified in UI spec under |
|
173 * chapter 4.7.7.2.1 Checking Fields Before Saving, and are used when user |
|
174 * presses 'Done' and tries to save entry. |
|
175 * |
|
176 * Only called when editing EThisOnly. |
|
177 */ |
|
178 TError CheckErrorsForThisOnlyL( CCalEntry& aParentEntry, |
|
179 CCalInstanceView& aInstanceView); |
|
180 |
|
181 /** |
|
182 * @brief checks validity of data and forces valid values |
|
183 * to fields, if they have errors. These checks are specified in UI spec |
|
184 * under chapter 4.6.4.1 Exiting Note Editor, and are used when editors |
|
185 * are forced to exit without anymore user interaction. These situations |
|
186 * include: - user selects Exit from Options menu |
|
187 * - user presses Red key |
|
188 * - power is turned-off |
|
189 * - application is closed by OS in OOM situation |
|
190 * - application is closed by OS when restoring data |
|
191 * |
|
192 |
|
193 */ |
|
194 void ForceValidValuesL( CalCommon::TRecurrenceRange aRepeatTarget ); |
|
195 |
|
196 /** |
|
197 * @brief check whether timed entry |
|
198 * @return ETrue if timed entry, else EFalse |
|
199 */ |
|
200 TBool IsTimedEntry() const; |
|
201 |
|
202 /** |
|
203 * @brief check if summary edited |
|
204 * @return ETrue if summary edited, else EFalse |
|
205 */ |
|
206 TBool IsSummaryEdited(); |
|
207 |
|
208 /** |
|
209 * @brief check if Location edited |
|
210 * @return ETrue if Location edited, else EFalse |
|
211 */ |
|
212 TBool IsLocationEdited(); |
|
213 |
|
214 /** |
|
215 * @brief check if Alarm edited |
|
216 * @return ETrue if Alarm edited, else EFalse |
|
217 */ |
|
218 TBool IsAlarmEditedL(); |
|
219 |
|
220 /** |
|
221 * @brief check if RepeatRule edited |
|
222 * @return ETrue if RepeatRule edited, else EFalse |
|
223 */ |
|
224 TBool IsRepeatRuleEdited(); |
|
225 |
|
226 /** |
|
227 * @brief check if EntryType edited |
|
228 * @return ETrue if EntryType edited, else EFalse |
|
229 */ |
|
230 TBool IsEntryTypeEdited(); |
|
231 /** |
|
232 * @brief check if StartDateTime edited |
|
233 * @return ETrue if StartDateTime edited, else EFalse |
|
234 */ |
|
235 TBool IsStartDateTimeEdited(); |
|
236 |
|
237 /** |
|
238 * @brief check if EndDateTime edited |
|
239 * @return ETrue if EndDateTime edited, else EFalse |
|
240 */ |
|
241 TBool IsEndDateTimeEdited(); |
|
242 |
|
243 /** |
|
244 * @brief check if Description edited |
|
245 * @return ETrue if Description edited, else EFalse |
|
246 */ |
|
247 TBool IsDescriptionEdited(); |
|
248 |
|
249 /** |
|
250 * @brief check if Priority edited |
|
251 * @return ETrue if Priority edited, else EFalse |
|
252 */ |
|
253 TBool IsPriorityEdited(); |
|
254 |
|
255 /** |
|
256 * @brief Returns ETrue if the calendar filed has been edited, EFalse otherwise. |
|
257 */ |
|
258 TBool IsCalendarEditedL(); |
|
259 |
|
260 /** |
|
261 * @brief compares just date of edited and original start datetime. It is needed |
|
262 * when changing start date of repeating event |
|
263 */ |
|
264 TBool IsStartDateChanged(); |
|
265 |
|
266 /** |
|
267 * @brief Returns ETrue if attachment exists |
|
268 */ |
|
269 TBool IsAttachmentExists(); |
|
270 |
|
271 /** |
|
272 * @brief Returns ETrue if EventType field modified for already saved entry |
|
273 */ |
|
274 TBool IsEventTypeEdited(); |
|
275 |
|
276 /** |
|
277 * @brief Returns if the `All day event' field is modified or not. |
|
278 * |
|
279 * @return ETrue if modified, EFalse otherwise. |
|
280 */ |
|
281 TBool AllDayFieldEdited(); |
|
282 |
|
283 /** |
|
284 * @brief To set default Alarm date time. |
|
285 */ |
|
286 void SetDefaultAlarmDateTimeL(); // might need to be public |
|
287 |
|
288 /** |
|
289 * @brief Returns true if both summary and location are empty. |
|
290 * If UI doesn't support location for edited entry type(e.g. anniversaries), |
|
291 * it's enough for summary to be empty |
|
292 */ |
|
293 TBool AreTextFieldsEmptyL(); |
|
294 |
|
295 /** |
|
296 * @brief Reset original editor data |
|
297 */ |
|
298 void ResetOriginalDataL(); |
|
299 |
|
300 /** |
|
301 * @brief To set the entry type of handler data |
|
302 */ |
|
303 void SetEntryType( CCalEntry::TType aNewEntryType ); |
|
304 |
|
305 /** |
|
306 * @brief Returns ETrue if the entry should use floating time, EFalse otherwise. |
|
307 */ |
|
308 TBool UseFloatingTimeL() const; |
|
309 |
|
310 /** |
|
311 * @brief Returns the instance id of the instance being edited currently. |
|
312 * @return TCalenInstanceId |
|
313 */ |
|
314 const TCalenInstanceId CalenInstanceId(); |
|
315 |
|
316 private: |
|
317 |
|
318 /** |
|
319 * @brief default constrecture |
|
320 */ |
|
321 CCalenEditorDataHandler( CCalEntry& aEntry, |
|
322 const TCalTime& aInstanceDateTime, |
|
323 TBool aIsCreatingNew, |
|
324 TInt aMaxTextEditorLength, |
|
325 MCalenServices& aServices, |
|
326 RArray<TInt>& aCollectionIds); |
|
327 |
|
328 /** |
|
329 * @brief two-phase constrecture |
|
330 */ |
|
331 void ConstructL(); |
|
332 |
|
333 /** |
|
334 * @brief Check whether Text fields cleared |
|
335 */ |
|
336 TBool AreTextFieldsClearedL(); |
|
337 |
|
338 /** |
|
339 * @brief Returns ETrue if the location is a valid field for this type of entry |
|
340 */ |
|
341 TBool LocationEnabledInUiL(); |
|
342 |
|
343 |
|
344 /** |
|
345 * @brief Sets the default values when creating a new entry. |
|
346 * @param aData |
|
347 */ |
|
348 void SetDefaultNewValuesL( CCalenEntryUtil& aData ); |
|
349 |
|
350 /** |
|
351 * @brief Calculates the repeat rule for a given entry. |
|
352 * @param aStartDateTime |
|
353 * @param aNewREpeatType |
|
354 * @param aRepeatUntil |
|
355 * @param aRRule |
|
356 */ |
|
357 void CalculateRepeatRuleL( const TTime& aStartDateTime, |
|
358 TCalenRepeatIndex aNewRepeatType, |
|
359 const TTime& aRepeatUntil, |
|
360 TCalRRule& aRRule); |
|
361 |
|
362 /** |
|
363 * @brief Writes the start and end times from the form to the CCalEntry. |
|
364 * @param aRepeatTarget |
|
365 */ |
|
366 void WriteStartAndEndTimesToEntryL( CalCommon::TRecurrenceRange aRepeatTarget ); |
|
367 |
|
368 /** |
|
369 * @brief Applys a new repeat until date to the past repeat rule. |
|
370 * @param aRule, |
|
371 * @param aRepeatUntil, Time upto which rule should be repeated. |
|
372 */ |
|
373 void ApplyUntilDateToRRuleL( TCalRRule& aRule, const TTime& aRepeatUntil ) const; |
|
374 |
|
375 /** |
|
376 * @brief To check whether entry duration is greater than repeat interval |
|
377 * @return ETrue if the duration of instances of the meeting is greater than |
|
378 */ |
|
379 TBool DurationGreaterThanRepeatIntervalError(); |
|
380 |
|
381 /** |
|
382 * @brief Checks to see if the instance is being moved out of sequence, relative |
|
383 * to the rest of the series. |
|
384 */ |
|
385 TError CheckForOutOfSequenceL(); |
|
386 |
|
387 /** |
|
388 * @brief Check the alarm fields for errors. |
|
389 * @param aSerief |
|
390 * @return the error if found, or EFormErrNone if no error found. |
|
391 */ |
|
392 TError CheckAlarmFieldsForErrorsL(TBool aSeries = EFalse); |
|
393 |
|
394 /** |
|
395 * @brief Gets the start and end times of the next instance. Sets both to a null |
|
396 * time if there is no instance after the current one. |
|
397 * @param aNextStartTime |
|
398 * @param aNextEndTime |
|
399 */ |
|
400 void GetNextInstanceTimeL( TCalTime& aNextStartTime, TCalTime& aNextEndTime ); |
|
401 |
|
402 /** |
|
403 * @brief Gets the start and end times of the previous instance. Sets both to a |
|
404 * null time if there is no instance after the current one. |
|
405 * @param aPreviousStartTime |
|
406 * @param aPreviousEndTime |
|
407 */ |
|
408 void GetPreviousInstanceTimeL( TCalTime& aPreviousStartTime, |
|
409 TCalTime& aPreviousEndTime ); |
|
410 |
|
411 /** |
|
412 * @brief Chaeck whether entry is ToDo |
|
413 * @return Returns ETrue if the entry is ToDo, returns EFalse otherwise |
|
414 */ |
|
415 TBool IsToDo() const; |
|
416 |
|
417 /** |
|
418 * @brief Returns ETrue if the entry was already created previously so that |
|
419 * we are now editing it, returns EFalse otherwise. |
|
420 */ |
|
421 TBool IsOldEntry(); |
|
422 |
|
423 /** |
|
424 * @brief Returns ETrue, the summary was not empty in original && is empty |
|
425 * in the edited note, returns EFalse, otherwise |
|
426 */ |
|
427 TBool IsSummaryEmptied(); |
|
428 |
|
429 /** |
|
430 * @brief Returns ETrue, the location was not empty in original && is empty |
|
431 * in the edited note, returns EFalse, otherwise |
|
432 */ |
|
433 TBool IsLocationEmptied(); |
|
434 |
|
435 /** |
|
436 * @brief Returns ETrue, the description was not empty in original && is empty |
|
437 * in the edited note, returns EFalse, otherwise |
|
438 */ |
|
439 TBool IsDescriptionEmptied(); |
|
440 |
|
441 /** |
|
442 * @brief Checks if aAlarmTime is 31 days from aStartTime, |
|
443 * then sets aError to EFormErrAlarmDateTooManyDaysBeforeNote and returns EFalse |
|
444 * Checks if aAlarmTime is later aStartTime, |
|
445 * then sets aError to EFormErrAlarmTimeLaterThanNote and returns EFalse |
|
446 * returns ETrue otherwise, aError untouched |
|
447 */ |
|
448 TBool IsAlarmInAcceptablePeriod(TError& aError, const TTime& aAlarmTime, const TTime& aStartTime) const; |
|
449 |
|
450 /* |
|
451 * @brief Get EntryView using MCalenService |
|
452 * @return referance CCalEntryView |
|
453 */ |
|
454 CCalEntryView& EntryViewL(); |
|
455 |
|
456 /** |
|
457 * @brief Get referance to InstanceView using MCalenService |
|
458 * @return CCalInstanceView |
|
459 */ |
|
460 CCalInstanceView& InstanceViewL(); |
|
461 |
|
462 /** |
|
463 * @brief Get previous instance for repeating event |
|
464 * @return Returns TTime of previous instance of a repeating event when repeat type is ERepeatOther |
|
465 * returns NULLTime when not suitable pevious instance is not found |
|
466 */ |
|
467 TTime GetPreviousInstanceForRepeatOtherL(CCalEntry& aEntry, const CalCommon::TCalTimeRange& timeRange); |
|
468 |
|
469 /* |
|
470 * @brief Get next instance of a reapeating event |
|
471 * @return TTime of next instance of a repeating event when repeat type is ERepeatOther |
|
472 * returns NULLTime when not suitable next instance is not found |
|
473 */ |
|
474 TTime GetNextInstanceForRepeatOtherL(CCalEntry& aEntry, const CalCommon::TCalTimeRange& timeRange); |
|
475 |
|
476 /** |
|
477 * @brief add attachments to the entry as ccalattachments |
|
478 */ |
|
479 void AddAttachementsToEntryL(); |
|
480 |
|
481 |
|
482 public: |
|
483 /** |
|
484 * @brief Returns ETrue if the user is creating a new entry, EFalse if the user |
|
485 * is editing an existing entry. |
|
486 */ |
|
487 TBool IsCreatingNew() const; |
|
488 |
|
489 /** |
|
490 * @brief Set if calendar is been edited or not with previous and current collection id |
|
491 * @param TBool aEdited calendar edited or not |
|
492 * @param TCalCollectionId aPreviousColId previous collection id |
|
493 * @param TCalCollectionId aCurrentColId current collection id |
|
494 */ |
|
495 void SetCalendarFieldEditedL(TBool aEdited, |
|
496 TCalCollectionId aPreviousColId, |
|
497 TCalCollectionId aCurrentColId); |
|
498 |
|
499 /* |
|
500 * Get previous collection id |
|
501 */ |
|
502 TCalCollectionId PreviousDbCollectionId(); |
|
503 |
|
504 /* |
|
505 * Get current collection id |
|
506 */ |
|
507 TCalCollectionId CurrentDbCollectionId(); |
|
508 |
|
509 private: // data |
|
510 |
|
511 /** |
|
512 * @var iEntry |
|
513 * @brief This should not be modified anywhere else than WriteChangesToEntryL |
|
514 * function. |
|
515 */ |
|
516 CCalEntry& iEntry; |
|
517 |
|
518 /** |
|
519 * @var iInstanceDateTime |
|
520 * @brief Date and time of instance. This defines what instance of entry |
|
521 * is currently edited |
|
522 */ |
|
523 const TCalTime& iInstanceDateTime; |
|
524 |
|
525 /** |
|
526 * @var iRecurrenceId |
|
527 */ |
|
528 TCalTime iRecurrenceId; |
|
529 |
|
530 /** |
|
531 * @var iEntryType |
|
532 * @brief Entry type, stored from iEntry |
|
533 */ |
|
534 CCalEntry::TType iEntryType; |
|
535 |
|
536 /** |
|
537 * @var iIsCreatingNew |
|
538 * @brief iIsCreatingNew is true if user is creating totally new entry |
|
539 */ |
|
540 TBool iIsCreatingNew; |
|
541 |
|
542 /** |
|
543 * @var iEdited |
|
544 * @brief Edited entry data |
|
545 */ |
|
546 CCalenEntryUtil* iEdited; |
|
547 |
|
548 /** |
|
549 * @var iOrigianl |
|
550 * @brief Original entry data |
|
551 */ |
|
552 CCalenEntryUtil* iOriginal; |
|
553 |
|
554 /** |
|
555 * @var iMaxTextEditorLength |
|
556 * @brief Max length of text in editors. This is needed when comparing |
|
557 * subject and location. |
|
558 */ |
|
559 TInt iMaxTextEditorLength; |
|
560 |
|
561 /** |
|
562 * @var iServices |
|
563 * @brief referance to MCalenServices |
|
564 */ |
|
565 MCalenServices& iServices; |
|
566 |
|
567 /* |
|
568 * @var iPreviousDbColId |
|
569 * @brief previous collection id |
|
570 */ |
|
571 TCalCollectionId iPreviousDbColId; |
|
572 |
|
573 /* |
|
574 * @var iCurrentDbColId |
|
575 * @brief current collection id after editing |
|
576 */ |
|
577 TCalCollectionId iCurrentDbColId; |
|
578 |
|
579 |
|
580 /* |
|
581 * @var iCalendarFieldEdited |
|
582 * @brief Status of calendar been edited or not |
|
583 */ |
|
584 TBool iCalendarFieldEdited; |
|
585 |
|
586 |
|
587 /* |
|
588 * @var iCollectionIds |
|
589 * @brief collection ids for calendars |
|
590 */ |
|
591 RArray<TInt>& iCollectionIds; |
|
592 |
|
593 /** |
|
594 * @var iInstanceId |
|
595 * @brief Holds the id of the instance which is being edited currently. |
|
596 */ |
|
597 TCalenInstanceId iInstanceId; |
|
598 }; |
|
599 |
|
600 #endif // CALENEDITORDATAHANDLER_H |
|
601 |
|
602 // End of File |