1 /* |
|
2 * Copyright (c) 2002-2007 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: CCntParserCollector implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include <cntfilt.h> |
|
21 #include <cntitem.h> |
|
22 #include <cntfldst.h> |
|
23 |
|
24 #include <vcard.h> |
|
25 #include <versit.h> |
|
26 #include <s32mem.h> |
|
27 |
|
28 #include "cntparsercollector.h" |
|
29 #include "cntparserserver.h" |
|
30 #include "irmcconsts.h" |
|
31 #include "debug.h" |
|
32 |
|
33 //Next values are defined in cntdef.h |
|
34 const TUid typesToBeSearched[]={{KUidContactFieldPhoneNumberValue},{KUidContactFieldFaxValue}}; |
|
35 |
|
36 _LIT( KTotalCountFilePath, "count.txt" ); |
|
37 |
|
38 _LIT8( KNameProperty, "N" ); |
|
39 _LIT8( KTelProperty, "TEL" ); |
|
40 |
|
41 |
|
42 //------------------------------------------------------------ |
|
43 // CCntParserCollector::CCntParserCollector():CActive( 0 ) |
|
44 //------------------------------------------------------------ |
|
45 CCntParserCollector::CCntParserCollector():CActive( 0 ) |
|
46 { |
|
47 } |
|
48 //------------------------------------------------------------ |
|
49 // CCntParserCollector::~CCntParserCollector() |
|
50 //------------------------------------------------------------ |
|
51 CCntParserCollector::~CCntParserCollector() |
|
52 { |
|
53 LOGGER_ENTERFN( "CntParserCollector::~CCntParserCollector()" ); |
|
54 |
|
55 if( iVersitTLS ) |
|
56 { |
|
57 iVersitTLS->VersitTlsDataClose(); //Close reference |
|
58 } |
|
59 LOGGER_WRITE( "CntParserCollector: Versit OK!" ); |
|
60 |
|
61 iFsSession.Close(); |
|
62 LOGGER_WRITE( "CntParserCollector: FsSession OK!" ); |
|
63 iWriter.Close(); |
|
64 LOGGER_WRITE( "CntParserCollector: iWriter OK!" ); |
|
65 delete iFilter; |
|
66 LOGGER_LEAVEFN( "CntParserCollector::~CCntParserCollector()" ); |
|
67 } |
|
68 //------------------------------------------------------------ |
|
69 // CCntParserCollector::NewL(CCntParserServer* aServer,CContactDatabase* aCurrentDatabase) |
|
70 //------------------------------------------------------------ |
|
71 CCntParserCollector* CCntParserCollector::NewL(CCntParserServer* aServer,CContactDatabase* aCurrentDatabase) |
|
72 { |
|
73 CCntParserCollector* self=NewLC(aServer, aCurrentDatabase); |
|
74 CleanupStack::Pop(); |
|
75 return self; |
|
76 } |
|
77 //------------------------------------------------------------ |
|
78 // CCntParserCollector::NewLC(CCntParserServer* aServer,CContactDatabase* aCurrentDatabase) |
|
79 //------------------------------------------------------------ |
|
80 CCntParserCollector* CCntParserCollector::NewLC(CCntParserServer* aServer,CContactDatabase* aCurrentDatabase) |
|
81 { |
|
82 CCntParserCollector* self=new (ELeave) CCntParserCollector(); |
|
83 CleanupStack::PushL( self ); |
|
84 self->ConstructL( aServer, aCurrentDatabase ); |
|
85 return self; |
|
86 } |
|
87 //------------------------------------------------------------ |
|
88 // CCntParserCollector::ConstructL(CCntParserServer* aServer,CContactDatabase* aCurrentDatabase) |
|
89 //------------------------------------------------------------ |
|
90 void CCntParserCollector::ConstructL(CCntParserServer* aServer,CContactDatabase* aCurrentDatabase) |
|
91 { |
|
92 LOGGER_WRITE( "CntParserCollector: ConstructL" ); |
|
93 |
|
94 CVersitTlsData& VersitTLS = CVersitTlsData::VersitTlsDataL(); //For speed optimization take a reference to TLS, SEE DESTRUCTOR!! |
|
95 iVersitTLS = &VersitTLS; |
|
96 |
|
97 iServer = aServer; |
|
98 iContactsDb = aCurrentDatabase; |
|
99 PrepareParserL(); |
|
100 |
|
101 CActiveScheduler::Add(this); |
|
102 } |
|
103 //------------------------------------------------------------ |
|
104 // CCntParserCollector::CreateIrMCL2FileL(const TDesC& aFileName, TInt aMaxNumberOfContacts,TBool aForced) |
|
105 //------------------------------------------------------------ |
|
106 TInt CCntParserCollector::CreateIrMCL2FileL(const TDesC& aFileName, TInt aMaxNumberOfContacts,TBool aForced) |
|
107 { |
|
108 LOGGER_WRITE( "CntParserCollector: CreateIrMCL2FileL" ); |
|
109 LOGGER_WRITE_1( "CCntParserCollector::CreateIrMCL2FileL aFileName %S", &aFileName ); |
|
110 |
|
111 iMaxNumberOfContacts = aMaxNumberOfContacts; |
|
112 |
|
113 CContactIdArray* changedItems; |
|
114 TTime tTime; |
|
115 |
|
116 LOGGER_WRITE( "CntParserCollector: CreateIrMCL2FileL: Does the PB.VCF already exist" ); |
|
117 |
|
118 //Is there a previously created pb.vcf file? |
|
119 RFile file; |
|
120 TInt err = file.Open( iFsSession, aFileName, EFileShareExclusive ); //Open file |
|
121 if( err == KErrNone ) |
|
122 { |
|
123 LOGGER_WRITE( "CntParserCollector: CreateIrMCL2FileL: Yes, when created" ); |
|
124 file.Modified(tTime); //When modified |
|
125 } |
|
126 file.Close(); |
|
127 |
|
128 err = iWriter.Open( iFsSession, aFileName, EFileShareExclusive ); //Open stream |
|
129 CleanupClosePushL( iWriter ); //Yes, this is a member variable, but it's considered |
|
130 |
|
131 if( err == KErrPathNotFound ) |
|
132 { |
|
133 LOGGER_WRITE( "CntParserCollector: CreateIrMCL2FileL: dir did not exist, creating..." ); |
|
134 err = iFsSession.MkDir( aFileName ); |
|
135 LOGGER_WRITE_1( "CCntParserCollector MkDir returned %d", err ); |
|
136 if ( err == KErrNone ) |
|
137 { |
|
138 LOGGER_WRITE( "CntParserCollector: CreateIrMCL2FileL: New file after MkDir" ); |
|
139 //This is the situation that the file is created for the first time |
|
140 User::LeaveIfError( iWriter.Create( iFsSession, aFileName, EFileShareExclusive ) ); |
|
141 LOGGER_WRITE( "CntParserCollector: CreateIrMCL2FileL: New file created after MkDir" ); |
|
142 CleanupStack::Pop(); //iWriter |
|
143 ParseCntDatabaseL(); //create IrMC L2 stuff |
|
144 SaveTotalCountL(); |
|
145 return KErrNone; //File created normally |
|
146 } |
|
147 } |
|
148 if( err == KErrNotFound ) // file does not exist - create it |
|
149 { |
|
150 LOGGER_WRITE( "CntParserCollector: CreateIrMCL2FileL: New file" ); |
|
151 |
|
152 //This is the situation that the file is created for the first time |
|
153 User::LeaveIfError( iWriter.Create( iFsSession, aFileName, EFileShareExclusive ) ); |
|
154 LOGGER_WRITE( "CntParserCollector: CreateIrMCL2FileL: New file created" ); |
|
155 CleanupStack::Pop(); //iWriter |
|
156 ParseCntDatabaseL(); //create IrMC L2 stuff |
|
157 SaveTotalCountL(); |
|
158 return KErrNone; //File created normally |
|
159 } |
|
160 else |
|
161 { |
|
162 if( err != KErrNone ) |
|
163 { |
|
164 LOGGER_WRITE_1( "CreateIrMCL2FileL errror leaving %d", err ); |
|
165 User::Leave(err); |
|
166 } |
|
167 iWriter.Close(); |
|
168 |
|
169 LOGGER_WRITE( "CntParserCollector: CreateIrMCL2FileL: File exists, any changes in CDB?" ); |
|
170 //The file exists, but are there any changes? |
|
171 |
|
172 changedItems = iContactsDb->ContactsChangedSinceL( tTime ); //Create a contactidarray, user takes the ownership |
|
173 CleanupStack::PushL(changedItems); |
|
174 |
|
175 LOGGER_WRITE_1( "CreateIrMCL2FileL changedItems %d", changedItems->Count() ); |
|
176 LOGGER_WRITE_1( "CreateIrMCL2FileL aForced %d", aForced ); |
|
177 //Are there changes in any contact |
|
178 if( changedItems->Count()!=0 || aForced || ContactCountChanged() ) |
|
179 { |
|
180 LOGGER_WRITE( "CntParserCollector: CreateIrMCL2FileL: Changes in CDB, replace existing PB.VCF" ); |
|
181 |
|
182 CleanupStack::PopAndDestroy(changedItems); |
|
183 |
|
184 //Create pb.vcf |
|
185 User::LeaveIfError( iWriter.Replace( iFsSession, aFileName, EFileShareExclusive) ); |
|
186 LOGGER_WRITE( "CntParserCollector: CreateIrMCL2FileL: file replaced" ); |
|
187 CleanupStack::Pop(); //iWriter |
|
188 ParseCntDatabaseL(); //create IrMC L2 stuff |
|
189 SaveTotalCountL(); |
|
190 return KErrNone; //File created normally |
|
191 } |
|
192 |
|
193 //No changes |
|
194 CleanupStack::PopAndDestroy(changedItems); |
|
195 CleanupStack::PopAndDestroy(); |
|
196 |
|
197 LOGGER_WRITE( "CntParserCollector: CreateIrMCL2FileL: No Changes in CDB, keep old PB.VCF" ); |
|
198 } |
|
199 return KPBNotUpdated; //No error occured, KPBNotUpdated used as return value to tell that the file was not created.. |
|
200 } |
|
201 //------------------------------------------------------------ |
|
202 // CCntParserCollector::ParseCntDatabaseL() |
|
203 //------------------------------------------------------------ |
|
204 void CCntParserCollector::ParseCntDatabaseL() |
|
205 { |
|
206 LOGGER_WRITE( "CntParserCollector: ParseCntDatabaseL" ); |
|
207 |
|
208 iCurrentItem = 0; |
|
209 iCancel = EFalse; |
|
210 iContactsSaved = 0; |
|
211 |
|
212 //Create owncard (it's always included, even if it's empty) |
|
213 |
|
214 TFileName defaultDb; |
|
215 CContactDatabase::GetDefaultNameL( defaultDb ); |
|
216 TFileName currentDb; |
|
217 iContactsDb->GetCurrentDatabase( currentDb ); |
|
218 |
|
219 if( defaultDb.CompareF(currentDb) == 0 || currentDb == KNullDesC16 /*|| currentDb.CompareF(KSimDummyDatabase)==0*/) //Is current database also default? |
|
220 { |
|
221 LOGGER_WRITE( "CntParserCollector: ParseCntDatabaseL: Using default database" ); |
|
222 TContactItemId ownCardId = iContactsDb->OwnCardId(); |
|
223 ExternalizeCurrentContactL( iContactsDb, ownCardId, ETrue); |
|
224 } |
|
225 else |
|
226 { |
|
227 LOGGER_WRITE( "CntParserCollector: ParseCntDatabaseL: Not using default database" ); |
|
228 CContactDatabase* db=CContactDatabase::OpenL(); //My contact card is only in default db, so open it |
|
229 CleanupStack::PushL(db); |
|
230 |
|
231 TContactItemId ownCardId = db->OwnCardId(); |
|
232 ExternalizeCurrentContactL( db, ownCardId, ETrue ); |
|
233 |
|
234 CleanupStack::PopAndDestroy( db ); |
|
235 } |
|
236 |
|
237 //Start running RunL method and create everything else.. |
|
238 TRequestStatus* s = &iStatus; |
|
239 User::RequestComplete( s, KErrNone ); |
|
240 SetActive(); |
|
241 } |
|
242 //------------------------------------------------------------ |
|
243 // CCntParserCollector::CloseResources() |
|
244 //------------------------------------------------------------ |
|
245 void CCntParserCollector::CloseResources() |
|
246 { |
|
247 LOGGER_WRITE( "CntParserCollector: CloseResources: Closing resources (iWriter)" ); |
|
248 iWriter.Close(); |
|
249 } |
|
250 //------------------------------------------------------------ |
|
251 // CCntParserCollector::PrepareParserL() |
|
252 //------------------------------------------------------------ |
|
253 void CCntParserCollector::PrepareParserL() |
|
254 { |
|
255 LOGGER_WRITE( "CntParserCollector: PrepareParserL" ); |
|
256 iFilter = CCntFilter::NewL(); //Filter all contact cards out of others |
|
257 |
|
258 iFilter->SetContactFilterTypeALL( EFalse ); |
|
259 iFilter->SetContactFilterTypeCard( ETrue ); |
|
260 iContactsDb->FilterDatabaseL( *iFilter ); |
|
261 |
|
262 iIds=iFilter->iIds; //Get IDs to filtered contacts |
|
263 iCount=iIds->Count(); //Get number of contacts to be collected |
|
264 |
|
265 User::LeaveIfError( iFsSession.Connect() ); //Connect to the file server |
|
266 |
|
267 LOGGER_WRITE_1( "CntParserCollector: PrepareParserL: iCount == %d", iCount); |
|
268 } |
|
269 //------------------------------------------------------------ |
|
270 // CCntParserCollector::RunL() |
|
271 //------------------------------------------------------------ |
|
272 void CCntParserCollector::RunL() |
|
273 { |
|
274 //MaxNumberOfContacts-1 for OwnCard |
|
275 if( iCurrentItem < iCount && (iCurrentItem < ( iMaxNumberOfContacts - 1 ) || iMaxNumberOfContacts == -1 ) ) //If no more contacts left or maximum number of contacts already parsed |
|
276 { |
|
277 ExternalizeCurrentContactL( iContactsDb, (*iIds)[iCurrentItem], EFalse ); |
|
278 iCurrentItem++; |
|
279 TRequestStatus* s = &iStatus; //Let's rerun this RunL method as soon as possible |
|
280 User::RequestComplete( s, KErrNone ); |
|
281 SetActive(); |
|
282 return; |
|
283 } |
|
284 iCurrentItem++; //for OwnCard that is created separately |
|
285 LOGGER_WRITE( "CntParserCollector: RunL: No more items" ); |
|
286 CloseResources(); |
|
287 iServer->CompletePhoneBookRequests( KErrNone ); |
|
288 } |
|
289 //------------------------------------------------------------ |
|
290 // CCntParserCollector::ExternalizeCurrentContactL(CContactDatabase* aContactsDb,TInt aCurrentItem,TBool ExternalizeEmpty) |
|
291 //------------------------------------------------------------ |
|
292 void CCntParserCollector::ExternalizeCurrentContactL(CContactDatabase* aContactsDb,TInt aCurrentItem,TBool ExternalizeEmpty) |
|
293 { |
|
294 CContactItem* ownCard; |
|
295 |
|
296 if( aCurrentItem < 0 ) |
|
297 { |
|
298 ownCard = CContactCard::NewLC(); |
|
299 } |
|
300 else |
|
301 { |
|
302 ownCard = aContactsDb->ReadContactLC( aCurrentItem ); //Take a new contact item |
|
303 } |
|
304 |
|
305 CParserVCard* VCard=CParserVCard::NewL(); //Create new VCard |
|
306 CleanupStack::PushL( VCard ); |
|
307 |
|
308 TInt nField = ownCard->CardFields().Find( KUidContactFieldGivenName ); |
|
309 TInt fField = ownCard->CardFields().Find( KUidContactFieldFamilyName ); |
|
310 TInt cField = ownCard->CardFields().Find( KUidContactFieldCompanyName ); |
|
311 |
|
312 //FOR NAMES |
|
313 //N: -field always included even if it's empty |
|
314 CDesC16Array* ValueArray=new (ELeave) CDesCArrayFlat(4); |
|
315 CleanupStack::PushL( ValueArray ); |
|
316 CParserPropertyValueCDesCArray* NameValues=new (ELeave) CParserPropertyValueCDesCArray( ValueArray ); |
|
317 CleanupStack::PushL( NameValues ); |
|
318 CArrayPtr<CParserParam>* parameters=new (ELeave) CArrayPtrFlat<CParserParam>(1); |
|
319 CleanupStack::PushL( parameters ); |
|
320 |
|
321 TPtrC fName; |
|
322 TPtrC nName; |
|
323 TPtrC cName; |
|
324 |
|
325 if( fField != KErrNotFound ) |
|
326 { |
|
327 fName.Set( ownCard->CardFields()[fField].TextStorage()->Text() ); |
|
328 } |
|
329 if( nField != KErrNotFound ) |
|
330 { |
|
331 nName.Set( ownCard->CardFields()[nField].TextStorage()->Text() ); |
|
332 } |
|
333 if( cField != KErrNotFound ) |
|
334 { |
|
335 cName.Set( ownCard->CardFields()[cField].TextStorage()->Text() ); |
|
336 } |
|
337 |
|
338 if( fName.Length() == 0) |
|
339 { |
|
340 fField = KErrNotFound; |
|
341 } |
|
342 if(nName.Length()==0) |
|
343 { |
|
344 nField = KErrNotFound; |
|
345 if( fField==KErrNotFound ) |
|
346 { |
|
347 ValueArray->AppendL( cName ); |
|
348 } |
|
349 else |
|
350 { |
|
351 ValueArray->AppendL( fName ); |
|
352 } |
|
353 } |
|
354 else |
|
355 { |
|
356 ValueArray->AppendL( fName ); |
|
357 ValueArray->AppendL( nName ); |
|
358 } |
|
359 |
|
360 VCard->AddPropertyL( CParserProperty::NewL((*NameValues),KNameProperty,parameters) ); //Add name property to VCard (VCard takes the ownership of the property) |
|
361 CleanupStack::Pop(3); //parameters namevalues valuearray |
|
362 |
|
363 TBool isNumber = EFalse; |
|
364 |
|
365 TInt typeIndex = 0; |
|
366 TInt index = -1; //NOTE: +1 added before used first time |
|
367 |
|
368 for(;;) //Go through all fields (Number of fields is unknown) |
|
369 { |
|
370 index = ownCard->CardFields().FindNext(typesToBeSearched[typeIndex],index+1);//Find next field (of current type) |
|
371 if( index == KErrNotFound ) //No more phone numbers, move to the next group -> (See TypesToBeSearched) |
|
372 { |
|
373 typeIndex++; |
|
374 if( typeIndex >= (signed) (sizeof(typesToBeSearched) / sizeof(TUid)) ) |
|
375 { |
|
376 break; //if no more types to search -> exit FOR-loop |
|
377 } |
|
378 |
|
379 index=ownCard->CardFields().FindNext(typesToBeSearched[typeIndex],0); //Find next field |
|
380 if( index==KErrNotFound ) |
|
381 { |
|
382 break; //No fields -> exit |
|
383 } |
|
384 } |
|
385 |
|
386 TPtrC number = ownCard->CardFields()[index].TextStorage()->Text(); |
|
387 if( number.Length() != 0) |
|
388 { |
|
389 CDesC16Array* ValueArray2=new (ELeave) CDesCArrayFlat(4); |
|
390 CleanupStack::PushL( ValueArray2 ); |
|
391 CParserPropertyValueCDesCArray* NumberValues=new (ELeave) CParserPropertyValueCDesCArray(ValueArray2); |
|
392 CleanupStack::PushL( NumberValues ); |
|
393 CArrayPtr<CParserParam>* parameters2=new (ELeave) CArrayPtrFlat<CParserParam>(1); |
|
394 CleanupStack::PushL( parameters2 ); |
|
395 |
|
396 //Take label name to parameter |
|
397 |
|
398 for( TInt i=0;i<ownCard->CardFields()[index].ContentType().FieldTypeCount();i++ ) |
|
399 { |
|
400 TFieldType fieldType=ownCard->CardFields()[index].ContentType().FieldType(i); |
|
401 |
|
402 if(fieldType==KUidContactFieldVCardMapWORK) parameters2->AppendL(CParserParam::NewL(KVersitParam8Work,KNullDesC8)); |
|
403 if(fieldType==KUidContactFieldVCardMapHOME) parameters2->AppendL(CParserParam::NewL(KVersitParam8Home,KNullDesC8)); |
|
404 if(fieldType==KUidContactFieldVCardMapMSG) parameters2->AppendL(CParserParam::NewL(KVersitParam8Msg,KNullDesC8)); |
|
405 if(fieldType==KUidContactFieldVCardMapVOICE)parameters2->AppendL(CParserParam::NewL(KVersitParam8Voice,KNullDesC8)); |
|
406 if(fieldType==KUidContactFieldVCardMapFAX) parameters2->AppendL(CParserParam::NewL(KVersitParam8Fax,KNullDesC8)); |
|
407 if(fieldType==KUidContactFieldVCardMapPREF) parameters2->AppendL(CParserParam::NewL(KVersitParam8Pref,KNullDesC8)); |
|
408 if(fieldType==KUidContactFieldVCardMapCELL) parameters2->AppendL(CParserParam::NewL(KVersitParam8Cell,KNullDesC8)); |
|
409 if(fieldType==KUidContactFieldVCardMapPAGER)parameters2->AppendL(CParserParam::NewL(KVersitParam8Pager,KNullDesC8)); |
|
410 if(fieldType==KUidContactFieldVCardMapBBS) parameters2->AppendL(CParserParam::NewL(KVersitParam8Bbs,KNullDesC8)); |
|
411 if(fieldType==KUidContactFieldVCardMapMODEM)parameters2->AppendL(CParserParam::NewL(KVersitParam8Modem,KNullDesC8)); |
|
412 if(fieldType==KUidContactFieldVCardMapCAR) parameters2->AppendL(CParserParam::NewL(KVersitParam8Car,KNullDesC8)); |
|
413 if(fieldType==KUidContactFieldVCardMapISDN) parameters2->AppendL(CParserParam::NewL(KVersitParam8Isdn,KNullDesC8)); |
|
414 if(fieldType==KUidContactFieldVCardMapVIDEO)parameters2->AppendL(CParserParam::NewL(KVersitParam8Video,KNullDesC8)); |
|
415 } |
|
416 |
|
417 ValueArray2->AppendL( number ); |
|
418 VCard->AddPropertyL(CParserProperty::NewL((*NumberValues),KTelProperty,parameters2)); //VCard takes the ownership of the property |
|
419 isNumber=ETrue; |
|
420 |
|
421 CleanupStack::Pop(3); //parameters2 numbervalues valuearray2 |
|
422 } |
|
423 } |
|
424 |
|
425 if( (nField!=KErrNotFound) || (fField!=KErrNotFound) || (cField!=KErrNotFound) || isNumber || ExternalizeEmpty ) |
|
426 { |
|
427 if( !isNumber ) |
|
428 { |
|
429 //Create empty TEL field (required by the specs) |
|
430 |
|
431 CDesC16Array* ValueArray3=new (ELeave) CDesCArrayFlat(4); |
|
432 CleanupStack::PushL(ValueArray3); |
|
433 CParserPropertyValueCDesCArray* NumberValues2=new (ELeave) CParserPropertyValueCDesCArray(ValueArray3); |
|
434 CleanupStack::PushL(NumberValues2); |
|
435 CArrayPtr<CParserParam>* parameters3=new (ELeave) CArrayPtrFlat<CParserParam>(1); |
|
436 CleanupStack::PushL(parameters3); |
|
437 |
|
438 VCard->AddPropertyL(CParserProperty::NewL((*NumberValues2),KTelProperty,parameters3)); //VCard takes the ownership of the property |
|
439 |
|
440 CleanupStack::Pop(3); //parameters3 numbervalues valuearray3 |
|
441 } |
|
442 |
|
443 TRAPD( err, VCard->ExternalizeL( iWriter );) //If there are no name or numbers, then no externalizing.. |
|
444 //if error then only current contact card is discarded, but others will be still collected.. |
|
445 if( err == KErrNone ) |
|
446 { |
|
447 iContactsSaved++; |
|
448 } |
|
449 else |
|
450 { |
|
451 LOGGER_WRITE( "CntParserCollector: RunL: Error,VCARD _NOT_ saved" ); |
|
452 } |
|
453 } |
|
454 |
|
455 aContactsDb->CloseContactL( aCurrentItem ); //Close current contact item |
|
456 |
|
457 CleanupStack::PopAndDestroy( VCard ); // VCard and all arrays (parameters2, numvervalues, valuearray2) related to this VCard are deleted through the ownership relations |
|
458 CleanupStack::PopAndDestroy( ownCard ); |
|
459 } |
|
460 //------------------------------------------------------------ |
|
461 // CCntParserCollector::DoCancel() |
|
462 //------------------------------------------------------------ |
|
463 void CCntParserCollector::DoCancel() |
|
464 { |
|
465 LOGGER_WRITE( "CntParserCollector: DoCancel" ); |
|
466 CloseResources(); |
|
467 } |
|
468 //------------------------------------------------------------ |
|
469 // CCntParserCollector::RunError(TInt aError) |
|
470 //------------------------------------------------------------ |
|
471 TInt CCntParserCollector::RunError( TInt aError ) |
|
472 { |
|
473 LOGGER_WRITE( "CntParserCollector: RunError!" ); |
|
474 CloseResources(); //JIC |
|
475 |
|
476 iServer->CompletePhoneBookRequests( aError ); //complete all requests with an error |
|
477 return KErrNone; |
|
478 } |
|
479 //------------------------------------------------------------ |
|
480 // CCntParserCollector::CurrentItem() |
|
481 //------------------------------------------------------------ |
|
482 TInt CCntParserCollector::CurrentItem() |
|
483 { |
|
484 return iCurrentItem; |
|
485 } |
|
486 //------------------------------------------------------------ |
|
487 // CCntParserCollector::Count() |
|
488 //------------------------------------------------------------ |
|
489 TInt CCntParserCollector::Count() |
|
490 { |
|
491 return iCount; |
|
492 } |
|
493 //------------------------------------------------------------ |
|
494 // CCntParserCollector::ContactsSaved() |
|
495 //------------------------------------------------------------ |
|
496 TInt CCntParserCollector::ContactsSaved() |
|
497 { |
|
498 return iContactsSaved; |
|
499 } |
|
500 //------------------------------------------------------------ |
|
501 // CCntParserCollector::SaveTotalCountL() const |
|
502 //------------------------------------------------------------ |
|
503 void CCntParserCollector::SaveTotalCountL() |
|
504 { |
|
505 LOGGER_WRITE( "CntParserCollector: SaveTotalCount begin" ); |
|
506 |
|
507 if( iContactsDb ) |
|
508 { |
|
509 iTotalCount = iContactsDb->CountL(); |
|
510 LOGGER_WRITE_1( "CntParserCollector: SaveTotalCount iTotalCount %d", iTotalCount ); |
|
511 } |
|
512 |
|
513 RFs Fs; |
|
514 RFile writer; |
|
515 User::LeaveIfError(Fs.Connect()); //Connect to the file server |
|
516 CleanupClosePushL(Fs); |
|
517 |
|
518 User::LeaveIfError(Fs.CreatePrivatePath( EDriveC )); |
|
519 User::LeaveIfError(Fs.SetSessionToPrivate( EDriveC )); |
|
520 |
|
521 User::LeaveIfError(writer.Replace(Fs,KTotalCountFilePath,EFileWrite)); //Open file |
|
522 CleanupClosePushL(writer); |
|
523 LOGGER_WRITE( "CntParserCollector: SaveTotalCount file replaced" ); |
|
524 |
|
525 // Prepare externalized representation of iTotalCount |
|
526 TBuf8< 256 > countData; |
|
527 RDesWriteStream writeStream( countData ); |
|
528 CleanupClosePushL( writeStream ); |
|
529 writeStream.WriteInt32L( iTotalCount ); |
|
530 writeStream.CommitL(); |
|
531 CleanupStack::PopAndDestroy( &writeStream ); |
|
532 |
|
533 // Then write them to the file itself |
|
534 User::LeaveIfError(writer.Write( countData )); |
|
535 |
|
536 CleanupStack::PopAndDestroy(); //writer |
|
537 CleanupStack::PopAndDestroy(); //Fs |
|
538 |
|
539 LOGGER_WRITE( "CntParserCollector: SaveTotalCount end" ); |
|
540 } |
|
541 //------------------------------------------------------------ |
|
542 // CCntParserCollector::ReadTotalCountL() const |
|
543 //------------------------------------------------------------ |
|
544 TInt CCntParserCollector::ReadTotalCountL() const |
|
545 { |
|
546 LOGGER_WRITE( "CntParserCollector: ReadTotalCount begin" ); |
|
547 TInt total; |
|
548 RFs Fs; |
|
549 RFile reader; |
|
550 User::LeaveIfError(Fs.Connect()); //Connect to the file server |
|
551 CleanupClosePushL(Fs); |
|
552 |
|
553 User::LeaveIfError(Fs.CreatePrivatePath( EDriveC )); |
|
554 User::LeaveIfError(Fs.SetSessionToPrivate( EDriveC )); |
|
555 |
|
556 User::LeaveIfError(reader.Open(Fs,KTotalCountFilePath,EFileRead)); //Open file |
|
557 CleanupClosePushL(reader); |
|
558 LOGGER_WRITE( "CntParserCollector: ReadTotalCount file opened" ); |
|
559 |
|
560 RFileReadStream readStream(reader); |
|
561 readStream.PushL(); |
|
562 |
|
563 total = readStream.ReadInt32L(); |
|
564 |
|
565 LOGGER_WRITE_1( "CntParserCollector: ReadTotalCount total %d", total ); |
|
566 |
|
567 CleanupStack::PopAndDestroy(); //readStream |
|
568 CleanupStack::PopAndDestroy(); //writer |
|
569 CleanupStack::PopAndDestroy(); //Fs |
|
570 LOGGER_WRITE( "CntParserCollector: ReadTotalCount end" ); |
|
571 return total; |
|
572 } |
|
573 //------------------------------------------------------------ |
|
574 // CCntParserCollector::ContactCountChanged() const |
|
575 //------------------------------------------------------------ |
|
576 TBool CCntParserCollector::ContactCountChanged() |
|
577 { |
|
578 LOGGER_WRITE( "CntParserCollector: ContactCountChanged begin" ); |
|
579 TInt oldCount = 0; |
|
580 TInt err( KErrNone ); |
|
581 |
|
582 if( iContactsDb ) |
|
583 { |
|
584 TRAP( err, iTotalCount = iContactsDb->CountL() ); |
|
585 if ( err != KErrNone ) |
|
586 { |
|
587 LOGGER_WRITE_1( "iContactsDb->CountL leaved: %d", err ); |
|
588 LOGGER_WRITE( "CntParserCollector: ContactCountChanged ETrue" ); |
|
589 return ETrue; |
|
590 } |
|
591 LOGGER_WRITE_1( "CntParserCollector: ContactCountChanged iTotalCount %d", iTotalCount ); |
|
592 } |
|
593 |
|
594 TRAP( err, oldCount = ReadTotalCountL() ); |
|
595 |
|
596 LOGGER_WRITE_1( "CntParserCollector: ContactCountChanged err %d", err ); |
|
597 LOGGER_WRITE_1( "CntParserCollector: ContactCountChanged oldCount %d", oldCount ); |
|
598 LOGGER_WRITE_1( "CntParserCollector: ContactCountChanged iTotalCount %d", iTotalCount ); |
|
599 |
|
600 if( err == KErrNone ) |
|
601 { |
|
602 if( iTotalCount != oldCount ) |
|
603 { |
|
604 LOGGER_WRITE( "CntParserCollector: ContactCountChanged ETrue" ); |
|
605 return ETrue; |
|
606 } |
|
607 else |
|
608 { |
|
609 LOGGER_WRITE( "CntParserCollector: ContactCountChanged EFalse" ); |
|
610 return EFalse; |
|
611 } |
|
612 } |
|
613 else |
|
614 { |
|
615 LOGGER_WRITE( "CntParserCollector: ContactCountChanged ETrue" ); |
|
616 return ETrue; |
|
617 } |
|
618 } |
|
619 |
|
620 // end of file |
|