|
1 /* |
|
2 * Copyright (c) 2006-2006 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: VirtualPhonebook support for importing VCard messages |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // system includes |
|
21 #include <AknQueryDialog.h> // CAknTextQueryDialog |
|
22 #include <vcardbc.rsg> // resource definitions |
|
23 |
|
24 //Phonebook 2 API |
|
25 #include <CPbk2StoreConfiguration.h> |
|
26 #include <VPbkContactStoreUris.h> |
|
27 #include <CVPbkContactStoreUriArray.h> |
|
28 #include <MVPbkContactStoreList.h> |
|
29 #include <MVPbkContactStore.h> |
|
30 #include <MVPbkContactOperationBase.h> |
|
31 #include <CVPbkVCardEng.h> |
|
32 #include <CVPbkContactManager.h> |
|
33 #include <MVPbkStoreContact.h> |
|
34 #include <MVPbkFieldType.h> |
|
35 #include <MVPbkContactStoreProperties.h> |
|
36 #include <MVPbkContactStoreInfo.h> |
|
37 #include <CPbk2SortOrderManager.h> |
|
38 #include <MPbk2ContactNameFormatter.h> |
|
39 #include <Pbk2ContactNameFormatterFactory.h> |
|
40 #include <MVPbkContactFieldData.h> |
|
41 #include <MVPbkContactFieldTextData.h> |
|
42 #include <Pbk2UIControls.rsg> |
|
43 #include <VPbkSyncConstants.h> |
|
44 #include <TVPbkFieldVersitProperty.h> |
|
45 #include <TVPbkContactStoreUriPtr.h> |
|
46 #include <MVPbkContactFieldDateTimeData.h> |
|
47 #include <CVPbkFieldTypeSelector.h> |
|
48 #include <CVPbkContactStoreUri.h> |
|
49 #include <StringLoader.h> // StringLoader |
|
50 #include <aknnotewrappers.h> |
|
51 #include <Pbk2CommonUi.rsg> |
|
52 #include "VCardLog.h" |
|
53 #include <s32file.h> // for RFileReadStream |
|
54 #include <barsread.h> // for ResourceReader |
|
55 |
|
56 // user includes |
|
57 #include "vcardvpbutil.h" |
|
58 |
|
59 // local constants & enumerations |
|
60 _LIT(KClassName, "CVCardVpbUtil"); |
|
61 _LIT(KUnnamedText, "Unnamed"); |
|
62 _LIT(KDEFAULT_CNTDB_URI, "cntdb://c:contacts.cdb"); |
|
63 |
|
64 enum TPanicCode |
|
65 { |
|
66 ENoContactImported, |
|
67 EInvalidIndex, |
|
68 EPanicPostCond_ReallocBufferL |
|
69 }; |
|
70 |
|
71 /// Unnamed namespace for this-file-only helper funtions |
|
72 namespace { |
|
73 |
|
74 // Initial size for the conversion buffer |
|
75 const TInt KBufferLength = 128; |
|
76 _LIT8(KWvAddressVersitExtensionName, "X-WV-ID"); |
|
77 |
|
78 /** |
|
79 * Searches Versit property aArray for field aName. |
|
80 */ |
|
81 TBool ContainsFieldType( |
|
82 TArray<TVPbkFieldVersitProperty> aArray, |
|
83 TVPbkFieldTypeName aName) |
|
84 { |
|
85 TBool ret = EFalse; |
|
86 const TInt size = aArray.Count(); |
|
87 for (TInt i=0; i<size; ++i) |
|
88 { |
|
89 if (aArray[i].Name() == aName) |
|
90 { |
|
91 ret = ETrue; |
|
92 break; |
|
93 } |
|
94 } |
|
95 return ret; |
|
96 } |
|
97 |
|
98 /** |
|
99 * Searches Versit property array for a field aName |
|
100 * which has aExtensionName. |
|
101 */ |
|
102 TBool ContainsFieldTypeAndExtensionName( |
|
103 TArray<TVPbkFieldVersitProperty> aArray, |
|
104 TVPbkFieldTypeName aName, |
|
105 const TDesC8& aExtensionName) |
|
106 { |
|
107 TBool ret = EFalse; |
|
108 const TInt size = aArray.Count(); |
|
109 for (TInt i=0; i<size; ++i) |
|
110 { |
|
111 if (aArray[i].Name() == aName && |
|
112 aArray[i].ExtensionName().CompareF(aExtensionName) == 0) |
|
113 { |
|
114 ret = ETrue; |
|
115 break; |
|
116 } |
|
117 } |
|
118 return ret; |
|
119 } |
|
120 |
|
121 |
|
122 /** |
|
123 * Inspects is number conversion allowed. It is not allowed |
|
124 * for certain fields, like for email field. |
|
125 */ |
|
126 inline TBool IsNumberConversionAllowed(const MVPbkFieldType& aFieldType) |
|
127 { |
|
128 TBool ret = ETrue; |
|
129 |
|
130 // Perform number conversion if allowed |
|
131 if (ContainsFieldType(aFieldType.VersitProperties(), EVPbkVersitNameURL)) |
|
132 { |
|
133 ret = EFalse; |
|
134 } |
|
135 else if (ContainsFieldType(aFieldType.VersitProperties(), EVPbkVersitNameEMAIL)) |
|
136 { |
|
137 ret = EFalse; |
|
138 } |
|
139 // search for the X-WV-ID field |
|
140 else if (ContainsFieldTypeAndExtensionName( |
|
141 aFieldType.VersitProperties(), EVPbkVersitNameX, KWvAddressVersitExtensionName)) |
|
142 { |
|
143 ret = EFalse; |
|
144 } |
|
145 |
|
146 return ret; |
|
147 } |
|
148 |
|
149 |
|
150 } // namespace |
|
151 |
|
152 |
|
153 // ======== MEMBER FUNCTIONS ======== |
|
154 |
|
155 CVCardVpbUtil* CVCardVpbUtil::NewL() |
|
156 { |
|
157 CVCardVpbUtil* self = new( ELeave ) CVCardVpbUtil(); |
|
158 CleanupStack::PushL( self ); |
|
159 self->ConstructL(); |
|
160 CleanupStack::Pop( self ); |
|
161 return self; |
|
162 } |
|
163 |
|
164 CVCardVpbUtil::~CVCardVpbUtil() |
|
165 { |
|
166 delete iAvailableUris; |
|
167 |
|
168 iContactsToShow.ResetAndDestroy(); |
|
169 |
|
170 iContactsToStore.ResetAndDestroy(); |
|
171 |
|
172 if ( iDefaultContactStore ) |
|
173 { |
|
174 iDefaultContactStore->Close( *this ); |
|
175 } |
|
176 |
|
177 if ( iShowContactStore ) |
|
178 { |
|
179 iShowContactStore->Close( *this ); |
|
180 } |
|
181 |
|
182 if(iStoreList) |
|
183 { |
|
184 iStoreList->CloseAll( *this ); |
|
185 } |
|
186 |
|
187 delete iContactManager; |
|
188 delete iVCardEngine; |
|
189 delete iBuffer; |
|
190 } |
|
191 |
|
192 void CVCardVpbUtil::ImportVCardL( TVCardBCBusinessCardType aVCardType, RFile aFileHandle ) |
|
193 { |
|
194 RFileReadStream stream; |
|
195 stream.Attach( aFileHandle ); |
|
196 CleanupClosePushL( stream ); |
|
197 iVCardType = aVCardType; |
|
198 |
|
199 //import is done to both store at this point as the fileHandle is not |
|
200 //accessible later |
|
201 VCardToPhoneStoreL( stream ); |
|
202 VCardToDefaultStoreL( stream ); |
|
203 CleanupStack::Pop(); //stream |
|
204 |
|
205 //were done with stream as the data has been imported |
|
206 //this will also close the fileHandle |
|
207 stream.Release(); |
|
208 stream.Close(); |
|
209 } |
|
210 |
|
211 TBool CVCardVpbUtil::CommitVCardToStoreL() |
|
212 { |
|
213 MVPbkContactOperationBase* ope( NULL ); |
|
214 if( DefaultStoreSupportsAllFieldsL()&& !StoreFullL() ) |
|
215 { |
|
216 ope = |
|
217 iContactManager->CommitContactsL( iContactsToStore.Array(), *this ); |
|
218 } |
|
219 else |
|
220 { |
|
221 //dialog to ask user if contact data is to be stored to phone memory |
|
222 //this is the case if the contact data can not be fitted to the |
|
223 //default saving store ie. SIM store |
|
224 CAknQueryDialog* qDlg = CAknQueryDialog::NewL(); |
|
225 if ( qDlg->ExecuteLD( R_VCARD_STORE_QUERY ) ) |
|
226 { |
|
227 ope = |
|
228 iContactManager->CommitContactsL( iContactsToShow.Array(), *this ); |
|
229 } |
|
230 } |
|
231 if( ope ) |
|
232 { |
|
233 CleanupDeletePushL( ope ); |
|
234 |
|
235 //the active scheduler needs two iterations |
|
236 for ( TInt i = 0; i < 2; ++i ) |
|
237 { |
|
238 StartSchedulerAndDecideToLeaveL(); |
|
239 } |
|
240 CleanupStack::PopAndDestroy(); |
|
241 return ETrue; |
|
242 } |
|
243 return EFalse; |
|
244 } |
|
245 |
|
246 MVPbkStoreContact* CVCardVpbUtil::ContactData() const |
|
247 { |
|
248 __ASSERT_DEBUG( iContactsToShow.Count() > 0, Panic( ENoContactImported ) ); |
|
249 // If iContactsToShow.Count() is zero, then it is not possible to parse the fields,so it has to return from here.. |
|
250 if ( iContactsToShow.Count() == 0 ) |
|
251 { |
|
252 return NULL; |
|
253 } |
|
254 return iContactsToShow[0]; |
|
255 } |
|
256 |
|
257 TBool CVCardVpbUtil::IsContactItemEmpty() |
|
258 { |
|
259 TBool ret( ETrue ); |
|
260 MVPbkStoreContact* storeContact = ContactData(); |
|
261 if ( !storeContact ) |
|
262 { |
|
263 return ret; |
|
264 } |
|
265 const MVPbkStoreContactFieldCollection& fields = storeContact->Fields(); |
|
266 TInt count = fields.FieldCount(); |
|
267 |
|
268 while( count ) |
|
269 { |
|
270 __ASSERT_DEBUG( count <= fields.FieldCount() && count > 0, |
|
271 Panic( EInvalidIndex ) ); |
|
272 |
|
273 const MVPbkStoreContactField& field = fields.FieldAt( count - 1 ); |
|
274 |
|
275 if( !field.FieldData().IsEmpty() ) |
|
276 { |
|
277 ret = EFalse; |
|
278 break; |
|
279 } |
|
280 count--; |
|
281 } |
|
282 return ret; |
|
283 } |
|
284 |
|
285 void CVCardVpbUtil::OpenComplete() |
|
286 { |
|
287 //nothing to do |
|
288 } |
|
289 |
|
290 void CVCardVpbUtil::StoreReady( MVPbkContactStore& /*aContactStore*/ ) |
|
291 { |
|
292 if( iRespondToObserverEvent ) |
|
293 { |
|
294 iLastError = KErrNone; |
|
295 CActiveScheduler::Stop(); |
|
296 } |
|
297 } |
|
298 |
|
299 void CVCardVpbUtil::StoreUnavailable( |
|
300 MVPbkContactStore& aContactStore, |
|
301 TInt /*aReason*/ ) |
|
302 { |
|
303 // Remove the store from the available uri list. This is the case e.g. in when SIM card |
|
304 // is set to be default saving memory and SIM card is not inserted to phone. |
|
305 TVPbkContactStoreUriPtr uri = aContactStore.StoreProperties().Uri(); |
|
306 iAvailableUris->Remove( uri ); |
|
307 if( iRespondToObserverEvent ) |
|
308 { |
|
309 //we do not consider an unavailable store as leaving error situation |
|
310 iLastError = KErrNone; |
|
311 CActiveScheduler::Stop(); |
|
312 } |
|
313 } |
|
314 |
|
315 void CVCardVpbUtil::HandleStoreEventL( |
|
316 MVPbkContactStore& /*aContactStore*/, |
|
317 TVPbkContactStoreEvent /*aStoreEvent*/ ) |
|
318 { |
|
319 if( iRespondToObserverEvent ) |
|
320 { |
|
321 CActiveScheduler::Stop(); |
|
322 } |
|
323 } |
|
324 |
|
325 void CVCardVpbUtil::VPbkSingleContactOperationComplete( |
|
326 MVPbkContactOperationBase& /*aOperation*/, |
|
327 MVPbkStoreContact* /*aContact*/ ) |
|
328 { |
|
329 if( iRespondToObserverEvent ) |
|
330 { |
|
331 CActiveScheduler::Stop(); |
|
332 } |
|
333 } |
|
334 |
|
335 void CVCardVpbUtil::VPbkSingleContactOperationFailed( |
|
336 MVPbkContactOperationBase& /*aOperation*/, |
|
337 TInt aError ) |
|
338 { |
|
339 if( iRespondToObserverEvent ) |
|
340 { |
|
341 iLastError = aError; |
|
342 CActiveScheduler::Stop(); |
|
343 } |
|
344 } |
|
345 |
|
346 void CVCardVpbUtil::StepComplete( |
|
347 MVPbkContactOperationBase& /*aOperation*/, |
|
348 TInt /*aStepSize*/ ) |
|
349 { |
|
350 if( iRespondToObserverEvent ) |
|
351 { |
|
352 iLastError = KErrNone; |
|
353 } |
|
354 } |
|
355 |
|
356 |
|
357 TBool CVCardVpbUtil::StepFailed( |
|
358 MVPbkContactOperationBase& /*aOperation*/, |
|
359 TInt /*aStepSize*/, |
|
360 TInt aError ) |
|
361 { |
|
362 if( iRespondToObserverEvent ) |
|
363 { |
|
364 iLastError = aError; |
|
365 CActiveScheduler::Stop(); |
|
366 |
|
367 //since we trigger a leave we can also cancel the |
|
368 //ongoing operation |
|
369 return EFalse; |
|
370 } |
|
371 return ETrue; |
|
372 } |
|
373 |
|
374 void CVCardVpbUtil::OperationComplete( |
|
375 MVPbkContactOperationBase& /*aOperation*/ ) |
|
376 { |
|
377 if( iRespondToObserverEvent ) |
|
378 { |
|
379 iLastError = KErrNone; |
|
380 CActiveScheduler::Stop(); |
|
381 } |
|
382 } |
|
383 |
|
384 CVCardVpbUtil::CVCardVpbUtil() |
|
385 { |
|
386 } |
|
387 |
|
388 void CVCardVpbUtil::ConstructL() |
|
389 { |
|
390 CPbk2StoreConfiguration* storeConfiguration = CPbk2StoreConfiguration::NewL(); |
|
391 CleanupStack::PushL( storeConfiguration ); |
|
392 iAvailableUris = storeConfiguration->CurrentConfigurationL(); |
|
393 |
|
394 //if default contact store is not included in uriarray we will add it manually |
|
395 //this happens if the store is not enabled in phonebook settings |
|
396 TVPbkContactStoreUriPtr defaultCntDbUriPtr( VPbkContactStoreUris::DefaultCntDbUri() ); |
|
397 if ( !iAvailableUris->IsIncluded( defaultCntDbUriPtr ) ) |
|
398 { |
|
399 iAvailableUris->AppendL( defaultCntDbUriPtr ); |
|
400 } |
|
401 |
|
402 iContactManager = CVPbkContactManager::NewL( *iAvailableUris ); |
|
403 iStoreList = &iContactManager->ContactStoresL(); |
|
404 TInt storeCount ( iStoreList->Count() ); |
|
405 iStoreList->OpenAllL( *this ); |
|
406 |
|
407 // Every store sends EStoreReady or EOpenError event |
|
408 for ( TInt i = 0; i < storeCount; ++i ) |
|
409 { |
|
410 StartSchedulerAndDecideToLeaveL(); |
|
411 } |
|
412 |
|
413 iVCardEngine = CVPbkVCardEng::NewL( *iContactManager ); |
|
414 |
|
415 if ( iAvailableUris->Count() > 0 ) |
|
416 { |
|
417 // It is assumed that phone memory store is always succesfully opened. |
|
418 |
|
419 // Default saving memory might not be available. E.g. if it set to SIM and SIM is |
|
420 // not inserted to phone. |
|
421 TVPbkContactStoreUriPtr defaultsavingstore = storeConfiguration->DefaultSavingStoreL(); |
|
422 if ( iAvailableUris->IsIncluded( defaultsavingstore ) ) |
|
423 { |
|
424 iDefaultContactStore = |
|
425 iContactManager->ContactStoresL().Find( defaultsavingstore ); |
|
426 } |
|
427 else |
|
428 { |
|
429 iDefaultContactStore = |
|
430 iContactManager->ContactStoresL().Find( defaultCntDbUriPtr ); |
|
431 } |
|
432 |
|
433 iShowContactStore = |
|
434 iContactManager->ContactStoresL().Find( defaultCntDbUriPtr ); |
|
435 } |
|
436 else |
|
437 { |
|
438 // Even the phone memory store could not be opened. We can leave, since it is impossible |
|
439 // to open vCard. |
|
440 User::Leave( KErrCouldNotConnect ); |
|
441 } |
|
442 |
|
443 iBuffer = HBufC::NewL(KBufferLength); |
|
444 CleanupStack::PopAndDestroy( storeConfiguration ); |
|
445 } |
|
446 |
|
447 TBool CVCardVpbUtil::DefaultStoreSupportsAllFieldsL() |
|
448 { |
|
449 TBool retVal( ETrue ); |
|
450 TInt shownCount = iContactsToShow[0]->Fields().FieldCount(); |
|
451 TInt storedCount = iContactsToStore[0]->Fields().FieldCount(); |
|
452 |
|
453 CPbk2SortOrderManager* sortOrderManager = CPbk2SortOrderManager::NewL( iContactManager->FieldTypes() ); |
|
454 CleanupStack::PushL( sortOrderManager ); |
|
455 |
|
456 MPbk2ContactNameFormatter* nameFormatter = Pbk2ContactNameFormatterFactory::CreateL( |
|
457 KUnnamedText, iContactManager->FieldTypes(), |
|
458 *sortOrderManager ); |
|
459 CleanupStack::PushL( nameFormatter ); |
|
460 |
|
461 TInt shownTitleFields( 0 ); |
|
462 for( TInt counter = 0; counter < shownCount; counter++ ) |
|
463 { |
|
464 const MVPbkBaseContactField& srcField = iContactsToShow[0]->Fields().FieldAt( counter ); |
|
465 const MVPbkFieldType* fieldType = srcField.BestMatchingFieldType(); |
|
466 if( nameFormatter->IsTitleFieldType( *fieldType ) ) |
|
467 shownTitleFields++; |
|
468 } |
|
469 |
|
470 TInt storedTitleFields( 0 ); |
|
471 for( TInt counter = 0; counter < storedCount; counter++ ) |
|
472 { |
|
473 const MVPbkBaseContactField& srcField = iContactsToStore[0]->Fields().FieldAt( counter ); |
|
474 const MVPbkFieldType* fieldType = srcField.BestMatchingFieldType(); |
|
475 if( nameFormatter->IsTitleFieldType( *fieldType ) ) |
|
476 storedTitleFields++; |
|
477 } |
|
478 |
|
479 CleanupStack::Pop( 2 ); |
|
480 delete nameFormatter; |
|
481 delete sortOrderManager; |
|
482 |
|
483 //check if any of the dropped fields was title field |
|
484 if( shownCount - shownTitleFields > storedCount - storedTitleFields ) |
|
485 retVal = EFalse; |
|
486 |
|
487 return retVal; |
|
488 } |
|
489 |
|
490 |
|
491 void CVCardVpbUtil::VCardToPhoneStoreL( RFileReadStream& aStream ) |
|
492 { |
|
493 if( iContactsToShow.Count() > 0 ) |
|
494 { |
|
495 iContactsToShow.ResetAndDestroy(); |
|
496 iContactsToShow.Close(); |
|
497 } |
|
498 |
|
499 //always ensure that the read stream is in the beginning |
|
500 //of the file |
|
501 aStream.Source()->SeekL( MStreamBuf::ERead, EStreamBeginning, 0 ); |
|
502 MVPbkContactOperationBase* op; |
|
503 if( iVCardType == EVCard ) |
|
504 { |
|
505 op = iVCardEngine->ImportVCardL( |
|
506 iContactsToShow, |
|
507 *iShowContactStore, |
|
508 aStream, |
|
509 *this); |
|
510 } |
|
511 else |
|
512 { |
|
513 op = |
|
514 iVCardEngine->ImportCompactBusinessCardL( |
|
515 iContactsToShow, |
|
516 *iShowContactStore, |
|
517 aStream, |
|
518 *this); |
|
519 } |
|
520 CleanupDeletePushL( op ); |
|
521 StartSchedulerAndDecideToLeaveL(); |
|
522 CleanupStack::PopAndDestroy(); |
|
523 |
|
524 } |
|
525 |
|
526 void CVCardVpbUtil::VCardToDefaultStoreL( RFileReadStream& aStream ) |
|
527 { |
|
528 if( iContactsToStore.Count() > 0 ) |
|
529 { |
|
530 iContactsToStore.ResetAndDestroy(); |
|
531 iContactsToStore.Close(); |
|
532 } |
|
533 |
|
534 //always ensure that the read stream is in the beginning |
|
535 //of the file |
|
536 aStream.Source()->SeekL( MStreamBuf::ERead, EStreamBeginning, 0 ); |
|
537 MVPbkContactOperationBase* op; |
|
538 if( iVCardType == EVCard ) |
|
539 { |
|
540 op = |
|
541 iVCardEngine->ImportVCardL( |
|
542 iContactsToStore, |
|
543 *iDefaultContactStore, |
|
544 aStream, |
|
545 *this); |
|
546 } |
|
547 else |
|
548 { |
|
549 op = |
|
550 iVCardEngine->ImportCompactBusinessCardL( |
|
551 iContactsToStore, |
|
552 *iDefaultContactStore, |
|
553 aStream, |
|
554 *this); |
|
555 } |
|
556 CleanupDeletePushL( op ); |
|
557 StartSchedulerAndDecideToLeaveL(); |
|
558 CleanupStack::PopAndDestroy(); |
|
559 |
|
560 } |
|
561 |
|
562 void CVCardVpbUtil::StartSchedulerAndDecideToLeaveL() |
|
563 { |
|
564 //we want to control the responding to observable events to only happen |
|
565 //to requests made from this module |
|
566 iRespondToObserverEvent = ETrue; |
|
567 CActiveScheduler::Start(); |
|
568 User::LeaveIfError( iLastError ); |
|
569 iRespondToObserverEvent = EFalse; |
|
570 } |
|
571 |
|
572 TPtrC CVCardVpbUtil::FormatFieldContentL |
|
573 (const MVPbkBaseContactField& aField) |
|
574 { |
|
575 const MVPbkFieldType* aFieldType = aField.BestMatchingFieldType(); |
|
576 TPtr text(iBuffer->Des()); |
|
577 |
|
578 switch (aField.FieldData().DataType()) |
|
579 { |
|
580 case EVPbkFieldStorageTypeText: |
|
581 { |
|
582 const MVPbkContactFieldTextData* fieldData = |
|
583 &MVPbkContactFieldTextData::Cast(aField.FieldData()); |
|
584 TPtrC fieldText(fieldData->Text()); |
|
585 |
|
586 if (IsFieldTypeL(*aFieldType, R_MESSAGING_PHONENUMBER_SELECTOR)) |
|
587 { |
|
588 // telephony field |
|
589 |
|
590 // convert number according to active number setting |
|
591 if ( fieldText.Length() <= KBufferLength ) |
|
592 { |
|
593 HBufC* formattedPhoneNumber = fieldText.AllocLC(); |
|
594 TPtr formatterNumber = formattedPhoneNumber->Des(); |
|
595 |
|
596 AknTextUtils::DisplayTextLanguageSpecificNumberConversion( |
|
597 formatterNumber ); |
|
598 text.Set(ReallocBufferL(formatterNumber.Length()+4)); |
|
599 _LIT( Kstr, " " ); |
|
600 TDesC16 tmp = Kstr; |
|
601 text.Copy(tmp); |
|
602 text.Append(0x202A); |
|
603 text.Append(formatterNumber); |
|
604 text.Append(0x202C); |
|
605 CleanupStack::PopAndDestroy(formattedPhoneNumber); |
|
606 } |
|
607 else |
|
608 { |
|
609 return fieldData->Text(); |
|
610 } |
|
611 } |
|
612 else if (IsFieldTypeL(*aFieldType, R_MESSAGING_SYNCRONIZATION_SELECTOR)) |
|
613 { |
|
614 // syncronization field |
|
615 if (!fieldText.CompareF(KVPbkContactSyncPublic)) |
|
616 { |
|
617 HBufC* textBuffer = CCoeEnv::Static()->AllocReadResourceLC( |
|
618 R_QTN_CALE_CONFIDENT_PUBLIC); |
|
619 TPtr localizedSyncText = textBuffer->Des(); |
|
620 text.Set(ReallocBufferL(localizedSyncText.Length())); |
|
621 text.Copy(localizedSyncText); |
|
622 CleanupStack::PopAndDestroy(textBuffer); |
|
623 } |
|
624 else if (!fieldText.CompareF(KVPbkContactSyncNoSync)) |
|
625 { |
|
626 HBufC* textBuffer = CCoeEnv::Static()->AllocReadResourceLC( |
|
627 R_QTN_CALE_CONFIDENT_NONE); |
|
628 TPtr localizedSyncText = textBuffer->Des(); |
|
629 text.Set(ReallocBufferL(localizedSyncText.Length())); |
|
630 text.Copy(localizedSyncText); |
|
631 CleanupStack::PopAndDestroy(textBuffer); |
|
632 } |
|
633 else |
|
634 { |
|
635 // otherwise sync setting is the default value - private |
|
636 HBufC* textBuffer = CCoeEnv::Static()->AllocReadResourceLC( |
|
637 R_QTN_CALE_CONFIDENT_PRIVATE); |
|
638 TPtr localizedSyncText = textBuffer->Des(); |
|
639 text.Set(ReallocBufferL(localizedSyncText.Length())); |
|
640 text.Copy(localizedSyncText); |
|
641 CleanupStack::PopAndDestroy(textBuffer); |
|
642 } |
|
643 } |
|
644 else |
|
645 { |
|
646 text.Set(ReallocBufferL(fieldText.Length())); |
|
647 text.Copy(fieldText); |
|
648 |
|
649 // Check is there need to display the digits in the |
|
650 // text with foreign characters |
|
651 // Perform number conversion if allowed |
|
652 if (IsNumberConversionAllowed(*aFieldType)) |
|
653 { |
|
654 AknTextUtils::DisplayTextLanguageSpecificNumberConversion( |
|
655 text); |
|
656 } |
|
657 } |
|
658 break; |
|
659 } |
|
660 case EVPbkFieldStorageTypeDateTime: |
|
661 { |
|
662 TInt error = KErrNone; |
|
663 do |
|
664 { |
|
665 HBufC* timeFormat = CCoeEnv::Static()->AllocReadResourceLC(R_QTN_DATE_USUAL); |
|
666 const MVPbkContactFieldDateTimeData* fieldData = |
|
667 &MVPbkContactFieldDateTimeData::Cast(aField.FieldData()); |
|
668 TRAPD(error, fieldData->DateTime().FormatL(text, *timeFormat)); |
|
669 AknTextUtils::DisplayTextLanguageSpecificNumberConversion(text); |
|
670 CleanupStack::PopAndDestroy(timeFormat); // timeFormat |
|
671 if (error == KErrOverflow) |
|
672 { |
|
673 // allocate bigger buffer for formatting text |
|
674 text.Set(ReallocBufferL(2*text.MaxLength())); |
|
675 } |
|
676 else if (error) |
|
677 { |
|
678 // rethrow other errors |
|
679 User::Leave(error); |
|
680 } |
|
681 } while (error == KErrOverflow); |
|
682 break; |
|
683 } |
|
684 default: |
|
685 { |
|
686 text.Zero(); |
|
687 break; |
|
688 } |
|
689 } |
|
690 |
|
691 return text; |
|
692 } |
|
693 |
|
694 /** |
|
695 * Checks the field type. |
|
696 */ |
|
697 TBool CVCardVpbUtil::IsFieldTypeL( |
|
698 const MVPbkFieldType& aFieldType, |
|
699 TInt aResourceId) const |
|
700 { |
|
701 TResourceReader reader; |
|
702 CCoeEnv::Static()->CreateResourceReaderLC(reader, aResourceId); |
|
703 |
|
704 CVPbkFieldTypeSelector* selector = CVPbkFieldTypeSelector::NewL( |
|
705 reader, iContactManager->FieldTypes()); |
|
706 // Check if the field type is the one needed |
|
707 TBool ret = selector->IsFieldTypeIncluded(aFieldType); |
|
708 CleanupStack::PopAndDestroy(); // resource buffer |
|
709 delete selector; |
|
710 return ret; |
|
711 } |
|
712 |
|
713 TPtr CVCardVpbUtil::ReallocBufferL |
|
714 (TInt aNewSize) |
|
715 { |
|
716 const TInt currMaxLength = iBuffer->Des().MaxLength(); |
|
717 if (aNewSize > currMaxLength) |
|
718 { |
|
719 iBuffer = iBuffer->ReAllocL(aNewSize); |
|
720 } |
|
721 |
|
722 //PostCond: |
|
723 __ASSERT_DEBUG(iBuffer->Des().MaxLength() >= aNewSize, |
|
724 Panic(EPanicPostCond_ReallocBufferL)); |
|
725 |
|
726 return iBuffer->Des(); |
|
727 } |
|
728 |
|
729 void CVCardVpbUtil::Panic( TInt aReason ) |
|
730 { |
|
731 User::Panic( KClassName, aReason ); |
|
732 } |
|
733 /** |
|
734 * Check whether default store is Full or Not. |
|
735 */ |
|
736 TBool CVCardVpbUtil::StoreFullL() |
|
737 { |
|
738 LOG("CVCardVpbUtil::StoreFullL"); |
|
739 TBool ret( EFalse ); |
|
740 const MVPbkContactStore* iTargetStore; |
|
741 HBufC* textBuffer; |
|
742 CPbk2StoreConfiguration* storeConfiguration = CPbk2StoreConfiguration::NewL(); |
|
743 CleanupStack::PushL( storeConfiguration ); |
|
744 TVPbkContactStoreUriPtr defaultsavingstore = storeConfiguration->DefaultSavingStoreL(); |
|
745 iTargetStore = iContactManager->ContactStoresL().Find(defaultsavingstore ); |
|
746 const MVPbkContactStoreInfo& storeInfo = iTargetStore->StoreInfo(); |
|
747 if ( storeInfo.MaxNumberOfContactsL() != KVPbkStoreInfoUnlimitedNumber && |
|
748 storeInfo.MaxNumberOfContactsL() <= storeInfo.NumberOfContactsL() ) |
|
749 { |
|
750 CVPbkContactStoreUri* uri = CVPbkContactStoreUri::NewL( defaultsavingstore ); |
|
751 CleanupStack::PushL( uri ); |
|
752 if(uri->Uri().UriDes().CompareC(KDEFAULT_CNTDB_URI) == 0 ) |
|
753 { |
|
754 LOG("CVCardVpbUtil::StoreFullL, Phone memory full"); |
|
755 textBuffer = StringLoader::LoadLC( R_QTN_PHOB_PB_INFO_MEMORY_PHONE ); |
|
756 } |
|
757 else |
|
758 { |
|
759 LOG("CVCardVpbUtil::StoreFullL, SIM memory full"); |
|
760 textBuffer = StringLoader::LoadLC( R_QTN_PHOB_PB_INFO_MEMORY_SIM ); |
|
761 } |
|
762 ShowNoteL( R_QTN_PHOB_NOTE_STORE_FULL, textBuffer->Des() ); |
|
763 CleanupStack::PopAndDestroy(textBuffer); |
|
764 CleanupStack::PopAndDestroy();//destroy uri |
|
765 ret = ETrue; |
|
766 } |
|
767 CleanupStack::PopAndDestroy( storeConfiguration ); |
|
768 return ret; |
|
769 } |
|
770 |
|
771 /** |
|
772 * Shows popup Note. |
|
773 */ |
|
774 void CVCardVpbUtil::ShowNoteL( TInt aResourceId, const TDesC& aString ) |
|
775 { |
|
776 LOG("CVCardVpbUtil::ShowNoteL"); |
|
777 HBufC* prompt = NULL; |
|
778 if( aString.Length() ) |
|
779 prompt = StringLoader::LoadLC( aResourceId, aString ); |
|
780 else |
|
781 prompt = StringLoader::LoadLC( aResourceId ); |
|
782 CAknInformationNote* dlg = new(ELeave) CAknInformationNote(ETrue); |
|
783 dlg->ExecuteLD(*prompt); |
|
784 CleanupStack::PopAndDestroy(); // prompt |
|
785 } |
|
786 |