rework on settings store

This commit is contained in:
Jehan Monnier 2012-09-05 10:33:56 +02:00
parent 9215dde5d9
commit 3752fab5ad
13 changed files with 104 additions and 46 deletions

View file

@ -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];
};
}

View file

@ -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];

View file

@ -23,6 +23,7 @@
#import "LinphoneManager.h"
@interface LinphoneCoreSettingsStore : IASKAbstractSettingsStore {
@private
NSDictionary *dict;
NSDictionary *changedDict;
}

View file

@ -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<IASKSettingsStore> 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;

View file

@ -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

View file

@ -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"]];
}
}

View file

@ -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)) {

View file

@ -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];

View file

@ -21,8 +21,11 @@
#import "UICompositeViewController.h"
#import "IASKAppSettingsViewController.h"
#import "LinphoneCoreSettingsStore.h"
@interface SettingsViewController: UIViewController<IASKSettingsDelegate, UICompositeViewDelegate> {
@private
LinphoneCoreSettingsStore* settingsStore;
}
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;

View file

@ -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"];
}

View file

@ -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];

View file

@ -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 {

@ -1 +1 @@
Subproject commit ba4ff464b3e382cfc0ac2f806f383c11752a8d8c
Subproject commit acd370ea93fff73c76a74f1cbb3f1c8b64bdef72