From 566cfbd491fc4bdcd30824ba1f05f10c50f28748 Mon Sep 17 00:00:00 2001 From: Jehan Monnier Date: Mon, 30 May 2011 17:25:06 +0200 Subject: [PATCH] implement fast address book lookup --- Classes/LinphoneUI/FastAddressBook.h | 41 ++++ Classes/LinphoneUI/FastAddressBook.m | 98 ++++++++ Classes/LinphoneUI/LinphoneManager.h | 5 +- Classes/LinphoneUI/LinphoneManager.m | 65 +++--- Settings.bundle/Root.plist | 336 ++++++++++++++------------- linphone.xcodeproj/project.pbxproj | 6 + 6 files changed, 349 insertions(+), 202 deletions(-) create mode 100644 Classes/LinphoneUI/FastAddressBook.h create mode 100644 Classes/LinphoneUI/FastAddressBook.m diff --git a/Classes/LinphoneUI/FastAddressBook.h b/Classes/LinphoneUI/FastAddressBook.h new file mode 100644 index 000000000..780ceb33c --- /dev/null +++ b/Classes/LinphoneUI/FastAddressBook.h @@ -0,0 +1,41 @@ +/* FastAddressBook.h + * + * Copyright (C) 2011 Belledonne Comunications, Grenoble, France + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#import +#import + +@interface Contact : NSObject { + ABRecordRef record; + NSString* numberType; +} +-(id) initWithRecord:(ABRecordRef) record ofType:(NSString*) type; +@property (nonatomic, readonly) ABRecordRef record; +@property (nonatomic, readonly) NSString* numberType; +@end + +@interface FastAddressBook : NSObject { + NSMutableDictionary* mAddressBookMap; +} + +-(Contact*) getMatchingRecord:(NSString*) number ; ++(NSString*) appendCountryCodeIfPossible:(NSString*) number ; ++(NSString*) normalizePhoneNumber:(NSString*) number ; +-(id) init ; + +@end diff --git a/Classes/LinphoneUI/FastAddressBook.m b/Classes/LinphoneUI/FastAddressBook.m new file mode 100644 index 000000000..ffb7e4336 --- /dev/null +++ b/Classes/LinphoneUI/FastAddressBook.m @@ -0,0 +1,98 @@ +/* FastAddressBook.h + * + * Copyright (C) 2011 Belledonne Comunications, Grenoble, France + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#import "FastAddressBook.h" +@implementation FastAddressBook + + -(Contact*) getMatchingRecord:(NSString*) number { + @synchronized (mAddressBookMap){ + return (Contact*) [mAddressBookMap objectForKey:number]; + } +} + ++(NSString*) appendCountryCodeIfPossible:(NSString*) number { + if (![number hasPrefix:@"+"] && ![number hasPrefix:@"00"]) { + NSString* lCountryCode = [[NSUserDefaults standardUserDefaults] stringForKey:@"countrycode_preference"]; + if (lCountryCode && [lCountryCode length]>0) { + //append country code + return [lCountryCode stringByAppendingString:number]; + } + } + return number; +} ++(NSString*) normalizePhoneNumber:(NSString*) number { + NSString* lNormalizedNumber = [(NSString*)number stringByReplacingOccurrencesOfString:@" " withString:@""]; + lNormalizedNumber = [lNormalizedNumber stringByReplacingOccurrencesOfString:@"(" withString:@""]; + lNormalizedNumber = [lNormalizedNumber stringByReplacingOccurrencesOfString:@")" withString:@""]; + lNormalizedNumber = [lNormalizedNumber stringByReplacingOccurrencesOfString:@"-" withString:@""]; + lNormalizedNumber = [FastAddressBook appendCountryCodeIfPossible:lNormalizedNumber]; + return lNormalizedNumber; +} +void sync_address_book (ABAddressBookRef addressBook, CFDictionaryRef info, void *context) { + NSMutableDictionary* lAddressBookMap = (NSMutableDictionary*)context; + @synchronized (lAddressBookMap) { + [lAddressBookMap removeAllObjects]; + + NSArray *lContacts = (NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook); + for (id lPerson in lContacts) { + ABMutableMultiValueRef lPhoneNumbers = ABRecordCopyValue((ABRecordRef)lPerson, kABPersonPhoneProperty); + for ( int i=0; i registrationDelegate; @property Connectivity connectivity; @end + + diff --git a/Classes/LinphoneUI/LinphoneManager.m b/Classes/LinphoneUI/LinphoneManager.m index 3be9f40e4..d97d85b4b 100644 --- a/Classes/LinphoneUI/LinphoneManager.m +++ b/Classes/LinphoneUI/LinphoneManager.m @@ -25,9 +25,7 @@ #include #import #import -#import - - +#import "FastAddressBook.h" static LinphoneCore* theLinphoneCore=nil; static LinphoneManager* theLinphoneManager=nil; @@ -40,12 +38,19 @@ extern void libmsamr_init(); @synthesize registrationDelegate; @synthesize connectivity; +-(id) init { + if ((self= [super init])) { + mFastAddressBook = [[FastAddressBook alloc] init]; + } + return self; +} +(LinphoneManager*) instance { if (theLinphoneManager==nil) { - theLinphoneManager = [LinphoneManager alloc]; + theLinphoneManager = [[LinphoneManager alloc] init]; } return theLinphoneManager; } + -(NSString*) appendCountryCodeIfPossible:(NSString*) number { if (![number hasPrefix:@"+"] && ![number hasPrefix:@"00"]) { NSString* lCountryCode = [[NSUserDefaults standardUserDefaults] stringForKey:@"countrycode_preference"]; @@ -58,41 +63,24 @@ extern void libmsamr_init(); } -(NSString*) getDisplayNameFromAddressBook:(NSString*) number andUpdateCallLog:(LinphoneCallLog*)log { - ABAddressBookRef lAddressBook = ABAddressBookCreate(); - NSArray *lContacts = (NSArray *)ABAddressBookCopyArrayOfAllPeople(lAddressBook); - for (id lContact in lContacts) { - ABMutableMultiValueRef lPhoneNumbers = ABRecordCopyValue((ABRecordRef)lContact, kABPersonPhoneProperty); - for ( int i=0; i0) { linphone_proxy_config_set_dial_prefix(proxyCfg, [prefix cStringUsingEncoding:[NSString defaultCStringEncoding]]); } - linphone_proxy_config_set_dial_escape_plus(proxyCfg,TRUE); + linphone_proxy_config_set_dial_escape_plus(proxyCfg,substitute_plus_by_00); linphone_core_add_proxy_config(theLinphoneCore,proxyCfg); //set to default proxy diff --git a/Settings.bundle/Root.plist b/Settings.bundle/Root.plist index 822a62a4c..5b703ede8 100644 --- a/Settings.bundle/Root.plist +++ b/Settings.bundle/Root.plist @@ -2,199 +2,218 @@ - StringsTable - Root PreferenceSpecifiers - Type - PSGroupSpecifier Title SIP account + Type + PSGroupSpecifier - Type - PSTextFieldSpecifier - Title - User name + AutocapitalizationType + None + AutocorrectionType + No + DefaultValue + + IsSecure + Key username_preference - DefaultValue - - IsSecure - KeyboardType Alphabet + Title + User name + Type + PSTextFieldSpecifier + + AutocapitalizationType None AutocorrectionType No - - - Type - PSTextFieldSpecifier - Title - Password + DefaultValue + + IsSecure + Key password_preference - DefaultValue - - IsSecure - KeyboardType Alphabet + Title + Password + Type + PSTextFieldSpecifier + + AutocapitalizationType None AutocorrectionType No - - - Type - PSTextFieldSpecifier - Title - Domain + DefaultValue + + IsSecure + Key domain_preference - DefaultValue - - IsSecure - KeyboardType URL + Title + Domain + Type + PSTextFieldSpecifier + + AutocapitalizationType None AutocorrectionType No - - - Type - PSTextFieldSpecifier - Title - Proxy + DefaultValue + + IsSecure + Key proxy_preference - DefaultValue - - IsSecure - KeyboardType URL + Title + Proxy + Type + PSTextFieldSpecifier + + + DefaultValue + + Key + outbound_proxy_preference + Title + Outbound proxy + Type + PSToggleSwitchSpecifier + + + Title + Codecs + Type + PSGroupSpecifier + + + DefaultValue + + Key + speex_16k_preference + Title + Speex 16Khz + Type + PSToggleSwitchSpecifier + + + DefaultValue + + Key + speex_8k_preference + Title + Speex 8Khz + Type + PSToggleSwitchSpecifier + + + DefaultValue + + Key + gsm_8k_preference + Title + GSM + Type + PSToggleSwitchSpecifier + + + DefaultValue + + Key + ilbc_preference + Title + ILBC + Type + PSToggleSwitchSpecifier + + + DefaultValue + + Key + pcmu_preference + Title + PCMU + Type + PSToggleSwitchSpecifier + + + DefaultValue + + Key + pcma_preference + Title + PCMA + Type + PSToggleSwitchSpecifier + + + Title + Advanced + Type + PSGroupSpecifier + + + DefaultValue + + Key + debugenable_preference + Title + Debug + Type + PSToggleSwitchSpecifier + + AutocapitalizationType None AutocorrectionType No - - - Type - PSToggleSwitchSpecifier - Title - Outbound proxy - Key - outbound_proxy_preference - DefaultValue - - - - Type - PSGroupSpecifier - Title - Codecs - - - Type - PSToggleSwitchSpecifier - Title - Speex 16Khz - Key - speex_16k_preference - DefaultValue - - - - Type - PSToggleSwitchSpecifier - Title - Speex 8Khz - Key - speex_8k_preference - DefaultValue - - - - Type - PSToggleSwitchSpecifier - Title - GSM - Key - gsm_8k_preference - DefaultValue - - - - Type - PSToggleSwitchSpecifier - Title - ILBC - Key - ilbc_preference - DefaultValue - - - - Type - PSToggleSwitchSpecifier - Title - PCMU - Key - pcmu_preference - DefaultValue - - - - Type - PSToggleSwitchSpecifier - Title - PCMA - Key - pcma_preference - DefaultValue - - - - Type - PSGroupSpecifier - Title - Advanced - - - Type - PSToggleSwitchSpecifier - Title - Debug - Key - debugenable_preference - DefaultValue - - - - Type - PSTextFieldSpecifier - Title - Prefix - Key - prefix_preference DefaultValue IsSecure + Key + prefix_preference KeyboardType NumberPad - AutocapitalizationType - None - AutocorrectionType - No + Title + Prefix + Type + PSTextFieldSpecifier + DefaultValue + + Key + substitute_+_by_00_preference + Title + Substitue + by 00 + Type + PSToggleSwitchSpecifier + + + DefaultValue + udp + Key + transport_preference + Title + Transport + Titles + + udp + tcp + Type PSMultiValueSpecifier Values @@ -202,28 +221,19 @@ udp tcp - Titles - - udp - tcp - - Title - Transport - Key - transport_preference - DefaultValue - udp - Type - PSToggleSwitchSpecifier - Title - Background mode - Key - backgroundmode_preference DefaultValue + Key + backgroundmode_preference + Title + Background mode + Type + PSToggleSwitchSpecifier + StringsTable + Root diff --git a/linphone.xcodeproj/project.pbxproj b/linphone.xcodeproj/project.pbxproj index 4c9dca969..fb7b5197d 100755 --- a/linphone.xcodeproj/project.pbxproj +++ b/linphone.xcodeproj/project.pbxproj @@ -35,6 +35,7 @@ 223148E41178A08200637D6A /* libilbc.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 223148E31178A08200637D6A /* libilbc.a */; }; 223148E61178A09900637D6A /* libmsilbc.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 223148E51178A09900637D6A /* libmsilbc.a */; }; 2237D4091084D7A9001383EE /* oldphone-mono.wav in Resources */ = {isa = PBXBuildFile; fileRef = 2237D4081084D7A9001383EE /* oldphone-mono.wav */; }; + 223963171393CFAF001DE689 /* FastAddressBook.m in Sources */ = {isa = PBXBuildFile; fileRef = 223963161393CFAF001DE689 /* FastAddressBook.m */; }; 2242D91610D66BF300E9963F /* in_call.png in Resources */ = {isa = PBXBuildFile; fileRef = 2242D91410D66BF300E9963F /* in_call.png */; }; 2242D91710D66BF300E9963F /* out_call.png in Resources */ = {isa = PBXBuildFile; fileRef = 2242D91510D66BF300E9963F /* out_call.png */; }; 2242D91A10D66C2100E9963F /* mic_active.png in Resources */ = {isa = PBXBuildFile; fileRef = 2242D91810D66C2100E9963F /* mic_active.png */; }; @@ -257,6 +258,8 @@ 223148E31178A08200637D6A /* libilbc.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libilbc.a; path = "liblinphone-sdk/apple-darwin/lib/libilbc.a"; sourceTree = ""; }; 223148E51178A09900637D6A /* libmsilbc.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libmsilbc.a; path = "liblinphone-sdk/apple-darwin/lib/mediastreamer/plugins/libmsilbc.a"; sourceTree = ""; }; 2237D4081084D7A9001383EE /* oldphone-mono.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; name = "oldphone-mono.wav"; path = "liblinphone-sdk/apple-darwin/share/sounds/linphone/rings/oldphone-mono.wav"; sourceTree = ""; }; + 223963151393CFAE001DE689 /* FastAddressBook.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FastAddressBook.h; sourceTree = ""; }; + 223963161393CFAF001DE689 /* FastAddressBook.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FastAddressBook.m; sourceTree = ""; }; 2242D91410D66BF300E9963F /* in_call.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = in_call.png; path = Resources/in_call.png; sourceTree = ""; }; 2242D91510D66BF300E9963F /* out_call.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = out_call.png; path = Resources/out_call.png; sourceTree = ""; }; 2242D91810D66C2100E9963F /* mic_active.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = mic_active.png; path = "liblinphone-sdk/apple-darwin/share/pixmaps/linphone/mic_active.png"; sourceTree = ""; }; @@ -687,6 +690,8 @@ 22C7555F1317E59C007BC101 /* UIBluetoothButton.m */, 22BB1A67132FF16A005CD7AA /* UIEraseButton.h */, 22BB1A68132FF16A005CD7AA /* UIEraseButton.m */, + 223963151393CFAE001DE689 /* FastAddressBook.h */, + 223963161393CFAF001DE689 /* FastAddressBook.m */, ); path = LinphoneUI; sourceTree = ""; @@ -998,6 +1003,7 @@ 2218A92512FBE1340088A667 /* FirstLoginViewController.m in Sources */, 22C755601317E59C007BC101 /* UIBluetoothButton.m in Sources */, 22BB1A69132FF16A005CD7AA /* UIEraseButton.m in Sources */, + 223963171393CFAF001DE689 /* FastAddressBook.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; };