From 3752fab5ad6a6d7b6905dd9e56055add4fe85622 Mon Sep 17 00:00:00 2001 From: Jehan Monnier Date: Wed, 5 Sep 2012 10:33:56 +0200 Subject: [PATCH] rework on settings store --- Classes/FirstLoginViewController.m | 30 +++++++++----- Classes/InCallViewController.m | 2 +- Classes/LinphoneCoreSettingsStore.h | 1 + Classes/LinphoneManager.h | 13 +++++- Classes/LinphoneManager.m | 40 +++++++++++++++---- Classes/LinphoneUI/UICallBar.m | 8 ++-- .../LinphoneUI/UICompositeViewController.m | 2 +- Classes/PhoneMainView.m | 4 +- Classes/SettingsViewController.h | 3 ++ Classes/SettingsViewController.m | 21 +++++----- Classes/Utils/FastAddressBook.m | 2 +- Classes/WizardViewController.m | 22 +++++----- submodules/linphone | 2 +- 13 files changed, 104 insertions(+), 46 deletions(-) diff --git a/Classes/FirstLoginViewController.m b/Classes/FirstLoginViewController.m index 9d447b0d5..014cf0c35 100644 --- a/Classes/FirstLoginViewController.m +++ b/Classes/FirstLoginViewController.m @@ -79,8 +79,9 @@ static UICompositeViewDescription *compositeDescription = nil; name:kLinphoneRegistrationUpdate object:nil]; - [usernameField setText:[[LinphoneManager instance].settingsStore objectForKey:@"username_preference"]]; - [passwordField setText:[[LinphoneManager instance].settingsStore objectForKey:@"password_preference"]]; + + [usernameField setText:[[LinphoneManager instance] lpConfigStringForKey:@"wizard_username"]]; + [passwordField setText:[[LinphoneManager instance] lpConfigStringForKey:@"wizard_password"]]; // Update on show const MSList* list = linphone_core_get_proxy_config_list([LinphoneManager getLc]); @@ -104,7 +105,7 @@ static UICompositeViewDescription *compositeDescription = nil; - (void)viewDidLoad { [super viewDidLoad]; - NSString* siteUrl = [[LinphoneManager instance].settingsStore objectForKey:@"first_login_view_url"]; + NSString* siteUrl = [[LinphoneManager instance] lpConfigStringForKey:@"first_login_view_url"]; if (siteUrl==nil) { siteUrl=@"http://www.linphone.org"; } @@ -123,7 +124,7 @@ static UICompositeViewDescription *compositeDescription = nil; - (void)registrationUpdate:(LinphoneRegistrationState)state { switch (state) { case LinphoneRegistrationOk: { - [[LinphoneManager instance].settingsStore setBool:false forKey:@"enable_first_login_view_preference"]; + [[LinphoneManager instance] lpConfigSetBool:FALSE forKey:@"enable_first_login_view_preference"]; [waitView setHidden:true]; [[PhoneMainView instance] changeCurrentView:[DialerViewController compositeViewDescription]]; break; @@ -137,8 +138,8 @@ static UICompositeViewDescription *compositeDescription = nil; [waitView setHidden:true]; //erase uername passwd - [[LinphoneManager instance].settingsStore setObject:Nil forKey:@"username_preference"]; - [[LinphoneManager instance].settingsStore setObject:Nil forKey:@"password_preference"]; + [[LinphoneManager instance] lpConfigSetString:nil forKey:@"wizard_username"]; + [[LinphoneManager instance] lpConfigSetString:nil forKey:@"wizard_password"]; break; } case LinphoneRegistrationProgress: { @@ -175,10 +176,21 @@ static UICompositeViewDescription *compositeDescription = nil; [error show]; [error release]; } else { - [[LinphoneManager instance].settingsStore setObject:usernameField.text forKey:@"username_preference"]; - [[LinphoneManager instance].settingsStore setObject:passwordField.text forKey:@"password_preference"]; + linphone_core_clear_all_auth_info([LinphoneManager getLc]); + linphone_core_clear_proxy_config([LinphoneManager getLc]); + LinphoneProxyConfig* proxyCfg = linphone_core_create_proxy_config([LinphoneManager getLc]); + /*default domain is supposed to be preset from linphonerc*/ + NSString* identity = [NSString stringWithFormat:@"sip:%@@%@",usernameField.text,linphone_proxy_config_get_addr(proxyCfg)]; + linphone_proxy_config_set_identity(proxyCfg,[identity UTF8String]); + LinphoneAuthInfo* auth_info =linphone_auth_info_new([usernameField.text UTF8String] + ,[usernameField.text UTF8String] + ,[passwordField.text UTF8String] + ,NULL + ,NULL); + linphone_core_add_auth_info([LinphoneManager getLc], auth_info); + linphone_core_add_proxy_config([LinphoneManager getLc], proxyCfg); + linphone_core_set_default_proxy([LinphoneManager getLc], proxyCfg); [self.waitView setHidden:false]; - [[LinphoneManager instance].settingsStore synchronize]; }; } diff --git a/Classes/InCallViewController.m b/Classes/InCallViewController.m index 1c66439b7..a3a6c0a11 100644 --- a/Classes/InCallViewController.m +++ b/Classes/InCallViewController.m @@ -403,7 +403,7 @@ static UICompositeViewDescription *compositeDescription = nil; [UIView commitAnimations]; } - if([[[LinphoneManager instance] settingsStore] boolForKey:@"self_video_preference"]) { + if([[LinphoneManager instance] lpConfigBoolForKey:@"self_video_preference"]) { [videoPreview setHidden:FALSE]; } else { [videoPreview setHidden:TRUE]; diff --git a/Classes/LinphoneCoreSettingsStore.h b/Classes/LinphoneCoreSettingsStore.h index ab6b214c8..ee73e33ea 100644 --- a/Classes/LinphoneCoreSettingsStore.h +++ b/Classes/LinphoneCoreSettingsStore.h @@ -23,6 +23,7 @@ #import "LinphoneManager.h" @interface LinphoneCoreSettingsStore : IASKAbstractSettingsStore { + @private NSDictionary *dict; NSDictionary *changedDict; } diff --git a/Classes/LinphoneManager.h b/Classes/LinphoneManager.h index 7e9bbea89..ee87cf12a 100644 --- a/Classes/LinphoneManager.h +++ b/Classes/LinphoneManager.h @@ -80,6 +80,7 @@ typedef struct _LinphoneManagerSounds { Connectivity connectivity; BOOL stopWaitingRegisters; NSMutableArray *inhibitedEvent; + @public CallContext currentCallContextBeforeGoingBackground; @@ -123,7 +124,17 @@ typedef struct _LinphoneManagerSounds { - (void)call:(NSString *)address displayName:(NSString*)displayName transfer:(BOOL)transfer; -@property (nonatomic, retain) id settingsStore; +-(void)lpConfigSetString:(NSString*) value forKey:(NSString*) key; +-(NSString*)lpConfigStringForKey:(NSString*) key; + +-(void)lpConfigSetInt:(NSInteger) value forKey:(NSString*) key; +-(NSInteger)lpConfigIntForKey:(NSString*) key; + +-(void)lpConfigSetBool:(BOOL) value forKey:(NSString*) key; +-(BOOL)lpConfigBoolForKey:(NSString*) key; + + + @property (readonly) FastAddressBook* fastAddressBook; @property Connectivity connectivity; @property (readonly) const char* frontCamId; diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index a2e2a5739..641c285c5 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -73,7 +73,6 @@ extern void libmsbcg729_init(); @synthesize connectivity; @synthesize frontCamId; @synthesize backCamId; -@synthesize settingsStore; @synthesize database; @synthesize fastAddressBook; @synthesize pushNotificationToken; @@ -180,7 +179,7 @@ struct codec_name_pref_table codec_pref_table[]={ - (id)init { if ((self = [super init])) { - fastAddressBook = [[FastAddressBook alloc] init]; + { NSString *path = [[NSBundle mainBundle] pathForResource:@"ring" ofType:@"wav"]; @@ -201,7 +200,6 @@ struct codec_name_pref_table codec_pref_table[]={ inhibitedEvent = [[NSMutableArray alloc] init]; logs = [[NSMutableArray alloc] init]; database = NULL; - settingsStore = nil; [self openDatabase]; [self copyDefaultSettings]; lastRemoteNotificationTime=0; @@ -220,7 +218,6 @@ struct codec_name_pref_table codec_pref_table[]={ [inhibitedEvent release]; [fastAddressBook release]; [self closeDatabase]; - [settingsStore release]; [logs release]; [super dealloc]; @@ -616,6 +613,9 @@ static LinphoneCoreVTable linphonec_vtable = { , [factoryConfig cStringUsingEncoding:[NSString defaultCStringEncoding]] ,self); + + fastAddressBook = [[FastAddressBook alloc] init]; + linphone_core_set_root_ca(theLinphoneCore, lRootCa); // Set audio assets const char* lRing = [[myBundle pathForResource:@"ring"ofType:@"wav"] cStringUsingEncoding:[NSString defaultCStringEncoding]]; @@ -691,8 +691,7 @@ static LinphoneCoreVTable linphonec_vtable = { else ms_set_cpu_count(1); - if (!settingsStore) - settingsStore = [[LinphoneCoreSettingsStore alloc] init]; + [LinphoneLogger logc:LinphoneLoggerWarning format:"Linphone [%s] started on [%s]" ,linphone_core_get_version() @@ -742,8 +741,6 @@ static LinphoneCoreVTable linphonec_vtable = { } - (BOOL)resignActive { - if ([[LinphoneManager instance] settingsStore] != Nil) - [[[LinphoneManager instance] settingsStore] synchronize]; linphone_core_stop_dtmf_stream(theLinphoneCore); return YES; } @@ -1061,4 +1058,31 @@ static LinphoneCoreVTable linphonec_vtable = { return TRUE; } + + + + +-(void)lpConfigSetString:(NSString*) value forKey:(NSString*) key { + lp_config_set_string(linphone_core_get_config(theLinphoneCore),"app",value?[key UTF8String]:NULL, [value UTF8String]); +} +-(NSString*)lpConfigStringForKey:(NSString*) key { + const char* value=lp_config_get_string(linphone_core_get_config(theLinphoneCore),"app",[key UTF8String],NULL); + if (value) + return [NSString stringWithCString:value encoding:[NSString defaultCStringEncoding]]; + else + return nil; +} +-(void)lpConfigSetInt:(NSInteger) value forKey:(NSString*) key { + lp_config_set_int(linphone_core_get_config(theLinphoneCore),"app",[key UTF8String], value ); +} +-(NSInteger)lpConfigIntForKey:(NSString*) key { + return lp_config_get_int(linphone_core_get_config(theLinphoneCore),"app",[key UTF8String],-1); +} + +-(void)lpConfigSetBool:(BOOL) value forKey:(NSString*) key { + return [self lpConfigSetInt:(NSInteger)(value==TRUE) forKey:key]; +} +-(BOOL)lpConfigBoolForKey:(NSString*) key { + return [self lpConfigIntForKey:key] == 1; +} @end diff --git a/Classes/LinphoneUI/UICallBar.m b/Classes/LinphoneUI/UICallBar.m index db7d1c8a6..b6a02a307 100644 --- a/Classes/LinphoneUI/UICallBar.m +++ b/Classes/LinphoneUI/UICallBar.m @@ -374,9 +374,9 @@ - (IBAction)onPadClick:(id)sender { if([padView isHidden]) { - [self showPad:[[LinphoneManager instance].settingsStore boolForKey:@"animations_preference"]]; + [self showPad:[[LinphoneManager instance] lpConfigBoolForKey:@"animations_preference"]]; } else { - [self hidePad:[[LinphoneManager instance].settingsStore boolForKey:@"animations_preference"]]; + [self hidePad:[[LinphoneManager instance] lpConfigBoolForKey:@"animations_preference"]]; } } @@ -402,9 +402,9 @@ - (IBAction)onOptionsClick:(id)sender { if([optionsView isHidden]) { - [self showOptions:[[LinphoneManager instance].settingsStore boolForKey:@"animations_preference"]]; + [self showOptions:[[LinphoneManager instance] lpConfigBoolForKey:@"animations_preference"]]; } else { - [self hideOptions:[[LinphoneManager instance].settingsStore boolForKey:@"animations_preference"]]; + [self hideOptions:[[LinphoneManager instance] lpConfigBoolForKey:@"animations_preference"]]; } } diff --git a/Classes/LinphoneUI/UICompositeViewController.m b/Classes/LinphoneUI/UICompositeViewController.m index b1f6b8c77..68e2037f0 100644 --- a/Classes/LinphoneUI/UICompositeViewController.m +++ b/Classes/LinphoneUI/UICompositeViewController.m @@ -326,7 +326,7 @@ return [UIApplication sharedApplication].statusBarOrientation; } - NSString* rotationPreference = [[LinphoneManager instance].settingsStore objectForKey:@"rotation_preference"]; + NSString* rotationPreference = [[LinphoneManager instance] lpConfigStringForKey:@"rotation_preference"]; if([rotationPreference isEqualToString:@"auto"]) { // Don't rotate in UIDeviceOrientationFaceUp UIDeviceOrientationFaceDown if(!UIDeviceOrientationIsPortrait(deviceOrientation) && !UIDeviceOrientationIsLandscape(deviceOrientation)) { diff --git a/Classes/PhoneMainView.m b/Classes/PhoneMainView.m index 845764367..4daf01701 100644 --- a/Classes/PhoneMainView.m +++ b/Classes/PhoneMainView.m @@ -371,7 +371,7 @@ static PhoneMainView* phoneMainViewInstance=nil; #pragma mark - - (void)startUp { - if ([[LinphoneManager instance].settingsStore boolForKey:@"enable_first_login_view_preference"] == true) { + if ([[LinphoneManager instance] lpConfigBoolForKey:@"enable_first_login_view_preference"] == true) { // Change to fist login view [self changeCurrentView: [FirstLoginViewController compositeViewDescription]]; } else { @@ -484,7 +484,7 @@ static PhoneMainView* phoneMainViewInstance=nil; if(force || ![view equal: currentView]) { if(transition == nil) transition = [PhoneMainView getTransition:currentView new:view]; - if ([[LinphoneManager instance].settingsStore boolForKey:@"animations_preference"] == true) { + if ([[LinphoneManager instance] lpConfigBoolForKey:@"animations_preference"] == true) { [mainViewController setViewTransition:transition]; } else { [mainViewController setViewTransition:nil]; diff --git a/Classes/SettingsViewController.h b/Classes/SettingsViewController.h index 9cc04a88e..af0be21d4 100644 --- a/Classes/SettingsViewController.h +++ b/Classes/SettingsViewController.h @@ -21,8 +21,11 @@ #import "UICompositeViewController.h" #import "IASKAppSettingsViewController.h" +#import "LinphoneCoreSettingsStore.h" @interface SettingsViewController: UIViewController { + @private + LinphoneCoreSettingsStore* settingsStore; } @property (nonatomic, retain) IBOutlet UINavigationController *navigationController; diff --git a/Classes/SettingsViewController.m b/Classes/SettingsViewController.m index dbaba1d44..bd10907d0 100644 --- a/Classes/SettingsViewController.m +++ b/Classes/SettingsViewController.m @@ -29,7 +29,7 @@ #import "IASKPSTextFieldSpecifierViewCell.h" #import "IASKSpecifier.h" #import "IASKTextField.h" - +#include "lpconfig.h" #pragma mark - IASKSwitchEx Class @@ -349,9 +349,9 @@ - (void)dealloc { // Remove all observer [[NSNotificationCenter defaultCenter] removeObserver:self]; - [settingsController release]; + [settingsStore release]; + [settingsController release]; [navigationController release]; - [super dealloc]; } @@ -379,12 +379,15 @@ static UICompositeViewDescription *compositeDescription = nil; - (void)viewDidLoad { [super viewDidLoad]; - + + settingsStore = [[LinphoneCoreSettingsStore alloc] init]; + [settingsStore transformLinphoneCoreToKeys]; + settingsController.showDoneButton = FALSE; settingsController.delegate = self; settingsController.showCreditsFooter = FALSE; settingsController.hiddenKeys = [self findHiddenKeys]; - settingsController.settingsStore = [[LinphoneManager instance] settingsStore]; + settingsController.settingsStore = settingsStore; [navigationController.view setBackgroundColor:[UIColor clearColor]]; @@ -491,7 +494,7 @@ static UICompositeViewDescription *compositeDescription = nil; [hiddenKeys addObject:@"backgroundmode_preference"]; [hiddenKeys addObject:@"start_at_boot_preference"]; } else { - if(![[[[LinphoneManager instance] settingsStore] objectForKey:@"backgroundmode_preference"] boolValue]) { + if(![[LinphoneManager instance] lpConfigBoolForKey:@"backgroundmode_preference"]) { [hiddenKeys addObject:@"start_at_boot_preference"]; } } @@ -505,15 +508,15 @@ static UICompositeViewDescription *compositeDescription = nil; [hiddenKeys addObjectsFromArray:[[LinphoneManager unsupportedCodecs] allObjects]]; - if([[[[LinphoneManager instance] settingsStore] objectForKey:@"random_port_preference"] boolValue]) { + if(lp_config_get_int(linphone_core_get_config([LinphoneManager getLc]),"sip","sip_random_port",0)==1) { [hiddenKeys addObject:@"port_preference"]; } - if([[[[LinphoneManager instance] settingsStore] objectForKey:@"stun_preference"] length] == 0) { + if(linphone_core_get_stun_server([LinphoneManager getLc]) != NULL) { [hiddenKeys addObject:@"ice_preference"]; } - if(![[[[LinphoneManager instance] settingsStore] objectForKey:@"debugenable_preference"] boolValue]) { + if(![[LinphoneManager instance] lpConfigBoolForKey:@"debugenable_preference"]) { [hiddenKeys addObject:@"console_button"]; } diff --git a/Classes/Utils/FastAddressBook.m b/Classes/Utils/FastAddressBook.m index e09152d7a..3994fb536 100644 --- a/Classes/Utils/FastAddressBook.m +++ b/Classes/Utils/FastAddressBook.m @@ -57,7 +57,7 @@ + (NSString*)appendCountryCodeIfPossible:(NSString*)number { if (![number hasPrefix:@"+"] && ![number hasPrefix:@"00"]) { - NSString* lCountryCode = [[LinphoneManager instance].settingsStore objectForKey:@"countrycode_preference"]; + NSString* lCountryCode = [[LinphoneManager instance] lpConfigStringForKey:@"countrycode_preference"]; if (lCountryCode && [lCountryCode length]>0) { //append country code return [lCountryCode stringByAppendingString:number]; diff --git a/Classes/WizardViewController.m b/Classes/WizardViewController.m index e2607d7a6..e1cdf533f 100644 --- a/Classes/WizardViewController.m +++ b/Classes/WizardViewController.m @@ -226,7 +226,7 @@ static UICompositeViewDescription *compositeDescription = nil; } // Animation - if(animation && [[LinphoneManager instance].settingsStore boolForKey:@"animations_preference"] == true) { + if(animation && [[LinphoneManager instance] lpConfigBoolForKey:@"animations_preference"] == true) { CATransition* trans = [CATransition animation]; [trans setType:kCATransitionPush]; [trans setDuration:0.35]; @@ -254,17 +254,21 @@ static UICompositeViewDescription *compositeDescription = nil; } - (void)clearProxyConfig { - [[LinphoneManager instance].settingsStore setObject:@"" forKey:@"username_preference"]; - [[LinphoneManager instance].settingsStore setObject:@"" forKey:@"password_preference"]; - [[LinphoneManager instance].settingsStore setObject:@"" forKey:@"domain_preference"]; - [[LinphoneManager instance].settingsStore synchronize]; + linphone_core_clear_proxy_config([LinphoneManager getLc]); + linphone_core_clear_all_auth_info([LinphoneManager getLc]); } - (void)addProxyConfig:(NSString*)username password:(NSString*)password domain:(NSString*)domain { - [[LinphoneManager instance].settingsStore setObject:username forKey:@"username_preference"]; - [[LinphoneManager instance].settingsStore setObject:password forKey:@"password_preference"]; - [[LinphoneManager instance].settingsStore setObject:domain forKey:@"domain_preference"]; - [[LinphoneManager instance].settingsStore synchronize]; + const char* identity = [[NSString stringWithFormat:@"sip:%@@%@",username,domain] UTF8String]; + LinphoneProxyConfig* proxyCfg = linphone_core_create_proxy_config([LinphoneManager getLc]); + LinphoneAuthInfo* info=linphone_auth_info_new([username UTF8String],NULL,[password UTF8String],NULL,NULL); + linphone_proxy_config_set_identity(proxyCfg,identity); + linphone_proxy_config_set_server_addr(proxyCfg,[domain UTF8String]); + linphone_proxy_config_enable_register(proxyCfg,true); + linphone_core_add_proxy_config([LinphoneManager getLc], proxyCfg); + linphone_core_set_default_proxy([LinphoneManager getLc], proxyCfg); + linphone_core_add_auth_info([LinphoneManager getLc],info) + ; } - (void)checkUserExist:(NSString*)username { diff --git a/submodules/linphone b/submodules/linphone index ba4ff464b..acd370ea9 160000 --- a/submodules/linphone +++ b/submodules/linphone @@ -1 +1 @@ -Subproject commit ba4ff464b3e382cfc0ac2f806f383c11752a8d8c +Subproject commit acd370ea93fff73c76a74f1cbb3f1c8b64bdef72