From 40588f3d31223bc21d5e4050629fc7a6740c3b0c Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Tue, 12 Mar 2013 12:01:06 +0100 Subject: [PATCH] Allow adding an email address to a contact from history. --- Classes/ContactDetailsTableViewController.h | 1 + Classes/ContactDetailsViewController.m | 26 +++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Classes/ContactDetailsTableViewController.h b/Classes/ContactDetailsTableViewController.h index 9d59e805b..7d804793e 100644 --- a/Classes/ContactDetailsTableViewController.h +++ b/Classes/ContactDetailsTableViewController.h @@ -39,5 +39,6 @@ - (BOOL)isValid; - (void)addSipField:(NSString*)address; +- (void)addEmailField:(NSString*)address; @end diff --git a/Classes/ContactDetailsViewController.m b/Classes/ContactDetailsViewController.m index e160786c1..7ae9d7e5b 100644 --- a/Classes/ContactDetailsViewController.m +++ b/Classes/ContactDetailsViewController.m @@ -158,7 +158,18 @@ static void sync_address_book (ABAddressBookRef addressBook, CFDictionaryRef inf [self resetData]; contact = ABPersonCreate(); [tableController setContact:contact]; - [tableController addSipField:address]; + if ([[LinphoneManager instance] lpConfigBoolForKey:@"show_contacts_emails_preference"] == true) { + LinphoneAddress *linphoneAddress = linphone_address_new([address cStringUsingEncoding:[NSString defaultCStringEncoding]]); + NSString *username = [NSString stringWithUTF8String:linphone_address_get_username(linphoneAddress)]; + if ([username rangeOfString:@"@"].length > 0) { + [tableController addEmailField:username]; + } else { + [tableController addSipField:address]; + } + linphone_address_destroy(linphoneAddress); + } else { + [tableController addSipField:address]; + } [self enableEdit:FALSE]; [[tableController tableView] reloadData]; } @@ -179,7 +190,18 @@ static void sync_address_book (ABAddressBookRef addressBook, CFDictionaryRef inf [self resetData]; contact = ABAddressBookGetPersonWithRecordID(addressBook, ABRecordGetRecordID(acontact)); [tableController setContact:contact]; - [tableController addSipField:address]; + if ([[LinphoneManager instance] lpConfigBoolForKey:@"show_contacts_emails_preference"] == true) { + LinphoneAddress *linphoneAddress = linphone_address_new([address cStringUsingEncoding:[NSString defaultCStringEncoding]]); + NSString *username = [NSString stringWithUTF8String:linphone_address_get_username(linphoneAddress)]; + if ([username rangeOfString:@"@"].length > 0) { + [tableController addEmailField:username]; + } else { + [tableController addSipField:address]; + } + linphone_address_destroy(linphoneAddress); + } else { + [tableController addSipField:address]; + } [self enableEdit:FALSE]; [[tableController tableView] reloadData]; }