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 |
34 #include <crcseprofileregistry.h> |
35 #include <crcseprofileregistry.h> |
|
36 //</cmail> |
35 #include <NetworkHandlingDomainPSKeys.h> |
37 #include <NetworkHandlingDomainPSKeys.h> |
36 #include <MVPbkStoreContact.h> |
38 #include <MVPbkStoreContact.h> |
37 #include <MVPbkStoreContactFieldCollection.h> |
39 #include <MVPbkStoreContactFieldCollection.h> |
38 #include <MVPbkStoreContactField.h> |
40 #include <MVPbkStoreContactField.h> |
39 #include <MVPbkFieldType.h> |
41 #include <MVPbkFieldType.h> |
40 #include <TVPbkFieldVersitProperty.h> |
42 #include <TVPbkFieldVersitProperty.h> |
41 #include <MVPbkContactFieldData.h> |
43 #include <MVPbkContactFieldData.h> |
42 #include <MVPbkContactFieldTextData.h> |
44 #include <MVPbkContactFieldTextData.h> |
|
45 //<cmail> |
43 #include "fscactionplugincrkeys.h" |
46 #include "fscactionplugincrkeys.h" |
44 #include "fsccontactactionservicedefines.h" |
47 #include "fsccontactactionservicedefines.h" |
|
48 //</cmail> |
45 #include <FscActionUtils.rsg> |
49 #include <FscActionUtils.rsg> |
46 #include <barsread.h> |
50 #include <barsread.h> |
47 #include <Pbk2ContactNameFormatterFactory.h> |
51 #include <Pbk2ContactNameFormatterFactory.h> |
48 #include <MPbk2ContactNameFormatter.h> |
52 #include <MPbk2ContactNameFormatter.h> |
49 #include <CPbk2SortOrderManager.h> |
53 #include <CPbk2SortOrderManager.h> |
50 #include <CVPbkContactManager.h> |
54 #include <CVPbkContactManager.h> |
51 #include <MPbk2FieldProperty.h> |
55 #include <MPbk2FieldProperty.h> |
52 #include <CVPbkFieldTypeSelector.h> |
56 #include <CVPbkFieldTypeSelector.h> |
53 #include <CVPbkFieldFilter.h> |
57 #include <CVPbkFieldFilter.h> |
54 #include <commonphoneparser.h> |
58 #include <commonphoneparser.h> |
55 #include <bautils.h> |
59 #include <bautils.h> // Fix for EMZG-7M23KX |
|
60 //<cmail> hardcoded paths removal |
56 #include <data_caging_path_literals.hrh> |
61 #include <data_caging_path_literals.hrh> |
|
62 //</cmail> |
|
63 |
57 #include "cfscactionutils.h" |
64 #include "cfscactionutils.h" |
58 #include "cfsccontactaction.h" |
65 #include "cfsccontactaction.h" |
59 #include "mfscreasoncallback.h" |
66 #include "mfscreasoncallback.h" |
60 #include <VPbkFieldType.hrh> |
67 #include <VPbkFieldType.hrh> |
61 #include "FscPresentationUtils.h" |
68 #include "FscPresentationUtils.h" |
251 // CFscActionUtils::GetContactNameL |
267 // CFscActionUtils::GetContactNameL |
252 // --------------------------------------------------------------------------- |
268 // --------------------------------------------------------------------------- |
253 HBufC* CFscActionUtils::GetContactNameL( MVPbkStoreContact& aStoreContact ) |
269 HBufC* CFscActionUtils::GetContactNameL( MVPbkStoreContact& aStoreContact ) |
254 { |
270 { |
255 FUNC_LOG; |
271 FUNC_LOG; |
256 |
272 HBufC* contactName = HBufC::NewLC( KMaxLengthOfName + 1 ); // one ' ' char |
257 TBuf<KMaxLengthOfName> contactName; |
273 |
258 |
274 // Search for the contact name |
|
275 // Fix for EMZG-7M23KX |
259 TInt offset = FindAndAddResourceFileL(); |
276 TInt offset = FindAndAddResourceFileL(); |
260 |
277 |
261 TInt err( KErrNone ); |
278 TResourceReader selectorReader; |
262 TRAP( err, AppendFieldToContactL( |
279 CCoeEnv::Static()->CreateResourceReaderLC( selectorReader, |
263 contactName, R_FSC_FIRST_NAME_SELECTOR, aStoreContact ) ); |
280 R_FSC_FIRST_NAME_SELECTOR ); |
264 if ( err == KErrNone ) |
281 |
265 { |
282 CVPbkFieldTypeSelector* fieldTypeSelector = CVPbkFieldTypeSelector::NewL( |
266 TRAP( err, AppendFieldToContactL( |
283 selectorReader, iContactManager.FieldTypes() ); |
267 contactName, R_FSC_LAST_NAME_SELECTOR, aStoreContact, |
284 CleanupStack::PopAndDestroy(); // selectorReader |
268 ETrue ) ); |
285 |
269 } |
286 CVPbkFieldFilter::TConfig config( |
270 if ( err == KErrNone && contactName.Length() <= 0 ) |
287 const_cast<MVPbkStoreContactFieldCollection&> ( |
271 { |
288 aStoreContact.Fields() ), fieldTypeSelector, NULL ); |
272 // If no first or last name was found, try to append company name |
289 |
273 TRAP_IGNORE( AppendFieldToContactL( |
290 CVPbkFieldFilter* fieldFilter = CVPbkFieldFilter::NewL( config ); |
274 contactName, R_FSC_COMPANY_NAME_SELECTOR, aStoreContact ) ); |
291 TInt fieldCount = fieldFilter->FieldCount(); |
275 } |
292 const MVPbkStoreContactField* field = NULL; |
276 |
293 if ( fieldCount == 1 ) |
277 // If there was an error or the contact name is zero length, use |
294 { |
278 // pre-defined unnamed string instead.. |
295 field = fieldFilter->FieldAtLC(0); |
279 if ( err != KErrNone || contactName.Length() <= 0 ) |
296 contactName->Des().Append( |
280 { |
297 MVPbkContactFieldTextData::Cast( |
|
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) |
281 HBufC* unnamed = StringLoader::LoadL( R_QTN_FS_UNNAMED ); |
356 HBufC* unnamed = StringLoader::LoadL( R_QTN_FS_UNNAMED ); |
282 contactName.Zero(); |
357 contactName->Des().Append( *unnamed ); |
283 contactName.Append( *unnamed ); |
|
284 delete unnamed; |
358 delete unnamed; |
285 } |
359 } |
|
360 |
|
361 delete fieldFilter; |
|
362 delete fieldTypeSelector; |
|
363 CleanupStack::Pop( contactName ); |
|
364 |
286 CCoeEnv::Static()->DeleteResourceFile( offset ); |
365 CCoeEnv::Static()->DeleteResourceFile( offset ); |
287 return contactName.AllocL(); |
366 |
|
367 return contactName; |
288 } |
368 } |
289 |
369 |
290 // --------------------------------------------------------------------------- |
370 // --------------------------------------------------------------------------- |
291 // CFscActionUtils::OpenSelectDialogL |
371 // CFscActionUtils::OpenSelectDialogL |
292 // --------------------------------------------------------------------------- |
372 // --------------------------------------------------------------------------- |
934 CCoeEnv::Static()->CreateResourceReaderLC( selectorReader, selector ); |
1023 CCoeEnv::Static()->CreateResourceReaderLC( selectorReader, selector ); |
935 |
1024 |
936 fieldTypeSelector = CVPbkFieldTypeSelector::NewL( selectorReader, |
1025 fieldTypeSelector = CVPbkFieldTypeSelector::NewL( selectorReader, |
937 iContactManager.FieldTypes() ); |
1026 iContactManager.FieldTypes() ); |
938 CleanupStack::PopAndDestroy(); // selectorReader |
1027 CleanupStack::PopAndDestroy(); // selectorReader |
939 CleanupStack::PushL( fieldTypeSelector ); |
1028 |
940 |
|
941 CVPbkFieldFilter::TConfig config( |
1029 CVPbkFieldFilter::TConfig config( |
942 const_cast<MVPbkStoreContactFieldCollection&> ( |
1030 const_cast<MVPbkStoreContactFieldCollection&> ( |
943 aStoreContact.Fields() ), fieldTypeSelector, NULL); |
1031 aStoreContact.Fields() ), fieldTypeSelector, NULL); |
944 |
1032 |
945 fieldFilter = CVPbkFieldFilter::NewL( config ); |
1033 fieldFilter = CVPbkFieldFilter::NewL( config ); |
946 CleanupStack::PushL( fieldFilter ); |
1034 fieldCount = fieldFilter->FieldCount(); |
947 |
1035 |
948 if ( fieldFilter->FieldCount() ) |
1036 if ( fieldCount ) |
949 { |
1037 { |
950 if ( selector == R_FSC_CONF_NUMBER_SELECTOR ) |
1038 if ( selector == R_FSC_CONF_NUMBER_SELECTOR ) |
951 { |
1039 { |
952 TBuf<KMaxLengthOfNumber> confNum; |
1040 TBuf<KMaxLengthOfNumber> confNum; |
953 const MVPbkStoreContactField* field = NULL; |
1041 const MVPbkStoreContactField* field = NULL; |
954 field = fieldFilter->FieldAtLC(0); |
1042 field = fieldFilter->FieldAtLC(0); |
955 confNum.Append( MVPbkContactFieldTextData::Cast( |
1043 confNum.Append( MVPbkContactFieldTextData::Cast( |
956 field->FieldData() ).Text() ); |
1044 field->FieldData() ).Text() ); |
957 CleanupStack::PopAndDestroy(); // field |
1045 CleanupStack::PopAndDestroy();//field |
958 |
1046 |
959 if ( CommonPhoneParser::IsValidPhoneNumber( confNum, |
1047 if ( CommonPhoneParser::IsValidPhoneNumber( confNum, |
960 CommonPhoneParser::EContactCardNumber ) ) |
1048 CommonPhoneParser::EContactCardNumber ) ) |
961 { |
1049 { |
962 available = ETrue; |
1050 available = ETrue; |
1190 fileName.Append( aFilePath ); |
1289 fileName.Append( aFilePath ); |
1191 |
1290 |
1192 return fileName; |
1291 return fileName; |
1193 } |
1292 } |
1194 |
1293 |
|
1294 // Fix for EMZG-7M23KX |
1195 // --------------------------------------------------------------------------- |
1295 // --------------------------------------------------------------------------- |
1196 // CFscActionUtils::FindAndAddResourceFileL |
1296 // CFscActionUtils::FindAndAddResourceFileL |
1197 // --------------------------------------------------------------------------- |
1297 // --------------------------------------------------------------------------- |
1198 // |
1298 // |
1199 TInt CFscActionUtils::FindAndAddResourceFileL() |
1299 TInt CFscActionUtils::FindAndAddResourceFileL() |
1200 { |
1300 { |
1201 FUNC_LOG; |
1301 FUNC_LOG; |
|
1302 //<cmail> hardcoded removed |
1202 TFileName resourceFileName( KDC_RESOURCE_FILES_DIR ); |
1303 TFileName resourceFileName( KDC_RESOURCE_FILES_DIR ); |
1203 resourceFileName.Append( KFscRscFileName ); |
1304 resourceFileName.Append(KFscRscFileName); |
|
1305 //</cmail> |
1204 BaflUtils::NearestLanguageFile( CCoeEnv::Static()->FsSession(), resourceFileName ); |
1306 BaflUtils::NearestLanguageFile( CCoeEnv::Static()->FsSession(), resourceFileName ); |
1205 return CCoeEnv::Static()->AddResourceFileL( resourceFileName ); |
1307 TInt offset = CCoeEnv::Static()->AddResourceFileL( resourceFileName ); |
|
1308 |
|
1309 return offset; |
1206 } |
1310 } |
1207 // --------------------------------------------------------------------------- |
1311 // --------------------------------------------------------------------------- |
1208 // CFscActionUtils::CloseSelectDialogL |
1312 // CFscActionUtils::CloseSelectDialogL |
1209 // --------------------------------------------------------------------------- |
1313 // --------------------------------------------------------------------------- |
1210 // |
1314 // |
1215 { |
1319 { |
1216 iAddressSelect->AttemptExitL( EFalse ); |
1320 iAddressSelect->AttemptExitL( EFalse ); |
1217 } |
1321 } |
1218 } |
1322 } |
1219 |
1323 |
1220 // --------------------------------------------------------------------------- |
1324 |
1221 // CFscActionUtils::AppendFieldToContactL |
1325 // ======== GLOBAL FUNCTIONS ======== |
1222 // --------------------------------------------------------------------------- |
1326 |
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 if ( aAddSpace && aContact.Length() > 0 ) |
|
1250 { |
|
1251 if ( aContact.Length() < KMaxLengthOfName ) |
|
1252 { |
|
1253 aContact.Append( KSpace ); |
|
1254 } |
|
1255 else |
|
1256 { |
|
1257 User::Leave( KErrOverflow ); |
|
1258 } |
|
1259 } |
|
1260 MVPbkStoreContactField* field = fieldFilter->FieldAtLC( 0 ); |
|
1261 TPtrC castFieldText = MVPbkContactFieldTextData::Cast( |
|
1262 field->FieldData() ).Text(); |
|
1263 |
|
1264 if ( ( aContact.Length() + castFieldText.Length() ) > KMaxLengthOfName ) |
|
1265 { |
|
1266 User::Leave( KErrOverflow ); |
|
1267 } |
|
1268 |
|
1269 aContact.Append( castFieldText ); |
|
1270 CleanupStack::PopAndDestroy( field ); |
|
1271 } |
|
1272 CleanupStack::PopAndDestroy( 2 ); // fieldFilter, fieldTypeSelector |
|
1273 } |
|
1274 |
|