// // SettingsViewController.m // Geopher OpenCaching // // Created by Jeremy on 1/6/11. // Copyright 2011 Stone Software. All rights reserved. // #import "SettingScreenViewController.h" #import "Geopher_OpenCachingAppDelegate.h" @implementation SettingScreenViewController @synthesize loginButton; @synthesize oAuthStatus; @synthesize showFoundCaches; @synthesize showMetric; @synthesize searchResultsLabel; @synthesize searchResultsSlider; @synthesize oAuthUserName; @synthesize oAuthPassword; @synthesize oAuthBackButton; @synthesize oAuthView; @synthesize oAuthLoginButton; #pragma mark - #pragma mark utils and misc - (void) savePref:(id)val withKey:(id)key { Geopher_OpenCachingAppDelegate* del = GetAppDelegate(); if (key && val) [[del appPrefs] setObject:val forKey:key]; [del savePrefs]; } - (void) updateSearchResultsLabel { searchResultsLabel.text = [NSString stringWithFormat:@"%d", lrint(searchResultsSlider.value)]; } - (void) loadFields { // search slider int val = [[[GetAppDelegate() appPrefs] objectForKey:kSearchResultsPrefKey] intValue]; searchResultsSlider.value = val; [self updateSearchResultsLabel]; // metric BOOL on = [[[GetAppDelegate() appPrefs] objectForKey:kMeasurementInMetersKey] intValue]; showMetric.on = on; // set the other field values here as appropriate. } #pragma mark - #pragma mark Actions - (IBAction) searchSliderChanged:(id)sender { // set the search results pref int prefValue = lrint(searchResultsSlider.value); [self savePref:[NSNumber numberWithInt:prefValue] withKey:kSearchResultsPrefKey]; // update the label [self updateSearchResultsLabel]; } - (IBAction) metricToggleChanged:(id)Sender { // set the metric pref [self savePref:[NSNumber numberWithBool:showMetric.on] withKey:kMeasurementInMetersKey]; } - (IBAction) foundCachesToggleChanged:(id)Sender { // set the found caches pref // save the pref } - (IBAction) loginScreenButton:(id)sender { // open the oAuth login screen } - (IBAction) closeLoginScreenButton:(id)sender { // close the login screen // set the auth label appropriately // enable the logged in prefs } #pragma mark - #pragma mark default code // The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. /* - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization. } return self; } */ // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void) viewDidLoad { [super viewDidLoad]; [self loadFields]; } /* // Override to allow orientations other than the default portrait orientation. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations. return (interfaceOrientation == UIInterfaceOrientationPortrait); } */ - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Release any cached data, images, etc. that aren't in use. } - (void)viewDidUnload { [super viewDidUnload]; // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (void)dealloc { [loginButton release]; [oAuthStatus release]; [showFoundCaches release]; [showMetric release]; [searchResultsLabel release]; [searchResultsSlider release]; [oAuthUserName release]; [oAuthPassword release]; [oAuthBackButton release]; [oAuthView release]; [oAuthLoginButton release]; [super dealloc]; } @end