25
|
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: Implementation of the class CESMRMixedFieldStorage
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "emailtrace.h"
|
|
19 |
#include "cesmrmixedfieldstorage.h"
|
|
20 |
|
|
21 |
//<cmail>
|
|
22 |
#include "cesmrpolicy.h"
|
|
23 |
#include "esmrdef.h"
|
|
24 |
//</cmail>
|
|
25 |
|
|
26 |
#include "cesmrmeetingtimevalidator.h"
|
|
27 |
#include "tesmrentryfield.h"
|
|
28 |
#include "mesmrresponseobserver.h"
|
|
29 |
#include "mesmrcalentry.h"
|
|
30 |
#include "cesmrvalidatorfactory.h"
|
|
31 |
#include "cesmrglobalnote.h"
|
|
32 |
#include "cesmrfield.h"
|
|
33 |
#include "cesmrfieldeventqueue.h"
|
|
34 |
|
|
35 |
// Unnamed namespace for local definitions
|
|
36 |
namespace { // codescanner::namespace
|
|
37 |
|
|
38 |
/**
|
|
39 |
* Tests, if entry has valid recurrence for editing.
|
|
40 |
* @param aEntry Reference to entry.
|
|
41 |
* @param aRecurrenceValue On return contains entrys recurrence
|
|
42 |
* @return ETrue, if entry has valid recurrence for editing.
|
|
43 |
* EFalse, if entry hasn't valid recurrence for editing.
|
|
44 |
*/
|
|
45 |
TBool HasValidRecurrenceForEditingL(
|
|
46 |
const MESMRCalEntry& aEntry,
|
|
47 |
TESMRRecurrenceValue& aRecurrenceValue )
|
|
48 |
{
|
|
49 |
TBool retValue( ETrue );
|
|
50 |
|
|
51 |
if ( aEntry.IsRecurrentEventL() )
|
|
52 |
{
|
|
53 |
TTime until;
|
|
54 |
|
|
55 |
aEntry.GetRecurrenceL( aRecurrenceValue, until );
|
|
56 |
|
|
57 |
if ( ERecurrenceNot == aRecurrenceValue ||
|
|
58 |
ERecurrenceUnknown == aRecurrenceValue )
|
|
59 |
{
|
|
60 |
// Entry has unrecognized recurrende type
|
|
61 |
// --> Cannot be edited.
|
|
62 |
retValue = EFalse;
|
|
63 |
}
|
|
64 |
}
|
|
65 |
return retValue;
|
|
66 |
}
|
|
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 |
}
|
|
82 |
break;
|
|
83 |
|
|
84 |
case MESMRFieldValidator::EErrorRecDifferetStartAndEnd:
|
|
85 |
{
|
|
86 |
aUpdatedFocus = EESMRFieldStopDate;
|
|
87 |
CESMRGlobalNote::ExecuteL(
|
|
88 |
CESMRGlobalNote::EESMRRepeatDifferentStartAndEndDate );
|
|
89 |
}
|
|
90 |
break;
|
|
91 |
|
|
92 |
case MESMRFieldValidator::EErrorRecUntilEarlierThanStart:
|
|
93 |
{
|
|
94 |
aUpdatedFocus = EESMRFieldRecurrenceDate;
|
|
95 |
CESMRGlobalNote::ExecuteL(
|
|
96 |
CESMRGlobalNote::EESMRRepeatEndEarlierThanItStart );
|
|
97 |
}
|
|
98 |
break;
|
|
99 |
|
|
100 |
case MESMRFieldValidator::EErrorAlarmLaterThanStart:
|
|
101 |
{
|
|
102 |
aUpdatedFocus = EESMRFieldAlarmDate;
|
|
103 |
CESMRGlobalNote::ExecuteL(
|
|
104 |
CESMRGlobalNote::EESMRCalenLaterDate );
|
|
105 |
}
|
|
106 |
break;
|
|
107 |
|
|
108 |
case MESMRFieldValidator::EErrorAlarmInPast:
|
|
109 |
{
|
|
110 |
aUpdatedFocus = EESMRFieldAlarmDate;
|
|
111 |
CESMRGlobalNote::ExecuteL(
|
|
112 |
CESMRGlobalNote::EESMRAlarmAlreadyPassed );
|
|
113 |
}
|
|
114 |
break;
|
|
115 |
|
|
116 |
case MESMRFieldValidator::EErrorRescheduleInstance:
|
|
117 |
{
|
|
118 |
CESMRGlobalNote::ExecuteL(
|
|
119 |
CESMRGlobalNote::EESMRRepeatReSchedule );
|
|
120 |
}
|
|
121 |
break;
|
|
122 |
|
|
123 |
case MESMRFieldValidator::EErrorInstanceOverlapsExistingOne:
|
|
124 |
{
|
|
125 |
CESMRGlobalNote::ExecuteL(
|
|
126 |
CESMRGlobalNote::EESMROverlapsExistingInstance );
|
|
127 |
}
|
|
128 |
break;
|
|
129 |
|
|
130 |
case MESMRFieldValidator::EErrorInstanceAlreadyExistsOnThisDay:
|
|
131 |
{
|
|
132 |
CESMRGlobalNote::ExecuteL(
|
|
133 |
CESMRGlobalNote::EESMRInstanceAlreadyExistsOnThisDay );
|
|
134 |
}
|
|
135 |
break;
|
|
136 |
|
|
137 |
case MESMRFieldValidator::EErrorInstanceOutOfSequence:
|
|
138 |
{
|
|
139 |
CESMRGlobalNote::ExecuteL(
|
|
140 |
CESMRGlobalNote::EESMRInstanceOutOfSequence );
|
|
141 |
}
|
|
142 |
break;
|
|
143 |
|
|
144 |
default:
|
|
145 |
err = KErrNone;
|
|
146 |
break;
|
|
147 |
}
|
|
148 |
|
|
149 |
User::LeaveIfError( err );
|
|
150 |
}
|
|
151 |
|
|
152 |
} // namespace
|
|
153 |
|
|
154 |
// ======== MEMBER FUNCTIONS ========
|
|
155 |
|
|
156 |
// ---------------------------------------------------------------------------
|
|
157 |
// CESMRMixedFieldStorage::CESMRMixedFieldStorage
|
|
158 |
// ---------------------------------------------------------------------------
|
|
159 |
//
|
|
160 |
CESMRMixedFieldStorage::CESMRMixedFieldStorage(
|
|
161 |
MESMRFieldEventObserver& aEventObserver,
|
|
162 |
MESMRResponseObserver* aResponseObserver ) :
|
|
163 |
CESMRFieldStorage( aEventObserver),
|
|
164 |
iResponseObserver(aResponseObserver)
|
|
165 |
{
|
|
166 |
FUNC_LOG;
|
|
167 |
// Do nothing
|
|
168 |
}
|
|
169 |
|
|
170 |
// ---------------------------------------------------------------------------
|
|
171 |
// CESMRMixedFieldStorage::~CESMRMixedFieldStorage
|
|
172 |
// ---------------------------------------------------------------------------
|
|
173 |
//
|
|
174 |
CESMRMixedFieldStorage::~CESMRMixedFieldStorage( )
|
|
175 |
{
|
|
176 |
FUNC_LOG;
|
|
177 |
delete iValidator;
|
|
178 |
}
|
|
179 |
|
|
180 |
// ---------------------------------------------------------------------------
|
|
181 |
// CESMRMixedFieldStorage::NewL
|
|
182 |
// ---------------------------------------------------------------------------
|
|
183 |
//
|
|
184 |
CESMRMixedFieldStorage* CESMRMixedFieldStorage::NewL(
|
|
185 |
MESMRFieldEventObserver& aEventObserver,
|
|
186 |
const CESMRPolicy& aPolicy,
|
|
187 |
MESMRResponseObserver* aResponseObserver,
|
|
188 |
MESMRCalEntry& aEntry )
|
|
189 |
{
|
|
190 |
FUNC_LOG;
|
|
191 |
CESMRMixedFieldStorage* self =
|
|
192 |
new (ELeave) CESMRMixedFieldStorage(
|
|
193 |
aEventObserver,
|
|
194 |
aResponseObserver );
|
|
195 |
|
|
196 |
CleanupStack::PushL( self );
|
|
197 |
self->ConstructL( aPolicy, aEntry );
|
|
198 |
CleanupStack::Pop( self );
|
|
199 |
|
|
200 |
return self;
|
|
201 |
}
|
|
202 |
|
|
203 |
// ---------------------------------------------------------------------------
|
|
204 |
// CESMRMixedFieldStorage::ConstructL
|
|
205 |
// ---------------------------------------------------------------------------
|
|
206 |
//
|
|
207 |
void CESMRMixedFieldStorage::ConstructL(
|
|
208 |
const CESMRPolicy& aPolicy,
|
|
209 |
MESMRCalEntry& aEntry )
|
|
210 |
{
|
|
211 |
FUNC_LOG;
|
|
212 |
CESMRFieldStorage::BaseConstructL();
|
|
213 |
|
|
214 |
DoChangePolicyL( aPolicy, aEntry );
|
|
215 |
}
|
|
216 |
|
|
217 |
// ---------------------------------------------------------------------------
|
|
218 |
// CESMRMixedFieldStorage::ExternalizeL
|
|
219 |
// ---------------------------------------------------------------------------
|
|
220 |
//
|
|
221 |
void CESMRMixedFieldStorage::ExternalizeL( MESMRCalEntry& aEntry )
|
|
222 |
{
|
|
223 |
FUNC_LOG;
|
|
224 |
CESMRFieldStorage::ExternalizeL ( aEntry );
|
|
225 |
if ( iValidator )
|
|
226 |
{
|
|
227 |
iValidator->StoreValuesToEntryL( aEntry );
|
|
228 |
}
|
|
229 |
}
|
|
230 |
|
|
231 |
// ---------------------------------------------------------------------------
|
|
232 |
// CESMRMixedFieldStorage::InternalizeL
|
|
233 |
// ---------------------------------------------------------------------------
|
|
234 |
//
|
|
235 |
void CESMRMixedFieldStorage::InternalizeL( MESMRCalEntry& aEntry )
|
|
236 |
{
|
|
237 |
FUNC_LOG;
|
|
238 |
CESMRFieldStorage::InternalizeL ( aEntry );
|
|
239 |
if ( iValidator )
|
|
240 |
{
|
|
241 |
iValidator->ReadValuesFromEntryL( aEntry );
|
|
242 |
}
|
|
243 |
}
|
|
244 |
|
|
245 |
// ---------------------------------------------------------------------------
|
|
246 |
// CESMRMixedFieldStorage::Validate
|
|
247 |
// ---------------------------------------------------------------------------
|
|
248 |
//
|
|
249 |
TInt CESMRMixedFieldStorage::Validate(
|
|
250 |
TESMREntryFieldId& aUpdatedFocus, TBool aForceValidation )
|
|
251 |
{
|
|
252 |
FUNC_LOG;
|
|
253 |
TInt err( KErrNone );
|
|
254 |
if ( iValidator )
|
|
255 |
{
|
|
256 |
MESMRFieldValidator::TESMRFieldValidatorError error;
|
|
257 |
TRAP( err, error = iValidator->ValidateL( aForceValidation ) );
|
|
258 |
|
|
259 |
if ( !aForceValidation )
|
|
260 |
{
|
|
261 |
// If error note does not success, there is much we can do.
|
|
262 |
TRAP( err, ShowValidationErrorL( error, aUpdatedFocus ) );
|
|
263 |
}
|
|
264 |
else
|
|
265 |
{
|
|
266 |
// Force exit is used.
|
|
267 |
err = KErrNone;
|
|
268 |
}
|
|
269 |
}
|
|
270 |
return err;
|
|
271 |
}
|
|
272 |
|
|
273 |
// ---------------------------------------------------------------------------
|
|
274 |
// CESMRMixedFieldStorage::ChangePolicyL
|
|
275 |
// ---------------------------------------------------------------------------
|
|
276 |
//
|
|
277 |
void CESMRMixedFieldStorage::ChangePolicyL(
|
|
278 |
const CESMRPolicy& aNewPolicy,
|
|
279 |
MESMRCalEntry& aEntry )
|
|
280 |
{
|
|
281 |
// Delegate to non-virtual
|
|
282 |
DoChangePolicyL( aNewPolicy, aEntry );
|
|
283 |
}
|
|
284 |
|
|
285 |
|
|
286 |
// ---------------------------------------------------------------------------
|
|
287 |
// CESMRMixedFieldStorage::ConstructForwardEventL
|
|
288 |
// ---------------------------------------------------------------------------
|
|
289 |
//
|
|
290 |
void CESMRMixedFieldStorage::ConstructForwardEventL(
|
|
291 |
const CESMRPolicy& aPolicy,
|
|
292 |
MESMRFieldValidator* aValidator )
|
|
293 |
{
|
|
294 |
FUNC_LOG;
|
|
295 |
iValidator = aValidator;
|
|
296 |
|
|
297 |
RArray< TESMREntryField > array = aPolicy.Fields();
|
|
298 |
|
|
299 |
TInt fieldCount( array.Count() );
|
|
300 |
for (TInt i(0); i < fieldCount; i++ )
|
|
301 |
{
|
|
302 |
CESMRField* field = NULL;
|
|
303 |
TBool visible = ( array[i].iFieldViewMode == EESMRFieldTypeDefault );
|
|
304 |
switch ( array[i].iFieldId )
|
|
305 |
{
|
|
306 |
case EESMRFieldAttendee: //Fall through
|
|
307 |
case EESMRFieldOptAttendee: //Fall through
|
|
308 |
case EESMRFieldDescription:
|
|
309 |
{
|
|
310 |
field = CreateEditorFieldL( iValidator, array[i] );
|
|
311 |
}
|
|
312 |
break;
|
|
313 |
default:
|
|
314 |
{
|
|
315 |
field =
|
|
316 |
CreateViewerFieldL( iResponseObserver, array[i], visible );
|
|
317 |
field->LockL();
|
|
318 |
}
|
|
319 |
break;
|
|
320 |
}
|
|
321 |
|
|
322 |
if( field->FieldViewMode() != EESMRFieldTypeDisabled )
|
|
323 |
{
|
|
324 |
CleanupStack::PushL( field );
|
|
325 |
AddFieldL( field, visible );
|
|
326 |
CleanupStack::Pop( field );
|
|
327 |
}
|
|
328 |
else
|
|
329 |
{
|
|
330 |
delete field;
|
|
331 |
field = NULL;
|
|
332 |
}
|
|
333 |
}
|
|
334 |
}
|
|
335 |
|
|
336 |
// ---------------------------------------------------------------------------
|
|
337 |
// CESMRMixedFieldStorage::ConstructRecurrentEventL
|
|
338 |
// ---------------------------------------------------------------------------
|
|
339 |
//
|
|
340 |
void CESMRMixedFieldStorage::ConstructRecurrentEventL(
|
|
341 |
const CESMRPolicy& aPolicy,
|
|
342 |
MESMRFieldValidator* aValidator )
|
|
343 |
{
|
|
344 |
FUNC_LOG;
|
|
345 |
iValidator = aValidator;
|
|
346 |
iValidator->SetFieldEventQueue( &EventQueueL() );
|
|
347 |
|
|
348 |
const RArray<TESMREntryField>& array = aPolicy.Fields();
|
|
349 |
TInt fieldCount( array.Count() );
|
|
350 |
for (TInt i(0); i < fieldCount; ++i )
|
|
351 |
{
|
|
352 |
CESMRField* field = NULL;
|
|
353 |
TBool visible = array[i].iFieldViewMode == EESMRFieldTypeDefault;
|
|
354 |
switch ( array[i].iFieldId )
|
|
355 |
{
|
|
356 |
case EESMRFieldRecurrence: //Fall through
|
|
357 |
case EESMRFieldRecurrenceDate:
|
|
358 |
default:
|
|
359 |
field = CreateEditorFieldL( iValidator, array[i] );
|
|
360 |
break;
|
|
361 |
}
|
|
362 |
|
|
363 |
if ( field )
|
|
364 |
{
|
|
365 |
CleanupStack::PushL( field );
|
|
366 |
AddFieldL(field, visible );
|
|
367 |
CleanupStack::Pop( field );
|
|
368 |
}
|
|
369 |
}
|
|
370 |
}
|
|
371 |
|
|
372 |
// ---------------------------------------------------------------------------
|
|
373 |
// CESMRMixedFieldStorage::ConstructEditSeriesEventL
|
|
374 |
// ---------------------------------------------------------------------------
|
|
375 |
//
|
|
376 |
void CESMRMixedFieldStorage::ConstructEditSeriesEventL(
|
|
377 |
const CESMRPolicy& aPolicy,
|
|
378 |
MESMRFieldValidator* aValidator )
|
|
379 |
{
|
|
380 |
FUNC_LOG;
|
|
381 |
TESMRRecurrenceValue recurrenceType;
|
|
382 |
TBool validRecurrence(
|
|
383 |
HasValidRecurrenceForEditingL(
|
|
384 |
*iEntry,
|
|
385 |
recurrenceType ) );
|
|
386 |
|
|
387 |
iValidator = aValidator;
|
|
388 |
iValidator->SetFieldEventQueue( &EventQueueL() );
|
|
389 |
|
|
390 |
const RArray<TESMREntryField>& array = aPolicy.Fields();
|
|
391 |
CESMRField* field = NULL;
|
|
392 |
|
|
393 |
TInt fieldCount( array.Count() );
|
|
394 |
for (TInt i(0); i < fieldCount; i++ )
|
|
395 |
{
|
|
396 |
const TESMREntryField& tfield = array[i];
|
|
397 |
TBool visible = tfield.iFieldViewMode == EESMRFieldTypeDefault;
|
|
398 |
switch ( tfield.iFieldId )
|
|
399 |
{
|
|
400 |
// Flowthrough
|
|
401 |
case EESMRFieldRecurrence:
|
|
402 |
case EESMRFieldRecurrenceDate:
|
|
403 |
{
|
|
404 |
if ( validRecurrence )
|
|
405 |
{
|
|
406 |
field = CreateEditorFieldL( iValidator, tfield );
|
|
407 |
}
|
|
408 |
else
|
|
409 |
{
|
|
410 |
// Entry has unrecognized recurrende type
|
|
411 |
// --> Cannot be edited.
|
|
412 |
field = CreateViewerFieldL(
|
|
413 |
iResponseObserver, tfield, visible );
|
|
414 |
field->LockL();
|
|
415 |
}
|
|
416 |
}
|
|
417 |
break;
|
|
418 |
default:
|
|
419 |
{
|
|
420 |
field = CreateEditorFieldL( iValidator, tfield );
|
|
421 |
}
|
|
422 |
break;
|
|
423 |
}
|
|
424 |
|
|
425 |
if( field->FieldViewMode() != EESMRFieldTypeDisabled )
|
|
426 |
{
|
|
427 |
CleanupStack::PushL( field );
|
|
428 |
AddFieldL( field, visible );
|
|
429 |
CleanupStack::Pop( field );
|
|
430 |
}
|
|
431 |
else
|
|
432 |
{
|
|
433 |
delete field;
|
|
434 |
field = NULL;
|
|
435 |
}
|
|
436 |
}
|
|
437 |
}
|
|
438 |
|
|
439 |
// ---------------------------------------------------------------------------
|
|
440 |
// CESMRMixedFieldStorage::ConstructEditSeriesEventL
|
|
441 |
// ---------------------------------------------------------------------------
|
|
442 |
//
|
|
443 |
void CESMRMixedFieldStorage::Reset()
|
|
444 |
{
|
|
445 |
CESMRFieldStorage::Reset();
|
|
446 |
delete iValidator;
|
|
447 |
iValidator = NULL;
|
|
448 |
}
|
|
449 |
|
|
450 |
// ---------------------------------------------------------------------------
|
|
451 |
// CESMRMixedFieldStorage::DoChangePolicyL
|
|
452 |
// ---------------------------------------------------------------------------
|
|
453 |
//
|
|
454 |
void CESMRMixedFieldStorage::DoChangePolicyL(
|
|
455 |
const CESMRPolicy& aNewPolicy,
|
|
456 |
MESMRCalEntry& aEntry )
|
|
457 |
{
|
|
458 |
Reset();
|
|
459 |
iEntry = &aEntry;
|
|
460 |
|
|
461 |
// FORWARD allows only attendee fields and description to be edited.
|
|
462 |
// EDIT RECURRENT EVENT allows only start-end time and start date
|
|
463 |
// to be edited.
|
|
464 |
|
|
465 |
MESMRCalEntry::TESMRRecurrenceModifyingRule rule(
|
|
466 |
iEntry->RecurrenceModRule() );
|
|
467 |
|
|
468 |
if ( iEntry->IsRecurrentEventL() &&
|
|
469 |
rule == MESMRCalEntry::EESMRAllInSeries &&
|
|
470 |
EESMREditMR == aNewPolicy.ViewMode())
|
|
471 |
{
|
|
472 |
// Contruct edit series
|
|
473 |
// validator ownership is transferred
|
|
474 |
MESMRFieldValidator* validator =
|
|
475 |
CESMRValidatorFactory::CreateValidatorL (
|
|
476 |
aNewPolicy.EventType() );
|
|
477 |
|
|
478 |
ConstructEditSeriesEventL(
|
|
479 |
aNewPolicy,
|
|
480 |
validator );
|
|
481 |
|
|
482 |
iEventType = EMixedFieldStorageEditSeriesEvent;
|
|
483 |
}
|
|
484 |
|
|
485 |
else if ( aNewPolicy.ViewMode() != EESMRForwardMR )
|
|
486 |
{
|
|
487 |
MESMRFieldValidator* validator =
|
|
488 |
CESMRValidatorFactory::CreateValidatorL (
|
|
489 |
aNewPolicy.EventType() );
|
|
490 |
|
|
491 |
ConstructRecurrentEventL ( aNewPolicy,
|
|
492 |
validator );
|
|
493 |
|
|
494 |
iEventType = EMixedFieldStorageRecurrentEvent;
|
|
495 |
}
|
|
496 |
else
|
|
497 |
{
|
|
498 |
// No validator is needed because forwarding does not
|
|
499 |
// affecto to any time fields.
|
|
500 |
MESMRFieldValidator* validator = NULL;
|
|
501 |
ConstructForwardEventL (
|
|
502 |
aNewPolicy,
|
|
503 |
validator );
|
|
504 |
|
|
505 |
iEventType = EMixedFieldStorageForward;
|
|
506 |
}
|
|
507 |
}
|
|
508 |
|
|
509 |
// EOF
|
|
510 |
|