|
1 /* |
|
2 * Copyright (c) 2004 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 class methods for creating Db , boot and missed alarm manager |
|
15 * implements CServer2 methods as part of IPC message interaction with client. |
|
16 * |
|
17 */ |
|
18 |
|
19 #include <centralrepository.h> |
|
20 #include <CalendarInternalCRKeys.h> |
|
21 #include <calsession.h> |
|
22 #include <calcalendarinfo.h> |
|
23 #include <calenmulticalutil.h> |
|
24 #include <CalenInterimUtils2.h> |
|
25 #include <calensvrmissedalarmmanagerresource.rsg> |
|
26 #include <data_caging_path_literals.hrh> |
|
27 #include <bautils.h> |
|
28 #include <pathinfo.h> |
|
29 #include <calsession.h> |
|
30 |
|
31 //debug |
|
32 #include "calendarui_debug.h" |
|
33 |
|
34 // INCLUDES |
|
35 #include "CalenServer.h" |
|
36 |
|
37 #include "CalSvrSession.h" |
|
38 #include "CalSvrDef.h" |
|
39 //#include "CalenSvrAlarmManager.h" |
|
40 #include "CalenSvrBootManager.h" |
|
41 #include "CalenSvrDBManager.h" |
|
42 #include "calensvrmissedalarmmanager.h" |
|
43 #include "calenmissedalarmconstants.h" |
|
44 |
|
45 // LOCAL CONSTANTS AND MACROS |
|
46 |
|
47 const TInt KCalenServerPriority(CActive::EPriorityStandard); |
|
48 _LIT( KCalendarDatabaseFilePath, "c:calendar" ); |
|
49 const TInt KBufferStartingSize( 128 ); |
|
50 const TInt KBufferSizeIncrement( 64 ); |
|
51 const TInt KBuffLength = 128; |
|
52 |
|
53 |
|
54 const TInt KComma( ',' ); |
|
55 |
|
56 _LIT(KPersonal,"Personal"); |
|
57 |
|
58 |
|
59 // ================= MEMBER FUNCTIONS ======================= |
|
60 // |
|
61 // Construction and destruction |
|
62 // |
|
63 // ----------------------------------------------------------------------------- |
|
64 // ?classname::?member_function |
|
65 // ?implementation_description |
|
66 // (other items were commented in a header). |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 CCalenServer* CCalenServer::NewL() |
|
70 { |
|
71 TRACE_ENTRY_POINT; |
|
72 |
|
73 CCalenServer* server = new( ELeave )CCalenServer( KCalenServerPriority ); |
|
74 |
|
75 CleanupStack::PushL(server); |
|
76 server->ConstructL(); |
|
77 CleanupStack::Pop(); |
|
78 |
|
79 TRACE_EXIT_POINT; |
|
80 return server; |
|
81 } |
|
82 |
|
83 // ----------------------------------------------------------------------------- |
|
84 // ?classname::?member_function |
|
85 // ?implementation_description |
|
86 // (other items were commented in a header). |
|
87 // ----------------------------------------------------------------------------- |
|
88 // |
|
89 CCalenServer::CCalenServer(TInt aPriority) |
|
90 : CServer2(aPriority, ESharableSessions) |
|
91 { |
|
92 TRACE_ENTRY_POINT; |
|
93 TRACE_EXIT_POINT; |
|
94 } |
|
95 |
|
96 // ----------------------------------------------------------------------------- |
|
97 // ?classname::?member_function |
|
98 // ?implementation_description |
|
99 // (other items were commented in a header). |
|
100 // ----------------------------------------------------------------------------- |
|
101 // |
|
102 CCalenServer::~CCalenServer() |
|
103 { |
|
104 TRACE_ENTRY_POINT; |
|
105 if( iSession ) |
|
106 { |
|
107 // stop listening for calendar file change notifications |
|
108 iSession->StopFileChangeNotification(); |
|
109 delete iSession; |
|
110 } |
|
111 |
|
112 //delete iAlarmManager; |
|
113 delete iDBManager; |
|
114 delete iBootManager; |
|
115 delete iMissedAlarmHandler; |
|
116 |
|
117 TRACE_EXIT_POINT; |
|
118 } |
|
119 |
|
120 // ----------------------------------------------------------------------------- |
|
121 // ?classname::?member_function |
|
122 // ?implementation_description |
|
123 // (other items were commented in a header). |
|
124 // ----------------------------------------------------------------------------- |
|
125 // |
|
126 void CCalenServer::ConstructL() |
|
127 { |
|
128 TRACE_ENTRY_POINT; |
|
129 |
|
130 TBool firstStartUp(EFalse); |
|
131 CheckForFirstStartUpL(firstStartUp); |
|
132 |
|
133 if(!firstStartUp) |
|
134 { |
|
135 TRAPD(error,CreateCalendarFilesL()); |
|
136 if(error==KErrNone) |
|
137 { |
|
138 SetFirstStartUpL(ETrue); |
|
139 } |
|
140 } |
|
141 |
|
142 iBootManager = CCalenSvrBootManager::NewL( *this ); |
|
143 iDBManager = CCalenSvrDBManager::NewL(); |
|
144 //iAlarmManager = CCalenSvrAlarmManager::NewL(); |
|
145 iMissedAlarmHandler = CCalenSvrMissedAlarmManager::NewL(); |
|
146 |
|
147 |
|
148 // create cal session |
|
149 iSession = CCalSession::NewL(); |
|
150 // start listening for calendar file change notifications |
|
151 iSession->StartFileChangeNotificationL(*this); |
|
152 |
|
153 StartL( KCalendarServerName ); |
|
154 |
|
155 TRACE_EXIT_POINT; |
|
156 } |
|
157 |
|
158 // |
|
159 // CServer mandatory functions, e.g. session creation and error handling |
|
160 // |
|
161 |
|
162 // ----------------------------------------------------------------------------- |
|
163 // ?classname::?member_function |
|
164 // ?implementation_description |
|
165 // (other items were commented in a header). |
|
166 // ----------------------------------------------------------------------------- |
|
167 // |
|
168 CSession2* CCalenServer::NewSessionL(const TVersion& /*aVersion*/, const RMessage2& /*aMessage*/) const |
|
169 { |
|
170 TRACE_ENTRY_POINT; |
|
171 |
|
172 CCalSvrSession* session = new( ELeave )CCalSvrSession(); |
|
173 |
|
174 CleanupStack::PushL( session ); |
|
175 session->ConstructL( *const_cast<CCalenServer*>( this ) ); |
|
176 CleanupStack::Pop( session ); |
|
177 |
|
178 TRACE_EXIT_POINT; |
|
179 return session; |
|
180 } |
|
181 |
|
182 // ----------------------------------------------------------------------------- |
|
183 // ?classname::?member_function |
|
184 // ?implementation_description |
|
185 // (other items were commented in a header). |
|
186 // ----------------------------------------------------------------------------- |
|
187 // |
|
188 TInt CCalenServer::RunError(TInt aErr) |
|
189 /** |
|
190 * Handle leaves from ServiceL. |
|
191 * Any leave from a ServiceL() will land up here. |
|
192 **/ |
|
193 { |
|
194 TRACE_ENTRY_POINT; |
|
195 |
|
196 // if it's a bad descriptor, panic the client |
|
197 if (aErr==KErrBadDescriptor) // client had a bad descriptor |
|
198 { |
|
199 PanicClient(Message(), EBadDescriptor); |
|
200 // If client message is panicked, it is also completed. |
|
201 } |
|
202 else |
|
203 { |
|
204 // otherwise, complete the outstanding message with error |
|
205 Message().Complete(aErr); |
|
206 } |
|
207 ReStart(); // really means just continue reading client requests |
|
208 |
|
209 TRACE_EXIT_POINT; |
|
210 return KErrNone; |
|
211 } |
|
212 |
|
213 // ----------------------------------------------------------------------------- |
|
214 // ?classname::?member_function |
|
215 // ?implementation_description |
|
216 // (other items were commented in a header). |
|
217 // ----------------------------------------------------------------------------- |
|
218 // |
|
219 void CCalenServer::PanicClient(const RMessage2& aMessage, TInt aPanic) const |
|
220 { |
|
221 TRACE_ENTRY_POINT; |
|
222 |
|
223 // FIXME: should we Panic Client, if client is running in |
|
224 // phone thread ? |
|
225 // ok, go for it |
|
226 _LIT(KCalenSvrClientPanic, "CalenServer"); |
|
227 aMessage.Panic(KCalenSvrClientPanic, aPanic); |
|
228 |
|
229 TRACE_EXIT_POINT; |
|
230 } |
|
231 |
|
232 // |
|
233 // Calendar server specific functionality |
|
234 // |
|
235 |
|
236 // ----------------------------------------------------------------------------- |
|
237 // ?classname::?member_function |
|
238 // ?implementation_description |
|
239 // (other items were commented in a header). |
|
240 // ----------------------------------------------------------------------------- |
|
241 // |
|
242 void CCalenServer::BootReadyL() |
|
243 { |
|
244 TRACE_ENTRY_POINT; |
|
245 iDBManager->BootReadyL(); |
|
246 TRACE_EXIT_POINT; |
|
247 } |
|
248 |
|
249 // ----------------------------------------------------------------------------- |
|
250 // ?classname::?member_function |
|
251 // ?implementation_description |
|
252 // (other items were commented in a header). |
|
253 // ----------------------------------------------------------------------------- |
|
254 // |
|
255 void CCalenServer::RegisterUserL(CCalenSvrDBManager::MCalenDBUser& aUser) |
|
256 { |
|
257 TRACE_ENTRY_POINT; |
|
258 iDBManager->RegisterUserL(aUser); |
|
259 TRACE_EXIT_POINT; |
|
260 } |
|
261 |
|
262 // ----------------------------------------------------------------------------- |
|
263 // ?classname::?member_function |
|
264 // ?implementation_description |
|
265 // (other items were commented in a header). |
|
266 // ----------------------------------------------------------------------------- |
|
267 // |
|
268 void CCalenServer::UnregisterUserL(CCalenSvrDBManager::MCalenDBUser& aUser) |
|
269 { |
|
270 TRACE_ENTRY_POINT; |
|
271 iDBManager->UnregisterUserL(aUser); |
|
272 TRACE_EXIT_POINT; |
|
273 } |
|
274 |
|
275 // ----------------------------------------------------------------------------- |
|
276 // CCalenServer::ServerMessage |
|
277 // Returns the current IPC message. |
|
278 // (other items were commented in a header). |
|
279 // ----------------------------------------------------------------------------- |
|
280 // |
|
281 const RMessage2 CCalenServer::ServerMessage() const |
|
282 { |
|
283 TRACE_ENTRY_POINT; |
|
284 |
|
285 TRACE_EXIT_POINT; |
|
286 return Message(); |
|
287 } |
|
288 |
|
289 // ----------------------------------------------------------------------------- |
|
290 // CCalenServer::CheckForFirstStartUpL |
|
291 // checks for first start up by reading the information from cenrep key |
|
292 // ----------------------------------------------------------------------------- |
|
293 // |
|
294 void CCalenServer::CheckForFirstStartUpL(TBool& aFirstStartUp) |
|
295 { |
|
296 TRACE_ENTRY_POINT; |
|
297 CRepository* cenRep = CRepository::NewLC(KCRUidCalendar); |
|
298 User::LeaveIfError(cenRep->Get(KCalendarStartupStatus, aFirstStartUp)); |
|
299 CleanupStack::PopAndDestroy(cenRep); |
|
300 TRACE_EXIT_POINT; |
|
301 } |
|
302 |
|
303 // ----------------------------------------------------------------------------- |
|
304 // CCalenServer::SetFirstStartUpL |
|
305 // Sets first start up value to ETrue |
|
306 // ----------------------------------------------------------------------------- |
|
307 // |
|
308 void CCalenServer::SetFirstStartUpL(TBool aFirstStartUp) |
|
309 { |
|
310 TRACE_ENTRY_POINT; |
|
311 CRepository* cenRep = CRepository::NewLC(KCRUidCalendar); |
|
312 User::LeaveIfError(cenRep->Set(KCalendarStartupStatus, aFirstStartUp)); |
|
313 CleanupStack::PopAndDestroy(cenRep); |
|
314 TRACE_EXIT_POINT; |
|
315 } |
|
316 |
|
317 // ----------------------------------------------------------------------------- |
|
318 // CCalenServer::CreateCalendarFilesL |
|
319 // Create default calendar files |
|
320 // ----------------------------------------------------------------------------- |
|
321 // |
|
322 TInt CCalenServer::CreateCalendarFilesL() |
|
323 { |
|
324 TRACE_ENTRY_POINT; |
|
325 |
|
326 CDesC16ArrayFlat* calendarNamesList = new (ELeave) CDesC16ArrayFlat(2); |
|
327 CleanupStack::PushL(calendarNamesList); |
|
328 // read calendar names from central repository |
|
329 ReadCalendarNamesFromResourceL(*calendarNamesList); |
|
330 |
|
331 RArray<TInt> calendarColors; |
|
332 // read calendar colors from central repository |
|
333 ReadCalendarColorsFromCenrepL(calendarColors); |
|
334 |
|
335 TInt calendarsCount = calendarNamesList->Count(); |
|
336 TInt error(KErrNone); |
|
337 for (TInt index = 0; index < calendarsCount; index++) |
|
338 { |
|
339 // create cal session |
|
340 CCalSession* session = CCalSession::NewL(); |
|
341 CleanupStack::PushL(session); |
|
342 |
|
343 // create and set metadata information from central repository |
|
344 CCalCalendarInfo* calendarInfo = CCalCalendarInfo::NewL(); |
|
345 CleanupStack::PushL(calendarInfo); |
|
346 |
|
347 SetCalendarAddPropertiesL(*calendarInfo); |
|
348 |
|
349 calendarInfo->SetNameL(calendarNamesList->MdcaPoint(index)); |
|
350 calendarInfo->SetColor(TRgb(calendarColors[index])); |
|
351 calendarInfo->SetEnabled(ETrue); |
|
352 |
|
353 if(!index) |
|
354 { |
|
355 TBuf<KMaxFileName> calendarFileName; |
|
356 calendarFileName.Append(KCalendarDatabaseFilePath); |
|
357 TRAPD(error,session->CreateCalFileL(calendarFileName,*calendarInfo)); |
|
358 User::LeaveIfError(error); |
|
359 } |
|
360 else |
|
361 { |
|
362 HBufC* calFileName = |
|
363 CCalenMultiCalUtil::GetNextAvailableCalFileL(); |
|
364 CleanupStack::PushL(calFileName); |
|
365 TRAPD(error,session->CreateCalFileL( calFileName->Des(), |
|
366 *calendarInfo)); |
|
367 User::LeaveIfError(error); |
|
368 CleanupStack::PopAndDestroy(calFileName); |
|
369 } |
|
370 CleanupStack::PopAndDestroy(calendarInfo); |
|
371 CleanupStack::PopAndDestroy(session); |
|
372 } |
|
373 calendarColors.Close(); |
|
374 CleanupStack::PopAndDestroy(calendarNamesList); |
|
375 TRACE_EXIT_POINT; |
|
376 return error; |
|
377 } |
|
378 |
|
379 // ----------------------------------------------------------------------------- |
|
380 // CCalenServer::ReadCalendarNamesFromCenrepL |
|
381 // Read calendar names from central repository |
|
382 // ----------------------------------------------------------------------------- |
|
383 // |
|
384 void CCalenServer::ReadCalendarNamesFromResourceL(CDesC16ArrayFlat& aCalendarNames) |
|
385 { |
|
386 TRACE_ENTRY_POINT; |
|
387 |
|
388 |
|
389 |
|
390 |
|
391 |
|
392 |
|
393 // personal |
|
394 HBufC* personalBuffer = KPersonal().AllocLC(); |
|
395 aCalendarNames.AppendL( personalBuffer->Des() ); |
|
396 CleanupStack::PopAndDestroy( personalBuffer ); |
|
397 |
|
398 |
|
399 |
|
400 |
|
401 TRACE_EXIT_POINT; |
|
402 } |
|
403 |
|
404 // ----------------------------------------------------------------------------- |
|
405 // CCalenServer::ReadCalendarColorsFromCenrepL |
|
406 // Read calendar colors from central repository |
|
407 // ----------------------------------------------------------------------------- |
|
408 // |
|
409 void CCalenServer::ReadCalendarColorsFromCenrepL(RArray<TInt>& aCalendarColors) |
|
410 { |
|
411 TRACE_ENTRY_POINT; |
|
412 |
|
413 CRepository* repository = CRepository::NewL(KCRUidCalendar); |
|
414 CleanupStack::PushL(repository); |
|
415 |
|
416 TInt bufSize(KBufferStartingSize); |
|
417 TBool wasRead(EFalse); |
|
418 do |
|
419 { |
|
420 RBuf buf; |
|
421 CleanupClosePushL(buf); |
|
422 buf.CreateL(bufSize); |
|
423 // read calendar colors from cenrep |
|
424 TInt err = repository->Get(KCalendarDefaultColors, buf); |
|
425 if (err == KErrNone) |
|
426 { |
|
427 wasRead = ETrue; |
|
428 PopulateCalendarColorListL(buf, aCalendarColors); |
|
429 } |
|
430 else if (err == KErrOverflow) |
|
431 { |
|
432 bufSize += KBufferSizeIncrement; |
|
433 } |
|
434 else |
|
435 { |
|
436 User::Leave(err); |
|
437 } |
|
438 CleanupStack::PopAndDestroy(&buf); |
|
439 } |
|
440 while (!wasRead); |
|
441 |
|
442 CleanupStack::PopAndDestroy(repository); |
|
443 TRACE_EXIT_POINT; |
|
444 } |
|
445 |
|
446 // ----------------------------------------------------------------------------- |
|
447 // CCalenServer::PopulateCalendarColorListL |
|
448 // Populate calendar colors list from central repository buffer |
|
449 // ----------------------------------------------------------------------------- |
|
450 // |
|
451 void CCalenServer::PopulateCalendarColorListL( const TDesC& aRepositoryBuffer, |
|
452 RArray<TInt>& aCalendarColors ) |
|
453 { |
|
454 TRACE_ENTRY_POINT; |
|
455 |
|
456 TPtrC marker = aRepositoryBuffer; |
|
457 TInt calendarColorOffset; |
|
458 |
|
459 |
|
460 |
|
461 while ((calendarColorOffset = marker.Locate(TChar(KComma))) |
|
462 != KErrNotFound) |
|
463 { |
|
464 TLex lex(marker.Left(calendarColorOffset)); |
|
465 TInt colorValue; |
|
466 User::LeaveIfError(lex.Val(colorValue)); |
|
467 // append calendar color value to list |
|
468 aCalendarColors.Append(colorValue); |
|
469 // Set marker to one char after the comma. |
|
470 marker.Set(marker.Mid(calendarColorOffset + 1)); |
|
471 if (marker.Locate(TChar(KComma)) == KErrNotFound) |
|
472 { |
|
473 lex = marker.Left(marker.Length()); |
|
474 User::LeaveIfError(lex.Val(colorValue)); |
|
475 aCalendarColors.Append(colorValue); |
|
476 } |
|
477 } |
|
478 TRACE_EXIT_POINT; |
|
479 } |
|
480 |
|
481 // ---------------------------------------------------------------------------- |
|
482 // CCalenServer::SetCalendarAddPropertiesL |
|
483 // (other items were commented in a header). |
|
484 // ---------------------------------------------------------------------------- |
|
485 // |
|
486 void CCalenServer::SetCalendarAddPropertiesL(CCalCalendarInfo& aCalendarInfo) |
|
487 { |
|
488 TRACE_ENTRY_POINT |
|
489 |
|
490 // EFolderLUID |
|
491 TBuf8<KBuffLength> keyBuff; |
|
492 keyBuff.AppendNum(EFolderLUID); |
|
493 TRAPD(err,aCalendarInfo.PropertyValueL(keyBuff)); |
|
494 |
|
495 if (KErrNotFound == err) |
|
496 { |
|
497 TUint calValue = 0; |
|
498 //Get the available offset value and set as property value. |
|
499 calValue = CCalenMultiCalUtil::GetNextAvailableOffsetL(); |
|
500 TPckgC<TUint> calValuePckg(calValue); |
|
501 aCalendarInfo.SetPropertyL(keyBuff, calValuePckg); |
|
502 } |
|
503 |
|
504 // ECreationTime |
|
505 TTime currentTime; |
|
506 currentTime.HomeTime(); |
|
507 |
|
508 keyBuff.Zero(); |
|
509 keyBuff.AppendNum(ECreationTime); |
|
510 TRAP( err, aCalendarInfo.PropertyValueL( keyBuff ) ); |
|
511 |
|
512 if (KErrNotFound == err) |
|
513 { |
|
514 TPckgC<TTime> pkgCreationTime(currentTime); |
|
515 aCalendarInfo.SetPropertyL(keyBuff, pkgCreationTime); |
|
516 } |
|
517 |
|
518 // EModificationTime |
|
519 keyBuff.Zero(); |
|
520 keyBuff.AppendNum(EModificationTime); |
|
521 |
|
522 //At creation modification time will be same as creation time |
|
523 TPckgC<TTime> pkgModificationTime(currentTime); |
|
524 aCalendarInfo.SetPropertyL(keyBuff, pkgModificationTime); |
|
525 |
|
526 |
|
527 // ESyncStatus |
|
528 keyBuff.Zero(); |
|
529 keyBuff.AppendNum(ESyncStatus); |
|
530 |
|
531 TBool status = ETrue; |
|
532 TPckgC<TBool> pkgSyncStatus(status); |
|
533 aCalendarInfo.SetPropertyL(keyBuff, pkgSyncStatus); |
|
534 |
|
535 // EIsSharedFolder |
|
536 keyBuff.Zero(); |
|
537 keyBuff.AppendNum(EIsSharedFolder); |
|
538 |
|
539 TPckgC<TBool> pkgIsSharedFolder(ETrue); |
|
540 aCalendarInfo.SetPropertyL(keyBuff, pkgIsSharedFolder); |
|
541 |
|
542 // EGlobalUUID |
|
543 keyBuff.Zero(); |
|
544 keyBuff.AppendNum(EGlobalUUID); |
|
545 TRAP(err,aCalendarInfo.PropertyValueL(keyBuff)); |
|
546 |
|
547 if (KErrNotFound == err) |
|
548 { |
|
549 CCalenInterimUtils2* interimUtils = CCalenInterimUtils2::NewL(); |
|
550 CleanupStack::PushL( interimUtils ); |
|
551 HBufC8* guuid = interimUtils->GlobalUidL(); |
|
552 TPtr8 guuidPtr = guuid->Des(); |
|
553 CleanupStack::PushL( guuid ); |
|
554 aCalendarInfo.SetPropertyL(keyBuff, guuidPtr); |
|
555 CleanupStack::PopAndDestroy( guuid ); |
|
556 CleanupStack::PopAndDestroy( interimUtils ); |
|
557 } |
|
558 |
|
559 // EOwnerName |
|
560 keyBuff.Zero(); |
|
561 keyBuff.AppendNum(EOwnerName); |
|
562 TRAP(err,aCalendarInfo.PropertyValueL(keyBuff)); |
|
563 |
|
564 if (KErrNotFound == err) |
|
565 { |
|
566 _LIT8( KCalendarOwnerName, "myself" ); |
|
567 aCalendarInfo.SetPropertyL(keyBuff, KCalendarOwnerName); |
|
568 } |
|
569 |
|
570 // EMarkAsDelete |
|
571 keyBuff.Zero(); |
|
572 keyBuff.AppendNum(EMarkAsDelete); |
|
573 TPckgC<TBool> pkgMarkAsDelete(EFalse); |
|
574 aCalendarInfo.SetPropertyL(keyBuff, pkgMarkAsDelete); |
|
575 |
|
576 TRACE_EXIT_POINT |
|
577 } |
|
578 |
|
579 // ---------------------------------------------------------------------------- |
|
580 // CCalenServer::CalendarInfoChangeNotificationL |
|
581 // Handle calendar file change notifications |
|
582 // ---------------------------------------------------------------------------- |
|
583 void CCalenServer::CalendarInfoChangeNotificationL( |
|
584 RPointerArray<CCalFileChangeInfo>& aCalendarInfoChangeEntries) |
|
585 { |
|
586 TRACE_ENTRY_POINT; |
|
587 |
|
588 // get the file change count |
|
589 TInt calenInfoChangeCount = aCalendarInfoChangeEntries.Count(); |
|
590 RArray<TInt> calendarColors; |
|
591 // read calendar colors from central repository |
|
592 ReadCalendarColorsFromCenrepL(calendarColors); |
|
593 |
|
594 for(TInt index = 0;index < calenInfoChangeCount;index++) |
|
595 { |
|
596 // default calendar is deleted/updated. |
|
597 if( !aCalendarInfoChangeEntries[index]->FileNameL().CompareF(KCalendarDatabaseFilePath) ) |
|
598 { |
|
599 MCalFileChangeObserver::TChangeType changeType = |
|
600 aCalendarInfoChangeEntries[index]->ChangeType(); |
|
601 switch(changeType) |
|
602 { |
|
603 case MCalFileChangeObserver::ECalendarFileDeleted: |
|
604 { |
|
605 // create cal session |
|
606 CCalSession* session = CCalSession::NewL(); |
|
607 CleanupStack::PushL(session); |
|
608 |
|
609 // create and set metadata information from central repository |
|
610 CCalCalendarInfo* calendarInfo = CCalCalendarInfo::NewL(); |
|
611 CleanupStack::PushL(calendarInfo); |
|
612 |
|
613 // EFolderLUID |
|
614 TBuf8<KBuffLength> keyBuff; |
|
615 keyBuff.AppendNum(EFolderLUID); |
|
616 TRAPD(err,calendarInfo->PropertyValueL(keyBuff)); |
|
617 |
|
618 //First set the folder uid as 100000 for default calendar. |
|
619 // Later set the other properties |
|
620 if (KErrNotFound == err) |
|
621 { |
|
622 TUint calValue = 0; |
|
623 //Get the available offset value and set as property value. |
|
624 calValue = 100000; |
|
625 TPckgC<TUint> calValuePckg(calValue); |
|
626 calendarInfo->SetPropertyL(keyBuff, calValuePckg); |
|
627 } |
|
628 SetCalendarAddPropertiesL(*calendarInfo); |
|
629 calendarInfo->SetNameL(KCalendarDatabaseFilePath); |
|
630 calendarInfo->SetColor(TRgb(calendarColors[0])); |
|
631 calendarInfo->SetEnabled(ETrue); |
|
632 TBuf<KMaxFileName> calendarFileName; |
|
633 calendarFileName.Append(KCalendarDatabaseFilePath); |
|
634 //create the default calendar. |
|
635 TRAPD(error,session->CreateCalFileL(calendarFileName,*calendarInfo)); |
|
636 User::LeaveIfError(error); |
|
637 CleanupStack::PopAndDestroy(calendarInfo); |
|
638 CleanupStack::PopAndDestroy(session); |
|
639 } |
|
640 break; |
|
641 case MCalFileChangeObserver::ECalendarInfoUpdated: |
|
642 { |
|
643 // create cal session |
|
644 CCalSession* session = CCalSession::NewL(); |
|
645 CleanupStack::PushL(session); |
|
646 session->OpenL(KCalendarDatabaseFilePath); |
|
647 |
|
648 CCalCalendarInfo* calendarInfo = session->CalendarInfoL(); |
|
649 CleanupStack::PushL(calendarInfo); |
|
650 |
|
651 TBuf8<KBuffLength> keyBuff; |
|
652 keyBuff.AppendNum(EMarkAsDelete); |
|
653 |
|
654 TBool markAsdelete; |
|
655 TPckgC<TBool> pkgMarkAsDelete(markAsdelete); |
|
656 TRAPD(err,pkgMarkAsDelete.Set(calendarInfo->PropertyValueL(keyBuff))); |
|
657 markAsdelete = pkgMarkAsDelete(); |
|
658 if( markAsdelete ) |
|
659 { |
|
660 // Mark the CalFile as visible. |
|
661 calendarInfo->SetEnabled( ETrue ); |
|
662 TBuf8<KBuffLength> keyBuff; |
|
663 |
|
664 // Set the modification time as home time. |
|
665 keyBuff.Zero(); |
|
666 keyBuff.AppendNum(EModificationTime); |
|
667 TTime modificationTime; |
|
668 modificationTime.HomeTime(); |
|
669 TPckgC<TTime> pkgModificationTime(modificationTime); |
|
670 calendarInfo->SetPropertyL(keyBuff, pkgModificationTime); |
|
671 |
|
672 // Set the SyncStatus to ETrue |
|
673 keyBuff.Zero(); |
|
674 keyBuff.AppendNum( ESyncStatus ); |
|
675 TBool syncstatus( ETrue ); |
|
676 TPckgC<TBool> pckgSyncStatusValue( syncstatus ); |
|
677 calendarInfo->SetPropertyL( keyBuff, pckgSyncStatusValue ); |
|
678 |
|
679 // Mark the meta property as SoftDeleted |
|
680 keyBuff.Zero(); |
|
681 keyBuff.AppendNum(EMarkAsDelete); |
|
682 TPckgC<TBool> pkgSoftDelete( EFalse ); |
|
683 calendarInfo->SetPropertyL(keyBuff, pkgSoftDelete); |
|
684 |
|
685 session->SetCalendarInfoL( *calendarInfo ); |
|
686 } |
|
687 CleanupStack::PopAndDestroy(calendarInfo); |
|
688 CleanupStack::PopAndDestroy(session); |
|
689 } |
|
690 } |
|
691 } |
|
692 } |
|
693 TRACE_EXIT_POINT; |
|
694 } |
|
695 // End of File |