|
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: This class is wrapper class of agenda engine. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 //debug |
|
20 #include "calendarui_debug.h" |
|
21 |
|
22 // INCLUDES |
|
23 #include "CalenEngine.h" |
|
24 #include "CalenAsyncCommands.h" |
|
25 #include "CalEngineCallback.h" |
|
26 #include "CleanupResetAndDestroy.h" |
|
27 |
|
28 |
|
29 #include <calinstanceview.h> |
|
30 #include <calsession.h> |
|
31 #include <calcalendarinfo.h> |
|
32 #include <calcalendariterator.h> |
|
33 |
|
34 enum TCalenEnginePanic |
|
35 { |
|
36 EMultipleCommands = 0 |
|
37 }; |
|
38 |
|
39 |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // ?implementation_description |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 static void Panic(TInt aReason) |
|
46 { |
|
47 TRACE_ENTRY_POINT; |
|
48 |
|
49 _LIT(KPanicCategory, "CalenEngine"); |
|
50 User::Panic(KPanicCategory, aReason); |
|
51 |
|
52 TRACE_EXIT_POINT; |
|
53 } |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // ?implementation_description |
|
57 // ----------------------------------------------------------------------------- |
|
58 // |
|
59 CCalenEngine::CCalenEngine() |
|
60 { |
|
61 TRACE_ENTRY_POINT; |
|
62 |
|
63 TRACE_EXIT_POINT; |
|
64 } |
|
65 |
|
66 // ----------------------------------------------------------------------------- |
|
67 // ?implementation_description |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 CCalenEngine* CCalenEngine::NewL() |
|
71 { |
|
72 TRACE_ENTRY_POINT; |
|
73 |
|
74 CCalenEngine* self = new (ELeave) CCalenEngine; |
|
75 //CleanupStack::PushL(self); |
|
76 //self->ConstructL(); |
|
77 //CleanupStack::Pop(self); |
|
78 |
|
79 TRACE_EXIT_POINT; |
|
80 return self; |
|
81 } |
|
82 |
|
83 // ----------------------------------------------------------------------------- |
|
84 // ?implementation_description |
|
85 // ----------------------------------------------------------------------------- |
|
86 // |
|
87 CCalenEngine::~CCalenEngine() |
|
88 { |
|
89 TRACE_ENTRY_POINT; |
|
90 |
|
91 Close(); |
|
92 |
|
93 TRACE_EXIT_POINT; |
|
94 } |
|
95 |
|
96 // ----------------------------------------------------------------------------- |
|
97 // ?implementation_description |
|
98 // ----------------------------------------------------------------------------- |
|
99 // |
|
100 void CCalenEngine::Close() |
|
101 { |
|
102 TRACE_ENTRY_POINT; |
|
103 |
|
104 if( iCommand ) |
|
105 { |
|
106 // cancel all asynchronous operations before(!) deleting the object! |
|
107 iCommand->Cancel(); |
|
108 delete iCommand; |
|
109 iCommand = NULL; |
|
110 } |
|
111 ReleaseCalendarDatabase(); |
|
112 |
|
113 TRACE_EXIT_POINT; |
|
114 } |
|
115 |
|
116 // ----------------------------------------------------------------------------- |
|
117 // CCalenEngine::GetActiveSessionsL |
|
118 // ----------------------------------------------------------------------------- |
|
119 // |
|
120 RPointerArray<CCalSession>& CCalenEngine::GetActiveSessionsL() |
|
121 { |
|
122 TRACE_ENTRY_POINT; |
|
123 TRACE_EXIT_POINT; |
|
124 return iSessionReferanceArray; |
|
125 } |
|
126 |
|
127 // ----------------------------------------------------------------------------- |
|
128 // CCalenEngine::UpdateCalSessionsL |
|
129 // ----------------------------------------------------------------------------- |
|
130 // |
|
131 void CCalenEngine::UpdateCalSessionsL() |
|
132 { |
|
133 TRACE_ENTRY_POINT; |
|
134 |
|
135 Reset(); |
|
136 |
|
137 GetAllCalendarInfoL(); |
|
138 |
|
139 CCalSession* defaultSession = CCalSession::NewL(); //Default session |
|
140 iSessionOwningArray.AppendL(defaultSession); |
|
141 |
|
142 CCalSession* tempSession = NULL; //Temp session |
|
143 for (TInt index = 0; index < iCalInfoArray.Count(); index++) |
|
144 { |
|
145 TPtrC calFileName = iCalInfoArray[index].iFileName; |
|
146 |
|
147 RDebug::Print(calFileName); |
|
148 if (!calFileName.CompareF(defaultSession->DefaultFileNameL())) |
|
149 { |
|
150 CleanupStack::PushL(defaultSession); |
|
151 defaultSession->OpenL(calFileName); |
|
152 CleanupStack::Pop(defaultSession); |
|
153 |
|
154 tempSession = defaultSession; |
|
155 iCalInfoArray[index].iColltectionId |
|
156 = tempSession->CollectionIdL(); |
|
157 } |
|
158 else |
|
159 { |
|
160 tempSession = CCalSession::NewL(*defaultSession); |
|
161 CleanupStack::PushL(tempSession); |
|
162 tempSession->OpenL(calFileName); |
|
163 CleanupStack::Pop(tempSession); |
|
164 iCalInfoArray[index].iColltectionId |
|
165 = tempSession->CollectionIdL(); |
|
166 |
|
167 iSessionOwningArray.AppendL(tempSession); |
|
168 } |
|
169 iSessionReferanceArray.AppendL(tempSession); |
|
170 } |
|
171 |
|
172 TRACE_EXIT_POINT; |
|
173 } |
|
174 |
|
175 // ----------------------------------------------------------------------------- |
|
176 // CCalenEngine::GetAllCalendarsL |
|
177 // ----------------------------------------------------------------------------- |
|
178 // |
|
179 void CCalenEngine::GetAllCalendarInfoL( ) |
|
180 { |
|
181 TRACE_ENTRY_POINT |
|
182 CCalSession* sessionIter = CCalSession::NewL(); |
|
183 CleanupStack::PushL(sessionIter); |
|
184 CCalCalendarIterator* calIter = CCalCalendarIterator::NewL(*sessionIter); |
|
185 CleanupStack::PushL(calIter); |
|
186 |
|
187 for(CCalCalendarInfo* calendarInfo = calIter->FirstL() ; |
|
188 calendarInfo != NULL ; calendarInfo = calIter->NextL() ) |
|
189 { |
|
190 if(calendarInfo->Enabled()) |
|
191 { |
|
192 TCalInfo calInfo; |
|
193 calInfo.iFileName = calendarInfo->FileNameL(); |
|
194 calInfo.iColor = calendarInfo->Color().Value(); |
|
195 iCalInfoArray.AppendL(calInfo); |
|
196 } |
|
197 delete calendarInfo; |
|
198 } |
|
199 |
|
200 CleanupStack::PopAndDestroy(calIter); |
|
201 CleanupStack::PopAndDestroy(sessionIter); |
|
202 TRACE_EXIT_POINT |
|
203 } |
|
204 |
|
205 // ----------------------------------------------------------------------------- |
|
206 // CCalenEngine::Reset |
|
207 // ----------------------------------------------------------------------------- |
|
208 // |
|
209 void CCalenEngine::Reset() |
|
210 { |
|
211 TRACE_ENTRY_POINT |
|
212 if(iCalInfoArray.Count()) |
|
213 { |
|
214 iCalInfoArray.Reset(); |
|
215 } |
|
216 |
|
217 if (iSessionReferanceArray.Count()) |
|
218 { |
|
219 iSessionReferanceArray.Reset(); |
|
220 } |
|
221 |
|
222 if (iSessionOwningArray.Count()) |
|
223 { |
|
224 iSessionOwningArray.ResetAndDestroy(); |
|
225 } |
|
226 TRACE_EXIT_POINT |
|
227 } |
|
228 |
|
229 // ----------------------------------------------------------------------------- |
|
230 // ?implementation_description |
|
231 // ----------------------------------------------------------------------------- |
|
232 // |
|
233 void CCalenEngine::StartCommand( CMultistepCommandBase* aCommand, |
|
234 MCalenEngineGeneralCallback& aCallback ) |
|
235 { |
|
236 TRACE_ENTRY_POINT; |
|
237 |
|
238 __ASSERT_ALWAYS(iCommand == NULL, Panic(EMultipleCommands)); |
|
239 iCallback = &aCallback; |
|
240 iCommand = aCommand; |
|
241 iCommand->Start(); |
|
242 |
|
243 TRACE_EXIT_POINT; |
|
244 } |
|
245 |
|
246 // ----------------------------------------------------------------------------- |
|
247 // ?implementation_description |
|
248 // ----------------------------------------------------------------------------- |
|
249 // |
|
250 void CCalenEngine::FinishCommand() |
|
251 { |
|
252 TRACE_ENTRY_POINT; |
|
253 |
|
254 __ASSERT_ALWAYS(iCommand != NULL, User::Invariant()); |
|
255 delete iCommand; |
|
256 iCommand = NULL; |
|
257 |
|
258 TRACE_EXIT_POINT; |
|
259 } |
|
260 |
|
261 // ----------------------------------------------------------------------------- |
|
262 // ?implementation_description |
|
263 // ----------------------------------------------------------------------------- |
|
264 // |
|
265 void CCalenEngine::OpenDatabaseL(MCalenEngineOpenCallback& aCallback) |
|
266 { |
|
267 TRACE_ENTRY_POINT; |
|
268 |
|
269 StartCommand(new (ELeave) COpenCommand(*this), aCallback); |
|
270 |
|
271 TRACE_EXIT_POINT; |
|
272 } |
|
273 |
|
274 // ----------------------------------------------------------------------------- |
|
275 // ?implementation_description |
|
276 // ----------------------------------------------------------------------------- |
|
277 // |
|
278 void CCalenEngine::OpenCompleted() |
|
279 { |
|
280 TRACE_ENTRY_POINT; |
|
281 |
|
282 FinishCommand(); |
|
283 static_cast<MCalenEngineOpenCallback*>(iCallback)->OpenDatabaseCompleted(); |
|
284 |
|
285 TRACE_EXIT_POINT; |
|
286 } |
|
287 |
|
288 // ----------------------------------------------------------------------------- |
|
289 // ?implementation_description |
|
290 // ----------------------------------------------------------------------------- |
|
291 // |
|
292 void CCalenEngine::GetEntriesForDayL( MCalenEngineEntryFetchCallback& aCallback, |
|
293 const TTime& aDay, |
|
294 RPointerArray<CCalInstance>& aInstanceArray ) |
|
295 { |
|
296 TRACE_ENTRY_POINT; |
|
297 |
|
298 StartCommand( |
|
299 CGetEntriesCommand::NewL( *this, aDay, aInstanceArray ), |
|
300 aCallback ); |
|
301 |
|
302 TRACE_EXIT_POINT; |
|
303 } |
|
304 |
|
305 // ----------------------------------------------------------------------------- |
|
306 // ?implementation_description |
|
307 // ----------------------------------------------------------------------------- |
|
308 // |
|
309 void CCalenEngine::GetEventForNextSevenDaysL( MCalenEngineEntryFetchCallback& aCallback, |
|
310 const TTime& aStartDay, const TInt aDaysToSearch, |
|
311 RPointerArray<CCalInstance>& aInstanceArray ) |
|
312 { |
|
313 TRACE_ENTRY_POINT; |
|
314 |
|
315 StartCommand( |
|
316 CGetNextEventCommand::NewL( *this, aStartDay, aDaysToSearch, aInstanceArray ), |
|
317 aCallback ); |
|
318 |
|
319 TRACE_EXIT_POINT; |
|
320 } |
|
321 |
|
322 // ----------------------------------------------------------------------------- |
|
323 // ?implementation_description |
|
324 // ----------------------------------------------------------------------------- |
|
325 // |
|
326 void CCalenEngine::GetTodosL( MCalenEngineEntryFetchCallback& aCallback, |
|
327 RPointerArray<CCalInstance>& aInstanceArray ) |
|
328 { |
|
329 TRACE_ENTRY_POINT; |
|
330 |
|
331 StartCommand( |
|
332 CGetTodosCommand::NewL( *this, aInstanceArray ), |
|
333 aCallback ); |
|
334 |
|
335 TRACE_EXIT_POINT; |
|
336 } |
|
337 |
|
338 // ----------------------------------------------------------------------------- |
|
339 // ?implementation_description |
|
340 // ----------------------------------------------------------------------------- |
|
341 // |
|
342 void CCalenEngine::GetCalendarDataL( MCalenEngineEntryFetchCallback& aCallback, |
|
343 RPointerArray<CCalInstance>& aInstanceArray, |
|
344 const TTime& aStartDay, |
|
345 const TInt aDaysToSearch ) |
|
346 { |
|
347 TRACE_ENTRY_POINT; |
|
348 |
|
349 StartCommand( |
|
350 CGetEntriesForDaysCommand::NewL( *this, aInstanceArray, aStartDay, aDaysToSearch ), |
|
351 aCallback ); |
|
352 |
|
353 TRACE_EXIT_POINT; |
|
354 } |
|
355 |
|
356 // ----------------------------------------------------------------------------- |
|
357 // ?implementation_description |
|
358 // ----------------------------------------------------------------------------- |
|
359 // |
|
360 void CCalenEngine::GetEntriesCompleted() |
|
361 { |
|
362 TRACE_ENTRY_POINT; |
|
363 |
|
364 FinishCommand(); |
|
365 static_cast<MCalenEngineEntryFetchCallback*>(iCallback)->GetEntriesCompleted(); |
|
366 |
|
367 TRACE_EXIT_POINT; |
|
368 } |
|
369 |
|
370 // ----------------------------------------------------------------------------- |
|
371 // ?implementation_description |
|
372 // ----------------------------------------------------------------------------- |
|
373 // |
|
374 void CCalenEngine::GetTodosCompleted() |
|
375 { |
|
376 TRACE_ENTRY_POINT; |
|
377 |
|
378 FinishCommand(); |
|
379 static_cast<MCalenEngineEntryFetchCallback*>(iCallback)->GetTodosCompleted(); |
|
380 |
|
381 TRACE_EXIT_POINT; |
|
382 } |
|
383 |
|
384 // ----------------------------------------------------------------------------- |
|
385 // ?implementation_description |
|
386 // ----------------------------------------------------------------------------- |
|
387 // |
|
388 void CCalenEngine::GetFutureEventCompleted(void) |
|
389 { |
|
390 TRACE_ENTRY_POINT; |
|
391 |
|
392 FinishCommand(); |
|
393 static_cast<MCalenEngineEntryFetchCallback*>(iCallback)->GetFutureEventCompleted(); |
|
394 |
|
395 TRACE_EXIT_POINT; |
|
396 } |
|
397 |
|
398 // ----------------------------------------------------------------------------- |
|
399 // ?implementation_description |
|
400 // ----------------------------------------------------------------------------- |
|
401 // |
|
402 void CCalenEngine::GetCalendarDataCompleted(void) |
|
403 { |
|
404 TRACE_ENTRY_POINT; |
|
405 |
|
406 FinishCommand(); |
|
407 static_cast<MCalenEngineEntryFetchCallback*>(iCallback)->GetCalendarDataCompleted(); |
|
408 |
|
409 TRACE_EXIT_POINT; |
|
410 } |
|
411 |
|
412 // ----------------------------------------------------------------------------- |
|
413 // ?implementation_description |
|
414 // ----------------------------------------------------------------------------- |
|
415 // |
|
416 void CCalenEngine::HandleError(TInt aError) |
|
417 { |
|
418 TRACE_ENTRY_POINT; |
|
419 |
|
420 FinishCommand(); |
|
421 static_cast<MCalenEngineGeneralCallback*>(iCallback)->HandleError( aError ); |
|
422 |
|
423 TRACE_EXIT_POINT; |
|
424 } |
|
425 |
|
426 // ----------------------------------------------------------------------------- |
|
427 // ?implementation_description |
|
428 // ----------------------------------------------------------------------------- |
|
429 // |
|
430 void CCalenEngine::ReleaseCalendarDatabase() |
|
431 { |
|
432 TRACE_ENTRY_POINT; |
|
433 |
|
434 delete iInstanceView; |
|
435 iInstanceView = NULL; |
|
436 |
|
437 Reset(); |
|
438 |
|
439 TRACE_EXIT_POINT; |
|
440 } |
|
441 |
|
442 |
|
443 // End of File |