|
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 return iContactsToShow[0]; |
|
250 } |
|
251 |
|
252 TBool CVCardVpbUtil::IsContactItemEmpty() |
|
253 { |
|
254 const MVPbkStoreContactFieldCollection& fields = ContactData()->Fields(); |
|
255 TInt count = fields.FieldCount(); |
|
256 |
|
257 TBool ret( ETrue ); |
|
258 while( count ) |
|
259 { |
|
260 __ASSERT_DEBUG( count <= fields.FieldCount() && count > 0, |
|
261 Panic( EInvalidIndex ) ); |
|
262 |
|
263 const MVPbkStoreContactField& field = fields.FieldAt( count - 1 ); |
|
264 |
|
265 if( !field.FieldData().IsEmpty() ) |
|
266 { |
|
267 ret = EFalse; |
|
268 break; |
|
269 } |
|
270 count--; |
|
271 } |
|
272 return ret; |
|
273 } |
|
274 |
|
275 void CVCardVpbUtil::OpenComplete() |
|
276 { |
|
277 //nothing to do |
|
278 } |
|
279 |
|
280 void CVCardVpbUtil::StoreReady( MVPbkContactStore& /*aContactStore*/ ) |
|
281 { |
|
282 if( iRespondToObserverEvent ) |
|
283 { |
|
284 iLastError = KErrNone; |
|
285 CActiveScheduler::Stop(); |
|
286 } |
|
287 } |
|
288 |
|
289 void CVCardVpbUtil::StoreUnavailable( |
|
290 MVPbkContactStore& aContactStore, |
|
291 TInt /*aReason*/ ) |
|
292 { |
|
293 // Remove the store from the available uri list. This is the case e.g. in when SIM card |
|
294 // is set to be default saving memory and SIM card is not inserted to phone. |
|
295 TVPbkContactStoreUriPtr uri = aContactStore.StoreProperties().Uri(); |
|
296 iAvailableUris->Remove( uri ); |
|
297 if( iRespondToObserverEvent ) |
|
298 { |
|
299 //we do not consider an unavailable store as leaving error situation |
|
300 iLastError = KErrNone; |
|
301 CActiveScheduler::Stop(); |
|
302 } |
|
303 } |
|
304 |
|
305 void CVCardVpbUtil::HandleStoreEventL( |
|
306 MVPbkContactStore& /*aContactStore*/, |
|
307 TVPbkContactStoreEvent /*aStoreEvent*/ ) |
|
308 { |
|
309 if( iRespondToObserverEvent ) |
|
310 { |
|
311 CActiveScheduler::Stop(); |
|
312 } |
|
313 } |
|
314 |
|
315 void CVCardVpbUtil::VPbkSingleContactOperationComplete( |
|
316 MVPbkContactOperationBase& /*aOperation*/, |
|
317 MVPbkStoreContact* /*aContact*/ ) |
|
318 { |
|
319 if( iRespondToObserverEvent ) |
|
320 { |
|
321 CActiveScheduler::Stop(); |
|
322 } |
|
323 } |
|
324 |
|
325 void CVCardVpbUtil::VPbkSingleContactOperationFailed( |
|
326 MVPbkContactOperationBase& /*aOperation*/, |
|
327 TInt aError ) |
|
328 { |
|
329 if( iRespondToObserverEvent ) |
|
330 { |
|
331 iLastError = aError; |
|
332 CActiveScheduler::Stop(); |
|
333 } |
|
334 } |
|
335 |
|
336 void CVCardVpbUtil::StepComplete( |
|
337 MVPbkContactOperationBase& /*aOperation*/, |
|
338 TInt /*aStepSize*/ ) |
|
339 { |
|
340 if( iRespondToObserverEvent ) |
|
341 { |
|
342 iLastError = KErrNone; |
|
343 } |
|
344 } |
|
345 |
|
346 |
|
347 TBool CVCardVpbUtil::StepFailed( |
|
348 MVPbkContactOperationBase& /*aOperation*/, |
|
349 TInt /*aStepSize*/, |
|
350 TInt aError ) |
|
351 { |
|
352 if( iRespondToObserverEvent ) |
|
353 { |
|
354 iLastError = aError; |
|
355 CActiveScheduler::Stop(); |
|
356 |
|
357 //since we trigger a leave we can also cancel the |
|
358 //ongoing operation |
|
359 return EFalse; |
|
360 } |
|
361 return ETrue; |
|
362 } |
|
363 |
|
364 void CVCardVpbUtil::OperationComplete( |
|
365 MVPbkContactOperationBase& /*aOperation*/ ) |
|
366 { |
|
367 if( iRespondToObserverEvent ) |
|
368 { |
|
369 iLastError = KErrNone; |
|
370 CActiveScheduler::Stop(); |
|
371 } |
|
372 } |
|
373 |
|
374 CVCardVpbUtil::CVCardVpbUtil() |
|
375 { |
|
376 } |
|
377 |
|
378 void CVCardVpbUtil::ConstructL() |
|
379 { |
|
380 CPbk2StoreConfiguration* storeConfiguration = CPbk2StoreConfiguration::NewL(); |
|
381 CleanupStack::PushL( storeConfiguration ); |
|
382 iAvailableUris = storeConfiguration->CurrentConfigurationL(); |
|
383 |
|
384 //if default contact store is not included in uriarray we will add it manually |
|
385 //this happens if the store is not enabled in phonebook settings |
|
386 TVPbkContactStoreUriPtr defaultCntDbUriPtr( VPbkContactStoreUris::DefaultCntDbUri() ); |
|
387 if ( !iAvailableUris->IsIncluded( defaultCntDbUriPtr ) ) |
|
388 { |
|
389 iAvailableUris->AppendL( defaultCntDbUriPtr ); |
|
390 } |
|
391 |
|
392 iContactManager = CVPbkContactManager::NewL( *iAvailableUris ); |
|
393 iStoreList = &iContactManager->ContactStoresL(); |
|
394 TInt storeCount ( iStoreList->Count() ); |
|
395 iStoreList->OpenAllL( *this ); |
|
396 |
|
397 // Every store sends EStoreReady or EOpenError event |
|
398 for ( TInt i = 0; i < storeCount; ++i ) |
|
399 { |
|
400 StartSchedulerAndDecideToLeaveL(); |
|
401 } |
|
402 |
|
403 iVCardEngine = CVPbkVCardEng::NewL( *iContactManager ); |
|
404 |
|
405 if ( iAvailableUris->Count() > 0 ) |
|
406 { |
|
407 // It is assumed that phone memory store is always succesfully opened. |
|
408 |
|
409 // Default saving memory might not be available. E.g. if it set to SIM and SIM is |
|
410 // not inserted to phone. |
|
411 TVPbkContactStoreUriPtr defaultsavingstore = storeConfiguration->DefaultSavingStoreL(); |
|
412 if ( iAvailableUris->IsIncluded( defaultsavingstore ) ) |
|
413 { |
|
414 iDefaultContactStore = |
|
415 iContactManager->ContactStoresL().Find( defaultsavingstore ); |
|
416 } |
|
417 else |
|
418 { |
|
419 iDefaultContactStore = |
|
420 iContactManager->ContactStoresL().Find( defaultCntDbUriPtr ); |
|
421 } |
|
422 |
|
423 iShowContactStore = |
|
424 iContactManager->ContactStoresL().Find( defaultCntDbUriPtr ); |
|
425 } |
|
426 else |
|
427 { |
|
428 // Even the phone memory store could not be opened. We can leave, since it is impossible |
|
429 // to open vCard. |
|
430 User::Leave( KErrCouldNotConnect ); |
|
431 } |
|
432 |
|
433 iBuffer = HBufC::NewL(KBufferLength); |
|
434 CleanupStack::PopAndDestroy( storeConfiguration ); |
|
435 } |
|
436 |
|
437 TBool CVCardVpbUtil::DefaultStoreSupportsAllFieldsL() |
|
438 { |
|
439 TBool retVal( ETrue ); |
|
440 TInt shownCount = iContactsToShow[0]->Fields().FieldCount(); |
|
441 TInt storedCount = iContactsToStore[0]->Fields().FieldCount(); |
|
442 |
|
443 CPbk2SortOrderManager* sortOrderManager = CPbk2SortOrderManager::NewL( iContactManager->FieldTypes() ); |
|
444 CleanupStack::PushL( sortOrderManager ); |
|
445 |
|
446 MPbk2ContactNameFormatter* nameFormatter = Pbk2ContactNameFormatterFactory::CreateL( |
|
447 KUnnamedText, iContactManager->FieldTypes(), |
|
448 *sortOrderManager ); |
|
449 CleanupStack::PushL( nameFormatter ); |
|
450 |
|
451 TInt shownTitleFields( 0 ); |
|
452 for( TInt counter = 0; counter < shownCount; counter++ ) |
|
453 { |
|
454 const MVPbkBaseContactField& srcField = iContactsToShow[0]->Fields().FieldAt( counter ); |
|
455 const MVPbkFieldType* fieldType = srcField.BestMatchingFieldType(); |
|
456 if( nameFormatter->IsTitleFieldType( *fieldType ) ) |
|
457 shownTitleFields++; |
|
458 } |
|
459 |
|
460 TInt storedTitleFields( 0 ); |
|
461 for( TInt counter = 0; counter < storedCount; counter++ ) |
|
462 { |
|
463 const MVPbkBaseContactField& srcField = iContactsToStore[0]->Fields().FieldAt( counter ); |
|
464 const MVPbkFieldType* fieldType = srcField.BestMatchingFieldType(); |
|
465 if( nameFormatter->IsTitleFieldType( *fieldType ) ) |
|
466 storedTitleFields++; |
|
467 } |
|
468 |
|
469 CleanupStack::Pop( 2 ); |
|
470 delete nameFormatter; |
|
471 delete sortOrderManager; |
|
472 |
|
473 //check if any of the dropped fields was title field |
|
474 if( shownCount - shownTitleFields > storedCount - storedTitleFields ) |
|
475 retVal = EFalse; |
|
476 |
|
477 return retVal; |
|
478 } |
|
479 |
|
480 |
|
481 void CVCardVpbUtil::VCardToPhoneStoreL( RFileReadStream& aStream ) |
|
482 { |
|
483 if( iContactsToShow.Count() > 0 ) |
|
484 { |
|
485 iContactsToShow.ResetAndDestroy(); |
|
486 iContactsToShow.Close(); |
|
487 } |
|
488 |
|
489 //always ensure that the read stream is in the beginning |
|
490 //of the file |
|
491 aStream.Source()->SeekL( MStreamBuf::ERead, EStreamBeginning, 0 ); |
|
492 MVPbkContactOperationBase* op; |
|
493 if( iVCardType == EVCard ) |
|
494 { |
|
495 op = iVCardEngine->ImportVCardL( |
|
496 iContactsToShow, |
|
497 *iShowContactStore, |
|
498 aStream, |
|
499 *this); |
|
500 } |
|
501 else |
|
502 { |
|
503 op = |
|
504 iVCardEngine->ImportCompactBusinessCardL( |
|
505 iContactsToShow, |
|
506 *iShowContactStore, |
|
507 aStream, |
|
508 *this); |
|
509 } |
|
510 CleanupDeletePushL( op ); |
|
511 StartSchedulerAndDecideToLeaveL(); |
|
512 CleanupStack::PopAndDestroy(); |
|
513 |
|
514 } |
|
515 |
|
516 void CVCardVpbUtil::VCardToDefaultStoreL( RFileReadStream& aStream ) |
|
517 { |
|
518 if( iContactsToStore.Count() > 0 ) |
|
519 { |
|
520 iContactsToStore.ResetAndDestroy(); |
|
521 iContactsToStore.Close(); |
|
522 } |
|
523 |
|
524 //always ensure that the read stream is in the beginning |
|
525 //of the file |
|
526 aStream.Source()->SeekL( MStreamBuf::ERead, EStreamBeginning, 0 ); |
|
527 MVPbkContactOperationBase* op; |
|
528 if( iVCardType == EVCard ) |
|
529 { |
|
530 op = |
|
531 iVCardEngine->ImportVCardL( |
|
532 iContactsToStore, |
|
533 *iDefaultContactStore, |
|
534 aStream, |
|
535 *this); |
|
536 } |
|
537 else |
|
538 { |
|
539 op = |
|
540 iVCardEngine->ImportCompactBusinessCardL( |
|
541 iContactsToStore, |
|
542 *iDefaultContactStore, |
|
543 aStream, |
|
544 *this); |
|
545 } |
|
546 CleanupDeletePushL( op ); |
|
547 StartSchedulerAndDecideToLeaveL(); |
|
548 CleanupStack::PopAndDestroy(); |
|
549 |
|
550 } |
|
551 |
|
552 void CVCardVpbUtil::StartSchedulerAndDecideToLeaveL() |
|
553 { |
|
554 //we want to control the responding to observable events to only happen |
|
555 //to requests made from this module |
|
556 iRespondToObserverEvent = ETrue; |
|
557 CActiveScheduler::Start(); |
|
558 User::LeaveIfError( iLastError ); |
|
559 iRespondToObserverEvent = EFalse; |
|
560 } |
|
561 |
|
562 TPtrC CVCardVpbUtil::FormatFieldContentL |
|
563 (const MVPbkBaseContactField& aField) |
|
564 { |
|
565 const MVPbkFieldType* aFieldType = aField.BestMatchingFieldType(); |
|
566 TPtr text(iBuffer->Des()); |
|
567 |
|
568 switch (aField.FieldData().DataType()) |
|
569 { |
|
570 case EVPbkFieldStorageTypeText: |
|
571 { |
|
572 const MVPbkContactFieldTextData* fieldData = |
|
573 &MVPbkContactFieldTextData::Cast(aField.FieldData()); |
|
574 TPtrC fieldText(fieldData->Text()); |
|
575 |
|
576 if (IsFieldTypeL(*aFieldType, R_MESSAGING_PHONENUMBER_SELECTOR)) |
|
577 { |
|
578 // telephony field |
|
579 |
|
580 // convert number according to active number setting |
|
581 if ( fieldText.Length() <= KBufferLength ) |
|
582 { |
|
583 HBufC* formattedPhoneNumber = fieldText.AllocLC(); |
|
584 TPtr formatterNumber = formattedPhoneNumber->Des(); |
|
585 |
|
586 AknTextUtils::DisplayTextLanguageSpecificNumberConversion( |
|
587 formatterNumber ); |
|
588 text.Set(ReallocBufferL(formatterNumber.Length()+4)); |
|
589 _LIT( Kstr, " " ); |
|
590 TDesC16 tmp = Kstr; |
|
591 text.Copy(tmp); |
|
592 text.Append(0x202A); |
|
593 text.Append(formatterNumber); |
|
594 text.Append(0x202C); |
|
595 CleanupStack::PopAndDestroy(formattedPhoneNumber); |
|
596 } |
|
597 else |
|
598 { |
|
599 return fieldData->Text(); |
|
600 } |
|
601 } |
|
602 else if (IsFieldTypeL(*aFieldType, R_MESSAGING_SYNCRONIZATION_SELECTOR)) |
|
603 { |
|
604 // syncronization field |
|
605 if (!fieldText.CompareF(KVPbkContactSyncPublic)) |
|
606 { |
|
607 HBufC* textBuffer = CCoeEnv::Static()->AllocReadResourceLC( |
|
608 R_QTN_CALE_CONFIDENT_PUBLIC); |
|
609 TPtr localizedSyncText = textBuffer->Des(); |
|
610 text.Set(ReallocBufferL(localizedSyncText.Length())); |
|
611 text.Copy(localizedSyncText); |
|
612 CleanupStack::PopAndDestroy(textBuffer); |
|
613 } |
|
614 else if (!fieldText.CompareF(KVPbkContactSyncNoSync)) |
|
615 { |
|
616 HBufC* textBuffer = CCoeEnv::Static()->AllocReadResourceLC( |
|
617 R_QTN_CALE_CONFIDENT_NONE); |
|
618 TPtr localizedSyncText = textBuffer->Des(); |
|
619 text.Set(ReallocBufferL(localizedSyncText.Length())); |
|
620 text.Copy(localizedSyncText); |
|
621 CleanupStack::PopAndDestroy(textBuffer); |
|
622 } |
|
623 else |
|
624 { |
|
625 // otherwise sync setting is the default value - private |
|
626 HBufC* textBuffer = CCoeEnv::Static()->AllocReadResourceLC( |
|
627 R_QTN_CALE_CONFIDENT_PRIVATE); |
|
628 TPtr localizedSyncText = textBuffer->Des(); |
|
629 text.Set(ReallocBufferL(localizedSyncText.Length())); |
|
630 text.Copy(localizedSyncText); |
|
631 CleanupStack::PopAndDestroy(textBuffer); |
|
632 } |
|
633 } |
|
634 else |
|
635 { |
|
636 text.Set(ReallocBufferL(fieldText.Length())); |
|
637 text.Copy(fieldText); |
|
638 |
|
639 // Check is there need to display the digits in the |
|
640 // text with foreign characters |
|
641 // Perform number conversion if allowed |
|
642 if (IsNumberConversionAllowed(*aFieldType)) |
|
643 { |
|
644 AknTextUtils::DisplayTextLanguageSpecificNumberConversion( |
|
645 text); |
|
646 } |
|
647 } |
|
648 break; |
|
649 } |
|
650 case EVPbkFieldStorageTypeDateTime: |
|
651 { |
|
652 TInt error = KErrNone; |
|
653 do |
|
654 { |
|
655 HBufC* timeFormat = CCoeEnv::Static()->AllocReadResourceLC(R_QTN_DATE_USUAL); |
|
656 const MVPbkContactFieldDateTimeData* fieldData = |
|
657 &MVPbkContactFieldDateTimeData::Cast(aField.FieldData()); |
|
658 TRAPD(error, fieldData->DateTime().FormatL(text, *timeFormat)); |
|
659 AknTextUtils::DisplayTextLanguageSpecificNumberConversion(text); |
|
660 CleanupStack::PopAndDestroy(timeFormat); // timeFormat |
|
661 if (error == KErrOverflow) |
|
662 { |
|
663 // allocate bigger buffer for formatting text |
|
664 text.Set(ReallocBufferL(2*text.MaxLength())); |
|
665 } |
|
666 else if (error) |
|
667 { |
|
668 // rethrow other errors |
|
669 User::Leave(error); |
|
670 } |
|
671 } while (error == KErrOverflow); |
|
672 break; |
|
673 } |
|
674 default: |
|
675 { |
|
676 text.Zero(); |
|
677 break; |
|
678 } |
|
679 } |
|
680 |
|
681 return text; |
|
682 } |
|
683 |
|
684 /** |
|
685 * Checks the field type. |
|
686 */ |
|
687 TBool CVCardVpbUtil::IsFieldTypeL( |
|
688 const MVPbkFieldType& aFieldType, |
|
689 TInt aResourceId) const |
|
690 { |
|
691 TResourceReader reader; |
|
692 CCoeEnv::Static()->CreateResourceReaderLC(reader, aResourceId); |
|
693 |
|
694 CVPbkFieldTypeSelector* selector = CVPbkFieldTypeSelector::NewL( |
|
695 reader, iContactManager->FieldTypes()); |
|
696 // Check if the field type is the one needed |
|
697 TBool ret = selector->IsFieldTypeIncluded(aFieldType); |
|
698 CleanupStack::PopAndDestroy(); // resource buffer |
|
699 delete selector; |
|
700 return ret; |
|
701 } |
|
702 |
|
703 TPtr CVCardVpbUtil::ReallocBufferL |
|
704 (TInt aNewSize) |
|
705 { |
|
706 const TInt currMaxLength = iBuffer->Des().MaxLength(); |
|
707 if (aNewSize > currMaxLength) |
|
708 { |
|
709 iBuffer = iBuffer->ReAllocL(aNewSize); |
|
710 } |
|
711 |
|
712 //PostCond: |
|
713 __ASSERT_DEBUG(iBuffer->Des().MaxLength() >= aNewSize, |
|
714 Panic(EPanicPostCond_ReallocBufferL)); |
|
715 |
|
716 return iBuffer->Des(); |
|
717 } |
|
718 |
|
719 void CVCardVpbUtil::Panic( TInt aReason ) |
|
720 { |
|
721 User::Panic( KClassName, aReason ); |
|
722 } |
|
723 /** |
|
724 * Check whether default store is Full or Not. |
|
725 */ |
|
726 TBool CVCardVpbUtil::StoreFullL() |
|
727 { |
|
728 LOG("CVCardVpbUtil::StoreFullL"); |
|
729 TBool ret( EFalse ); |
|
730 const MVPbkContactStore* iTargetStore; |
|
731 HBufC* textBuffer; |
|
732 CPbk2StoreConfiguration* storeConfiguration = CPbk2StoreConfiguration::NewL(); |
|
733 CleanupStack::PushL( storeConfiguration ); |
|
734 TVPbkContactStoreUriPtr defaultsavingstore = storeConfiguration->DefaultSavingStoreL(); |
|
735 iTargetStore = iContactManager->ContactStoresL().Find(defaultsavingstore ); |
|
736 const MVPbkContactStoreInfo& storeInfo = iTargetStore->StoreInfo(); |
|
737 if ( storeInfo.MaxNumberOfContactsL() != KVPbkStoreInfoUnlimitedNumber && |
|
738 storeInfo.MaxNumberOfContactsL() <= storeInfo.NumberOfContactsL() ) |
|
739 { |
|
740 CVPbkContactStoreUri* uri = CVPbkContactStoreUri::NewL( defaultsavingstore ); |
|
741 CleanupStack::PushL( uri ); |
|
742 if(uri->Uri().UriDes().CompareC(KDEFAULT_CNTDB_URI) == 0 ) |
|
743 { |
|
744 LOG("CVCardVpbUtil::StoreFullL, Phone memory full"); |
|
745 textBuffer = StringLoader::LoadLC( R_QTN_PHOB_PB_INFO_MEMORY_PHONE ); |
|
746 } |
|
747 else |
|
748 { |
|
749 LOG("CVCardVpbUtil::StoreFullL, SIM memory full"); |
|
750 textBuffer = StringLoader::LoadLC( R_QTN_PHOB_PB_INFO_MEMORY_SIM ); |
|
751 } |
|
752 ShowNoteL( R_QTN_PHOB_NOTE_STORE_FULL, textBuffer->Des() ); |
|
753 CleanupStack::PopAndDestroy(textBuffer); |
|
754 CleanupStack::PopAndDestroy();//destroy uri |
|
755 ret = ETrue; |
|
756 } |
|
757 CleanupStack::PopAndDestroy( storeConfiguration ); |
|
758 return ret; |
|
759 } |
|
760 |
|
761 /** |
|
762 * Shows popup Note. |
|
763 */ |
|
764 void CVCardVpbUtil::ShowNoteL( TInt aResourceId, const TDesC& aString ) |
|
765 { |
|
766 LOG("CVCardVpbUtil::ShowNoteL"); |
|
767 HBufC* prompt = NULL; |
|
768 if( aString.Length() ) |
|
769 prompt = StringLoader::LoadLC( aResourceId, aString ); |
|
770 else |
|
771 prompt = StringLoader::LoadLC( aResourceId ); |
|
772 CAknInformationNote* dlg = new(ELeave) CAknInformationNote(ETrue); |
|
773 dlg->ExecuteLD(*prompt); |
|
774 CleanupStack::PopAndDestroy(); // prompt |
|
775 } |
|
776 |