|
1 /* |
|
2 * Copyright (c) 2005 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: This file implements class CESMRCalDbMgr. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 //INCLUDE FILES |
|
20 #include "emailtrace.h" |
|
21 #include "cesmrcaldbmgr.h" |
|
22 #include "cesmrcaldbnormal.h" |
|
23 #include "cesmrentrycmditeratorao.h" |
|
24 #include "esmrhelper.h" |
|
25 #include "esmrentryhelper.h" |
|
26 //<cmail> |
|
27 #include "mesmrutilstombsext.h" |
|
28 //</cmail> |
|
29 |
|
30 // From System |
|
31 #include <ct/rcpointerarray.h> |
|
32 #include <calsession.h> |
|
33 #include <calentryview.h> |
|
34 #include <calinstance.h> |
|
35 #include <calinstanceview.h> |
|
36 #include <calentry.h> |
|
37 #include <calcommon.h> |
|
38 #include <caluser.h> |
|
39 #include <CalenInterimUtils2.h> |
|
40 |
|
41 // CONSTANTS |
|
42 |
|
43 // Unnamed namespace for local definitions |
|
44 namespace { |
|
45 |
|
46 const TInt KDbInitReady = 100; |
|
47 |
|
48 #ifdef _DEBUG |
|
49 |
|
50 // Panic code definitions |
|
51 enum TPanicCode |
|
52 { |
|
53 EPanicIllegalFetchParams = 1, |
|
54 EPanicAccessedWhenUnavailable, |
|
55 EPanicAsyncOpAlreadyExists, |
|
56 EPanicIllegalEntryStatus, |
|
57 EPanicIllegalResurrect, |
|
58 EPanicUnexpectedUidValue |
|
59 }; |
|
60 |
|
61 // Panic string definition |
|
62 _LIT( KPanicMsg, "CESMRCalDbMgr" ); |
|
63 |
|
64 /** |
|
65 * Raises system panic |
|
66 * @param aReason Panic reason. |
|
67 */ |
|
68 void Panic( TPanicCode aReason ) |
|
69 { |
|
70 User::Panic( KPanicMsg, aReason ); |
|
71 } |
|
72 |
|
73 #endif // _DEBUG |
|
74 |
|
75 } // namespace |
|
76 |
|
77 |
|
78 // ======== MEMBER FUNCTIONS ======== |
|
79 |
|
80 // ---------------------------------------------------------------------------- |
|
81 // CESMRCalDbMgr::NewL |
|
82 // ---------------------------------------------------------------------------- |
|
83 // |
|
84 EXPORT_C CESMRCalDbMgr* CESMRCalDbMgr::NewL( |
|
85 CCalSession& aCalSession, |
|
86 MMRUtilsObserver& aObserver ) |
|
87 { |
|
88 FUNC_LOG; |
|
89 CESMRCalDbMgr* self = |
|
90 new( ELeave ) CESMRCalDbMgr( |
|
91 aCalSession, |
|
92 aObserver ); |
|
93 CleanupStack::PushL( self ); |
|
94 self->ConstructL(); |
|
95 CleanupStack::Pop(); |
|
96 |
|
97 |
|
98 return self; |
|
99 } |
|
100 |
|
101 // ---------------------------------------------------------------------------- |
|
102 // CESMRCalDbMgr::CESMRCalDbMgr |
|
103 // |
|
104 // Constructor. |
|
105 // ---------------------------------------------------------------------------- |
|
106 // |
|
107 CESMRCalDbMgr::CESMRCalDbMgr( |
|
108 CCalSession& aCalSession, |
|
109 MMRUtilsObserver& aObserver ) |
|
110 : iCurrentAsyncOp( CMRUtils::ENoOperation ), |
|
111 iCalSession( aCalSession ), |
|
112 iObserver( aObserver ) |
|
113 { |
|
114 FUNC_LOG; |
|
115 } |
|
116 |
|
117 // ---------------------------------------------------------------------------- |
|
118 // CESMRCalDbMgr::~CESMRCalDbMgr |
|
119 // |
|
120 // Destructor. |
|
121 // ---------------------------------------------------------------------------- |
|
122 // |
|
123 CESMRCalDbMgr::~CESMRCalDbMgr() |
|
124 { |
|
125 FUNC_LOG; |
|
126 delete iCmdIterator; |
|
127 delete iNormalDb; |
|
128 } |
|
129 |
|
130 // ---------------------------------------------------------------------------- |
|
131 // CESMRCalDbMgr::ConstructL |
|
132 // ---------------------------------------------------------------------------- |
|
133 // |
|
134 void CESMRCalDbMgr::ConstructL() |
|
135 { |
|
136 FUNC_LOG; |
|
137 |
|
138 iNormalDb = CESMRCalDbNormal::NewL( iCalSession, *this, *this ); |
|
139 iCmdIterator = CESMREntryCmdIteratorAO::NewL( *this ); |
|
140 |
|
141 } |
|
142 |
|
143 // ---------------------------------------------------------------------------- |
|
144 // CESMRCalDbMgr::HandleCalDbStatus |
|
145 // ---------------------------------------------------------------------------- |
|
146 // |
|
147 void CESMRCalDbMgr::HandleCalDbStatus( |
|
148 const CESMRCalDbBase* /*aNotifier*/, |
|
149 MESMRCalDbObserver::TDbStatus aStatus ) |
|
150 { |
|
151 FUNC_LOG; |
|
152 |
|
153 if ( aStatus == EReseting ) |
|
154 { // reset db is ongoing, engine becomes unavailable |
|
155 iObserver.HandleCalEngStatus( MMRUtilsObserver::ENotReady ); |
|
156 } |
|
157 else if ( iNormalDb->DbStatus() == MESMRCalDbObserver::EFinishedOk ) |
|
158 { |
|
159 iObserver.HandleCalEngStatus( MMRUtilsObserver::EAvailable ); |
|
160 } |
|
161 else if ( iNormalDb->DbStatus() == MESMRCalDbObserver::EFinishedOk ) |
|
162 { |
|
163 iObserver.HandleCalEngStatus( |
|
164 MMRUtilsObserver::EAvailableWithoutTombs ); |
|
165 } |
|
166 else if ( iNormalDb->DbStatus() == MESMRCalDbObserver::EFinishedError ) |
|
167 { |
|
168 iObserver.HandleCalEngStatus( MMRUtilsObserver::ENotAvailable ); |
|
169 } |
|
170 |
|
171 |
|
172 // In other cases either db is not yet finished |
|
173 } |
|
174 |
|
175 // ---------------------------------------------------------------------------- |
|
176 // CESMRCalDbMgr::Progress |
|
177 // ---------------------------------------------------------------------------- |
|
178 // |
|
179 void CESMRCalDbMgr::Progress( TInt /*aPercentageCompleted*/ ) |
|
180 { |
|
181 FUNC_LOG; |
|
182 // Not interested in progress currently |
|
183 } |
|
184 |
|
185 // ---------------------------------------------------------------------------- |
|
186 // CESMRCalDbMgr::NotifyProgress |
|
187 // ---------------------------------------------------------------------------- |
|
188 // |
|
189 TBool CESMRCalDbMgr::NotifyProgress() |
|
190 { |
|
191 FUNC_LOG; |
|
192 // Not interested in progress currently |
|
193 return EFalse; |
|
194 } |
|
195 |
|
196 // ---------------------------------------------------------------------------- |
|
197 // CESMRCalDbMgr::Completed |
|
198 // ---------------------------------------------------------------------------- |
|
199 // |
|
200 void CESMRCalDbMgr::Completed( TInt aError ) |
|
201 { |
|
202 FUNC_LOG; |
|
203 |
|
204 iObserver.HandleOperation( iCurrentAsyncOp, KDbInitReady, aError ); |
|
205 iCurrentAsyncOp = CMRUtils::ENoOperation; |
|
206 |
|
207 } |
|
208 |
|
209 // ---------------------------------------------------------------------------- |
|
210 // CESMRCalDbMgr::NormalDbEntryView |
|
211 // ---------------------------------------------------------------------------- |
|
212 // |
|
213 CCalEntryView* CESMRCalDbMgr::NormalDbEntryView() |
|
214 { |
|
215 FUNC_LOG; |
|
216 return iNormalDb->EntryView(); |
|
217 } |
|
218 |
|
219 // ---------------------------------------------------------------------------- |
|
220 // CESMRCalDbMgr::NormalDbInstanceView |
|
221 // ---------------------------------------------------------------------------- |
|
222 // |
|
223 CCalInstanceView* CESMRCalDbMgr::NormalDbInstanceView() |
|
224 { |
|
225 FUNC_LOG; |
|
226 return iNormalDb->InstanceView(); |
|
227 } |
|
228 |
|
229 // ---------------------------------------------------------------------------- |
|
230 // CESMRCalDbMgr::FetchEntriesL |
|
231 // ---------------------------------------------------------------------------- |
|
232 // |
|
233 void CESMRCalDbMgr::FetchEntriesL( |
|
234 RPointerArray<CCalEntry>& aCalEntryArray, |
|
235 const CalCommon::TCalTimeRange& aTimeRange ) |
|
236 { |
|
237 FUNC_LOG; |
|
238 |
|
239 __ASSERT_DEBUG( aCalEntryArray.Count() == 0, |
|
240 Panic( EPanicIllegalFetchParams ) ); |
|
241 aCalEntryArray.ResetAndDestroy(); |
|
242 // caller definitely wants to get full copies -> ETrue as 3rd argument: |
|
243 iNormalDb->FetchWithRangeL( aCalEntryArray, |
|
244 aTimeRange, |
|
245 ETrue ); |
|
246 |
|
247 } |
|
248 |
|
249 // ---------------------------------------------------------------------------- |
|
250 // CESMRCalDbMgr::FetchEntryL |
|
251 // ---------------------------------------------------------------------------- |
|
252 // |
|
253 CCalEntry* CESMRCalDbMgr::FetchEntryL( |
|
254 const TDesC8& aUid, |
|
255 const TCalTime& aRecurrenceId ) |
|
256 { |
|
257 FUNC_LOG; |
|
258 |
|
259 __ASSERT_DEBUG( aUid.Length() > 0, |
|
260 Panic( EPanicIllegalFetchParams ) ); |
|
261 |
|
262 RCPointerArray<CCalEntry> tmpFetchArray; |
|
263 CleanupClosePushL( tmpFetchArray ); |
|
264 |
|
265 CCalEntry* retVal = NULL; |
|
266 |
|
267 TInt index( -1 ); |
|
268 if ( EntryExistsInDbL( aUid, |
|
269 aRecurrenceId, |
|
270 *iNormalDb, |
|
271 tmpFetchArray, |
|
272 index ) ) |
|
273 { |
|
274 retVal = tmpFetchArray[index]; |
|
275 tmpFetchArray.Remove( index ); // ownership transferred to retVal |
|
276 } |
|
277 |
|
278 CleanupStack::PopAndDestroy(); // tmpFetchArray |
|
279 |
|
280 |
|
281 return retVal; |
|
282 } |
|
283 |
|
284 // ---------------------------------------------------------------------------- |
|
285 // CESMRCalDbMgr::StoreEntryL |
|
286 // ---------------------------------------------------------------------------- |
|
287 // |
|
288 TInt CESMRCalDbMgr::StoreEntryL( |
|
289 CCalEntry& aCalEntry, |
|
290 TBool aToNormalDb ) |
|
291 { |
|
292 FUNC_LOG; |
|
293 |
|
294 TInt retVal( KErrNone ); |
|
295 |
|
296 if(aToNormalDb) |
|
297 { |
|
298 CCalenInterimUtils2::StoreL( *( iNormalDb->EntryView() ), |
|
299 aCalEntry, |
|
300 ETrue ); |
|
301 |
|
302 } |
|
303 |
|
304 |
|
305 |
|
306 return retVal; |
|
307 } |
|
308 |
|
309 // ---------------------------------------------------------------------------- |
|
310 // CESMRCalDbMgr::UpdateEntryL |
|
311 // ---------------------------------------------------------------------------- |
|
312 // |
|
313 TInt CESMRCalDbMgr::UpdateEntryL( const CCalEntry& aCalEntry ) |
|
314 { |
|
315 FUNC_LOG; |
|
316 |
|
317 RPointerArray<CCalEntry> calEntryTmpArray( 1 ); // entry not own |
|
318 CleanupClosePushL( calEntryTmpArray ); |
|
319 calEntryTmpArray.AppendL( &aCalEntry ); |
|
320 TInt numSuccessfulEntry( 0 ); |
|
321 // entry view surely exists when status is 'available': |
|
322 iNormalDb->EntryView()->UpdateL( calEntryTmpArray, numSuccessfulEntry ); |
|
323 TInt retVal( numSuccessfulEntry == 1 ? KErrNone : KErrGeneral ); |
|
324 CleanupStack::PopAndDestroy(); // calEntryTmpArray, only close array |
|
325 |
|
326 |
|
327 return retVal; |
|
328 } |
|
329 |
|
330 // ---------------------------------------------------------------------------- |
|
331 // CESMRCalDbMgr::DeleteEntryL |
|
332 // ---------------------------------------------------------------------------- |
|
333 // |
|
334 TInt CESMRCalDbMgr::DeleteEntryL( const TDesC8& aUid ) |
|
335 { |
|
336 FUNC_LOG; |
|
337 |
|
338 CDesC8ArrayFlat* uidArray = new( ELeave ) CDesC8ArrayFlat( 1 ); |
|
339 CleanupStack::PushL( uidArray ); |
|
340 uidArray->AppendL( aUid ); |
|
341 // entry view surely exists when status is 'available': |
|
342 iNormalDb->EntryView()->DeleteL( *uidArray ); |
|
343 CleanupStack::PopAndDestroy( uidArray ); |
|
344 |
|
345 |
|
346 return KErrNone; |
|
347 } |
|
348 |
|
349 // ---------------------------------------------------------------------------- |
|
350 // CESMRCalDbMgr::DeleteEntryL |
|
351 // ---------------------------------------------------------------------------- |
|
352 // |
|
353 TInt CESMRCalDbMgr::DeleteEntryL( const TCalLocalUid& aLocalUid ) |
|
354 { |
|
355 FUNC_LOG; |
|
356 |
|
357 RArray<TCalLocalUid> localUidArray( 1 ); |
|
358 CleanupClosePushL( localUidArray ); |
|
359 localUidArray.AppendL( aLocalUid ); |
|
360 TInt numSuccessfulEntry( 0 ); |
|
361 iNormalDb->EntryView()->DeleteL( localUidArray, numSuccessfulEntry ); |
|
362 TInt retVal( numSuccessfulEntry == 1 ? KErrNone : KErrGeneral ); |
|
363 CleanupStack::PopAndDestroy(); // localUidArray |
|
364 |
|
365 |
|
366 return retVal; |
|
367 } |
|
368 |
|
369 // ---------------------------------------------------------------------------- |
|
370 // CESMRCalDbMgr::StoreEntryCondL |
|
371 // aResurrect can only be ETrue if aCheckOnly is EFalse, i.e. when user is |
|
372 // really trying to store something. |
|
373 // ---------------------------------------------------------------------------- |
|
374 // |
|
375 MESMRUtilsTombsExt::TESMRUtilsDbResult CESMRCalDbMgr::StoreEntryCondL( |
|
376 CCalEntry& aCalEntry, |
|
377 TBool aResurrect, |
|
378 TBool aCheckOnly ) |
|
379 { |
|
380 FUNC_LOG; |
|
381 |
|
382 RCPointerArray<CCalEntry> tmpFetchArray; |
|
383 CleanupClosePushL( tmpFetchArray ); |
|
384 |
|
385 MESMRUtilsTombsExt::TESMRUtilsDbResult entryStatus( |
|
386 MESMRUtilsTombsExt::EUndefined ); |
|
387 TInt index( -1 ); |
|
388 |
|
389 // 1. Normal db part, if entry is found in there then tombstones aren't |
|
390 // checked at all: |
|
391 |
|
392 if ( EntryExistsInDbL( aCalEntry, *iNormalDb, tmpFetchArray, index ) ) |
|
393 { // Entry exists in normal db |
|
394 entryStatus = EvaluateExistingEntryL( aCalEntry, |
|
395 *( tmpFetchArray[index] ) ); |
|
396 if ( entryStatus == MESMRUtilsTombsExt::ECheckedValidUpdate && |
|
397 !aCheckOnly ) |
|
398 { |
|
399 StoreEntryL( aCalEntry ); |
|
400 entryStatus = MESMRUtilsTombsExt::EStoredUpdate; |
|
401 } |
|
402 else if ( entryStatus == MESMRUtilsTombsExt::EErrorCancelled && |
|
403 aResurrect ) |
|
404 { |
|
405 __ASSERT_DEBUG( !aCheckOnly, Panic( EPanicIllegalResurrect ) ); |
|
406 StoreEntryL( aCalEntry ); |
|
407 entryStatus = MESMRUtilsTombsExt::EResurrectedCancelled; |
|
408 } |
|
409 // entry can't be new if it exists in the db already: |
|
410 __ASSERT_DEBUG( entryStatus != MESMRUtilsTombsExt::ECheckedValidNew, |
|
411 Panic( EPanicIllegalEntryStatus) ); |
|
412 } |
|
413 |
|
414 // 2. New entry in this phone: |
|
415 |
|
416 else |
|
417 { // Completely new entry (or tombstone has disappeared) |
|
418 entryStatus = EvaluateNewEntryL( aCalEntry ); |
|
419 if ( entryStatus == MESMRUtilsTombsExt::ECheckedValidNew && !aCheckOnly ) |
|
420 { |
|
421 StoreEntryL( aCalEntry ); |
|
422 entryStatus = MESMRUtilsTombsExt::EStoredNew; |
|
423 } |
|
424 |
|
425 // entry can't be update if doesn't exist in the db already: |
|
426 __ASSERT_DEBUG( entryStatus != MESMRUtilsTombsExt::ECheckedValidUpdate, |
|
427 Panic( EPanicIllegalEntryStatus) ); |
|
428 } |
|
429 |
|
430 CleanupStack::PopAndDestroy(); // tmpFetchArray |
|
431 |
|
432 |
|
433 return entryStatus; |
|
434 } |
|
435 |
|
436 // ---------------------------------------------------------------------------- |
|
437 // CESMRCalDbMgr::DeleteEntryCondL |
|
438 // ---------------------------------------------------------------------------- |
|
439 // |
|
440 void CESMRCalDbMgr::DeleteEntryCondL( const TDesC8& aUid ) |
|
441 { |
|
442 FUNC_LOG; |
|
443 |
|
444 RCPointerArray<CCalEntry> tmpFetchArray; |
|
445 CleanupClosePushL( tmpFetchArray ); |
|
446 |
|
447 // 1. Delete all found entries from normal db: |
|
448 |
|
449 iNormalDb->EntryView()->FetchL( aUid, tmpFetchArray ); |
|
450 DeleteEntryL( aUid ); |
|
451 |
|
452 CleanupStack::PopAndDestroy(); // tmpFetchArray |
|
453 |
|
454 } |
|
455 |
|
456 // ---------------------------------------------------------------------------- |
|
457 // CESMRCalDbMgr::DeleteEntryCondL |
|
458 // ---------------------------------------------------------------------------- |
|
459 // |
|
460 void CESMRCalDbMgr::DeleteEntryCondL( const TCalLocalUid& aLocalUid ) |
|
461 { |
|
462 FUNC_LOG; |
|
463 |
|
464 CCalEntry* entry = iNormalDb->EntryView()->FetchL( aLocalUid ); |
|
465 if ( entry ) |
|
466 { |
|
467 CleanupStack::PushL( entry ); |
|
468 DeleteEntryCondL( *entry ); |
|
469 CleanupStack::PopAndDestroy( entry ); |
|
470 } |
|
471 |
|
472 } |
|
473 |
|
474 // ---------------------------------------------------------------------------- |
|
475 // CESMRCalDbMgr::DeleteEntryCondL |
|
476 // ---------------------------------------------------------------------------- |
|
477 // |
|
478 void CESMRCalDbMgr::DeleteEntryCondL( const CCalEntry& aCalEntry ) |
|
479 { |
|
480 FUNC_LOG; |
|
481 |
|
482 if ( ESMREntryHelper::IsModifyingEntryL( aCalEntry ) ) |
|
483 { |
|
484 // Modifying entry |
|
485 // 1. Delete entry from normal db: |
|
486 iNormalDb->EntryView()->DeleteL( aCalEntry ); |
|
487 } |
|
488 |
|
489 else |
|
490 { // Originating entry, this is the same case as deleting with GUID: |
|
491 DeleteEntryCondL( aCalEntry.UidL() ); |
|
492 } |
|
493 |
|
494 } |
|
495 |
|
496 // ---------------------------------------------------------------------------- |
|
497 // CESMRCalDbMgr::DeleteEntryCondL |
|
498 // ---------------------------------------------------------------------------- |
|
499 // |
|
500 void CESMRCalDbMgr::DeleteEntryCondL( |
|
501 const CalCommon::TCalTimeRange& aCalTimeRange ) |
|
502 { |
|
503 FUNC_LOG; |
|
504 |
|
505 __ASSERT_DEBUG( iCurrentAsyncOp == CMRUtils::ENoOperation, |
|
506 Panic( EPanicAsyncOpAlreadyExists ) ); |
|
507 |
|
508 RCPointerArray<CCalEntry> tmpFetchArray; |
|
509 CleanupClosePushL( tmpFetchArray ); |
|
510 // skeleton copies are enough -> set 3rd argument to EFalse: |
|
511 iNormalDb->FetchWithRangeL( tmpFetchArray, aCalTimeRange, EFalse ); |
|
512 iCmdIterator->StartCmdIterationL( tmpFetchArray, CMRUtils::EDeleteEntries ); |
|
513 iCurrentAsyncOp = CMRUtils::EDeleteEntries; |
|
514 tmpFetchArray.Reset(); // ownership of entries was transferred |
|
515 CleanupStack::PopAndDestroy(); // tmpFetchArray |
|
516 |
|
517 } |
|
518 |
|
519 // ---------------------------------------------------------------------------- |
|
520 // CESMRCalDbMgr::DeleteEntryCondL |
|
521 // ---------------------------------------------------------------------------- |
|
522 // |
|
523 CCalSession& CESMRCalDbMgr::CalSession() |
|
524 { |
|
525 FUNC_LOG; |
|
526 return iCalSession; |
|
527 } |
|
528 |
|
529 // ---------------------------------------------------------------------------- |
|
530 // CESMRCalDbMgr::EntryExistsInDbL |
|
531 // ---------------------------------------------------------------------------- |
|
532 // |
|
533 TBool CESMRCalDbMgr::EntryExistsInDbL( |
|
534 const TDesC8& aUid, |
|
535 const TCalTime& aRecurrenceId, |
|
536 const CESMRCalDbBase& aDb, |
|
537 RPointerArray<CCalEntry>& aCalEntryArray, |
|
538 TInt& aIndex ) const |
|
539 { |
|
540 FUNC_LOG; |
|
541 |
|
542 TBool retVal( EFalse ); |
|
543 aIndex = KErrNotFound; |
|
544 |
|
545 aDb.EntryView()->FetchL( aUid, aCalEntryArray ); |
|
546 TInt count( aCalEntryArray.Count() ); |
|
547 for ( TInt i( 0 ); i < count; ++i ) |
|
548 { |
|
549 const CCalEntry& dbEntry( *( aCalEntryArray[i] ) ); |
|
550 if ( aRecurrenceId.TimeUtcL() == dbEntry.RecurrenceIdL().TimeUtcL() ) |
|
551 { // Entry was found in the db, |
|
552 // it may be either originating or modifying entry |
|
553 retVal = ETrue; |
|
554 aIndex = i; |
|
555 } |
|
556 } |
|
557 |
|
558 |
|
559 return retVal; |
|
560 } |
|
561 |
|
562 // ---------------------------------------------------------------------------- |
|
563 // CESMRCalDbMgr::EntryExistsInDbL |
|
564 // ---------------------------------------------------------------------------- |
|
565 // |
|
566 inline TBool CESMRCalDbMgr::EntryExistsInDbL( |
|
567 const CCalEntry& aEntry, |
|
568 const CESMRCalDbBase& aDb, |
|
569 RPointerArray<CCalEntry>& aCalEntryArray, |
|
570 TInt& aIndex ) const |
|
571 { |
|
572 FUNC_LOG; |
|
573 return EntryExistsInDbL( aEntry.UidL(), |
|
574 aEntry.RecurrenceIdL(), |
|
575 aDb, |
|
576 aCalEntryArray, |
|
577 aIndex ); |
|
578 } |
|
579 |
|
580 // ---------------------------------------------------------------------------- |
|
581 // CESMRCalDbMgr::EvaluateExistingEntryL |
|
582 // ---------------------------------------------------------------------------- |
|
583 // |
|
584 MESMRUtilsTombsExt::TESMRUtilsDbResult CESMRCalDbMgr::EvaluateExistingEntryL( |
|
585 const CCalEntry& aEntry, |
|
586 const CCalEntry& aDbEntry ) const |
|
587 { |
|
588 FUNC_LOG; |
|
589 |
|
590 __ASSERT_DEBUG( aEntry.UidL() == aEntry.UidL(), |
|
591 Panic( EPanicUnexpectedUidValue ) ); |
|
592 MESMRUtilsTombsExt::TESMRUtilsDbResult retVal( MESMRUtilsTombsExt::EUndefined ); |
|
593 |
|
594 TInt seq( aEntry.SequenceNumberL() ); |
|
595 TInt dbSeq( aDbEntry.SequenceNumberL() ); |
|
596 TTime stamp = aEntry.DTStampL().TimeUtcL(); |
|
597 TTime dbStamp = aDbEntry.DTStampL().TimeUtcL(); |
|
598 |
|
599 if ( ( seq >= dbSeq ) && ( stamp >= dbStamp ) ) |
|
600 { |
|
601 if ( ( seq == dbSeq ) && ( stamp == dbStamp ) ) |
|
602 { |
|
603 retVal = MESMRUtilsTombsExt::EErrorIdenticalExists; |
|
604 } |
|
605 |
|
606 else if ( aDbEntry.StatusL() == CCalEntry::ECancelled ) |
|
607 { |
|
608 retVal = MESMRUtilsTombsExt::EErrorCancelled; |
|
609 } |
|
610 else |
|
611 { |
|
612 retVal = MESMRUtilsTombsExt::ECheckedValidUpdate; |
|
613 } |
|
614 } |
|
615 else |
|
616 { |
|
617 retVal = MESMRUtilsTombsExt::EErrorObsolete; |
|
618 } |
|
619 |
|
620 |
|
621 return retVal; |
|
622 } |
|
623 |
|
624 // ---------------------------------------------------------------------------- |
|
625 // CESMRCalDbMgr::EvaluateNewEntryL |
|
626 // This method is only used with iNormalDb |
|
627 // ---------------------------------------------------------------------------- |
|
628 // |
|
629 MESMRUtilsTombsExt::TESMRUtilsDbResult CESMRCalDbMgr::EvaluateNewEntryL( |
|
630 const CCalEntry& aEntry ) const |
|
631 { |
|
632 FUNC_LOG; |
|
633 |
|
634 MESMRUtilsTombsExt::TESMRUtilsDbResult retVal( MESMRUtilsTombsExt::EUndefined ); |
|
635 |
|
636 if ( ESMREntryHelper::IsModifyingEntryL( aEntry ) && |
|
637 !IsValidNewModL( aEntry ) ) |
|
638 { // recurrence id does not match to any instance of an entry |
|
639 retVal = MESMRUtilsTombsExt::EErrorRecurrence; |
|
640 } |
|
641 else |
|
642 { |
|
643 retVal = MESMRUtilsTombsExt::ECheckedValidNew; |
|
644 } |
|
645 |
|
646 |
|
647 return retVal; |
|
648 } |
|
649 |
|
650 // ---------------------------------------------------------------------------- |
|
651 // CESMRCalDbMgr::EvaluateNewEntryL |
|
652 // This method is only used with iNormalDb |
|
653 // ---------------------------------------------------------------------------- |
|
654 // |
|
655 TBool CESMRCalDbMgr::IsValidNewModL( const CCalEntry& aModEntry ) const |
|
656 { |
|
657 FUNC_LOG; |
|
658 |
|
659 TBool retVal( EFalse ); |
|
660 RCPointerArray<CCalInstance> instances; // takes ownership |
|
661 CleanupClosePushL( instances ); |
|
662 TCalTime recurrenceId( aModEntry.RecurrenceIdL() ); |
|
663 CalCommon::TCalTimeRange range( recurrenceId, recurrenceId ); |
|
664 |
|
665 iNormalDb->InstanceView()->FindInstanceL( instances, |
|
666 CalCommon::EIncludeAppts, |
|
667 range ); |
|
668 TInt count( instances.Count() ); |
|
669 for ( TInt i( 0 ); i < count; ++i ) |
|
670 { |
|
671 // When creating a new modifying entry, recurrence id must match |
|
672 // to an existing instance start time (later on start time may get |
|
673 // modified whereas recurrence id remains unchanged). |
|
674 if ( instances[i]->Entry().UidL() == aModEntry.UidL() && |
|
675 instances[i]->StartTimeL().TimeUtcL() == recurrenceId.TimeUtcL() ) |
|
676 { |
|
677 retVal = ETrue; |
|
678 break; // match found, ready to return |
|
679 } |
|
680 } |
|
681 CleanupStack::PopAndDestroy(); // instances, delete array items |
|
682 |
|
683 |
|
684 return retVal; |
|
685 } |
|
686 |
|
687 // ---------------------------------------------------------------------------- |
|
688 // CESMRCalDbMgr::OriginatingExistInDbL |
|
689 // This method is only used with iNormalDb |
|
690 // ---------------------------------------------------------------------------- |
|
691 // |
|
692 TBool CESMRCalDbMgr::OriginatingExistInDbL( |
|
693 const CCalEntry& aModEntry ) |
|
694 { |
|
695 FUNC_LOG; |
|
696 |
|
697 TInt retVal( EFalse ); |
|
698 CCalEntry* dbEntry = FetchEntryL( aModEntry.UidL(), TCalTime() ); |
|
699 if ( dbEntry ) |
|
700 { |
|
701 delete dbEntry; |
|
702 retVal = ETrue; |
|
703 } |
|
704 |
|
705 |
|
706 return retVal; |
|
707 } |
|
708 |
|
709 // End of file |
|
710 |