Contact: use composite name if available

This commit is contained in:
Gautier Pelloux-Prayer 2015-11-13 09:59:02 +01:00
parent 30f2aef528
commit 61a9d393c1
2 changed files with 8 additions and 25 deletions

View file

@ -82,25 +82,8 @@ static int ms_strcmpfuz(const char *fuzzy_word, const char *sentence) {
}
- (NSString *)displayNameForContact:(ABRecordRef)person {
NSString *lFirstName = CFBridgingRelease(ABRecordCopyValue(person, kABPersonFirstNameProperty));
NSString *lLocalizedFirstName = [FastAddressBook localizedLabel:lFirstName];
NSString *lLastName = CFBridgingRelease(ABRecordCopyValue(person, kABPersonLastNameProperty));
NSString *lLocalizedLastName = [FastAddressBook localizedLabel:lLastName];
NSString *lOrganization = CFBridgingRelease(ABRecordCopyValue(person, kABPersonOrganizationProperty));
NSString *lLocalizedlOrganization = [FastAddressBook localizedLabel:lOrganization];
NSString *name = nil;
if (lLocalizedFirstName.length && lLocalizedLastName.length) {
name = [NSString stringWithFormat:@"%@ %@", lLocalizedFirstName, lLocalizedLastName];
} else if (lLocalizedLastName.length) {
name = [NSString stringWithFormat:@"%@", lLocalizedLastName];
} else if (lLocalizedFirstName.length) {
name = [NSString stringWithFormat:@"%@", lLocalizedFirstName];
} else if (lLocalizedlOrganization.length) {
name = [NSString stringWithFormat:@"%@", lLocalizedlOrganization];
}
if (name != nil && [name length] > 0) {
NSString *name = [FastAddressBook displayNameForContact:person];
if (name != nil && [name length] > 0 && ![name isEqualToString:NSLocalizedString(@"Unkonwn", nil)]) {
// Add the contact only if it fuzzy match filter too (if any)
if ([ContactSelection getNameOrEmailFilter] == nil ||
(ms_strcmpfuz([[[ContactSelection getNameOrEmailFilter] lowercaseString] UTF8String],

View file

@ -305,9 +305,7 @@ void sync_address_book(ABAddressBookRef addressBook, CFDictionaryRef info, void
if (contact != nil) {
NSString *lFirstName = CFBridgingRelease(ABRecordCopyValue(contact, kABPersonFirstNameProperty));
NSString *lLocalizedFirstName = [FastAddressBook localizedLabel:lFirstName];
// TODO: we may use the following so that first name / last name is properly displayed?
// retString = CFBridgingRelease(ABRecordCopyCompositeName(contact));
NSString *compositeName = CFBridgingRelease(ABRecordCopyCompositeName(contact));
NSString *lLastName = CFBridgingRelease(ABRecordCopyValue(contact, kABPersonLastNameProperty));
NSString *lLocalizedLastName = [FastAddressBook localizedLabel:lLastName];
@ -315,10 +313,12 @@ void sync_address_book(ABAddressBookRef addressBook, CFDictionaryRef info, void
NSString *lOrganization = CFBridgingRelease(ABRecordCopyValue(contact, kABPersonOrganizationProperty));
NSString *lLocalizedOrganization = [FastAddressBook localizedLabel:lOrganization];
if (lLocalizedFirstName == nil && lLocalizedLastName == nil) {
ret = (NSString *)lLocalizedOrganization;
} else {
if (compositeName) {
ret = compositeName;
} else if (lLocalizedFirstName || lLocalizedLastName) {
ret = [NSString stringWithFormat:@"%@ %@", lLocalizedFirstName, lLocalizedLastName];
} else {
ret = (NSString *)lLocalizedOrganization;
}
}
return ret;