|
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 Field storage for editor dialog |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "emailtrace.h" |
|
19 #include "cesmreditorfieldstorage.h" |
|
20 |
|
21 //<cmail> |
|
22 #include "cesmrpolicy.h" |
|
23 #include "esmrdef.h" |
|
24 //</cmail> |
|
25 |
|
26 #include "mesmrfieldvalidator.h" |
|
27 #include "tesmrentryfield.h" |
|
28 #include "cesmrvalidatorfactory.h" |
|
29 #include "cesmrglobalnote.h" |
|
30 #include "cesmrfield.h" |
|
31 #include "cesmrfieldeventqueue.h" |
|
32 |
|
33 #include <ct/rcpointerarray.h> |
|
34 |
|
35 //logging |
|
36 //performance profiling |
|
37 // <cmail> Removed profiling. </cmail> |
|
38 |
|
39 // Unnamed namespace for local definitions |
|
40 namespace { // codescanner::namespace |
|
41 |
|
42 #ifdef _DEBUG |
|
43 |
|
44 // Definition for panic literal |
|
45 _LIT( KESMREditorFieldStorage, "ESMREditorFieldStorage" ); |
|
46 |
|
47 /** CESMREditorFieldStorage panic codes */ |
|
48 enum TSMREditorFieldStoragePanic |
|
49 { |
|
50 /** No validator defined */ |
|
51 EESMREditorFieldStorageNoValidator = 0 |
|
52 }; |
|
53 |
|
54 void Panic( TSMREditorFieldStoragePanic aPanic ) |
|
55 { |
|
56 |
|
57 User::Panic( KESMREditorFieldStorage, aPanic ); |
|
58 } |
|
59 |
|
60 #endif // _DEBUG |
|
61 |
|
62 /** |
|
63 * Shows validation error. |
|
64 * @param aError Defines the validation error |
|
65 * @param aUpdatedFocus On return contains the id of the field, |
|
66 * which should be focused. |
|
67 */ |
|
68 void ShowValidationErrorL( |
|
69 const MESMRFieldValidator::TESMRFieldValidatorError& aError, |
|
70 TESMREntryFieldId& aUpdatedFocus ) |
|
71 { |
|
72 FUNC_LOG; |
|
73 TInt err( KErrArgument ); |
|
74 switch ( aError ) |
|
75 { |
|
76 case MESMRFieldValidator::EErrorEndEarlierThanStart: |
|
77 { |
|
78 aUpdatedFocus = EESMRFieldMeetingTime; |
|
79 CESMRGlobalNote::ExecuteL( |
|
80 CESMRGlobalNote::EESMREntryEndEarlierThanItStart ); |
|
81 break; |
|
82 } |
|
83 |
|
84 case MESMRFieldValidator::EErrorRecDifferetStartAndEnd: |
|
85 { |
|
86 aUpdatedFocus = EESMRFieldStopDate; |
|
87 CESMRGlobalNote::ExecuteL( |
|
88 CESMRGlobalNote::EESMRRepeatDifferentStartAndEndDate ); |
|
89 break; |
|
90 } |
|
91 |
|
92 case MESMRFieldValidator::EErrorRecUntilEarlierThanStart: |
|
93 { |
|
94 aUpdatedFocus = EESMRFieldRecurrenceDate; |
|
95 CESMRGlobalNote::ExecuteL( |
|
96 CESMRGlobalNote::EESMRRepeatEndEarlierThanItStart ); |
|
97 break; |
|
98 } |
|
99 |
|
100 case MESMRFieldValidator::EErrorAlarmLaterThanStart: |
|
101 { |
|
102 aUpdatedFocus = EESMRFieldAlarmDate; |
|
103 CESMRGlobalNote::ExecuteL( |
|
104 CESMRGlobalNote::EESMRCalenLaterDate ); |
|
105 break; |
|
106 } |
|
107 |
|
108 case MESMRFieldValidator::EErrorAlarmInPast: |
|
109 { |
|
110 aUpdatedFocus = EESMRFieldAlarmDate; |
|
111 CESMRGlobalNote::ExecuteL( |
|
112 CESMRGlobalNote::EESMRAlarmAlreadyPassed ); |
|
113 break; |
|
114 } |
|
115 |
|
116 case MESMRFieldValidator::EErrorAlarmTooMuchInPast: |
|
117 { |
|
118 aUpdatedFocus = EESMRFieldAlarmDate; |
|
119 CESMRGlobalNote::ExecuteL( |
|
120 CESMRGlobalNote::EESMRDiffMoreThanMonth ); |
|
121 break; |
|
122 } |
|
123 |
|
124 case MESMRFieldValidator::EErrorRelativeAlarmInPast: |
|
125 { |
|
126 aUpdatedFocus = EESMRFieldAlarm; |
|
127 CESMRGlobalNote::ExecuteL( |
|
128 CESMRGlobalNote::EESMRAlarmAlreadyPassed ); |
|
129 break; |
|
130 } |
|
131 |
|
132 case MESMRFieldValidator::EErrorRescheduleInstance: |
|
133 { |
|
134 CESMRGlobalNote::ExecuteL( |
|
135 CESMRGlobalNote::EESMRRepeatReSchedule ); |
|
136 break; |
|
137 } |
|
138 case MESMRFieldValidator::EErrorInstanceOverlapsExistingOne: |
|
139 { |
|
140 CESMRGlobalNote::ExecuteL( |
|
141 CESMRGlobalNote::EESMROverlapsExistingInstance ); |
|
142 break; |
|
143 } |
|
144 |
|
145 case MESMRFieldValidator::EErrorInstanceAlreadyExistsOnThisDay: |
|
146 { |
|
147 CESMRGlobalNote::ExecuteL( |
|
148 CESMRGlobalNote::EESMRInstanceAlreadyExistsOnThisDay ); |
|
149 break; |
|
150 } |
|
151 |
|
152 case MESMRFieldValidator::EErrorInstanceOutOfSequence: |
|
153 { |
|
154 CESMRGlobalNote::ExecuteL( |
|
155 CESMRGlobalNote::EESMRInstanceOutOfSequence ); |
|
156 break; |
|
157 } |
|
158 default: |
|
159 { |
|
160 err = KErrNone; |
|
161 break; |
|
162 } |
|
163 } |
|
164 |
|
165 User::LeaveIfError( err ); |
|
166 } |
|
167 |
|
168 } // namespace |
|
169 |
|
170 // ======== MEMBER FUNCTIONS ======== |
|
171 |
|
172 // --------------------------------------------------------------------------- |
|
173 // CESMREditorFieldStorage::CESMREditorFieldStorage |
|
174 // --------------------------------------------------------------------------- |
|
175 // |
|
176 CESMREditorFieldStorage::CESMREditorFieldStorage( |
|
177 MESMRFieldEventObserver& aEventObserver ) |
|
178 : CESMRFieldStorage( aEventObserver ) |
|
179 { |
|
180 FUNC_LOG; |
|
181 // Do nothing |
|
182 } |
|
183 |
|
184 // --------------------------------------------------------------------------- |
|
185 // CESMREditorFieldStorage::~CESMREditorFieldStorage |
|
186 // --------------------------------------------------------------------------- |
|
187 // |
|
188 CESMREditorFieldStorage::~CESMREditorFieldStorage( ) |
|
189 { |
|
190 FUNC_LOG; |
|
191 delete iValidator; |
|
192 } |
|
193 |
|
194 // --------------------------------------------------------------------------- |
|
195 // CESMREditorFieldStorage::NewL |
|
196 // --------------------------------------------------------------------------- |
|
197 // |
|
198 CESMREditorFieldStorage* CESMREditorFieldStorage::NewL( |
|
199 const CESMRPolicy& aPolicy, |
|
200 MESMRFieldEventObserver& aEventObserver ) |
|
201 { |
|
202 FUNC_LOG; |
|
203 CESMREditorFieldStorage* self = |
|
204 new (ELeave) CESMREditorFieldStorage( aEventObserver ); |
|
205 CleanupStack::PushL ( self ); |
|
206 self->ConstructL ( aPolicy ); |
|
207 CleanupStack::Pop ( self ); |
|
208 return self; |
|
209 } |
|
210 |
|
211 // --------------------------------------------------------------------------- |
|
212 // CESMREditorFieldStorage::ConstructL |
|
213 // --------------------------------------------------------------------------- |
|
214 // |
|
215 void CESMREditorFieldStorage::ConstructL( const CESMRPolicy& aPolicy ) |
|
216 { |
|
217 FUNC_LOG; |
|
218 CESMRFieldStorage::BaseConstructL(); |
|
219 iValidator = |
|
220 CESMRValidatorFactory::CreateValidatorL( aPolicy.EventType() ); |
|
221 |
|
222 __ASSERT_DEBUG( iValidator, Panic( EESMREditorFieldStorageNoValidator) ); |
|
223 |
|
224 iValidator->SetFieldEventQueue( &EventQueueL() ); |
|
225 |
|
226 RArray<TESMREntryField> fields = aPolicy.Fields(); |
|
227 const TInt count(fields.Count()); |
|
228 |
|
229 for (TInt i(0); i < count; i++ ) |
|
230 { |
|
231 TESMREntryField entryField = fields[i]; |
|
232 TBool visible( entryField.iFieldViewMode == EESMRFieldTypeDefault ); |
|
233 CESMRField* field = CreateEditorFieldL( iValidator, entryField ); |
|
234 |
|
235 if( field->FieldViewMode() != EESMRFieldTypeDisabled ) |
|
236 { |
|
237 CleanupStack::PushL( field ); |
|
238 AddFieldL( field, visible ); |
|
239 CleanupStack::Pop( field ); |
|
240 } |
|
241 else |
|
242 { |
|
243 delete field; |
|
244 field = NULL; |
|
245 } |
|
246 } |
|
247 } |
|
248 |
|
249 // --------------------------------------------------------------------------- |
|
250 // CESMREditorFieldStorage::ExternalizeL |
|
251 // --------------------------------------------------------------------------- |
|
252 // |
|
253 void CESMREditorFieldStorage::ExternalizeL( MESMRCalEntry& aEntry ) |
|
254 { |
|
255 FUNC_LOG; |
|
256 CESMRFieldStorage::ExternalizeL ( aEntry ); |
|
257 iValidator->StoreValuesToEntryL( aEntry ); |
|
258 } |
|
259 |
|
260 // --------------------------------------------------------------------------- |
|
261 // CESMREditorFieldStorage::InternalizeL |
|
262 // --------------------------------------------------------------------------- |
|
263 // |
|
264 void CESMREditorFieldStorage::InternalizeL( MESMRCalEntry& aEntry ) |
|
265 { |
|
266 FUNC_LOG; |
|
267 CESMRFieldStorage::InternalizeL ( aEntry ); |
|
268 iValidator->ReadValuesFromEntryL( aEntry ); |
|
269 } |
|
270 |
|
271 // --------------------------------------------------------------------------- |
|
272 // CESMREditorFieldStorage::Validate |
|
273 // --------------------------------------------------------------------------- |
|
274 // |
|
275 TInt CESMREditorFieldStorage::Validate( |
|
276 TESMREntryFieldId& aUpdatedFocus, TBool aForceValidation ) |
|
277 { |
|
278 FUNC_LOG; |
|
279 MESMRFieldValidator::TESMRFieldValidatorError error; |
|
280 TRAPD( err, error = iValidator->ValidateL( aForceValidation ) ); |
|
281 |
|
282 if ( !aForceValidation ) |
|
283 { |
|
284 // If error note does not success, there is much we can do. |
|
285 TRAP( err, ShowValidationErrorL( error, aUpdatedFocus ) ); |
|
286 } |
|
287 else |
|
288 { |
|
289 // force exit is used. |
|
290 err = KErrNone; |
|
291 } |
|
292 |
|
293 return err; |
|
294 } |
|
295 |
|
296 // --------------------------------------------------------------------------- |
|
297 // CESMREditorFieldStorage::ChangePolicyL |
|
298 // --------------------------------------------------------------------------- |
|
299 // |
|
300 void CESMREditorFieldStorage::ChangePolicyL( |
|
301 const CESMRPolicy& aNewPolicy, |
|
302 MESMRCalEntry& /*aEntry*/ ) |
|
303 { |
|
304 MESMRFieldValidator* validator = |
|
305 CESMRValidatorFactory::CreateValidatorL( aNewPolicy.EventType() ); |
|
306 |
|
307 __ASSERT_DEBUG( validator, Panic( EESMREditorFieldStorageNoValidator) ); |
|
308 CleanupDeletePushL( validator ); |
|
309 |
|
310 validator->SetFieldEventQueue( &EventQueueL() ); |
|
311 |
|
312 // Iterate through policy and create fields into tmp array |
|
313 RArray<TESMREntryField> fields = aNewPolicy.Fields(); |
|
314 |
|
315 TInt count( fields.Count() ); |
|
316 |
|
317 RCPointerArray< CESMRField > fieldArray; |
|
318 CleanupClosePushL( fieldArray ); |
|
319 |
|
320 fieldArray.ReserveL( count ); |
|
321 |
|
322 CESMRField* field = NULL; |
|
323 |
|
324 // Append new fields to array |
|
325 for (TInt i(0); i < count; ++i ) |
|
326 { |
|
327 field = CreateEditorFieldL( validator, fields[i] ); |
|
328 // Append field |
|
329 if( field->FieldViewMode() != EESMRFieldTypeDisabled ) |
|
330 { |
|
331 fieldArray.AppendL( field ); |
|
332 } |
|
333 else |
|
334 { |
|
335 delete field; |
|
336 field = NULL; |
|
337 } |
|
338 } |
|
339 |
|
340 // Reseting field array from storage, so that it can be |
|
341 // reused |
|
342 Reset(); |
|
343 |
|
344 count = fieldArray.Count(); |
|
345 |
|
346 // Reserve space in strorage for all required fields |
|
347 ReserveL( count ); |
|
348 |
|
349 // Insert fields from fieldArray into storage |
|
350 for ( TInt i = 0; i < count; ++i ) |
|
351 { |
|
352 AddFieldL( fieldArray[ i ] ); |
|
353 |
|
354 TBool visible( fields[ i ].iFieldViewMode == EESMRFieldTypeDefault ); |
|
355 Field( i )->MakeVisible( visible ); |
|
356 } |
|
357 |
|
358 // Remove items from field array |
|
359 for ( TInt i = 0; i < count; ++i ) |
|
360 { |
|
361 fieldArray.Remove( 0 ); |
|
362 } |
|
363 |
|
364 // Assign new validator |
|
365 delete iValidator; |
|
366 iValidator = validator; |
|
367 CleanupStack::PopAndDestroy( &fieldArray ); |
|
368 CleanupStack::Pop( validator ); |
|
369 } |
|
370 |
|
371 // EOF |
|
372 |