|
1 /* |
|
2 * Copyright (c) 2002 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: Provides asynchronous wrapper functions for |
|
15 * common InterimAPI operations. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 //debug |
|
21 #include "calendarui_debug.h" |
|
22 |
|
23 // INCLUDES |
|
24 #include "CalenAsyncCommands.h" |
|
25 #include "CalenEngine.h" |
|
26 #include "calenagendautils.h" |
|
27 #include "calendateutils.h" |
|
28 #include "CleanupResetAndDestroy.h" |
|
29 |
|
30 #include <calsession.h> |
|
31 #include <calcommon.h> |
|
32 #include <calinstance.h> |
|
33 #include <calinstanceview.h> |
|
34 |
|
35 #include "CalenPaths.h" |
|
36 |
|
37 //////////////////////////////////////////////////////////////////////// |
|
38 // CMultiStepCommandBase method definitions |
|
39 /////////////////////////////////////////////////////////////////////// |
|
40 |
|
41 CMultistepCommandBase::CMultistepCommandBase(CCalenEngine& aEngine) : |
|
42 CActive( 0 ), |
|
43 iEngine( aEngine ) |
|
44 { |
|
45 TRACE_ENTRY_POINT; |
|
46 |
|
47 CActiveScheduler::Add( this ); |
|
48 |
|
49 TRACE_EXIT_POINT; |
|
50 } |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // ?classname::?member_function |
|
54 // ?implementation_description |
|
55 // (other items were commented in a header). |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 CMultistepCommandBase::~CMultistepCommandBase() |
|
59 { |
|
60 TRACE_ENTRY_POINT; |
|
61 |
|
62 /* !!! NOTE !!! |
|
63 * Do NOT call Cancel() in here. |
|
64 * Calling Cancel() will cause the code to panic! |
|
65 * Cancel() can only be called in a class that implements |
|
66 * the DoCancel() function. |
|
67 */ |
|
68 |
|
69 TRACE_EXIT_POINT; |
|
70 } |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // ?classname::?member_function |
|
74 // ?implementation_description |
|
75 // (other items were commented in a header). |
|
76 // ----------------------------------------------------------------------------- |
|
77 // |
|
78 void CMultistepCommandBase::Start() |
|
79 { |
|
80 TRACE_ENTRY_POINT; |
|
81 |
|
82 CompleteSelf(); |
|
83 |
|
84 TRACE_EXIT_POINT; |
|
85 } |
|
86 |
|
87 // ----------------------------------------------------------------------------- |
|
88 // ?classname::?member_function |
|
89 // ?implementation_description |
|
90 // (other items were commented in a header). |
|
91 // ----------------------------------------------------------------------------- |
|
92 // |
|
93 void CMultistepCommandBase::CompleteSelf() |
|
94 { |
|
95 TRACE_ENTRY_POINT; |
|
96 |
|
97 TRequestStatus* pStat = &iStatus; |
|
98 if( IsAdded() ) |
|
99 { |
|
100 if (!IsActive()) |
|
101 { |
|
102 SetActive(); |
|
103 } |
|
104 User::RequestComplete( pStat, KErrNone ); |
|
105 } |
|
106 |
|
107 TRACE_EXIT_POINT; |
|
108 } |
|
109 |
|
110 |
|
111 //////////////////////////////////////////////////////////////////////// |
|
112 // COpenCommand method definitions |
|
113 /////////////////////////////////////////////////////////////////////// |
|
114 |
|
115 // ----------------------------------------------------------------------------- |
|
116 // ?classname::?member_function |
|
117 // ?implementation_description |
|
118 // (other items were commented in a header). |
|
119 // ----------------------------------------------------------------------------- |
|
120 // |
|
121 COpenCommand::COpenCommand(CCalenEngine& aEngine) |
|
122 : CMultistepCommandBase( aEngine ), |
|
123 iState( ECreateSession ), |
|
124 iAgendaError( KErrNone ) |
|
125 { |
|
126 TRACE_ENTRY_POINT; |
|
127 TRACE_EXIT_POINT; |
|
128 } |
|
129 |
|
130 // ----------------------------------------------------------------------------- |
|
131 // ?classname::?member_function |
|
132 // ?implementation_description |
|
133 // (other items were commented in a header). |
|
134 // ----------------------------------------------------------------------------- |
|
135 // |
|
136 COpenCommand::~COpenCommand() |
|
137 { |
|
138 TRACE_ENTRY_POINT; |
|
139 |
|
140 Cancel(); |
|
141 |
|
142 TRACE_EXIT_POINT; |
|
143 } |
|
144 |
|
145 // ----------------------------------------------------------------------------- |
|
146 // ?classname::?member_function |
|
147 // ?implementation_description |
|
148 // (other items were commented in a header). |
|
149 // ----------------------------------------------------------------------------- |
|
150 // |
|
151 void COpenCommand::Panic(TInt aReason) |
|
152 { |
|
153 TRACE_ENTRY_POINT; |
|
154 |
|
155 __ASSERT_DEBUG( EFalse, User::Panic( _L("COpenCommand"), aReason ) ); |
|
156 |
|
157 TRACE_EXIT_POINT; |
|
158 } |
|
159 |
|
160 // ----------------------------------------------------------------------------- |
|
161 // ?classname::?member_function |
|
162 // ?implementation_description |
|
163 // (other items were commented in a header). |
|
164 // ----------------------------------------------------------------------------- |
|
165 // |
|
166 void COpenCommand::RunL() |
|
167 { |
|
168 TRACE_ENTRY_POINT; |
|
169 |
|
170 if (iStatus.Int()) |
|
171 { |
|
172 return; |
|
173 } |
|
174 |
|
175 switch( iState ) |
|
176 { |
|
177 case ECreateSession: |
|
178 { |
|
179 iEngine.UpdateCalSessionsL(); |
|
180 |
|
181 iState = ECreateView; |
|
182 CompleteSelf(); |
|
183 } |
|
184 break; |
|
185 |
|
186 case ECreateView: |
|
187 { |
|
188 |
|
189 if(iEngine.iInstanceView) |
|
190 { |
|
191 delete iEngine.iInstanceView; |
|
192 iEngine.iInstanceView = NULL; |
|
193 } |
|
194 |
|
195 RPointerArray<CCalSession>& sessionArray = iEngine.GetActiveSessionsL(); |
|
196 // Creating a view will create the index |
|
197 // This is an asynch function: |
|
198 // -> we don't complete ourselves here, agenda model calls back to the Completed method. |
|
199 |
|
200 |
|
201 if(sessionArray.Count()) |
|
202 { |
|
203 iEngine.iInstanceView = CCalInstanceView::NewL( sessionArray, *this ); |
|
204 } |
|
205 else |
|
206 { |
|
207 iState = ESignalCaller; |
|
208 CompleteSelf(); |
|
209 } |
|
210 } |
|
211 break; |
|
212 |
|
213 case ESignalCaller: |
|
214 { |
|
215 User::LeaveIfError( iAgendaError ); |
|
216 iState = EReady; |
|
217 iEngine.OpenCompleted(); |
|
218 } |
|
219 break; |
|
220 |
|
221 default: |
|
222 { |
|
223 Panic( EInvalidState ); |
|
224 } |
|
225 } |
|
226 |
|
227 TRACE_EXIT_POINT; |
|
228 } |
|
229 |
|
230 // ----------------------------------------------------------------------------- |
|
231 // ?classname::?member_function |
|
232 // ?implementation_description |
|
233 // (other items were commented in a header). |
|
234 // ----------------------------------------------------------------------------- |
|
235 // |
|
236 void COpenCommand::DoCancel() |
|
237 { |
|
238 TRACE_ENTRY_POINT; |
|
239 |
|
240 iState = ECreateSession; |
|
241 iEngine.ReleaseCalendarDatabase(); |
|
242 |
|
243 TRACE_EXIT_POINT; |
|
244 } |
|
245 |
|
246 // ----------------------------------------------------------------------------- |
|
247 // ?classname::?member_function |
|
248 // ?implementation_description |
|
249 // (other items were commented in a header). |
|
250 // ----------------------------------------------------------------------------- |
|
251 // |
|
252 void COpenCommand::Completed(TInt aError) |
|
253 { |
|
254 TRACE_ENTRY_POINT; |
|
255 |
|
256 iAgendaError = aError; |
|
257 iState = ESignalCaller; |
|
258 CompleteSelf(); |
|
259 |
|
260 TRACE_EXIT_POINT; |
|
261 } |
|
262 |
|
263 // ----------------------------------------------------------------------------- |
|
264 // ?classname::?member_function |
|
265 // ?implementation_description |
|
266 // (other items were commented in a header). |
|
267 // ----------------------------------------------------------------------------- |
|
268 // |
|
269 void COpenCommand::Progress(TInt /*aPercentageCompleted*/) |
|
270 { |
|
271 TRACE_ENTRY_POINT; |
|
272 |
|
273 // do not care about progress, only completion matters |
|
274 TRACE_EXIT_POINT; |
|
275 } |
|
276 |
|
277 // ----------------------------------------------------------------------------- |
|
278 // ?classname::?member_function |
|
279 // ?implementation_description |
|
280 // (other items were commented in a header). |
|
281 // ----------------------------------------------------------------------------- |
|
282 // |
|
283 TBool COpenCommand::NotifyProgress() |
|
284 { |
|
285 TRACE_ENTRY_POINT; |
|
286 |
|
287 TRACE_EXIT_POINT; |
|
288 return EFalse; |
|
289 } |
|
290 |
|
291 // ----------------------------------------------------------------------------- |
|
292 // ?classname::?member_function |
|
293 // ?implementation_description |
|
294 // (other items were commented in a header). |
|
295 // ----------------------------------------------------------------------------- |
|
296 // |
|
297 TInt COpenCommand::RunError(TInt aError) |
|
298 { |
|
299 TRACE_ENTRY_POINT; |
|
300 |
|
301 // suppress any error |
|
302 iEngine.ReleaseCalendarDatabase(); |
|
303 iEngine.HandleError( aError ); |
|
304 |
|
305 TRACE_EXIT_POINT; |
|
306 return KErrNone; |
|
307 } |
|
308 |
|
309 //////////////////////////////////////////////////////////////////////// |
|
310 // CGetEntrisCommand method definitions |
|
311 /////////////////////////////////////////////////////////////////////// |
|
312 |
|
313 |
|
314 // ----------------------------------------------------------------------------- |
|
315 // ?classname::?member_function |
|
316 // ?implementation_description |
|
317 // (other items were commented in a header). |
|
318 // ----------------------------------------------------------------------------- |
|
319 // |
|
320 CGetEntriesCommand* CGetEntriesCommand::NewL( CCalenEngine& aEngine, |
|
321 const TTime& aDay, |
|
322 RPointerArray<CCalInstance>& aInstanceArray ) |
|
323 { |
|
324 TRACE_ENTRY_POINT; |
|
325 |
|
326 CGetEntriesCommand* self = new( ELeave )CGetEntriesCommand( aEngine, aDay, aInstanceArray ); |
|
327 |
|
328 TRACE_EXIT_POINT; |
|
329 return self; |
|
330 } |
|
331 |
|
332 // ----------------------------------------------------------------------------- |
|
333 // ?classname::?member_function |
|
334 // ?implementation_description |
|
335 // (other items were commented in a header). |
|
336 // ----------------------------------------------------------------------------- |
|
337 // |
|
338 CGetEntriesCommand::CGetEntriesCommand( CCalenEngine& aEngine, |
|
339 const TTime& aDay, |
|
340 RPointerArray<CCalInstance>& aInstanceArray ) |
|
341 : CMultistepCommandBase( aEngine ), |
|
342 iState( EFetch ), |
|
343 iDay( aDay ), |
|
344 iInstanceArray( aInstanceArray ) |
|
345 { |
|
346 TRACE_ENTRY_POINT; |
|
347 TRACE_EXIT_POINT; |
|
348 } |
|
349 |
|
350 // ----------------------------------------------------------------------------- |
|
351 // ?classname::?member_function |
|
352 // ?implementation_description |
|
353 // (other items were commented in a header). |
|
354 // ----------------------------------------------------------------------------- |
|
355 // |
|
356 CGetEntriesCommand::~CGetEntriesCommand() |
|
357 { |
|
358 TRACE_ENTRY_POINT; |
|
359 |
|
360 Cancel(); |
|
361 |
|
362 TRACE_EXIT_POINT; |
|
363 } |
|
364 |
|
365 // ----------------------------------------------------------------------------- |
|
366 // ?classname::?member_function |
|
367 // ?implementation_description |
|
368 // (other items were commented in a header). |
|
369 // ----------------------------------------------------------------------------- |
|
370 // |
|
371 void CGetEntriesCommand::RunL(void) |
|
372 { |
|
373 TRACE_ENTRY_POINT; |
|
374 |
|
375 if (iStatus.Int()) |
|
376 { |
|
377 return; |
|
378 } |
|
379 |
|
380 switch( iState ) |
|
381 { |
|
382 case EFetch: |
|
383 { |
|
384 if( !iEngine.iInstanceView ) |
|
385 { |
|
386 iState = EFinalize; |
|
387 CompleteSelf(); |
|
388 } |
|
389 else |
|
390 { |
|
391 |
|
392 CalCommon::TCalViewFilter filter = CalCommon::EIncludeAppts | |
|
393 CalCommon::EIncludeReminder | |
|
394 CalCommon::EIncludeEvents | |
|
395 CalCommon::EIncludeAnnivs; |
|
396 |
|
397 CalenAgendaUtils::FindEventsForDayRangeL( iEngine.iInstanceView, iInstanceArray, filter, iDay, iDay ); |
|
398 |
|
399 CalenAgendaUtils::RemoveEntriesEndingAtMidnightL( iInstanceArray, iDay ); |
|
400 |
|
401 iState = EFinalize; |
|
402 CompleteSelf(); |
|
403 } |
|
404 |
|
405 } |
|
406 break; |
|
407 |
|
408 case EFinalize: |
|
409 { |
|
410 |
|
411 iDay = CalenDateUtils::BeginningOfDay( iDay ); |
|
412 |
|
413 // Remove all events starting before iDay |
|
414 for(TInt i(0); i<iInstanceArray.Count(); ) |
|
415 { |
|
416 if( ( iInstanceArray[i]->Entry().EntryTypeL() == CCalEntry::EAppt || |
|
417 iInstanceArray[i]->Entry().EntryTypeL() == CCalEntry::EReminder ) |
|
418 && |
|
419 iInstanceArray[i]->StartTimeL().TimeLocalL() < iDay ) |
|
420 { |
|
421 CCalInstance* instance = iInstanceArray[i]; |
|
422 iInstanceArray.Remove( i ); |
|
423 delete instance; |
|
424 |
|
425 } |
|
426 else |
|
427 { |
|
428 i++; |
|
429 } |
|
430 } |
|
431 |
|
432 CalenAgendaUtils::SortInstanceList( iInstanceArray ); |
|
433 |
|
434 iState = ESignalCaller; |
|
435 CompleteSelf(); |
|
436 |
|
437 } |
|
438 break; |
|
439 |
|
440 case ESignalCaller: |
|
441 { |
|
442 iState = EReady; |
|
443 iEngine.GetEntriesCompleted(); |
|
444 } |
|
445 break; |
|
446 |
|
447 default: |
|
448 { |
|
449 Panic( EInvalidState ); |
|
450 } |
|
451 } |
|
452 |
|
453 TRACE_EXIT_POINT; |
|
454 } |
|
455 |
|
456 // ----------------------------------------------------------------------------- |
|
457 // ?classname::?member_function |
|
458 // ?implementation_description |
|
459 // (other items were commented in a header). |
|
460 // ----------------------------------------------------------------------------- |
|
461 // |
|
462 void CGetEntriesCommand::DoCancel(void) |
|
463 { |
|
464 TRACE_ENTRY_POINT; |
|
465 |
|
466 iState = EFetch; |
|
467 |
|
468 TRACE_EXIT_POINT; |
|
469 } |
|
470 |
|
471 // ----------------------------------------------------------------------------- |
|
472 // ?classname::?member_function |
|
473 // ?implementation_description |
|
474 // (other items were commented in a header). |
|
475 // ----------------------------------------------------------------------------- |
|
476 // |
|
477 TInt CGetEntriesCommand::RunError(TInt aError) |
|
478 { |
|
479 TRACE_ENTRY_POINT; |
|
480 |
|
481 iEngine.HandleError( aError ); |
|
482 |
|
483 TRACE_EXIT_POINT; |
|
484 return KErrNone; |
|
485 } |
|
486 |
|
487 // ----------------------------------------------------------------------------- |
|
488 // ?classname::?member_function |
|
489 // ?implementation_description |
|
490 // (other items were commented in a header). |
|
491 // ----------------------------------------------------------------------------- |
|
492 // |
|
493 void CGetEntriesCommand::Panic(TInt aReason) |
|
494 { |
|
495 TRACE_ENTRY_POINT; |
|
496 |
|
497 __ASSERT_DEBUG( EFalse, User::Panic( _L("CGetEntriesCommand"), aReason ) ); |
|
498 |
|
499 TRACE_EXIT_POINT; |
|
500 } |
|
501 |
|
502 |
|
503 //////////////////////////////////////////////////////////////////////// |
|
504 // CGetNextEventCommand method definitions |
|
505 /////////////////////////////////////////////////////////////////////// |
|
506 |
|
507 // ----------------------------------------------------------------------------- |
|
508 // ?classname::?member_function |
|
509 // ?implementation_description |
|
510 // (other items were commented in a header). |
|
511 // ----------------------------------------------------------------------------- |
|
512 // |
|
513 CGetNextEventCommand* CGetNextEventCommand::NewL( CCalenEngine& aEngine, |
|
514 const TTime& aStartDay, |
|
515 const TInt aDaysToSearch, |
|
516 RPointerArray<CCalInstance>& aInstanceArray ) |
|
517 { |
|
518 TRACE_ENTRY_POINT; |
|
519 |
|
520 CGetNextEventCommand* self = new( ELeave )CGetNextEventCommand( aEngine, aStartDay, aDaysToSearch, aInstanceArray ); |
|
521 |
|
522 TRACE_EXIT_POINT; |
|
523 return self; |
|
524 } |
|
525 |
|
526 // ----------------------------------------------------------------------------- |
|
527 // ?classname::?member_function |
|
528 // ?implementation_description |
|
529 // (other items were commented in a header). |
|
530 // ----------------------------------------------------------------------------- |
|
531 // |
|
532 CGetNextEventCommand::CGetNextEventCommand(CCalenEngine& aEngine, const TTime& aStartDay, const TInt aDaysToSearch, RPointerArray<CCalInstance>& aInstanceArray) |
|
533 : CMultistepCommandBase( aEngine ), |
|
534 iState( EFetch ), |
|
535 iStartDay( aStartDay ), |
|
536 iDaysToSearch( aDaysToSearch ), |
|
537 iInstanceArray( aInstanceArray ) |
|
538 { |
|
539 TRACE_ENTRY_POINT; |
|
540 TRACE_EXIT_POINT; |
|
541 } |
|
542 |
|
543 // ----------------------------------------------------------------------------- |
|
544 // ?classname::?member_function |
|
545 // ?implementation_description |
|
546 // (other items were commented in a header). |
|
547 // ----------------------------------------------------------------------------- |
|
548 // |
|
549 CGetNextEventCommand::~CGetNextEventCommand(void) |
|
550 { |
|
551 TRACE_ENTRY_POINT; |
|
552 |
|
553 Cancel(); |
|
554 iTmpArray.ResetAndDestroy(); |
|
555 |
|
556 TRACE_EXIT_POINT; |
|
557 } |
|
558 |
|
559 // ----------------------------------------------------------------------------- |
|
560 // ?classname::?member_function |
|
561 // ?implementation_description |
|
562 // (other items were commented in a header). |
|
563 // ----------------------------------------------------------------------------- |
|
564 // |
|
565 void CGetNextEventCommand::RunL(void) |
|
566 { |
|
567 TRACE_ENTRY_POINT; |
|
568 |
|
569 if (iStatus.Int()) |
|
570 { |
|
571 return; |
|
572 } |
|
573 |
|
574 switch( iState ) |
|
575 { |
|
576 case EFetch: |
|
577 { |
|
578 if( !iEngine.iInstanceView ) |
|
579 { |
|
580 iState = EFinalize; |
|
581 CompleteSelf(); |
|
582 } |
|
583 else |
|
584 { |
|
585 // create date range and fetch entries |
|
586 |
|
587 CalCommon::TCalViewFilter filter = CalCommon::EIncludeAppts | |
|
588 CalCommon::EIncludeReminder; |
|
589 |
|
590 TTime endDay = iStartDay +TTimeIntervalDays( iDaysToSearch-1 ); |
|
591 |
|
592 CalenAgendaUtils::FindEventsForDayRangeL( iEngine.iInstanceView, iTmpArray, filter, iStartDay, endDay ); |
|
593 |
|
594 iState = EFinalize; |
|
595 CompleteSelf(); |
|
596 } |
|
597 } |
|
598 break; |
|
599 |
|
600 case EFinalize: |
|
601 { |
|
602 if( iTmpArray.Count() ) |
|
603 { |
|
604 CalenAgendaUtils::SortInstanceList( iTmpArray ); |
|
605 |
|
606 iStartDay = CalenDateUtils::BeginningOfDay( iStartDay ); |
|
607 |
|
608 // Find first event starting on iStartDay or later |
|
609 for(TInt i(0); i<iTmpArray.Count(); i++) |
|
610 { |
|
611 if( iTmpArray[i]->StartTimeL().TimeLocalL() >= iStartDay ) |
|
612 { |
|
613 iInstanceArray.AppendL( iTmpArray[i] ); |
|
614 iTmpArray.Remove( i ); |
|
615 break; |
|
616 } |
|
617 } |
|
618 } |
|
619 |
|
620 iTmpArray.ResetAndDestroy(); |
|
621 iState = ESignalCaller; |
|
622 CompleteSelf(); |
|
623 } |
|
624 break; |
|
625 |
|
626 case ESignalCaller: |
|
627 { |
|
628 iState = EReady; |
|
629 iEngine.GetFutureEventCompleted(); |
|
630 } |
|
631 break; |
|
632 |
|
633 default: |
|
634 { |
|
635 Panic( EInvalidState ); |
|
636 } |
|
637 } |
|
638 |
|
639 TRACE_EXIT_POINT; |
|
640 } |
|
641 |
|
642 // ----------------------------------------------------------------------------- |
|
643 // ?classname::?member_function |
|
644 // ?implementation_description |
|
645 // (other items were commented in a header). |
|
646 // ----------------------------------------------------------------------------- |
|
647 // |
|
648 void CGetNextEventCommand::DoCancel(void) |
|
649 { |
|
650 TRACE_ENTRY_POINT; |
|
651 |
|
652 iState = EFetch; |
|
653 |
|
654 TRACE_EXIT_POINT; |
|
655 } |
|
656 |
|
657 // ----------------------------------------------------------------------------- |
|
658 // ?classname::?member_function |
|
659 // ?implementation_description |
|
660 // (other items were commented in a header). |
|
661 // ----------------------------------------------------------------------------- |
|
662 // |
|
663 TInt CGetNextEventCommand::RunError(TInt aError) |
|
664 { |
|
665 TRACE_ENTRY_POINT; |
|
666 |
|
667 iTmpArray.ResetAndDestroy(); |
|
668 iEngine.HandleError( aError ); |
|
669 |
|
670 TRACE_EXIT_POINT; |
|
671 return KErrNone; |
|
672 } |
|
673 |
|
674 // ----------------------------------------------------------------------------- |
|
675 // ?classname::?member_function |
|
676 // ?implementation_description |
|
677 // (other items were commented in a header). |
|
678 // ----------------------------------------------------------------------------- |
|
679 // |
|
680 void CGetNextEventCommand::Panic(TInt aReason) |
|
681 { |
|
682 TRACE_ENTRY_POINT; |
|
683 |
|
684 __ASSERT_DEBUG( EFalse, User::Panic( _L("CGetNextEventCommand"), aReason ) ); |
|
685 |
|
686 TRACE_EXIT_POINT; |
|
687 } |
|
688 |
|
689 |
|
690 /////////////////////////////////////////////////////////////// |
|
691 // CGetTodos |
|
692 /////////////////////////////////////////////////////////////// |
|
693 |
|
694 // ----------------------------------------------------------------------------- |
|
695 // ?classname::?member_function |
|
696 // ?implementation_description |
|
697 // (other items were commented in a header). |
|
698 // ----------------------------------------------------------------------------- |
|
699 // |
|
700 CGetTodosCommand* CGetTodosCommand::NewL( CCalenEngine& aEngine, |
|
701 RPointerArray<CCalInstance>& aInstanceArray ) |
|
702 { |
|
703 TRACE_ENTRY_POINT; |
|
704 |
|
705 CGetTodosCommand* self = new( ELeave )CGetTodosCommand( aEngine, aInstanceArray ); |
|
706 |
|
707 TRACE_EXIT_POINT; |
|
708 return self; |
|
709 } |
|
710 |
|
711 // ----------------------------------------------------------------------------- |
|
712 // ?classname::?member_function |
|
713 // ?implementation_description |
|
714 // (other items were commented in a header). |
|
715 // ----------------------------------------------------------------------------- |
|
716 // |
|
717 CGetTodosCommand::CGetTodosCommand(CCalenEngine& aEngine, RPointerArray<CCalInstance>& aInstanceArray) |
|
718 : CMultistepCommandBase( aEngine ), |
|
719 iState( EFetchInstances ), |
|
720 iInstanceArray( aInstanceArray ) |
|
721 { |
|
722 TRACE_ENTRY_POINT; |
|
723 TRACE_EXIT_POINT; |
|
724 } |
|
725 |
|
726 // ----------------------------------------------------------------------------- |
|
727 // ?classname::?member_function |
|
728 // ?implementation_description |
|
729 // (other items were commented in a header). |
|
730 // ----------------------------------------------------------------------------- |
|
731 // |
|
732 CGetTodosCommand::~CGetTodosCommand() |
|
733 { |
|
734 TRACE_ENTRY_POINT; |
|
735 |
|
736 Cancel(); |
|
737 |
|
738 TRACE_EXIT_POINT; |
|
739 } |
|
740 |
|
741 // ----------------------------------------------------------------------------- |
|
742 // ?classname::?member_function |
|
743 // ?implementation_description |
|
744 // (other items were commented in a header). |
|
745 // ----------------------------------------------------------------------------- |
|
746 // |
|
747 void CGetTodosCommand::RunL(void) |
|
748 { |
|
749 TRACE_ENTRY_POINT; |
|
750 |
|
751 if (iStatus.Int()) |
|
752 { |
|
753 return; |
|
754 } |
|
755 |
|
756 switch( iState ) |
|
757 { |
|
758 case EFetchInstances: |
|
759 { |
|
760 TCalTime dummy; |
|
761 CalCommon::TCalTimeRange dayRange( dummy, dummy ); |
|
762 CalenDateUtils::GetDayRangeL( TCalTime::MinTime(), TCalTime::MaxTime(), dayRange ); |
|
763 |
|
764 if( !iEngine.iInstanceView ) |
|
765 { |
|
766 iState = ESignalCaller; |
|
767 CompleteSelf(); |
|
768 } |
|
769 else |
|
770 { |
|
771 iEngine.iInstanceView->FindInstanceL( iInstanceArray, |
|
772 CalCommon::EIncludeIncompletedTodos | |
|
773 // only fetch the first instance for repeating to-dos! |
|
774 CalCommon::EIncludeRptsNextInstanceOnly, |
|
775 dayRange ); |
|
776 |
|
777 iState = ESignalCaller; |
|
778 CompleteSelf(); |
|
779 } |
|
780 } |
|
781 break; |
|
782 |
|
783 case ESignalCaller: |
|
784 { |
|
785 iState = EReady; |
|
786 iEngine.GetTodosCompleted(); |
|
787 } |
|
788 break; |
|
789 |
|
790 default: |
|
791 { |
|
792 Panic( EInvalidState ); |
|
793 } |
|
794 } |
|
795 |
|
796 TRACE_EXIT_POINT; |
|
797 } |
|
798 |
|
799 // ----------------------------------------------------------------------------- |
|
800 // ?classname::?member_function |
|
801 // ?implementation_description |
|
802 // (other items were commented in a header). |
|
803 // ----------------------------------------------------------------------------- |
|
804 // |
|
805 void CGetTodosCommand::DoCancel(void) |
|
806 { |
|
807 TRACE_ENTRY_POINT; |
|
808 |
|
809 iState = EFetchInstances; |
|
810 |
|
811 TRACE_EXIT_POINT; |
|
812 } |
|
813 |
|
814 // ----------------------------------------------------------------------------- |
|
815 // ?classname::?member_function |
|
816 // ?implementation_description |
|
817 // (other items were commented in a header). |
|
818 // ----------------------------------------------------------------------------- |
|
819 // |
|
820 TInt CGetTodosCommand::RunError(TInt aError) |
|
821 { |
|
822 TRACE_ENTRY_POINT; |
|
823 |
|
824 iEngine.HandleError( aError ); |
|
825 |
|
826 TRACE_EXIT_POINT; |
|
827 return KErrNone; |
|
828 } |
|
829 |
|
830 // ----------------------------------------------------------------------------- |
|
831 // ?classname::?member_function |
|
832 // ?implementation_description |
|
833 // (other items were commented in a header). |
|
834 // ----------------------------------------------------------------------------- |
|
835 // |
|
836 void CGetTodosCommand::Panic(TInt aReason) |
|
837 { |
|
838 TRACE_ENTRY_POINT; |
|
839 |
|
840 __ASSERT_DEBUG( EFalse, User::Panic( _L("CGetTodosCommand"), aReason ) ); |
|
841 |
|
842 TRACE_EXIT_POINT; |
|
843 } |
|
844 |
|
845 |
|
846 //////////////////////////////////////////////////////////////////////// |
|
847 // CGetEntriesForDaysCommand method definitions |
|
848 /////////////////////////////////////////////////////////////////////// |
|
849 |
|
850 |
|
851 // ----------------------------------------------------------------------------- |
|
852 // ?classname::?member_function |
|
853 // ?implementation_description |
|
854 // (other items were commented in a header). |
|
855 // ----------------------------------------------------------------------------- |
|
856 // |
|
857 CGetEntriesForDaysCommand* CGetEntriesForDaysCommand::NewL( CCalenEngine& aEngine, |
|
858 RPointerArray<CCalInstance>& aInstanceArray, |
|
859 const TTime& aDay, |
|
860 TInt aDaysToSearch ) |
|
861 { |
|
862 TRACE_ENTRY_POINT; |
|
863 |
|
864 CGetEntriesForDaysCommand* self = new( ELeave )CGetEntriesForDaysCommand( aEngine, aInstanceArray, aDay, aDaysToSearch ); |
|
865 |
|
866 TRACE_EXIT_POINT; |
|
867 return self; |
|
868 } |
|
869 |
|
870 // ----------------------------------------------------------------------------- |
|
871 // ?classname::?member_function |
|
872 // ?implementation_description |
|
873 // (other items were commented in a header). |
|
874 // ----------------------------------------------------------------------------- |
|
875 // |
|
876 CGetEntriesForDaysCommand::CGetEntriesForDaysCommand( CCalenEngine& aEngine, |
|
877 RPointerArray<CCalInstance>& aInstanceArray, |
|
878 const TTime& aDay, |
|
879 TInt aDaysToSearch ) |
|
880 : CMultistepCommandBase( aEngine ), |
|
881 iState( EFetch ), |
|
882 iInstanceArray( aInstanceArray ), |
|
883 iDay( aDay ), |
|
884 iDaysToSearch( aDaysToSearch ) |
|
885 { |
|
886 TRACE_ENTRY_POINT; |
|
887 TRACE_EXIT_POINT; |
|
888 } |
|
889 |
|
890 // ----------------------------------------------------------------------------- |
|
891 // ?classname::?member_function |
|
892 // ?implementation_description |
|
893 // (other items were commented in a header). |
|
894 // ----------------------------------------------------------------------------- |
|
895 // |
|
896 CGetEntriesForDaysCommand::~CGetEntriesForDaysCommand() |
|
897 { |
|
898 TRACE_ENTRY_POINT; |
|
899 |
|
900 Cancel(); |
|
901 |
|
902 TRACE_EXIT_POINT; |
|
903 } |
|
904 |
|
905 // ----------------------------------------------------------------------------- |
|
906 // ?classname::?member_function |
|
907 // ?implementation_description |
|
908 // (other items were commented in a header). |
|
909 // ----------------------------------------------------------------------------- |
|
910 // |
|
911 void CGetEntriesForDaysCommand::RunL(void) |
|
912 { |
|
913 TRACE_ENTRY_POINT; |
|
914 |
|
915 if (iStatus.Int()) |
|
916 { |
|
917 return; |
|
918 } |
|
919 |
|
920 switch( iState ) |
|
921 { |
|
922 case EFetch: |
|
923 { |
|
924 if( !iEngine.iInstanceView ) |
|
925 { |
|
926 iState = EFinalize; |
|
927 CompleteSelf(); |
|
928 } |
|
929 else |
|
930 { |
|
931 TTime endDay = iDay +TTimeIntervalDays( iDaysToSearch-1 ); |
|
932 CalCommon::TCalViewFilter filter = CalCommon::EIncludeAppts | |
|
933 CalCommon::EIncludeReminder | |
|
934 CalCommon::EIncludeEvents | |
|
935 CalCommon::EIncludeAnnivs; |
|
936 |
|
937 CalenAgendaUtils::FindTodosForDayRangeL( iEngine.iInstanceView, iInstanceArray, iDay, endDay ); |
|
938 CalenAgendaUtils::FindEventsForDayRangeL( iEngine.iInstanceView, iInstanceArray, filter, iDay, endDay ); |
|
939 CalenAgendaUtils::RemoveEntriesEndingAtMidnightL( iInstanceArray, iDay ); |
|
940 |
|
941 iState = EFinalize; |
|
942 CompleteSelf(); |
|
943 } |
|
944 } |
|
945 break; |
|
946 |
|
947 case EFinalize: |
|
948 { |
|
949 // remove all cancelled meetings |
|
950 for( TInt i(0); i<iInstanceArray.Count(); ) |
|
951 { |
|
952 CCalEntry& entry = iInstanceArray[i]->Entry(); |
|
953 |
|
954 if( entry.EntryTypeL() == CCalEntry::EAppt && |
|
955 entry.StatusL() == CCalEntry::ECancelled ) |
|
956 { |
|
957 CCalInstance* instance = iInstanceArray[i]; |
|
958 iInstanceArray.Remove( i ); |
|
959 delete instance; |
|
960 } |
|
961 else |
|
962 { |
|
963 i++; |
|
964 } |
|
965 } |
|
966 |
|
967 CalenAgendaUtils::SortInstanceList( iInstanceArray ); |
|
968 |
|
969 iState = ESignalCaller; |
|
970 CompleteSelf(); |
|
971 } |
|
972 break; |
|
973 |
|
974 case ESignalCaller: |
|
975 { |
|
976 iState = EReady; |
|
977 iEngine.GetCalendarDataCompleted(); |
|
978 } |
|
979 break; |
|
980 |
|
981 default: |
|
982 { |
|
983 Panic( EInvalidState ); |
|
984 } |
|
985 } |
|
986 |
|
987 TRACE_EXIT_POINT; |
|
988 } |
|
989 |
|
990 // ----------------------------------------------------------------------------- |
|
991 // ?classname::?member_function |
|
992 // ?implementation_description |
|
993 // (other items were commented in a header). |
|
994 // ----------------------------------------------------------------------------- |
|
995 // |
|
996 void CGetEntriesForDaysCommand::DoCancel(void) |
|
997 { |
|
998 TRACE_ENTRY_POINT; |
|
999 |
|
1000 iState = EFetch; |
|
1001 |
|
1002 TRACE_EXIT_POINT; |
|
1003 } |
|
1004 |
|
1005 // ----------------------------------------------------------------------------- |
|
1006 // ?classname::?member_function |
|
1007 // ?implementation_description |
|
1008 // (other items were commented in a header). |
|
1009 // ----------------------------------------------------------------------------- |
|
1010 // |
|
1011 TInt CGetEntriesForDaysCommand::RunError(TInt aError) |
|
1012 { |
|
1013 TRACE_ENTRY_POINT; |
|
1014 |
|
1015 iEngine.HandleError( aError ); |
|
1016 return KErrNone; |
|
1017 } |
|
1018 |
|
1019 // ----------------------------------------------------------------------------- |
|
1020 // ?classname::?member_function |
|
1021 // ?implementation_description |
|
1022 // (other items were commented in a header). |
|
1023 // ----------------------------------------------------------------------------- |
|
1024 // |
|
1025 void CGetEntriesForDaysCommand::Panic(TInt aReason) |
|
1026 { |
|
1027 TRACE_ENTRY_POINT; |
|
1028 |
|
1029 __ASSERT_DEBUG( EFalse, User::Panic( _L("CGetEntriesForDaysCommand"), aReason ) ); |
|
1030 |
|
1031 TRACE_EXIT_POINT; |
|
1032 } |
|
1033 |
|
1034 |
|
1035 // End of File |