1 /* |
|
2 * Copyright (c) 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <gdi.h> |
|
19 #include <utf.h> |
|
20 #include <barsc.h> |
|
21 #include <e32std.h> |
|
22 #include <bautils.h> |
|
23 #include <implementationproxy.h> |
|
24 #include <calsession.h> |
|
25 #include <calenmulticalutil.h> |
|
26 #include <calenmulticaluids.hrh> |
|
27 #include <calcalendarinfo.h> |
|
28 #include <nsmlfolderparser.h> |
|
29 #include <nsmldefaultagendahandler_1_2.rsg> |
|
30 #include "nsmldefaultagendahandlerplugin.h" |
|
31 #include "nsmldefaultagendahandlerutil.h" |
|
32 #include "nsmldefaultagendahandlerdebug.h" |
|
33 |
|
34 |
|
35 |
|
36 // CONSTANTS |
|
37 const TInt KBuffLength = 128; |
|
38 |
|
39 // ---------------------------------------------------------------------------- |
|
40 // CNSmlDefaultAgendaHandlerPlugin::NewL |
|
41 // Two Phase Construction |
|
42 // ---------------------------------------------------------------------------- |
|
43 EXPORT_C CNSmlDefaultAgendaHandlerPlugin* CNSmlDefaultAgendaHandlerPlugin::NewL() |
|
44 { |
|
45 FLOG( _L("CNSmlDefaultAgendaHandlerPlugin::NewL, BEGIN")); |
|
46 |
|
47 CNSmlDefaultAgendaHandlerPlugin* self = new ( ELeave ) CNSmlDefaultAgendaHandlerPlugin(); |
|
48 self->ConstructL(); |
|
49 |
|
50 FLOG( _L("CNSmlDefaultAgendaHandlerPlugin::NewL, END")); |
|
51 return self; |
|
52 } |
|
53 |
|
54 // ---------------------------------------------------------------------------- |
|
55 // CNSmlDefaultAgendaHandlerPlugin::~CNSmlDefaultAgendaHandlerPlugin |
|
56 // Destructor |
|
57 // ---------------------------------------------------------------------------- |
|
58 CNSmlDefaultAgendaHandlerPlugin::~CNSmlDefaultAgendaHandlerPlugin() |
|
59 { |
|
60 FLOG( _L("CNSmlDefaultAgendaHandlerPlugin::~CNSmlDefaultAgendaHandlerPlugin, BEGIN")); |
|
61 |
|
62 FLOG( _L("CNSmlDefaultAgendaHandlerPlugin::~CNSmlDefaultAgendaHandlerPlugin, END")); |
|
63 } |
|
64 |
|
65 // ---------------------------------------------------------------------------- |
|
66 // C++ constructor - not exported; |
|
67 // implicitly called from NewL() |
|
68 // ---------------------------------------------------------------------------- |
|
69 CNSmlDefaultAgendaHandlerPlugin::CNSmlDefaultAgendaHandlerPlugin() |
|
70 { |
|
71 FLOG( _L("CNSmlDefaultAgendaHandlerPlugin::CNSmlDefaultAgendaHandlerPlugin, BEGIN")); |
|
72 FLOG( _L("CNSmlDefaultAgendaHandlerPlugin::CNSmlDefaultAgendaHandlerPlugin, END")); |
|
73 } |
|
74 |
|
75 // ---------------------------------------------------------------------------- |
|
76 // 2nd phase constructor |
|
77 // ---------------------------------------------------------------------------- |
|
78 void CNSmlDefaultAgendaHandlerPlugin::ConstructL() |
|
79 { |
|
80 FLOG( _L("CNSmlDefaultAgendaHandlerPlugin::ConstructL, BEGIN")); |
|
81 |
|
82 // Initialize server supports for folder |
|
83 iServerSupportsForFolder.iSSName = EFalse; |
|
84 iServerSupportsForFolder.iSSCreated = EFalse; |
|
85 iServerSupportsForFolder.iSSModified = EFalse; |
|
86 |
|
87 FLOG( _L("CNSmlDefaultAgendaHandlerPlugin::ConstructL, END")); |
|
88 } |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CNSmlDefaultAgendaHandlerPlugin::CheckServerSupportForFolder |
|
92 // Method to check if needed properties are supported by remote server. |
|
93 // ----------------------------------------------------------------------------- |
|
94 void CNSmlDefaultAgendaHandlerPlugin::CheckServerSupportForFolder( const CSmlDataStoreFormat& aServerDataStoreFormat ) |
|
95 { |
|
96 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::CheckServerSupportForFolder: BEGIN")); |
|
97 |
|
98 iServerSupportsForFolder.iSSName = EFalse; |
|
99 iServerSupportsForFolder.iSSCreated = EFalse; |
|
100 iServerSupportsForFolder.iSSModified = EFalse; |
|
101 |
|
102 if ( aServerDataStoreFormat.FolderPropertyCount() == 0 ) |
|
103 { |
|
104 // Server has no restricition on folder property |
|
105 iServerSupportsForFolder.iSSName = ETrue; |
|
106 iServerSupportsForFolder.iSSCreated = ETrue; |
|
107 iServerSupportsForFolder.iSSModified = ETrue; |
|
108 return; |
|
109 } |
|
110 else |
|
111 { |
|
112 for ( TInt i = 0; |
|
113 i < aServerDataStoreFormat.FolderPropertyCount(); |
|
114 i++ ) |
|
115 { |
|
116 if ( aServerDataStoreFormat.FolderProperty( i ).Field().Name().DesC().Compare( KNSmlDataObjectNAME ) == 0 ) |
|
117 { |
|
118 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::CheckServerSupportForFolder: Supports NAME Property")); |
|
119 iServerSupportsForFolder.iSSName = ETrue; |
|
120 } |
|
121 else if ( aServerDataStoreFormat.FolderProperty( i ).Field().Name().DesC().Compare( KNSmlDataObjectCREATED ) == 0 ) |
|
122 { |
|
123 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::CheckServerSupportForFolder: Supports CREATED Property")); |
|
124 iServerSupportsForFolder.iSSCreated = ETrue; |
|
125 } |
|
126 else if ( aServerDataStoreFormat.FolderProperty( i ).Field().Name().DesC().Compare( KNSmlDataObjectMODIFIED ) == 0 ) |
|
127 { |
|
128 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::CheckServerSupportForFolder: Supports MODIFIED Property")); |
|
129 iServerSupportsForFolder.iSSModified = ETrue; |
|
130 } |
|
131 } |
|
132 } |
|
133 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::CheckServerSupportForFolder: END")); |
|
134 } |
|
135 |
|
136 // ----------------------------------------------------------------------------- |
|
137 // CNSmlDefaultAgendaHandlerPlugin::FetchFolderL |
|
138 // Method to read folder item from database. |
|
139 // ----------------------------------------------------------------------------- |
|
140 void CNSmlDefaultAgendaHandlerPlugin::FetchFolderL( const TSmlDbItemUid aUid, RBufWriteStream& aStream ) |
|
141 { |
|
142 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::FetchFolderL: begin")); |
|
143 |
|
144 // Create parser and set properties |
|
145 CNSmlFolderParser* parser = CNSmlFolderParser::NewLC(); |
|
146 TNSmlParserGeneratorError parseError = EErrorNone; |
|
147 HBufC8* generatedBuf = NULL; |
|
148 HBufC8* nameBuf = NULL; |
|
149 |
|
150 //Get the Folder Information |
|
151 CNSmlDefaultAgendaHandlerUtil* agendautil = CalendarInfoL(aUid); |
|
152 if( NULL == agendautil ) |
|
153 { |
|
154 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::FetchFolderL:Invalid CalendarInfo")); |
|
155 CleanupStack::PopAndDestroy( parser ); |
|
156 User::Leave( KErrNotFound ); |
|
157 } |
|
158 |
|
159 if ( iServerSupportsForFolder.iSSCreated ) |
|
160 { |
|
161 parser->iCreated = agendautil->iCreated; |
|
162 } |
|
163 else |
|
164 { |
|
165 parser->iCreated = Time::NullTTime(); |
|
166 } |
|
167 |
|
168 if ( iServerSupportsForFolder.iSSName ) |
|
169 { |
|
170 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::FetchFolderL: retrieving name")); |
|
171 nameBuf = HBufC8::NewL( agendautil->iName->Length() ); |
|
172 TPtr8 name( nameBuf->Des() ); |
|
173 CnvUtfConverter::ConvertFromUnicodeToUtf8(name , agendautil->iName->Des()); |
|
174 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::FetchFolderL: name converted")); |
|
175 parser->iName = nameBuf; |
|
176 } |
|
177 |
|
178 // Generate data and write it to buffer |
|
179 generatedBuf = HBufC8::NewLC( 1 ); |
|
180 generatedBuf->Des() = KNullDesC8; |
|
181 CleanupStack::Pop(); // generatedBuf |
|
182 parseError = parser->GenerateXml( generatedBuf ); |
|
183 CleanupStack::PushL( generatedBuf ); |
|
184 |
|
185 aStream.WriteL( generatedBuf->Des() ); |
|
186 |
|
187 delete agendautil; |
|
188 CleanupStack::PopAndDestroy( generatedBuf ); |
|
189 CleanupStack::PopAndDestroy( parser ); |
|
190 |
|
191 if ( parseError != EErrorNone ) |
|
192 { |
|
193 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::FetchFolderL(): end with leave")); |
|
194 User::Leave( KErrGeneral ); |
|
195 } |
|
196 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::FetchFolderL: end")); |
|
197 } |
|
198 |
|
199 // ----------------------------------------------------------------------------- |
|
200 // CNSmlDefaultAgendaHandlerPlugin::SynchronizableCalendarIdsL |
|
201 // Retrieve the CalendarFile ID |
|
202 // ----------------------------------------------------------------------------- |
|
203 void CNSmlDefaultAgendaHandlerPlugin::SynchronizableCalendarIdsL( CArrayFixFlat<TUint>* aFolderUidArray ) |
|
204 { |
|
205 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::SynchronizableCalendarIdsL BEGIN")); |
|
206 |
|
207 CCalSession* vCalSession = NULL; |
|
208 CCalSession* vCalSubSession = NULL; |
|
209 TBuf8<KBuffLength> keyBuff; |
|
210 |
|
211 aFolderUidArray->Reset(); |
|
212 |
|
213 vCalSession = CCalSession::NewL(); |
|
214 CleanupStack::PushL(vCalSession); |
|
215 |
|
216 CDesCArray* calfilearr = vCalSession->ListCalFilesL(); |
|
217 CleanupStack::PushL(calfilearr); |
|
218 |
|
219 for(TInt i = 0; i < calfilearr->Count(); i++) |
|
220 { |
|
221 TInt err = KErrNone; |
|
222 vCalSubSession = CCalSession::NewL(); |
|
223 CleanupStack::PushL(vCalSubSession); |
|
224 vCalSubSession->OpenL(calfilearr->MdcaPoint(i)); |
|
225 |
|
226 CCalCalendarInfo* caleninfo = vCalSubSession->CalendarInfoL(); |
|
227 CleanupStack::PushL(caleninfo); |
|
228 |
|
229 //Get UID value associated with the CalFile |
|
230 keyBuff.Zero(); |
|
231 TUint UidVal; |
|
232 keyBuff.AppendNum( EFolderLUID ); |
|
233 TPckgC<TUint> pckUidValue(UidVal); |
|
234 TRAP(err,pckUidValue.Set(caleninfo->PropertyValueL( keyBuff ))); |
|
235 UidVal = pckUidValue(); |
|
236 |
|
237 if( err != KErrNone ) |
|
238 { |
|
239 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::SynchronizableCalendarIdsL: Error while retrieving CalFile Property: '%d'"), err); |
|
240 CleanupStack::PopAndDestroy(caleninfo); |
|
241 CleanupStack::PopAndDestroy(vCalSubSession); |
|
242 continue; |
|
243 } |
|
244 |
|
245 //Get MARKASDELETE MetaData property |
|
246 keyBuff.Zero(); |
|
247 TBool markAsdelete = EFalse; |
|
248 keyBuff.AppendNum( EMarkAsDelete ); |
|
249 TPckgC<TBool> pckMarkAsDelete(markAsdelete); |
|
250 TRAP(err,pckMarkAsDelete.Set(caleninfo->PropertyValueL(keyBuff))); |
|
251 if ( err == KErrNone ) |
|
252 { |
|
253 markAsdelete = pckMarkAsDelete(); |
|
254 if( markAsdelete ) |
|
255 { |
|
256 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::SynchronizableCalendarIdsL: Dead Calendar, not including in the snapshot")); |
|
257 CleanupStack::PopAndDestroy(caleninfo); |
|
258 CleanupStack::PopAndDestroy(vCalSubSession); |
|
259 continue; |
|
260 } |
|
261 } |
|
262 |
|
263 //Get OWNER value associated with the CalFile |
|
264 keyBuff.Zero(); |
|
265 TInt SyncServiceOwnerVal; |
|
266 keyBuff.AppendNum( EDeviceSyncServiceOwner ); |
|
267 TPckgC<TInt> pckOwnerValue(SyncServiceOwnerVal); |
|
268 TRAP(err,pckOwnerValue.Set(caleninfo->PropertyValueL( keyBuff ))); |
|
269 SyncServiceOwnerVal = pckOwnerValue(); |
|
270 |
|
271 if( err == KErrNotFound ) |
|
272 { |
|
273 // Set DS Application as owner |
|
274 SyncServiceOwnerVal = KCRUidNSmlDSApp.iUid; |
|
275 TPckgC<TInt> pckOwnerValue(SyncServiceOwnerVal); |
|
276 caleninfo->SetPropertyL( keyBuff, pckOwnerValue ); |
|
277 vCalSubSession->SetCalendarInfoL( *caleninfo ); |
|
278 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::SynchronizableCalendarIdsL: Empty Owner LUID '%d'"), UidVal ); |
|
279 aFolderUidArray->AppendL(UidVal); |
|
280 } |
|
281 else if( err == KErrNone ) |
|
282 { |
|
283 if( KCRUidNSmlDSApp.iUid == SyncServiceOwnerVal ) |
|
284 { |
|
285 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::SynchronizableCalendarIdsL: DS Owner LUID '%d'"), UidVal ); |
|
286 aFolderUidArray->AppendL(UidVal); |
|
287 } |
|
288 } |
|
289 else |
|
290 { |
|
291 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::SynchronizableCalendarIdsL: Error while retrieving Owner Property: '%d'"), err); |
|
292 } |
|
293 CleanupStack::PopAndDestroy(caleninfo); |
|
294 CleanupStack::PopAndDestroy(vCalSubSession); |
|
295 } |
|
296 CleanupStack::PopAndDestroy(calfilearr); |
|
297 CleanupStack::PopAndDestroy(vCalSession); |
|
298 |
|
299 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::SynchronizableCalendarIdsL END")); |
|
300 } |
|
301 |
|
302 // ----------------------------------------------------------------------------- |
|
303 // CNSmlDefaultAgendaHandlerPlugin::CreateFolderItemL |
|
304 // Creates the Folder item with the stream provided |
|
305 // ----------------------------------------------------------------------------- |
|
306 TCalLocalUid CNSmlDefaultAgendaHandlerPlugin::CreateFolderL( RBufReadStream& aStream ) |
|
307 { |
|
308 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::CreateFolderItemL BEGIN")); |
|
309 |
|
310 TBuf8<KBuffLength> keyBuff; |
|
311 TUint calValue = 0; |
|
312 CNSmlDefaultAgendaHandlerUtil* agendautil = NULL; |
|
313 CCalCalendarInfo* calinfo = CCalCalendarInfo::NewL(); |
|
314 CleanupStack::PushL(calinfo); |
|
315 |
|
316 // Parse the buffer for the folder data and construct the calendar info |
|
317 agendautil = ParseFolderDataL( aStream ); |
|
318 |
|
319 if( agendautil ) |
|
320 { |
|
321 // Visibility |
|
322 calinfo->SetEnabled( agendautil->iEnabled ); |
|
323 |
|
324 // LUID Meta Property |
|
325 keyBuff.Zero(); |
|
326 keyBuff.AppendNum( EFolderLUID ); |
|
327 calValue = CCalenMultiCalUtil::GetNextAvailableOffsetL(); |
|
328 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::CreateFolderItemL: nextoffset: '%d'"), calValue); |
|
329 TPckgC<TUint> pckgUidValue( calValue ); |
|
330 calinfo->SetPropertyL( keyBuff, pckgUidValue ); |
|
331 |
|
332 // Create & Modified Time Meta Property |
|
333 keyBuff.Zero(); |
|
334 keyBuff.AppendNum( ECreationTime ); |
|
335 TTime time; |
|
336 time.HomeTime(); |
|
337 TPckgC<TTime> pckgCreateTimeValue( time ); |
|
338 calinfo->SetPropertyL( keyBuff, pckgCreateTimeValue ); |
|
339 keyBuff.Zero(); |
|
340 keyBuff.AppendNum( EModificationTime ); |
|
341 calinfo->SetPropertyL( keyBuff, pckgCreateTimeValue ); |
|
342 |
|
343 // Sync Status Meta Property |
|
344 keyBuff.Zero(); |
|
345 keyBuff.AppendNum( ESyncStatus ); |
|
346 TBool syncstatus( ETrue ); |
|
347 TPckgC<TBool> pckgSyncStatusValue( syncstatus ); |
|
348 calinfo->SetPropertyL( keyBuff, pckgSyncStatusValue ); |
|
349 |
|
350 // Add |
|
351 CCalSession* calsession = CCalSession::NewL(); |
|
352 TInt err(KErrNone); |
|
353 if( agendautil->iName != NULL ) |
|
354 { |
|
355 calinfo->SetNameL( agendautil->iName->Des() ); |
|
356 HBufC* calfilename = CCalenMultiCalUtil::GetNextAvailableCalFileL(); |
|
357 TRAP( err, calsession->CreateCalFileL( *calfilename, *calinfo ) ); |
|
358 delete calfilename; |
|
359 } |
|
360 else |
|
361 { |
|
362 err = KErrNotFound; |
|
363 } |
|
364 |
|
365 delete calsession; |
|
366 delete agendautil; |
|
367 CleanupStack::PopAndDestroy(calinfo); |
|
368 |
|
369 if( err != KErrNone ) |
|
370 { |
|
371 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::CreateFolderItemL: Error while Creating Calfile")); |
|
372 User::Leave( KErrGeneral ); |
|
373 } |
|
374 } |
|
375 else |
|
376 { |
|
377 CleanupStack::PopAndDestroy(calinfo); |
|
378 User::Leave( KErrGeneral ); |
|
379 } |
|
380 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::CreateFolderItemL END")); |
|
381 return calValue; |
|
382 } |
|
383 |
|
384 // ----------------------------------------------------------------------------- |
|
385 // CNSmlDefaultAgendaHandlerPlugin::ReplaceFolderItemL |
|
386 // Replaces the Folder item with the ID provided |
|
387 // ----------------------------------------------------------------------------- |
|
388 void CNSmlDefaultAgendaHandlerPlugin::ReplaceFolderL( const TCalLocalUid& aUid, |
|
389 RBufReadStream& aStream, TBool& aSyncStatus ) |
|
390 { |
|
391 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::ReplaceFolderItemL: BEGIN")); |
|
392 |
|
393 TBuf8<KBuffLength> keyBuff; |
|
394 CNSmlDefaultAgendaHandlerUtil* agendautil = NULL; |
|
395 |
|
396 // Parse the buffer for the folder data and construct the calendar info |
|
397 agendautil = ParseFolderDataL( aStream ); |
|
398 |
|
399 if( agendautil ) |
|
400 { |
|
401 //Get the associated Calendar File |
|
402 CNSmlDefaultAgendaHandlerUtil* updateagendautil = CalendarInfoL( aUid ); |
|
403 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::ReplaceFolderItemL: After CalendarInfoL '%d'"), updateagendautil); |
|
404 |
|
405 if( NULL == updateagendautil ) |
|
406 { |
|
407 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::ReplaceFolderItemL:Invalid Updatable CalendarInfo")); |
|
408 delete agendautil; |
|
409 User::Leave( KErrNotFound ); |
|
410 } |
|
411 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::ReplaceFolderItemL:valid CalendarInfo")); |
|
412 if( updateagendautil->iFileName != NULL ) |
|
413 { |
|
414 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::ReplaceFolderItemL:valid name '%S'"), updateagendautil->iFileName); |
|
415 CCalSession* vCalSession = CCalSession::NewL(); |
|
416 CleanupStack::PushL(vCalSession); |
|
417 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::ReplaceFolderItemL:Open the session")); |
|
418 vCalSession->OpenL(updateagendautil->iFileName->Des()); |
|
419 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::ReplaceFolderItemL:Get the Calendar Info")); |
|
420 CCalCalendarInfo* caleninfo = vCalSession->CalendarInfoL(); |
|
421 CleanupStack::PushL(caleninfo); |
|
422 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::ReplaceFolderItemL:Set the status")); |
|
423 caleninfo->SetEnabled(agendautil->iEnabled); |
|
424 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::ReplaceFolderItemL:Set the name")); |
|
425 caleninfo->SetNameL(agendautil->iName->Des()); |
|
426 |
|
427 // Modified Time Meta Property |
|
428 keyBuff.Zero(); |
|
429 keyBuff.AppendNum( EModificationTime ); |
|
430 TTime time; |
|
431 time.HomeTime(); |
|
432 TPckgC<TTime> pckgCreateTimeValue( time ); |
|
433 caleninfo->SetPropertyL( keyBuff, pckgCreateTimeValue ); |
|
434 |
|
435 aSyncStatus = updateagendautil->iSyncStatus; |
|
436 |
|
437 // Update |
|
438 vCalSession->SetCalendarInfoL(*caleninfo); |
|
439 |
|
440 CleanupStack::PopAndDestroy(caleninfo); |
|
441 CleanupStack::PopAndDestroy( vCalSession ); |
|
442 } |
|
443 else |
|
444 { |
|
445 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::ReplaceFolderItemL:Invalid Updatable CalendarInfo Name")); |
|
446 delete agendautil; |
|
447 delete updateagendautil; |
|
448 User::Leave( KErrNotFound ); |
|
449 } |
|
450 } |
|
451 else |
|
452 { |
|
453 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::ReplaceFolderItemL:Invalid Parsed CalendarInfo")); |
|
454 User::Leave( KErrNotFound ); |
|
455 } |
|
456 |
|
457 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::ReplaceFolderItemL: END")); |
|
458 } |
|
459 |
|
460 // ----------------------------------------------------------------------------- |
|
461 // CNSmlDefaultAgendaHandlerPlugin::FolderNameL |
|
462 // Returns the FolderName for the given ID |
|
463 // ----------------------------------------------------------------------------- |
|
464 HBufC* CNSmlDefaultAgendaHandlerPlugin::FolderNameL( TSmlDbItemUid aUid ) |
|
465 { |
|
466 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::FolderNameL: BEGIN")); |
|
467 |
|
468 HBufC* calfilename = NULL; |
|
469 CNSmlDefaultAgendaHandlerUtil* agendautil = CalendarInfoL( aUid ); |
|
470 |
|
471 if( agendautil != NULL ) |
|
472 { |
|
473 calfilename = agendautil->iFileName->Alloc(); |
|
474 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::foldername: '%S'"), calfilename); |
|
475 } |
|
476 delete agendautil; |
|
477 |
|
478 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::FolderNameL: END")); |
|
479 |
|
480 return calfilename; |
|
481 } |
|
482 |
|
483 // ----------------------------------------------------------------------------- |
|
484 // CNSmlDefaultAgendaHandlerPlugin::StoreFormatL |
|
485 // Returns adapters supported store format which is read from Calendar Plug |
|
486 // In Adapter own resource file. |
|
487 // ----------------------------------------------------------------------------- |
|
488 CSmlDataStoreFormat* CNSmlDefaultAgendaHandlerPlugin::StoreFormatL( RStringPool& aStringPool ) |
|
489 { |
|
490 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::StoreFormatL: BEGIN")); |
|
491 |
|
492 TFileName fileName; |
|
493 TParse* parse = new(ELeave) TParse(); |
|
494 CleanupStack::PushL( parse ); |
|
495 |
|
496 parse->Set( KNSmlDefaultAgendaHandlerRsc_1_2, |
|
497 &KDC_RESOURCE_FILES_DIR, NULL ); |
|
498 |
|
499 fileName = parse->FullName(); |
|
500 RResourceFile resourceFile; |
|
501 RFs rfs; |
|
502 User::LeaveIfError(rfs.Connect()); |
|
503 |
|
504 BaflUtils::NearestLanguageFile( rfs, fileName ); |
|
505 |
|
506 TRAPD( leavecode, resourceFile.OpenL( rfs,fileName ) ); |
|
507 if ( leavecode != 0 ) |
|
508 { |
|
509 CleanupStack::PopAndDestroy(); // parse |
|
510 rfs.Close(); |
|
511 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin:::StoreFormatL(): Error END")); |
|
512 User::Leave( leavecode ); |
|
513 } |
|
514 |
|
515 CleanupClosePushL( resourceFile ); |
|
516 HBufC8* buffer = resourceFile.AllocReadLC( NSML_DEFAULT_AGENDA_HANDLER ); |
|
517 TResourceReader reader; |
|
518 reader.SetBuffer( buffer ); |
|
519 |
|
520 CSmlDataStoreFormat* dsFormat = NULL; |
|
521 dsFormat = CSmlDataStoreFormat::NewLC( aStringPool, reader ); |
|
522 CleanupStack::Pop(); // dsFormat |
|
523 CleanupStack::PopAndDestroy( 3 ); // buffer, resourceFile, parse |
|
524 rfs.Close(); |
|
525 |
|
526 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::StoreFormatL: END")); |
|
527 return dsFormat; |
|
528 } |
|
529 |
|
530 // ----------------------------------------------------------------------------- |
|
531 // CNSmlDefaultAgendaHandlerPlugin::DeviceSyncOwner |
|
532 // Returns the DS Application UID |
|
533 // ----------------------------------------------------------------------------- |
|
534 TInt CNSmlDefaultAgendaHandlerPlugin::DeviceSyncOwner() |
|
535 { |
|
536 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::DeviceSyncOwner: BEGIN")); |
|
537 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::DeviceSyncOwner: '%d' END"), KCRUidNSmlDSApp.iUid ); |
|
538 return KCRUidNSmlDSApp.iUid; |
|
539 } |
|
540 |
|
541 // ----------------------------------------------------------------------------- |
|
542 // CNSmlDefaultAgendaHandlerPlugin::FolderSyncStatusL |
|
543 // Returns the Sync Status for the given UID |
|
544 // ----------------------------------------------------------------------------- |
|
545 TBool CNSmlDefaultAgendaHandlerPlugin::FolderSyncStatusL( TSmlDbItemUid aUid ) |
|
546 { |
|
547 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::FolderSyncStatusL: BEGIN")); |
|
548 |
|
549 TBool syncstatus( EFalse ); |
|
550 CNSmlDefaultAgendaHandlerUtil* agendautil = CalendarInfoL( aUid ); |
|
551 if( agendautil != NULL ) |
|
552 { |
|
553 syncstatus = agendautil->iSyncStatus; |
|
554 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::syncstatus: '%d'"), syncstatus ); |
|
555 } |
|
556 delete agendautil; |
|
557 |
|
558 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::FolderSyncStatusL: END")); |
|
559 |
|
560 return syncstatus; |
|
561 } |
|
562 |
|
563 // ----------------------------------------------------------------------------- |
|
564 // CNSmlDefaultAgendaHandlerPlugin::FolderSyncStatusL |
|
565 // Returns the Sync Status for the given FolderName |
|
566 // ----------------------------------------------------------------------------- |
|
567 TBool CNSmlDefaultAgendaHandlerPlugin::FolderSyncStatusL( HBufC* aFolderName ) |
|
568 { |
|
569 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::FolderSyncStatusL: BEGIN")); |
|
570 |
|
571 TBool syncstatus( EFalse ); |
|
572 TBuf8<KBuffLength> keyBuff; |
|
573 CCalSession *calsession = CCalSession::NewL(); |
|
574 CleanupStack::PushL(calsession); |
|
575 calsession->OpenL(aFolderName->Des()); |
|
576 CCalCalendarInfo* caleninfo = calsession->CalendarInfoL(); |
|
577 CleanupStack::PushL(caleninfo); |
|
578 // Sync Status |
|
579 keyBuff.Zero(); |
|
580 keyBuff.AppendNum( ESyncStatus ); |
|
581 TPckgC<TBool> pckgSyncStatusValue(syncstatus); |
|
582 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::FolderSyncStatusL: Get sync status")); |
|
583 TRAPD(err,pckgSyncStatusValue.Set(caleninfo->PropertyValueL( keyBuff ))); |
|
584 |
|
585 syncstatus = pckgSyncStatusValue(); |
|
586 if( err != KErrNone ) |
|
587 { |
|
588 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::FolderSyncStatusL: Error while retrieving CalFile SYNC Property")); |
|
589 } |
|
590 CleanupStack::PopAndDestroy(caleninfo); |
|
591 CleanupStack::PopAndDestroy(calsession); |
|
592 |
|
593 |
|
594 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::FolderSyncStatusL: END")); |
|
595 |
|
596 return syncstatus; |
|
597 } |
|
598 |
|
599 // ----------------------------------------------------------------------------- |
|
600 // CNSmlDefaultAgendaHandlerPlugin::CreateFolderSnapShotItemL |
|
601 // Create the Folder SnapShot Item |
|
602 // ----------------------------------------------------------------------------- |
|
603 TNSmlSnapshotItem CNSmlDefaultAgendaHandlerPlugin::CreateFolderSnapShotItemL( const TCalLocalUid& aUid ) |
|
604 { |
|
605 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::CreateFolderSnapShotItemL: BEGIN")); |
|
606 |
|
607 TNSmlSnapshotItem item( 0 ); |
|
608 |
|
609 CNSmlDefaultAgendaHandlerUtil* agendautil = CalendarInfoL( aUid ); |
|
610 if( NULL == agendautil ) |
|
611 { |
|
612 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::CreateFolderSnapShotItemL:Invalid CalendarInfo")); |
|
613 return item; |
|
614 } |
|
615 item.SetItemId( aUid ); |
|
616 item.SetLastChangedDate(agendautil->iModified); |
|
617 item.SetSoftDelete(EFalse); |
|
618 delete agendautil; |
|
619 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::CreateFolderSnapShotItemL: END")); |
|
620 |
|
621 return item; |
|
622 } |
|
623 |
|
624 // ----------------------------------------------------------------------------- |
|
625 // CNSmlDefaultAgendaHandlerPlugin::ParseFolderDataL |
|
626 // Method to Parse the Folder Data Obtained |
|
627 // ----------------------------------------------------------------------------- |
|
628 CNSmlDefaultAgendaHandlerUtil* CNSmlDefaultAgendaHandlerPlugin::ParseFolderDataL( RBufReadStream& aStream ) |
|
629 { |
|
630 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::ParseFolderDataL: BEGIN")); |
|
631 |
|
632 CNSmlDefaultAgendaHandlerUtil* agendautil = CNSmlDefaultAgendaHandlerUtil::NewL(); |
|
633 |
|
634 // Create parser and parse data from Buffer |
|
635 CNSmlFolderParser* folderparser = CNSmlFolderParser::NewLC(); |
|
636 TParse name; |
|
637 |
|
638 TInt size = aStream.Source()->SizeL(); |
|
639 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::ParseFolderDataL: size:'%d'"), size); |
|
640 CBufFlat* buffer = CBufFlat::NewL( 64 ); |
|
641 CleanupStack::PushL( buffer ); |
|
642 buffer->ResizeL( size ); |
|
643 TPtr8 ptr = buffer->Ptr( 0 ); |
|
644 aStream.ReadL( ptr, size ); |
|
645 HBufC8* dataBuffer = HBufC8::NewLC( buffer->Size() ); |
|
646 TPtr8 dataBufferPtr = dataBuffer->Des(); |
|
647 buffer->Read( 0, dataBufferPtr, buffer->Size() ); |
|
648 |
|
649 TNSmlParserGeneratorError parseError = |
|
650 folderparser->ParseXml( dataBuffer ); |
|
651 CleanupStack::PopAndDestroy( 2 ); // dataBuffer, buffer |
|
652 |
|
653 if ( parseError != EErrorNone ) |
|
654 { |
|
655 delete agendautil; |
|
656 CleanupStack::PopAndDestroy( ); // folderparser |
|
657 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::ParseFolderDataL: end with leave")); |
|
658 User::Leave( KErrGeneral ); |
|
659 return NULL; |
|
660 } |
|
661 |
|
662 // Every folder item must have NAME property. Even replace because this |
|
663 // Plug In does not support field level update for folders. |
|
664 if ( !folderparser->iName ) |
|
665 { |
|
666 delete agendautil; |
|
667 CleanupStack::PopAndDestroy( ); // folderparser |
|
668 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::ParseFolderDataL: end with leave")); |
|
669 User::Leave( KErrArgument ); |
|
670 return NULL; |
|
671 } |
|
672 |
|
673 // Create Calendar info |
|
674 agendautil->iName = CnvUtfConverter::ConvertToUnicodeFromUtf8L(folderparser->iName->Des()); |
|
675 CleanupStack::PopAndDestroy( ); // folderparser; |
|
676 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::ParseFolderDataL: END")); |
|
677 return agendautil; |
|
678 } |
|
679 |
|
680 // ----------------------------------------------------------------------------- |
|
681 // CNSmlDefaultAgendaHandlerPlugin::CalendarInfoL |
|
682 // Retrieve the CalendarFile Info using the aUid value |
|
683 // ----------------------------------------------------------------------------- |
|
684 CNSmlDefaultAgendaHandlerUtil* CNSmlDefaultAgendaHandlerPlugin::CalendarInfoL( TSmlDbItemUid aUid ) |
|
685 { |
|
686 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::CalendarInfoL: BEGIN")); |
|
687 |
|
688 TBuf8<KBuffLength> keyBuff; |
|
689 CNSmlDefaultAgendaHandlerUtil* agendautil = NULL; |
|
690 CCalSession* vCalSession = NULL; |
|
691 CCalSession* vCalSubSession = NULL; |
|
692 |
|
693 vCalSession = CCalSession::NewL(); |
|
694 CleanupStack::PushL(vCalSession); |
|
695 |
|
696 CDesCArray* calfilearr = vCalSession->ListCalFilesL(); |
|
697 CleanupStack::PushL(calfilearr); |
|
698 |
|
699 for(TInt i = 0; i < calfilearr->Count(); i++) |
|
700 { |
|
701 vCalSubSession = CCalSession::NewL(*vCalSession); |
|
702 CleanupStack::PushL(vCalSubSession); |
|
703 vCalSubSession->OpenL(calfilearr->MdcaPoint(i)); |
|
704 |
|
705 CCalCalendarInfo* caleninfo = vCalSubSession->CalendarInfoL(); |
|
706 CleanupStack::PushL(caleninfo); |
|
707 |
|
708 TUint UidVal; |
|
709 keyBuff.Zero(); |
|
710 keyBuff.AppendNum( EFolderLUID ); |
|
711 TPckgC<TUint> intBuf(UidVal); |
|
712 TRAPD(err,intBuf.Set(caleninfo->PropertyValueL(keyBuff))); |
|
713 |
|
714 if( err != KErrNone ) |
|
715 { |
|
716 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::CalendarInfoL: Error while retrieving CalFile Property")); |
|
717 CleanupStack::PopAndDestroy(caleninfo); |
|
718 CleanupStack::PopAndDestroy(vCalSubSession); |
|
719 CleanupStack::PopAndDestroy(calfilearr); |
|
720 CleanupStack::PopAndDestroy(vCalSession); |
|
721 return agendautil; |
|
722 } |
|
723 |
|
724 UidVal = intBuf(); |
|
725 |
|
726 if(aUid == UidVal) |
|
727 { |
|
728 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::CalendarInfoL: Found a match")); |
|
729 agendautil = CNSmlDefaultAgendaHandlerUtil::NewL(); |
|
730 agendautil->iEnabled = caleninfo->Enabled(); |
|
731 agendautil->iName = caleninfo->NameL().AllocL(); |
|
732 agendautil->iFileName = caleninfo->FileNameL().AllocL(); |
|
733 |
|
734 TInt err(KErrNone); |
|
735 |
|
736 // Created Time |
|
737 TTime timeval; |
|
738 keyBuff.Zero(); |
|
739 keyBuff.AppendNum( ECreationTime ); |
|
740 TPckgC<TTime> pckgCreateTimeValue( timeval ); |
|
741 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::CalendarInfoL: Get Creation date")); |
|
742 TRAP(err,pckgCreateTimeValue.Set(caleninfo->PropertyValueL( keyBuff ))); |
|
743 |
|
744 if( err != KErrNone ) |
|
745 { |
|
746 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::CalendarInfoL: Error while retrieving CalFile CREATED Property")); |
|
747 } |
|
748 agendautil->iCreated = pckgCreateTimeValue(); |
|
749 |
|
750 // Modified Time |
|
751 keyBuff.Zero(); |
|
752 keyBuff.AppendNum( EModificationTime ); |
|
753 TPckgC<TTime> pckgModifyTimeValue( timeval ); |
|
754 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::CalendarInfoL: Get Modified date")); |
|
755 TRAP(err,pckgModifyTimeValue.Set(caleninfo->PropertyValueL( keyBuff ))); |
|
756 |
|
757 if( err != KErrNone ) |
|
758 { |
|
759 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::CalendarInfoL: Error while retrieving CalFile MODIFIED Property")); |
|
760 } |
|
761 agendautil->iModified = pckgModifyTimeValue(); |
|
762 |
|
763 // Sync Status |
|
764 TBool syncstatus; |
|
765 keyBuff.Zero(); |
|
766 keyBuff.AppendNum( ESyncStatus ); |
|
767 TPckgC<TBool> pckgSyncStatusValue(syncstatus); |
|
768 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::CalendarInfoL(): Get sync status")); |
|
769 TRAP(err,pckgSyncStatusValue.Set(caleninfo->PropertyValueL( keyBuff ))); |
|
770 |
|
771 if( err != KErrNone ) |
|
772 { |
|
773 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::CalendarInfoL: Error while retrieving CalFile SYNC Property")); |
|
774 } |
|
775 agendautil->iSyncStatus = pckgSyncStatusValue(); |
|
776 } |
|
777 CleanupStack::PopAndDestroy(caleninfo); |
|
778 CleanupStack::PopAndDestroy(vCalSubSession); |
|
779 } |
|
780 CleanupStack::PopAndDestroy(calfilearr); |
|
781 CleanupStack::PopAndDestroy(vCalSession); |
|
782 |
|
783 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::CalendarInfoL: END")); |
|
784 |
|
785 return agendautil; |
|
786 } |
|
787 |
|
788 /** |
|
789 * Provides a key value pair table, this is used to identify |
|
790 * the correct construction function for the requested interface. |
|
791 */ |
|
792 const TImplementationProxy ImplementationTable[] = |
|
793 { |
|
794 IMPLEMENTATION_PROXY_ENTRY(0x20029F16, CNSmlDefaultAgendaHandlerPlugin::NewL ) |
|
795 }; |
|
796 |
|
797 /** |
|
798 * Function used to return an instance of the proxy table.+ |
|
799 */ |
|
800 EXPORT_C const TImplementationProxy* ImplementationGroupProxy( TInt& aTableCount ) |
|
801 { |
|
802 aTableCount = sizeof( ImplementationTable ) / sizeof( TImplementationProxy ); |
|
803 return ImplementationTable; |
|
804 } |
|
805 |
|
806 #ifdef EKA2 |
|
807 GLDEF_C TInt E32Dll() |
|
808 #else |
|
809 GLDEF_C TInt E32Dll(TDllReason /*aReason*/) |
|
810 #endif |
|
811 // DLL entry point |
|
812 { |
|
813 return(KErrNone); |
|
814 } |
|
815 |
|
816 //End of file |
|
817 |
|