author | Simon Howkins <simonh@symbian.org> |
Thu, 25 Nov 2010 12:13:04 +0000 | |
branch | RCL_3 |
changeset 83 | 31a5fbf5db1d |
parent 80 | 726fba06891a |
permissions | -rw-r--r-- |
64 | 1 |
/* |
2 |
* Copyright (c) 2007-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 conflict checker implementation |
|
80
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
15 |
* Version : %version: e002sa33#10.1.2 % |
64 | 16 |
* |
17 |
*/ |
|
18 |
||
19 |
#include "emailtrace.h" |
|
20 |
#include "cesmrconflictchecker.h" |
|
21 |
#include "cesmrcaldbmgr.h" |
|
22 |
#include "esmrhelper.h" |
|
23 |
#include "esmrentryhelper.h" |
|
24 |
#include "esmrinternaluid.h" |
|
80
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
25 |
#include "cesmrcaluserutil.h" |
64 | 26 |
|
27 |
#include <calcommon.h> |
|
28 |
#include <calinstance.h> |
|
29 |
#include <calentryview.h> |
|
30 |
#include <calinstanceview.h> |
|
31 |
#include <calinstanceiterator.h> |
|
32 |
#include <ct/rcpointerarray.h> |
|
33 |
#include <calrrule.h> |
|
34 |
||
35 |
/// Unnamed namespace for local definitions |
|
36 |
namespace { // codescanner::namespace |
|
37 |
||
38 |
// Definition for zero |
|
39 |
const TInt KZero(0); |
|
40 |
||
41 |
/** Defines instace filter type */ |
|
42 |
enum TInstanceFilter |
|
43 |
{ |
|
44 |
EIncludeSameUID, |
|
45 |
ERemoveSameUID |
|
46 |
}; |
|
47 |
||
48 |
#ifdef _DEBUG |
|
49 |
||
50 |
// Literal for panic texts |
|
51 |
_LIT( KESMRConflictCheckerTxt, "ESMRConflictChecker" ); |
|
52 |
||
53 |
/** Enumeration for panic codes */ |
|
54 |
enum TESMRConflictCheckerPanic |
|
55 |
{ |
|
56 |
// Input entry is not appointment |
|
57 |
EESMRConflictCheckerInvalidEntryType |
|
58 |
}; |
|
59 |
||
60 |
/** |
|
61 |
* Thows system wide panic. |
|
62 |
* @param aPanic Panic code. |
|
63 |
*/ |
|
64 |
void Panic( TESMRConflictCheckerPanic aPanic ) |
|
65 |
{ |
|
66 |
||
67 |
User::Panic( KESMRConflictCheckerTxt, aPanic ); |
|
68 |
} |
|
69 |
||
70 |
#else |
|
71 |
||
72 |
/** |
|
73 |
* Thows system wide leave. |
|
74 |
* @param aError Leave code. |
|
75 |
*/ |
|
76 |
void Leave( TInt aError ) |
|
77 |
{ |
|
78 |
||
79 |
User::Leave( aError ); |
|
80 |
} |
|
81 |
||
82 |
#endif |
|
83 |
||
84 |
/** |
|
85 |
* Resolves time range for possible conflicting entries. Instance view |
|
86 |
* is used for resolving the time range. |
|
87 |
* |
|
88 |
* @param aStart Start time |
|
89 |
* @param aEnd End time |
|
90 |
* @param aInstanceView Pointer to calendar db instance view |
|
91 |
* @return Time range for possible conflicting entries |
|
92 |
*/ |
|
93 |
CalCommon::TCalTimeRange ResolveFetchTimeRangeL( |
|
94 |
TTime aStart, |
|
95 |
TTime aEnd, |
|
96 |
CCalInstanceView* aInstanceView ) |
|
97 |
{ |
|
98 |
FUNC_LOG; |
|
99 |
const CalCommon::TCalViewFilter instanceFilter = |
|
80
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
100 |
CalCommon::EIncludeAppts | CalCommon::EIncludeEvents; |
64 | 101 |
|
102 |
TDateTime start = aStart.DateTime(); |
|
103 |
TDateTime end = aEnd.DateTime(); |
|
104 |
||
105 |
start.SetHour( KZero ); |
|
106 |
start.SetMinute( KZero ); |
|
107 |
start.SetSecond( KZero ); |
|
108 |
start.SetMicroSecond( KZero ); |
|
109 |
||
110 |
end.SetHour( KZero ); |
|
111 |
end.SetMinute( KZero ); |
|
112 |
end.SetSecond( KZero ); |
|
113 |
end.SetMicroSecond( KZero ); |
|
114 |
TTime endTime = end; |
|
115 |
||
116 |
if ( TTime(start) == endTime || |
|
117 |
endTime < aEnd ) |
|
118 |
{ |
|
119 |
||
120 |
endTime += TTimeIntervalDays(1); |
|
121 |
end = endTime.DateTime(); |
|
122 |
} |
|
123 |
||
124 |
TCalTime rangeStart; |
|
125 |
rangeStart.SetTimeLocalL( start ); |
|
126 |
||
127 |
TCalTime instanceTime = aInstanceView->PreviousInstanceL( |
|
128 |
instanceFilter, |
|
129 |
rangeStart ); |
|
130 |
||
131 |
if ( Time::NullTTime() != instanceTime.TimeUtcL() ) |
|
132 |
{ |
|
133 |
rangeStart = instanceTime; |
|
134 |
} |
|
135 |
||
136 |
TCalTime rangeEnd; |
|
137 |
rangeEnd.SetTimeLocalL( end ); |
|
138 |
||
139 |
instanceTime = aInstanceView->NextInstanceL( |
|
140 |
instanceFilter, |
|
141 |
rangeEnd ); |
|
142 |
||
143 |
if ( instanceTime.TimeLocalL() != Time::NullTTime() ) |
|
144 |
{ |
|
145 |
rangeEnd = instanceTime; |
|
146 |
} |
|
147 |
||
148 |
return CalCommon::TCalTimeRange( rangeStart, rangeEnd ); |
|
149 |
} |
|
150 |
||
151 |
/** |
|
152 |
* Removes and deletes the entries, which do not conflict with |
|
153 |
* entry. Entry is considered to be conflicting entry if starts or |
|
154 |
* ends between aEntry's start and end time. |
|
155 |
* |
|
156 |
* @param aEntries Reference to entries, which may conflict |
|
157 |
* @param aEntry Reference to entry, which confilcts are resolved. |
|
158 |
*/ |
|
159 |
void RemoveAndDeleteNonConflictingInstancesL( |
|
160 |
RPointerArray<CCalInstance>& instanceArray, |
|
161 |
TCalTime aStartTime, |
|
162 |
TCalTime aEndTime, |
|
163 |
const TDesC8& aUid, |
|
164 |
TInstanceFilter aFilterType ) |
|
165 |
{ |
|
166 |
FUNC_LOG; |
|
167 |
TInt index(0); |
|
168 |
||
169 |
TTime startTimeLocal = aStartTime.TimeLocalL(); |
|
170 |
TTime endTimeLocal = aEndTime.TimeLocalL(); |
|
171 |
||
172 |
while( index < instanceArray.Count() ) |
|
173 |
{ |
|
174 |
TBool conflictingInstance( ETrue ); |
|
175 |
CCalInstance* instance = instanceArray[index]; |
|
176 |
||
177 |
TTime entryStartTimeLocal = instance->StartTimeL().TimeLocalL(); |
|
178 |
TTime entryEndTimeLocal = instance->EndTimeL().TimeLocalL(); |
|
179 |
||
180 |
TPtrC8 uid( instance->Entry().UidL() ); |
|
181 |
if ( ERemoveSameUID == aFilterType && |
|
182 |
0 == aUid.CompareF(uid) ) |
|
183 |
{ |
|
184 |
conflictingInstance = EFalse; |
|
185 |
} |
|
186 |
else if ( entryStartTimeLocal >= startTimeLocal && |
|
187 |
entryStartTimeLocal < endTimeLocal ) |
|
188 |
{ |
|
189 |
// Entry starts during another entry |
|
190 |
index++; |
|
191 |
} |
|
192 |
else if ( entryEndTimeLocal > startTimeLocal && |
|
193 |
entryEndTimeLocal <= endTimeLocal ) |
|
194 |
{ |
|
195 |
// Entry ends during another entry |
|
196 |
index++; |
|
197 |
} |
|
198 |
else if ( entryStartTimeLocal < startTimeLocal && |
|
199 |
entryEndTimeLocal > endTimeLocal ) |
|
200 |
{ |
|
201 |
// Antry starts and ends during another entry |
|
202 |
index++; |
|
203 |
} |
|
204 |
else |
|
205 |
{ |
|
206 |
conflictingInstance = EFalse; |
|
207 |
} |
|
208 |
||
209 |
// Remove non-conflicting instance from instance array |
|
210 |
if ( !conflictingInstance ) |
|
211 |
{ |
|
212 |
instanceArray.Remove(index); |
|
213 |
delete instance; |
|
214 |
instance = NULL; |
|
215 |
} |
|
216 |
} |
|
217 |
} |
|
218 |
||
219 |
/** |
|
220 |
* Creates calendar entries from the conflicting instances |
|
221 |
* and stores the created entries into entry array. |
|
222 |
* Ownership of the created entries is transferred to caller. |
|
223 |
* @param aInstanceArray Reference to instance array |
|
224 |
* @param aConflictingEntries Reference to entry array. |
|
225 |
*/ |
|
226 |
void CreateEntriesFromInstancesL( |
|
227 |
RPointerArray<CCalInstance>& instanceArray, |
|
228 |
RPointerArray<CCalEntry>& aConflictingEntries ) |
|
229 |
{ |
|
230 |
FUNC_LOG; |
|
231 |
TInt instanceCount( instanceArray.Count() ); |
|
232 |
for ( TInt i(0); i < instanceCount; ++i ) |
|
233 |
{ |
|
234 |
CCalEntry& parent( instanceArray[i]->Entry() ); |
|
235 |
CCalEntry* entry = ESMRHelper::CopyEntryLC( parent, |
|
236 |
parent.MethodL(), |
|
237 |
ESMRHelper::ECopyFull ); |
|
238 |
||
239 |
entry->SetStartAndEndTimeL( instanceArray[i]->StartTimeL(), |
|
240 |
instanceArray[i]->EndTimeL() ); |
|
241 |
||
242 |
aConflictingEntries.AppendL( entry ); |
|
243 |
CleanupStack::Pop( entry ); |
|
244 |
} |
|
245 |
} |
|
246 |
||
247 |
/** |
|
248 |
* Checks if entry is repeating. |
|
249 |
* @return ETrue if entry is repeating |
|
250 |
*/ |
|
251 |
TBool IsRepeatingMeetingL( const CCalEntry& aEntry, |
|
252 |
MESMRCalDbMgr& aDb ) |
|
253 |
{ |
|
254 |
FUNC_LOG; |
|
255 |
||
256 |
TBool recurrent( EFalse ); |
|
257 |
||
258 |
CCalInstance* instance = aDb.FindInstanceL( aEntry ); |
|
259 |
||
260 |
if ( instance ) |
|
261 |
{ |
|
262 |
CleanupStack::PushL( instance ); |
|
263 |
recurrent = ESMREntryHelper::IsRepeatingMeetingL( instance->Entry() ); |
|
264 |
CleanupStack::PopAndDestroy( instance ); |
|
265 |
} |
|
266 |
else |
|
267 |
{ |
|
268 |
recurrent = ESMREntryHelper::IsRepeatingMeetingL( aEntry ); |
|
269 |
} |
|
270 |
||
271 |
return recurrent; |
|
272 |
} |
|
273 |
||
274 |
/** |
|
275 |
* Finds conflicts for entry |
|
276 |
*/ |
|
277 |
void FindConflictsForEntryL( |
|
278 |
const CCalEntry& aEntry, |
|
279 |
RPointerArray< CCalInstance >& aInstances, |
|
280 |
MESMRCalDbMgr& aDb ) |
|
281 |
{ |
|
282 |
FUNC_LOG; |
|
283 |
||
284 |
// Get instance views of all calendar |
|
285 |
RPointerArray<CCalInstanceView> allCalenInstanceView = |
|
286 |
aDb.NormalDbAllCalenInstanceView(); |
|
287 |
||
288 |
// Check if there is any conflict in each calendar |
|
289 |
for( TInt i = 0; i < allCalenInstanceView.Count(); i++ ) |
|
290 |
{ |
|
291 |
CalCommon::TCalTimeRange timeRange = |
|
292 |
ResolveFetchTimeRangeL( |
|
293 |
aEntry.StartTimeL().TimeUtcL(), |
|
294 |
aEntry.EndTimeL().TimeUtcL(), |
|
295 |
allCalenInstanceView[i] ); |
|
296 |
||
297 |
allCalenInstanceView[i]->FindInstanceL( |
|
298 |
aInstances, |
|
80
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
299 |
CalCommon::EIncludeAppts | |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
300 |
CalCommon::EIncludeEvents , |
64 | 301 |
timeRange ); |
302 |
} |
|
303 |
||
304 |
RemoveAndDeleteNonConflictingInstancesL( |
|
305 |
aInstances, |
|
306 |
aEntry.StartTimeL(), |
|
307 |
aEntry.EndTimeL(), |
|
308 |
aEntry.UidL(), |
|
309 |
ERemoveSameUID ); |
|
310 |
} |
|
311 |
||
312 |
/** |
|
313 |
* Moves instances from an array to another. |
|
314 |
*/ |
|
315 |
void MoveInstancesL( |
|
316 |
RPointerArray< CCalInstance >& aFrom, |
|
317 |
RPointerArray< CCalInstance >& aTo ) |
|
318 |
{ |
|
319 |
FUNC_LOG; |
|
320 |
||
321 |
aTo.ReserveL( aTo.Count() + aFrom.Count() ); |
|
322 |
while ( aFrom.Count() ) |
|
323 |
{ |
|
324 |
aTo.AppendL( aFrom[ 0 ] ); |
|
325 |
aFrom.Remove( 0 ); |
|
326 |
} |
|
327 |
} |
|
328 |
||
329 |
/** |
|
330 |
* Finds conflicts based on Daily recurrence. |
|
331 |
* |
|
332 |
*/ |
|
333 |
void FindConflictsForDailyRRuleL( |
|
334 |
CCalEntry& aEntry, |
|
335 |
RPointerArray< CCalInstance >& aInstances, |
|
336 |
MESMRCalDbMgr& aDb, |
|
337 |
TBool aFindAllConflicts ) |
|
338 |
{ |
|
339 |
FUNC_LOG; |
|
340 |
||
341 |
TCalRRule rRule; |
|
342 |
aEntry.GetRRuleL( rRule ); |
|
343 |
RCPointerArray< CCalInstance > tmpInstanceArray; |
|
344 |
CleanupClosePushL( tmpInstanceArray ); |
|
345 |
||
346 |
// Entry start and end time |
|
347 |
TTime start( aEntry.StartTimeL().TimeUtcL() ); |
|
348 |
TTime end( aEntry.EndTimeL().TimeUtcL() ); |
|
349 |
||
350 |
if ( rRule.Count() ) |
|
351 |
{ |
|
352 |
for ( TInt i = 0; i < rRule.Count(); ++i ) |
|
353 |
{ |
|
354 |
// Set each occurence start and end time on entry |
|
355 |
TTimeIntervalDays interval( i * rRule.Interval() ); |
|
356 |
TCalTime startTime; |
|
357 |
startTime.SetTimeUtcL( start + interval ); |
|
358 |
TCalTime endTime; |
|
359 |
endTime.SetTimeUtcL( end + interval ); |
|
360 |
aEntry.SetStartAndEndTimeL( |
|
361 |
startTime, |
|
362 |
endTime ); |
|
363 |
||
364 |
// Find conflicts for this occurence |
|
365 |
FindConflictsForEntryL( aEntry, tmpInstanceArray, aDb ); |
|
366 |
||
367 |
if ( tmpInstanceArray.Count() ) |
|
368 |
{ |
|
369 |
MoveInstancesL( tmpInstanceArray, aInstances ); |
|
370 |
if ( !aFindAllConflicts ) |
|
371 |
{ |
|
80
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
372 |
//break; |
64 | 373 |
} |
374 |
} |
|
375 |
} |
|
376 |
} |
|
377 |
else if ( rRule.Until().TimeUtcL() != Time::NullTTime() ) |
|
378 |
{ |
|
379 |
TTime until( rRule.Until().TimeUtcL() ); |
|
380 |
TTime start( aEntry.StartTimeL().TimeUtcL() ); |
|
381 |
TTime end( aEntry.EndTimeL().TimeUtcL() ); |
|
382 |
TTimeIntervalDays interval( rRule.Interval() ); |
|
383 |
||
384 |
// Loop while start time is before until time |
|
385 |
while ( start <= until ) |
|
386 |
{ |
|
387 |
// Set start and end time for occurence |
|
388 |
TCalTime startTime; |
|
389 |
startTime.SetTimeUtcL( start ); |
|
390 |
TCalTime endTime; |
|
391 |
endTime.SetTimeUtcL( end ); |
|
392 |
aEntry.SetStartAndEndTimeL( |
|
393 |
startTime, |
|
394 |
endTime ); |
|
395 |
||
396 |
// Find conflicts |
|
397 |
FindConflictsForEntryL( aEntry, tmpInstanceArray, aDb ); |
|
398 |
||
399 |
if ( tmpInstanceArray.Count() ) |
|
400 |
{ |
|
401 |
MoveInstancesL( tmpInstanceArray, aInstances ); |
|
402 |
if ( !aFindAllConflicts ) |
|
403 |
{ |
|
80
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
404 |
//break; |
64 | 405 |
} |
406 |
} |
|
407 |
||
408 |
// Move to next occurence |
|
409 |
start += interval; |
|
410 |
end += interval; |
|
411 |
} |
|
412 |
} |
|
413 |
||
414 |
CleanupStack::PopAndDestroy( &tmpInstanceArray ); |
|
415 |
} |
|
416 |
||
417 |
/** |
|
418 |
* Finds conflicts based on Weekly recurrence. |
|
419 |
*/ |
|
420 |
void FindConflictsForWeeklyRRuleL( |
|
421 |
CCalEntry& aEntry, |
|
422 |
RPointerArray< CCalInstance >& aInstances, |
|
423 |
MESMRCalDbMgr& aDb, |
|
424 |
TBool aFindAllConflicts ) |
|
425 |
{ |
|
426 |
FUNC_LOG; |
|
427 |
||
428 |
TCalRRule rRule; |
|
429 |
aEntry.GetRRuleL( rRule ); |
|
430 |
||
431 |
// Tmp array for conflic instances |
|
432 |
RCPointerArray< CCalInstance > tmpInstanceArray; |
|
433 |
CleanupClosePushL( tmpInstanceArray ); |
|
434 |
||
435 |
// Array of recurrence days |
|
436 |
RArray< TDay > days; |
|
437 |
CleanupClosePushL( days ); |
|
438 |
rRule.GetByDayL( days ); |
|
439 |
||
440 |
// Recurrence start time |
|
441 |
TTime start( aEntry.StartTimeL().TimeUtcL() ); |
|
442 |
// Recurrence end time |
|
443 |
TTime end( aEntry.EndTimeL().TimeUtcL() ); |
|
444 |
const TTimeIntervalDays KWeek( 7 ); |
|
445 |
TDay startDayOfWeek( start.DayNoInWeek() ); |
|
446 |
||
447 |
// Instance duration |
|
448 |
TTimeIntervalMinutes duration; |
|
449 |
end.MinutesFrom( start, duration ); |
|
450 |
||
451 |
if ( rRule.Count() ) |
|
452 |
{ |
|
453 |
for ( TInt i = 0; i < rRule.Count(); ++i ) |
|
454 |
{ |
|
455 |
// Calculate weekly start time |
|
456 |
TTimeIntervalDays interval( i* KWeek.Int() ); |
|
457 |
TDateTime date( TTime( start + interval ).DateTime() ); |
|
458 |
date.SetDay( date.Day() - startDayOfWeek ); |
|
459 |
TTime weekStartTime( date ); |
|
460 |
||
461 |
for ( TInt j = 0; j < days.Count(); ++j ) |
|
462 |
{ |
|
463 |
// Iterate through days of week |
|
464 |
TTime entryStartTime( weekStartTime + TTimeIntervalDays( days[ j ] ) ); |
|
465 |
||
466 |
if ( start <= entryStartTime ) |
|
467 |
{ |
|
468 |
// Start time is in recurrence range |
|
469 |
// Calcualte end time |
|
470 |
TCalTime startCalTime; |
|
471 |
startCalTime.SetTimeUtcL( entryStartTime ); |
|
472 |
TCalTime endCalTime; |
|
473 |
endCalTime.SetTimeUtcL( entryStartTime + duration ); |
|
474 |
aEntry.SetStartAndEndTimeL( startCalTime, endCalTime ); |
|
475 |
||
476 |
// Find conflicts of for entry and move them to result array |
|
477 |
FindConflictsForEntryL( aEntry, tmpInstanceArray, aDb ); |
|
478 |
||
479 |
if ( tmpInstanceArray.Count() ) |
|
480 |
{ |
|
481 |
MoveInstancesL( tmpInstanceArray, aInstances ); |
|
482 |
if ( !aFindAllConflicts ) |
|
483 |
{ |
|
80
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
484 |
//break; |
64 | 485 |
} |
486 |
} |
|
487 |
} |
|
488 |
} |
|
489 |
||
490 |
if ( !aFindAllConflicts && aInstances.Count() ) |
|
491 |
{ |
|
492 |
break; |
|
493 |
} |
|
494 |
} |
|
495 |
} |
|
496 |
else if ( rRule.Until().TimeUtcL() != Time::NullTTime() ) |
|
497 |
{ |
|
498 |
TDateTime date( start.DateTime() ); |
|
499 |
date.SetDay( date.Day() - startDayOfWeek ); |
|
500 |
TTime weekStartTime( date ); |
|
501 |
TTime until( rRule.Until().TimeUtcL() ); |
|
502 |
||
503 |
while ( weekStartTime < until ) |
|
504 |
{ |
|
505 |
for ( TInt j = 0; j < days.Count(); ++j ) |
|
506 |
{ |
|
507 |
// Iterate through days of week |
|
508 |
TTime entryStartTime( weekStartTime + TTimeIntervalDays( days[ j ] ) ); |
|
509 |
||
510 |
if ( start <= entryStartTime ) |
|
511 |
{ |
|
512 |
// Start time is in recurrence range |
|
513 |
// Calculate end time |
|
514 |
TCalTime startCalTime; |
|
515 |
startCalTime.SetTimeUtcL( entryStartTime ); |
|
516 |
TCalTime endCalTime; |
|
517 |
endCalTime.SetTimeUtcL( entryStartTime + duration ); |
|
518 |
aEntry.SetStartAndEndTimeL( startCalTime, endCalTime ); |
|
519 |
||
520 |
// Find conflicts of for entry and move them to result array |
|
521 |
FindConflictsForEntryL( aEntry, tmpInstanceArray, aDb ); |
|
522 |
||
523 |
if ( tmpInstanceArray.Count() ) |
|
524 |
{ |
|
525 |
MoveInstancesL( tmpInstanceArray, aInstances ); |
|
526 |
if ( !aFindAllConflicts ) |
|
527 |
{ |
|
80
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
528 |
// break; |
64 | 529 |
} |
530 |
} |
|
531 |
} |
|
532 |
} |
|
533 |
||
534 |
if ( !aFindAllConflicts && aInstances.Count() ) |
|
535 |
{ |
|
536 |
break; |
|
537 |
} |
|
538 |
else |
|
539 |
{ |
|
540 |
weekStartTime += KWeek; |
|
541 |
} |
|
542 |
} |
|
543 |
} |
|
544 |
||
545 |
CleanupStack::PopAndDestroy( &days ); |
|
546 |
CleanupStack::PopAndDestroy( &tmpInstanceArray ); |
|
547 |
} |
|
548 |
||
549 |
/** |
|
80
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
550 |
* Judge is one CCalEntry is a all day event |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
551 |
* @param aEntry the entry be checked |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
552 |
* @return ETure if it is a all day event |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
553 |
*/ |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
554 |
TBool IsAllDayEventL( const CCalEntry& aEntry ) |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
555 |
{ |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
556 |
FUNC_LOG; |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
557 |
// for judge all day event |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
558 |
CCalEntry* tmpEntry = ESMRHelper::CopyEntryLC( |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
559 |
aEntry, |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
560 |
aEntry.MethodL(), |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
561 |
ESMRHelper::ECopyFull ); |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
562 |
|
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
563 |
CESMRCalUserUtil* entryUtil = CESMRCalUserUtil::NewLC( *tmpEntry ); |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
564 |
TBool allDayEvent( entryUtil->IsAlldayEventL() ); |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
565 |
CleanupStack::PopAndDestroy( entryUtil ); |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
566 |
CleanupStack::PopAndDestroy( tmpEntry ); |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
567 |
|
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
568 |
return allDayEvent; |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
569 |
} |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
570 |
/** |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
571 |
* Get the first visible instance from the iterater. |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
572 |
* @param aIterater the handler of the iterater. |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
573 |
* @return the first instance |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
574 |
*/ |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
575 |
CCalInstance* FirstInstanceL ( CCalInstanceIterator* aIterater) |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
576 |
{ |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
577 |
FUNC_LOG; |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
578 |
CCalInstance* previous = aIterater->PreviousL(); |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
579 |
while( previous ) |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
580 |
{ |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
581 |
CleanupStack::PushL( previous ); |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
582 |
CleanupStack::PopAndDestroy( previous ); |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
583 |
previous = aIterater->PreviousL(); |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
584 |
} |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
585 |
|
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
586 |
CCalInstance* next = aIterater->NextL(); |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
587 |
CleanupStack::PushL( next ); |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
588 |
CleanupStack::PopAndDestroy( next ); |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
589 |
previous = aIterater->PreviousL(); |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
590 |
return previous; |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
591 |
} |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
592 |
|
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
593 |
/** |
64 | 594 |
* Finds conflict for recurrent entry |
595 |
*/ |
|
596 |
void FindConflictsForRepeatingMeetingL( |
|
597 |
const CCalEntry& aEntry, |
|
598 |
RPointerArray< CCalInstance >& aInstances, |
|
599 |
MESMRCalDbMgr& aDb, |
|
600 |
TBool aFindAllConflicts ) |
|
601 |
{ |
|
602 |
FUNC_LOG; |
|
603 |
||
604 |
CCalInstance* instance = aDb.FindInstanceL( aEntry ); |
|
605 |
||
606 |
if ( instance ) // Instance is stored |
|
607 |
{ |
|
608 |
CleanupStack::PushL( instance ); |
|
609 |
RCPointerArray< CCalInstance > tmpInstanceArray; |
|
610 |
CleanupClosePushL( tmpInstanceArray ); |
|
80
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
611 |
CCalEntry& parent = instance->Entry(); |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
612 |
CCalInstanceView* instanceView = aDb.InstanceViewL( aEntry ); |
64 | 613 |
|
80
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
614 |
// create the iterator for instances by current entry |
64 | 615 |
CCalInstanceIterator* iterator = instanceView->FindInstanceByUidL( |
80
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
616 |
aEntry.UidL(), |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
617 |
aEntry.StartTimeL() ); |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
618 |
|
64 | 619 |
CleanupStack::PushL( iterator ); |
620 |
CCalEntry* entry = ESMRHelper::CopyEntryLC( |
|
621 |
parent, |
|
622 |
parent.MethodL(), |
|
623 |
ESMRHelper::ECopyFull ); |
|
80
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
624 |
// For CCalInstanceIterator class don't have any function on how to get current instance, |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
625 |
// handle the special situation for it. |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
626 |
if( iterator ->Count() == 1 ) |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
627 |
{ |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
628 |
entry->SetStartAndEndTimeL( aEntry.StartTimeL(), aEntry.EndTimeL() ); |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
629 |
|
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
630 |
FindConflictsForEntryL( *entry, |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
631 |
tmpInstanceArray, |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
632 |
aDb ); |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
633 |
|
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
634 |
if ( tmpInstanceArray.Count() ) |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
635 |
{ |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
636 |
MoveInstancesL( tmpInstanceArray, aInstances ); |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
637 |
} |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
638 |
} |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
639 |
else |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
640 |
{ |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
641 |
// For CCalInstanceIterator class don't have any function on how to get current instance, |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
642 |
// handle the first instance action when find conflict. |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
643 |
CCalInstance* previous = FirstInstanceL( iterator ); |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
644 |
CleanupStack::PushL( previous ); |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
645 |
entry->SetStartAndEndTimeL( previous->StartTimeL(), previous->EndTimeL() ); |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
646 |
CleanupStack::PopAndDestroy( previous ); |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
647 |
FindConflictsForEntryL( *entry, tmpInstanceArray, aDb ); |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
648 |
|
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
649 |
if ( tmpInstanceArray.Count() ) |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
650 |
{ |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
651 |
MoveInstancesL( tmpInstanceArray, aInstances ); |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
652 |
} |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
653 |
// does the normal find conflict action. From the second to the end. |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
654 |
while ( iterator->HasMore() ) |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
655 |
{ |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
656 |
CCalInstance* next = iterator->NextL(); |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
657 |
CleanupStack::PushL( next ); |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
658 |
entry->SetStartAndEndTimeL( next->StartTimeL(), next->EndTimeL() ); |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
659 |
|
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
660 |
CleanupStack::PopAndDestroy( next ); |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
661 |
|
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
662 |
FindConflictsForEntryL( *entry, |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
663 |
tmpInstanceArray, |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
664 |
aDb ); |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
665 |
|
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
666 |
if ( tmpInstanceArray.Count() ) |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
667 |
{ |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
668 |
MoveInstancesL( tmpInstanceArray, aInstances ); |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
669 |
} |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
670 |
} |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
671 |
} |
64 | 672 |
|
673 |
CleanupStack::PopAndDestroy( entry ); |
|
674 |
||
675 |
CleanupStack::PopAndDestroy( iterator ); |
|
676 |
||
677 |
if ( aFindAllConflicts |
|
678 |
|| !aInstances.Count() ) |
|
679 |
{ |
|
680 |
// Find conflicts also for parent entry |
|
681 |
FindConflictsForEntryL( parent, tmpInstanceArray, aDb ); |
|
682 |
MoveInstancesL( tmpInstanceArray, aInstances ); |
|
683 |
} |
|
684 |
||
685 |
CleanupStack::PopAndDestroy( &tmpInstanceArray ); |
|
686 |
CleanupStack::PopAndDestroy( instance ); |
|
687 |
} |
|
688 |
else // Entry is not stored yet |
|
689 |
{ |
|
690 |
CCalEntry* entry = ESMRHelper::CopyEntryLC( |
|
691 |
aEntry, |
|
692 |
aEntry.MethodL(), |
|
693 |
ESMRHelper::ECopyFull ); |
|
694 |
||
695 |
TCalRRule rRule; |
|
696 |
if ( aEntry.GetRRuleL( rRule ) ) |
|
697 |
{ |
|
698 |
switch ( rRule.Type() ) |
|
699 |
{ |
|
700 |
case TCalRRule::EDaily: |
|
701 |
{ |
|
702 |
FindConflictsForDailyRRuleL( |
|
703 |
*entry, |
|
704 |
aInstances, |
|
705 |
aDb, |
|
706 |
aFindAllConflicts ); |
|
707 |
break; |
|
708 |
} |
|
709 |
case TCalRRule::EWeekly: |
|
710 |
{ |
|
711 |
FindConflictsForWeeklyRRuleL( |
|
712 |
*entry, |
|
713 |
aInstances, |
|
714 |
aDb, |
|
715 |
aFindAllConflicts ); |
|
716 |
break; |
|
717 |
} |
|
718 |
default: |
|
719 |
break; |
|
720 |
} |
|
721 |
} |
|
722 |
else |
|
723 |
{ |
|
724 |
// Entry has RDates set |
|
725 |
RCPointerArray< CCalInstance > tmpInstanceArray; |
|
726 |
CleanupClosePushL( tmpInstanceArray ); |
|
727 |
||
728 |
RArray< TCalTime > rDates; |
|
729 |
CleanupClosePushL( rDates ); |
|
730 |
aEntry.GetRDatesL( rDates ); |
|
731 |
||
732 |
// Get entry start time, end time and duration |
|
733 |
TTime start( aEntry.StartTimeL().TimeUtcL() ); |
|
734 |
TTime end( aEntry.EndTimeL().TimeUtcL() ); |
|
735 |
TTimeIntervalMinutes duration(0); |
|
736 |
end.MinutesFrom( |
|
737 |
start, |
|
738 |
duration ); |
|
739 |
||
740 |
for ( TInt i = 0; i < rDates.Count(); ++i ) |
|
741 |
{ |
|
742 |
// Set start and end times for entry |
|
743 |
TCalTime startTime( rDates[ i ] ); |
|
744 |
TCalTime endTime; |
|
745 |
endTime.SetTimeUtcL( startTime.TimeUtcL() + duration ); |
|
746 |
entry->SetStartAndEndTimeL( startTime, endTime ); |
|
747 |
||
748 |
// Find conflicts |
|
749 |
FindConflictsForEntryL( *entry, tmpInstanceArray, aDb ); |
|
750 |
||
751 |
if ( tmpInstanceArray.Count() ) |
|
752 |
{ |
|
753 |
MoveInstancesL( tmpInstanceArray, aInstances ); |
|
754 |
if ( !aFindAllConflicts ) |
|
755 |
{ |
|
756 |
break; |
|
757 |
} |
|
758 |
} |
|
759 |
} |
|
760 |
||
761 |
CleanupStack::PopAndDestroy( &rDates ); |
|
762 |
||
763 |
if ( aFindAllConflicts |
|
764 |
|| aInstances.Count() == 0 ) |
|
765 |
{ |
|
766 |
// Find conflicts for parent entry |
|
767 |
FindConflictsForEntryL( aEntry, tmpInstanceArray, aDb ); |
|
768 |
MoveInstancesL( tmpInstanceArray, aInstances ); |
|
769 |
} |
|
770 |
||
771 |
CleanupStack::PopAndDestroy( &tmpInstanceArray ); |
|
772 |
} |
|
773 |
||
774 |
CleanupStack::PopAndDestroy( entry ); |
|
775 |
} |
|
776 |
} |
|
777 |
||
778 |
} // namespace |
|
779 |
||
780 |
// ======== MEMBER FUNCTIONS ======== |
|
781 |
||
782 |
// --------------------------------------------------------------------------- |
|
783 |
// CESMRConflictChecker::CESMRConflictChecker |
|
784 |
// --------------------------------------------------------------------------- |
|
785 |
// |
|
786 |
inline CESMRConflictChecker::CESMRConflictChecker( |
|
787 |
MESMRCalDbMgr& aDbMgr ) : |
|
788 |
iDbMgr( aDbMgr ) |
|
789 |
{ |
|
790 |
FUNC_LOG; |
|
791 |
// Not implementation yet |
|
792 |
} |
|
793 |
||
794 |
// --------------------------------------------------------------------------- |
|
795 |
// CESMRConflictChecker::~CESMRConflictChecker |
|
796 |
// --------------------------------------------------------------------------- |
|
797 |
// |
|
798 |
EXPORT_C CESMRConflictChecker::~CESMRConflictChecker() |
|
799 |
{ |
|
800 |
FUNC_LOG; |
|
801 |
// Not implementation yet |
|
802 |
} |
|
803 |
||
804 |
// --------------------------------------------------------------------------- |
|
805 |
// CESMRConflictChecker::NewL |
|
806 |
// --------------------------------------------------------------------------- |
|
807 |
// |
|
808 |
EXPORT_C CESMRConflictChecker* CESMRConflictChecker::NewL( |
|
809 |
MESMRCalDbMgr& aDbMgr ) |
|
810 |
{ |
|
811 |
FUNC_LOG; |
|
812 |
CESMRConflictChecker* self = |
|
813 |
new (ELeave) CESMRConflictChecker(aDbMgr); |
|
814 |
return self; |
|
815 |
} |
|
816 |
||
817 |
// --------------------------------------------------------------------------- |
|
818 |
// CESMRConflictChecker::FindConflictsL |
|
819 |
// --------------------------------------------------------------------------- |
|
820 |
// |
|
821 |
EXPORT_C void CESMRConflictChecker::FindConflictsL( |
|
822 |
const CCalEntry& aEntry, |
|
823 |
RPointerArray<CCalEntry>& aConflicts ) |
|
824 |
{ |
|
825 |
FUNC_LOG; |
|
826 |
||
827 |
// Checking input parameters |
|
828 |
#ifdef _DEBUG |
|
829 |
||
830 |
__ASSERT_DEBUG( |
|
831 |
CCalEntry::EAppt == aEntry.EntryTypeL(), |
|
832 |
Panic(EESMRConflictCheckerInvalidEntryType) ); |
|
833 |
||
834 |
#else |
|
835 |
||
836 |
if ( CCalEntry::EAppt != aEntry.EntryTypeL() ) |
|
837 |
{ |
|
838 |
Leave( KErrArgument ); |
|
839 |
} |
|
840 |
||
841 |
#endif |
|
842 |
||
843 |
RCPointerArray<CCalInstance> instanceArray; |
|
844 |
CleanupClosePushL( instanceArray ); |
|
845 |
||
846 |
if ( IsRepeatingMeetingL( aEntry, iDbMgr ) ) |
|
847 |
{ |
|
848 |
FindConflictsForRepeatingMeetingL( |
|
849 |
aEntry, |
|
850 |
instanceArray, |
|
851 |
iDbMgr, |
|
852 |
EFalse ); |
|
853 |
} |
|
854 |
else |
|
855 |
{ |
|
856 |
FindConflictsForEntryL( |
|
857 |
aEntry, |
|
858 |
instanceArray, |
|
859 |
iDbMgr ); |
|
860 |
} |
|
861 |
||
862 |
CreateEntriesFromInstancesL( instanceArray, aConflicts ); |
|
863 |
CleanupStack::PopAndDestroy( &instanceArray); |
|
864 |
} |
|
865 |
||
866 |
// --------------------------------------------------------------------------- |
|
867 |
// CESMRConflictChecker::FindInstancesForEntry |
|
868 |
// --------------------------------------------------------------------------- |
|
869 |
// |
|
870 |
EXPORT_C void CESMRConflictChecker::FindInstancesForEntryL( |
|
871 |
TTime aStart, |
|
872 |
TTime aEnd, |
|
873 |
const CCalEntry& aEntry, |
|
874 |
TCalCollectionId aColId, |
|
875 |
RPointerArray<CCalEntry>& aInstances ) |
|
876 |
{ |
|
877 |
FUNC_LOG; |
|
878 |
CCalInstanceView* instanceView = iDbMgr.InstanceViewL( aEntry ); |
|
879 |
||
880 |
RCPointerArray<CCalInstance> instanceArray; |
|
881 |
CleanupClosePushL( instanceArray ); |
|
882 |
||
883 |
// First we need the parent entry of the series ... |
|
884 |
CCalInstance* entryInstance = instanceView->FindInstanceL( |
|
885 |
aEntry.LocalUidL(), |
|
886 |
aEntry.StartTimeL() ); //Ownership gained |
|
887 |
CleanupStack::PushL( entryInstance ); |
|
888 |
||
889 |
CCalInstance* parentEntryInstance = instanceView->FindInstanceL( |
|
890 |
aEntry.LocalUidL(), |
|
891 |
entryInstance->Entry().StartTimeL() ); |
|
892 |
CleanupStack::PopAndDestroy( entryInstance ); |
|
893 |
CleanupStack::PushL( parentEntryInstance ); |
|
894 |
||
895 |
// ... And the parent entry instances start time |
|
896 |
TCalTime firstIntanceStartTime( parentEntryInstance->StartTimeL() ); |
|
897 |
||
898 |
CleanupStack::Pop( parentEntryInstance ); // ownership given to instanceArray |
|
899 |
instanceArray.Append( parentEntryInstance ); |
|
900 |
||
901 |
// Let's get all instances which have same uid and collection id |
|
902 |
// as the aEntry to an iterator. |
|
903 |
CCalInstanceIterator* instanceIterator = instanceView->FindInstanceByUidL( |
|
904 |
aColId, |
|
905 |
aEntry.UidL(), |
|
906 |
firstIntanceStartTime ); |
|
907 |
CleanupStack::PushL( instanceIterator ); |
|
908 |
||
909 |
TInt count( instanceIterator->Count() ); |
|
910 |
||
911 |
for( TInt i = 0; i < count; ++i ) |
|
912 |
{ |
|
913 |
CCalInstance* instance = NULL; |
|
914 |
TRAPD( err, instance = instanceIterator->NextL() ); //Ownership gained |
|
915 |
if( !err && instance ) |
|
916 |
{ |
|
917 |
instanceArray.Append( instance ); |
|
918 |
} |
|
919 |
} |
|
920 |
||
921 |
CleanupStack::PopAndDestroy( instanceIterator ); |
|
922 |
||
923 |
// Now the instanceArray has all instances of the aEntry, |
|
924 |
// let's remove this instance == instance of aEntry, from the array |
|
925 |
TInt i( 0 ); |
|
926 |
while( i < instanceArray.Count() ) |
|
927 |
{ |
|
928 |
CCalInstance* instance = instanceArray[i]; |
|
929 |
||
930 |
TBool thisInstance( |
|
931 |
instance->StartTimeL().TimeLocalL() == |
|
932 |
aEntry.StartTimeL().TimeLocalL() && |
|
933 |
instance->EndTimeL().TimeLocalL() == |
|
934 |
aEntry.EndTimeL().TimeLocalL() ); |
|
935 |
||
936 |
if( thisInstance ) |
|
937 |
{ |
|
938 |
delete instance; |
|
939 |
instanceArray.Remove( i ); |
|
940 |
} |
|
941 |
else |
|
942 |
{ |
|
943 |
++i; |
|
944 |
} |
|
945 |
} |
|
946 |
||
947 |
TCalTime start; |
|
948 |
start.SetTimeLocalL( aStart ); |
|
949 |
||
950 |
TCalTime end; |
|
951 |
end.SetTimeLocalL( aEnd ); |
|
952 |
||
953 |
RemoveAndDeleteNonConflictingInstancesL( |
|
954 |
instanceArray, |
|
955 |
start, |
|
956 |
end, |
|
957 |
aEntry.UidL(), |
|
958 |
EIncludeSameUID ); |
|
959 |
||
960 |
CreateEntriesFromInstancesL( instanceArray, aInstances ); |
|
961 |
||
962 |
CleanupStack::PopAndDestroy(); // instanceArray |
|
963 |
} |
|
964 |
||
965 |
// EOF |
|
966 |