66
|
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 |
#ifdef _DEBUG
|
|
147 |
RDebug::Print(calFileName);
|
|
148 |
#endif
|
|
149 |
if (!calFileName.CompareF(defaultSession->DefaultFileNameL()))
|
|
150 |
{
|
|
151 |
CleanupStack::PushL(defaultSession);
|
|
152 |
defaultSession->OpenL(calFileName);
|
|
153 |
CleanupStack::Pop(defaultSession);
|
|
154 |
|
|
155 |
tempSession = defaultSession;
|
|
156 |
iCalInfoArray[index].iColltectionId
|
|
157 |
= tempSession->CollectionIdL();
|
|
158 |
}
|
|
159 |
else
|
|
160 |
{
|
|
161 |
tempSession = CCalSession::NewL(*defaultSession);
|
|
162 |
CleanupStack::PushL(tempSession);
|
|
163 |
tempSession->OpenL(calFileName);
|
|
164 |
CleanupStack::Pop(tempSession);
|
|
165 |
iCalInfoArray[index].iColltectionId
|
|
166 |
= tempSession->CollectionIdL();
|
|
167 |
|
|
168 |
iSessionOwningArray.AppendL(tempSession);
|
|
169 |
}
|
|
170 |
iSessionReferanceArray.AppendL(tempSession);
|
|
171 |
}
|
|
172 |
|
|
173 |
TRACE_EXIT_POINT;
|
|
174 |
}
|
|
175 |
|
|
176 |
// -----------------------------------------------------------------------------
|
|
177 |
// CCalenEngine::GetAllCalendarsL
|
|
178 |
// -----------------------------------------------------------------------------
|
|
179 |
//
|
|
180 |
void CCalenEngine::GetAllCalendarInfoL( )
|
|
181 |
{
|
|
182 |
TRACE_ENTRY_POINT
|
|
183 |
CCalSession* sessionIter = CCalSession::NewL();
|
|
184 |
CleanupStack::PushL(sessionIter);
|
|
185 |
CCalCalendarIterator* calIter = CCalCalendarIterator::NewL(*sessionIter);
|
|
186 |
CleanupStack::PushL(calIter);
|
|
187 |
|
|
188 |
for(CCalCalendarInfo* calendarInfo = calIter->FirstL() ;
|
|
189 |
calendarInfo != NULL ; calendarInfo = calIter->NextL() )
|
|
190 |
{
|
|
191 |
if(calendarInfo->Enabled())
|
|
192 |
{
|
|
193 |
TCalInfo calInfo;
|
|
194 |
calInfo.iFileName = calendarInfo->FileNameL();
|
|
195 |
calInfo.iColor = calendarInfo->Color().Value();
|
|
196 |
iCalInfoArray.AppendL(calInfo);
|
|
197 |
}
|
|
198 |
delete calendarInfo;
|
|
199 |
}
|
|
200 |
|
|
201 |
CleanupStack::PopAndDestroy(calIter);
|
|
202 |
CleanupStack::PopAndDestroy(sessionIter);
|
|
203 |
TRACE_EXIT_POINT
|
|
204 |
}
|
|
205 |
|
|
206 |
// -----------------------------------------------------------------------------
|
|
207 |
// CCalenEngine::Reset
|
|
208 |
// -----------------------------------------------------------------------------
|
|
209 |
//
|
|
210 |
void CCalenEngine::Reset()
|
|
211 |
{
|
|
212 |
TRACE_ENTRY_POINT
|
|
213 |
if(iCalInfoArray.Count())
|
|
214 |
{
|
|
215 |
iCalInfoArray.Reset();
|
|
216 |
}
|
|
217 |
|
|
218 |
if (iSessionReferanceArray.Count())
|
|
219 |
{
|
|
220 |
iSessionReferanceArray.Reset();
|
|
221 |
}
|
|
222 |
|
|
223 |
if (iSessionOwningArray.Count())
|
|
224 |
{
|
|
225 |
iSessionOwningArray.ResetAndDestroy();
|
|
226 |
}
|
|
227 |
TRACE_EXIT_POINT
|
|
228 |
}
|
|
229 |
|
|
230 |
// -----------------------------------------------------------------------------
|
|
231 |
// ?implementation_description
|
|
232 |
// -----------------------------------------------------------------------------
|
|
233 |
//
|
|
234 |
void CCalenEngine::StartCommand( CMultistepCommandBase* aCommand,
|
|
235 |
MCalenEngineGeneralCallback& aCallback )
|
|
236 |
{
|
|
237 |
TRACE_ENTRY_POINT;
|
|
238 |
|
|
239 |
__ASSERT_ALWAYS(iCommand == NULL, Panic(EMultipleCommands));
|
|
240 |
iCallback = &aCallback;
|
|
241 |
iCommand = aCommand;
|
|
242 |
iCommand->Start();
|
|
243 |
|
|
244 |
TRACE_EXIT_POINT;
|
|
245 |
}
|
|
246 |
|
|
247 |
// -----------------------------------------------------------------------------
|
|
248 |
// ?implementation_description
|
|
249 |
// -----------------------------------------------------------------------------
|
|
250 |
//
|
|
251 |
void CCalenEngine::FinishCommand()
|
|
252 |
{
|
|
253 |
TRACE_ENTRY_POINT;
|
|
254 |
|
|
255 |
__ASSERT_ALWAYS(iCommand != NULL, User::Invariant());
|
|
256 |
delete iCommand;
|
|
257 |
iCommand = NULL;
|
|
258 |
|
|
259 |
TRACE_EXIT_POINT;
|
|
260 |
}
|
|
261 |
|
|
262 |
// -----------------------------------------------------------------------------
|
|
263 |
// ?implementation_description
|
|
264 |
// -----------------------------------------------------------------------------
|
|
265 |
//
|
|
266 |
void CCalenEngine::OpenDatabaseL(MCalenEngineOpenCallback& aCallback)
|
|
267 |
{
|
|
268 |
TRACE_ENTRY_POINT;
|
|
269 |
|
|
270 |
StartCommand(new (ELeave) COpenCommand(*this), aCallback);
|
|
271 |
|
|
272 |
TRACE_EXIT_POINT;
|
|
273 |
}
|
|
274 |
|
|
275 |
// -----------------------------------------------------------------------------
|
|
276 |
// ?implementation_description
|
|
277 |
// -----------------------------------------------------------------------------
|
|
278 |
//
|
|
279 |
void CCalenEngine::OpenCompleted()
|
|
280 |
{
|
|
281 |
TRACE_ENTRY_POINT;
|
|
282 |
|
|
283 |
FinishCommand();
|
|
284 |
static_cast<MCalenEngineOpenCallback*>(iCallback)->OpenDatabaseCompleted();
|
|
285 |
|
|
286 |
TRACE_EXIT_POINT;
|
|
287 |
}
|
|
288 |
|
|
289 |
// -----------------------------------------------------------------------------
|
|
290 |
// ?implementation_description
|
|
291 |
// -----------------------------------------------------------------------------
|
|
292 |
//
|
|
293 |
void CCalenEngine::GetEntriesForDayL( MCalenEngineEntryFetchCallback& aCallback,
|
|
294 |
const TTime& aDay,
|
|
295 |
RPointerArray<CCalInstance>& aInstanceArray )
|
|
296 |
{
|
|
297 |
TRACE_ENTRY_POINT;
|
|
298 |
|
|
299 |
StartCommand(
|
|
300 |
CGetEntriesCommand::NewL( *this, aDay, aInstanceArray ),
|
|
301 |
aCallback );
|
|
302 |
|
|
303 |
TRACE_EXIT_POINT;
|
|
304 |
}
|
|
305 |
|
|
306 |
// -----------------------------------------------------------------------------
|
|
307 |
// ?implementation_description
|
|
308 |
// -----------------------------------------------------------------------------
|
|
309 |
//
|
|
310 |
void CCalenEngine::GetEventForNextSevenDaysL( MCalenEngineEntryFetchCallback& aCallback,
|
|
311 |
const TTime& aStartDay, const TInt aDaysToSearch,
|
|
312 |
RPointerArray<CCalInstance>& aInstanceArray )
|
|
313 |
{
|
|
314 |
TRACE_ENTRY_POINT;
|
|
315 |
|
|
316 |
StartCommand(
|
|
317 |
CGetNextEventCommand::NewL( *this, aStartDay, aDaysToSearch, aInstanceArray ),
|
|
318 |
aCallback );
|
|
319 |
|
|
320 |
TRACE_EXIT_POINT;
|
|
321 |
}
|
|
322 |
|
|
323 |
// -----------------------------------------------------------------------------
|
|
324 |
// ?implementation_description
|
|
325 |
// -----------------------------------------------------------------------------
|
|
326 |
//
|
|
327 |
void CCalenEngine::GetTodosL( MCalenEngineEntryFetchCallback& aCallback,
|
|
328 |
RPointerArray<CCalInstance>& aInstanceArray )
|
|
329 |
{
|
|
330 |
TRACE_ENTRY_POINT;
|
|
331 |
|
|
332 |
StartCommand(
|
|
333 |
CGetTodosCommand::NewL( *this, aInstanceArray ),
|
|
334 |
aCallback );
|
|
335 |
|
|
336 |
TRACE_EXIT_POINT;
|
|
337 |
}
|
|
338 |
|
|
339 |
// -----------------------------------------------------------------------------
|
|
340 |
// ?implementation_description
|
|
341 |
// -----------------------------------------------------------------------------
|
|
342 |
//
|
|
343 |
void CCalenEngine::GetCalendarDataL( MCalenEngineEntryFetchCallback& aCallback,
|
|
344 |
RPointerArray<CCalInstance>& aInstanceArray,
|
|
345 |
const TTime& aStartDay,
|
|
346 |
const TInt aDaysToSearch )
|
|
347 |
{
|
|
348 |
TRACE_ENTRY_POINT;
|
|
349 |
|
|
350 |
StartCommand(
|
|
351 |
CGetEntriesForDaysCommand::NewL( *this, aInstanceArray, aStartDay, aDaysToSearch ),
|
|
352 |
aCallback );
|
|
353 |
|
|
354 |
TRACE_EXIT_POINT;
|
|
355 |
}
|
|
356 |
|
|
357 |
// -----------------------------------------------------------------------------
|
|
358 |
// ?implementation_description
|
|
359 |
// -----------------------------------------------------------------------------
|
|
360 |
//
|
|
361 |
void CCalenEngine::GetEntriesCompleted()
|
|
362 |
{
|
|
363 |
TRACE_ENTRY_POINT;
|
|
364 |
|
|
365 |
FinishCommand();
|
|
366 |
static_cast<MCalenEngineEntryFetchCallback*>(iCallback)->GetEntriesCompleted();
|
|
367 |
|
|
368 |
TRACE_EXIT_POINT;
|
|
369 |
}
|
|
370 |
|
|
371 |
// -----------------------------------------------------------------------------
|
|
372 |
// ?implementation_description
|
|
373 |
// -----------------------------------------------------------------------------
|
|
374 |
//
|
|
375 |
void CCalenEngine::GetTodosCompleted()
|
|
376 |
{
|
|
377 |
TRACE_ENTRY_POINT;
|
|
378 |
|
|
379 |
FinishCommand();
|
|
380 |
static_cast<MCalenEngineEntryFetchCallback*>(iCallback)->GetTodosCompleted();
|
|
381 |
|
|
382 |
TRACE_EXIT_POINT;
|
|
383 |
}
|
|
384 |
|
|
385 |
// -----------------------------------------------------------------------------
|
|
386 |
// ?implementation_description
|
|
387 |
// -----------------------------------------------------------------------------
|
|
388 |
//
|
|
389 |
void CCalenEngine::GetFutureEventCompleted(void)
|
|
390 |
{
|
|
391 |
TRACE_ENTRY_POINT;
|
|
392 |
|
|
393 |
FinishCommand();
|
|
394 |
static_cast<MCalenEngineEntryFetchCallback*>(iCallback)->GetFutureEventCompleted();
|
|
395 |
|
|
396 |
TRACE_EXIT_POINT;
|
|
397 |
}
|
|
398 |
|
|
399 |
// -----------------------------------------------------------------------------
|
|
400 |
// ?implementation_description
|
|
401 |
// -----------------------------------------------------------------------------
|
|
402 |
//
|
|
403 |
void CCalenEngine::GetCalendarDataCompleted(void)
|
|
404 |
{
|
|
405 |
TRACE_ENTRY_POINT;
|
|
406 |
|
|
407 |
FinishCommand();
|
|
408 |
static_cast<MCalenEngineEntryFetchCallback*>(iCallback)->GetCalendarDataCompleted();
|
|
409 |
|
|
410 |
TRACE_EXIT_POINT;
|
|
411 |
}
|
|
412 |
|
|
413 |
// -----------------------------------------------------------------------------
|
|
414 |
// ?implementation_description
|
|
415 |
// -----------------------------------------------------------------------------
|
|
416 |
//
|
|
417 |
void CCalenEngine::HandleError(TInt aError)
|
|
418 |
{
|
|
419 |
TRACE_ENTRY_POINT;
|
|
420 |
|
|
421 |
FinishCommand();
|
|
422 |
static_cast<MCalenEngineGeneralCallback*>(iCallback)->HandleError( aError );
|
|
423 |
|
|
424 |
TRACE_EXIT_POINT;
|
|
425 |
}
|
|
426 |
|
|
427 |
// -----------------------------------------------------------------------------
|
|
428 |
// ?implementation_description
|
|
429 |
// -----------------------------------------------------------------------------
|
|
430 |
//
|
|
431 |
void CCalenEngine::ReleaseCalendarDatabase()
|
|
432 |
{
|
|
433 |
TRACE_ENTRY_POINT;
|
|
434 |
|
|
435 |
delete iInstanceView;
|
|
436 |
iInstanceView = NULL;
|
|
437 |
|
|
438 |
Reset();
|
|
439 |
|
|
440 |
TRACE_EXIT_POINT;
|
|
441 |
}
|
|
442 |
|
|
443 |
|
|
444 |
// End of File
|