29 #include <eikapp.h> |
29 #include <eikapp.h> |
30 #include <apgcli.h> |
30 #include <apgcli.h> |
31 #include <centralrepository.h> |
31 #include <centralrepository.h> |
32 #include <CoreApplicationUIsSDKCRKeys.h> |
32 #include <CoreApplicationUIsSDKCRKeys.h> |
33 #include <settingsinternalcrkeys.h> |
33 #include <settingsinternalcrkeys.h> |
34 //<cmail> Header neither in Cmail nor in the platform |
|
35 #include <crcseprofileregistry.h> |
34 #include <crcseprofileregistry.h> |
36 //</cmail> |
|
37 #include <NetworkHandlingDomainPSKeys.h> |
35 #include <NetworkHandlingDomainPSKeys.h> |
38 #include <MVPbkStoreContact.h> |
36 #include <MVPbkStoreContact.h> |
39 #include <MVPbkStoreContactFieldCollection.h> |
37 #include <MVPbkStoreContactFieldCollection.h> |
40 #include <MVPbkStoreContactField.h> |
38 #include <MVPbkStoreContactField.h> |
41 #include <MVPbkFieldType.h> |
39 #include <MVPbkFieldType.h> |
42 #include <TVPbkFieldVersitProperty.h> |
40 #include <TVPbkFieldVersitProperty.h> |
43 #include <MVPbkContactFieldData.h> |
41 #include <MVPbkContactFieldData.h> |
44 #include <MVPbkContactFieldTextData.h> |
42 #include <MVPbkContactFieldTextData.h> |
45 //<cmail> |
|
46 #include "fscactionplugincrkeys.h" |
43 #include "fscactionplugincrkeys.h" |
47 #include "fsccontactactionservicedefines.h" |
44 #include "fsccontactactionservicedefines.h" |
48 //</cmail> |
|
49 #include <FscActionUtils.rsg> |
45 #include <FscActionUtils.rsg> |
50 #include <barsread.h> |
46 #include <barsread.h> |
51 #include <Pbk2ContactNameFormatterFactory.h> |
47 #include <Pbk2ContactNameFormatterFactory.h> |
52 #include <MPbk2ContactNameFormatter.h> |
48 #include <MPbk2ContactNameFormatter.h> |
53 #include <CPbk2SortOrderManager.h> |
49 #include <CPbk2SortOrderManager.h> |
54 #include <CVPbkContactManager.h> |
50 #include <CVPbkContactManager.h> |
55 #include <MPbk2FieldProperty.h> |
51 #include <MPbk2FieldProperty.h> |
56 #include <CVPbkFieldTypeSelector.h> |
52 #include <CVPbkFieldTypeSelector.h> |
57 #include <CVPbkFieldFilter.h> |
53 #include <CVPbkFieldFilter.h> |
58 #include <commonphoneparser.h> |
54 #include <commonphoneparser.h> |
59 #include <bautils.h> // Fix for EMZG-7M23KX |
55 #include <bautils.h> |
60 //<cmail> hardcoded paths removal |
|
61 #include <data_caging_path_literals.hrh> |
56 #include <data_caging_path_literals.hrh> |
62 //</cmail> |
|
63 |
|
64 #include "cfscactionutils.h" |
57 #include "cfscactionutils.h" |
65 #include "cfsccontactaction.h" |
58 #include "cfsccontactaction.h" |
66 #include "mfscreasoncallback.h" |
59 #include "mfscreasoncallback.h" |
67 #include <VPbkFieldType.hrh> |
60 #include <VPbkFieldType.hrh> |
68 #include "FscPresentationUtils.h" |
61 #include "FscPresentationUtils.h" |
267 // CFscActionUtils::GetContactNameL |
251 // CFscActionUtils::GetContactNameL |
268 // --------------------------------------------------------------------------- |
252 // --------------------------------------------------------------------------- |
269 HBufC* CFscActionUtils::GetContactNameL( MVPbkStoreContact& aStoreContact ) |
253 HBufC* CFscActionUtils::GetContactNameL( MVPbkStoreContact& aStoreContact ) |
270 { |
254 { |
271 FUNC_LOG; |
255 FUNC_LOG; |
272 HBufC* contactName = HBufC::NewLC( KMaxLengthOfName + 1 ); // one ' ' char |
256 |
273 |
257 TBuf<KMaxLengthOfName> contactName; |
274 // Search for the contact name |
258 |
275 // Fix for EMZG-7M23KX |
|
276 TInt offset = FindAndAddResourceFileL(); |
259 TInt offset = FindAndAddResourceFileL(); |
277 |
260 |
278 TResourceReader selectorReader; |
261 TInt err( KErrNone ); |
279 CCoeEnv::Static()->CreateResourceReaderLC( selectorReader, |
262 TRAP( err, AppendFieldToContactL( |
280 R_FSC_FIRST_NAME_SELECTOR ); |
263 contactName, R_FSC_FIRST_NAME_SELECTOR, aStoreContact ) ); |
281 |
264 if ( err == KErrNone ) |
282 CVPbkFieldTypeSelector* fieldTypeSelector = CVPbkFieldTypeSelector::NewL( |
265 { |
283 selectorReader, iContactManager.FieldTypes() ); |
266 TRAP( err, AppendFieldToContactL( |
284 CleanupStack::PopAndDestroy(); // selectorReader |
267 contactName, R_FSC_LAST_NAME_SELECTOR, aStoreContact, |
285 |
268 ETrue ) ); |
286 CVPbkFieldFilter::TConfig config( |
269 } |
287 const_cast<MVPbkStoreContactFieldCollection&> ( |
270 if ( err == KErrNone && contactName.Length() <= 0 ) |
288 aStoreContact.Fields() ), fieldTypeSelector, NULL ); |
271 { |
289 |
272 // If no first or last name was found, try to append company name |
290 CVPbkFieldFilter* fieldFilter = CVPbkFieldFilter::NewL( config ); |
273 TRAP_IGNORE( AppendFieldToContactL( |
291 TInt fieldCount = fieldFilter->FieldCount(); |
274 contactName, R_FSC_COMPANY_NAME_SELECTOR, aStoreContact ) ); |
292 const MVPbkStoreContactField* field = NULL; |
275 } |
293 if ( fieldCount == 1 ) |
276 |
294 { |
277 // If there was an error or the contact name is zero length, use |
295 field = fieldFilter->FieldAtLC(0); |
278 // pre-defined unnamed string instead.. |
296 contactName->Des().Append( |
279 if ( err != KErrNone || contactName.Length() <= 0 ) |
297 MVPbkContactFieldTextData::Cast( |
280 { |
298 field->FieldData() ).Text() ); |
|
299 CleanupStack::PopAndDestroy();//field |
|
300 } |
|
301 |
|
302 delete fieldFilter; |
|
303 delete fieldTypeSelector; |
|
304 |
|
305 // Search for the contact second name |
|
306 CCoeEnv::Static()->CreateResourceReaderLC( selectorReader, |
|
307 R_FSC_LAST_NAME_SELECTOR ); |
|
308 fieldTypeSelector = CVPbkFieldTypeSelector::NewL( selectorReader, |
|
309 iContactManager.FieldTypes() ); |
|
310 CleanupStack::PopAndDestroy();//selectorReader |
|
311 config.iFieldSelector = fieldTypeSelector; |
|
312 |
|
313 fieldFilter = CVPbkFieldFilter::NewL( config ); |
|
314 fieldCount = fieldFilter->FieldCount(); |
|
315 if ( fieldCount == 1 ) |
|
316 { |
|
317 field = fieldFilter->FieldAtLC(0); |
|
318 if ( contactName->Des().Length() > 0 ) |
|
319 { |
|
320 contactName->Des().Append( KSpace ); |
|
321 } |
|
322 contactName->Des().Append( |
|
323 MVPbkContactFieldTextData::Cast( |
|
324 field->FieldData() ).Text() ); |
|
325 CleanupStack::PopAndDestroy();//field |
|
326 } |
|
327 |
|
328 // If first or second name hasn't been found -> find company name |
|
329 if ( contactName->Des().Length() <= 0 ) |
|
330 { |
|
331 delete fieldFilter; |
|
332 delete fieldTypeSelector; |
|
333 |
|
334 CCoeEnv::Static()->CreateResourceReaderLC( selectorReader, |
|
335 R_FSC_COMPANY_NAME_SELECTOR ); |
|
336 fieldTypeSelector = CVPbkFieldTypeSelector::NewL( selectorReader, |
|
337 iContactManager.FieldTypes() ); |
|
338 CleanupStack::PopAndDestroy();//selectorReader |
|
339 config.iFieldSelector = fieldTypeSelector; |
|
340 |
|
341 fieldFilter = CVPbkFieldFilter::NewL( config ); |
|
342 fieldCount = fieldFilter->FieldCount(); |
|
343 if ( fieldCount == 1 ) |
|
344 { |
|
345 field = fieldFilter->FieldAtLC(0); |
|
346 contactName->Des().Append( |
|
347 MVPbkContactFieldTextData::Cast( |
|
348 field->FieldData() ).Text() ); |
|
349 CleanupStack::PopAndDestroy();//field |
|
350 } |
|
351 } |
|
352 // no first or second name, nor company name -> return "unnamed" string |
|
353 if ( contactName->Des().Length() <= 0 ) |
|
354 { |
|
355 //append (Unnamed) |
|
356 HBufC* unnamed = StringLoader::LoadL( R_QTN_FS_UNNAMED ); |
281 HBufC* unnamed = StringLoader::LoadL( R_QTN_FS_UNNAMED ); |
357 contactName->Des().Append( *unnamed ); |
282 contactName.Zero(); |
|
283 contactName.Append( *unnamed ); |
358 delete unnamed; |
284 delete unnamed; |
359 } |
285 } |
360 |
|
361 delete fieldFilter; |
|
362 delete fieldTypeSelector; |
|
363 CleanupStack::Pop( contactName ); |
|
364 |
|
365 CCoeEnv::Static()->DeleteResourceFile( offset ); |
286 CCoeEnv::Static()->DeleteResourceFile( offset ); |
366 |
287 return contactName.AllocL(); |
367 return contactName; |
|
368 } |
288 } |
369 |
289 |
370 // --------------------------------------------------------------------------- |
290 // --------------------------------------------------------------------------- |
371 // CFscActionUtils::OpenSelectDialogL |
291 // CFscActionUtils::OpenSelectDialogL |
372 // --------------------------------------------------------------------------- |
292 // --------------------------------------------------------------------------- |
1023 CCoeEnv::Static()->CreateResourceReaderLC( selectorReader, selector ); |
934 CCoeEnv::Static()->CreateResourceReaderLC( selectorReader, selector ); |
1024 |
935 |
1025 fieldTypeSelector = CVPbkFieldTypeSelector::NewL( selectorReader, |
936 fieldTypeSelector = CVPbkFieldTypeSelector::NewL( selectorReader, |
1026 iContactManager.FieldTypes() ); |
937 iContactManager.FieldTypes() ); |
1027 CleanupStack::PopAndDestroy(); // selectorReader |
938 CleanupStack::PopAndDestroy(); // selectorReader |
1028 |
939 CleanupStack::PushL( fieldTypeSelector ); |
|
940 |
1029 CVPbkFieldFilter::TConfig config( |
941 CVPbkFieldFilter::TConfig config( |
1030 const_cast<MVPbkStoreContactFieldCollection&> ( |
942 const_cast<MVPbkStoreContactFieldCollection&> ( |
1031 aStoreContact.Fields() ), fieldTypeSelector, NULL); |
943 aStoreContact.Fields() ), fieldTypeSelector, NULL); |
1032 |
944 |
1033 fieldFilter = CVPbkFieldFilter::NewL( config ); |
945 fieldFilter = CVPbkFieldFilter::NewL( config ); |
1034 fieldCount = fieldFilter->FieldCount(); |
946 CleanupStack::PushL( fieldFilter ); |
1035 |
947 |
1036 if ( fieldCount ) |
948 if ( fieldFilter->FieldCount() ) |
1037 { |
949 { |
1038 if ( selector == R_FSC_CONF_NUMBER_SELECTOR ) |
950 if ( selector == R_FSC_CONF_NUMBER_SELECTOR ) |
1039 { |
951 { |
1040 TBuf<KMaxLengthOfNumber> confNum; |
952 TBuf<KMaxLengthOfNumber> confNum; |
1041 const MVPbkStoreContactField* field = NULL; |
953 const MVPbkStoreContactField* field = NULL; |
1042 field = fieldFilter->FieldAtLC(0); |
954 field = fieldFilter->FieldAtLC(0); |
1043 confNum.Append( MVPbkContactFieldTextData::Cast( |
955 confNum.Append( MVPbkContactFieldTextData::Cast( |
1044 field->FieldData() ).Text() ); |
956 field->FieldData() ).Text() ); |
1045 CleanupStack::PopAndDestroy();//field |
957 CleanupStack::PopAndDestroy(); // field |
1046 |
958 |
1047 if ( CommonPhoneParser::IsValidPhoneNumber( confNum, |
959 if ( CommonPhoneParser::IsValidPhoneNumber( confNum, |
1048 CommonPhoneParser::EContactCardNumber ) ) |
960 CommonPhoneParser::EContactCardNumber ) ) |
1049 { |
961 { |
1050 available = ETrue; |
962 available = ETrue; |
1289 fileName.Append( aFilePath ); |
1190 fileName.Append( aFilePath ); |
1290 |
1191 |
1291 return fileName; |
1192 return fileName; |
1292 } |
1193 } |
1293 |
1194 |
1294 // Fix for EMZG-7M23KX |
|
1295 // --------------------------------------------------------------------------- |
1195 // --------------------------------------------------------------------------- |
1296 // CFscActionUtils::FindAndAddResourceFileL |
1196 // CFscActionUtils::FindAndAddResourceFileL |
1297 // --------------------------------------------------------------------------- |
1197 // --------------------------------------------------------------------------- |
1298 // |
1198 // |
1299 TInt CFscActionUtils::FindAndAddResourceFileL() |
1199 TInt CFscActionUtils::FindAndAddResourceFileL() |
1300 { |
1200 { |
1301 FUNC_LOG; |
1201 FUNC_LOG; |
1302 //<cmail> hardcoded removed |
|
1303 TFileName resourceFileName( KDC_RESOURCE_FILES_DIR ); |
1202 TFileName resourceFileName( KDC_RESOURCE_FILES_DIR ); |
1304 resourceFileName.Append(KFscRscFileName); |
1203 resourceFileName.Append( KFscRscFileName ); |
1305 //</cmail> |
|
1306 BaflUtils::NearestLanguageFile( CCoeEnv::Static()->FsSession(), resourceFileName ); |
1204 BaflUtils::NearestLanguageFile( CCoeEnv::Static()->FsSession(), resourceFileName ); |
1307 TInt offset = CCoeEnv::Static()->AddResourceFileL( resourceFileName ); |
1205 return CCoeEnv::Static()->AddResourceFileL( resourceFileName ); |
1308 |
|
1309 return offset; |
|
1310 } |
1206 } |
1311 // --------------------------------------------------------------------------- |
1207 // --------------------------------------------------------------------------- |
1312 // CFscActionUtils::CloseSelectDialogL |
1208 // CFscActionUtils::CloseSelectDialogL |
1313 // --------------------------------------------------------------------------- |
1209 // --------------------------------------------------------------------------- |
1314 // |
1210 // |
1319 { |
1215 { |
1320 iAddressSelect->AttemptExitL( EFalse ); |
1216 iAddressSelect->AttemptExitL( EFalse ); |
1321 } |
1217 } |
1322 } |
1218 } |
1323 |
1219 |
1324 |
1220 // --------------------------------------------------------------------------- |
1325 // ======== GLOBAL FUNCTIONS ======== |
1221 // CFscActionUtils::AppendFieldToContactL |
1326 |
1222 // --------------------------------------------------------------------------- |
|
1223 // |
|
1224 void CFscActionUtils::AppendFieldToContactL( TDes& aContact, |
|
1225 TInt aFieldResourceId, |
|
1226 MVPbkStoreContact& aStoreContact, |
|
1227 TBool aAddSpace ) |
|
1228 { |
|
1229 FUNC_LOG; |
|
1230 |
|
1231 TResourceReader selectorReader; |
|
1232 CCoeEnv::Static()->CreateResourceReaderLC( selectorReader, |
|
1233 aFieldResourceId ); |
|
1234 |
|
1235 CVPbkFieldTypeSelector* fieldTypeSelector = CVPbkFieldTypeSelector::NewL( |
|
1236 selectorReader, iContactManager.FieldTypes() ); |
|
1237 CleanupStack::PopAndDestroy(); // selectorReader |
|
1238 CleanupStack::PushL( fieldTypeSelector ); |
|
1239 |
|
1240 CVPbkFieldFilter::TConfig config( |
|
1241 const_cast<MVPbkStoreContactFieldCollection&> ( |
|
1242 aStoreContact.Fields() ), fieldTypeSelector, NULL ); |
|
1243 |
|
1244 CVPbkFieldFilter* fieldFilter = CVPbkFieldFilter::NewL( config ); |
|
1245 CleanupStack::PushL( fieldFilter ); |
|
1246 |
|
1247 if ( fieldFilter->FieldCount() == 1 ) |
|
1248 { |
|
1249 MVPbkStoreContactField* field = fieldFilter->FieldAtLC( 0 ); |
|
1250 if ( aAddSpace && aContact.Length() > 0 ) |
|
1251 { |
|
1252 aContact.Append( KSpace ); |
|
1253 } |
|
1254 TPtrC castFieldText = MVPbkContactFieldTextData::Cast( |
|
1255 field->FieldData() ).Text(); |
|
1256 |
|
1257 if ( ( aContact.Length() + castFieldText.Length() ) > KMaxLengthOfName ) |
|
1258 { |
|
1259 User::Leave( KErrOverflow ); |
|
1260 } |
|
1261 |
|
1262 aContact.Append( MVPbkContactFieldTextData::Cast( |
|
1263 field->FieldData() ).Text() ); |
|
1264 CleanupStack::PopAndDestroy(); // field |
|
1265 } |
|
1266 CleanupStack::PopAndDestroy( 2 ); // fieldFilter, fieldTypeSelector |
|
1267 } |
|
1268 |