From ef6a9d8adcabc7b3bbb5b7c300cb3430e94956a6 Mon Sep 17 00:00:00 2001 From: Patrick Huesler Date: Fri, 11 Dec 2009 16:14:24 +0100 Subject: [PATCH] made request run asynchronously --- HallenprojektStatusAppDelegate.m | 46 ++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/HallenprojektStatusAppDelegate.m b/HallenprojektStatusAppDelegate.m index 09e7e88..fb353e2 100644 --- a/HallenprojektStatusAppDelegate.m +++ b/HallenprojektStatusAppDelegate.m @@ -84,7 +84,24 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { [self fileNotifications]; } -- (NSError *)setLocation:(NSString *) place_id { +- (void)settingLocationFinished:(ASIHTTPRequest *)request { + if (self.currentlySelectedItem) { + [self.currentlySelectedItem setState:NSOnState]; + [self.logoutItem setEnabled:true]; + [self.logoutItem setTitle:[NSString stringWithFormat:@"Check out from %@", [self.currentlySelectedItem title]]]; + loggedIn = true; + [self setStatusIcon]; + } +} + +- (void)settingLocationFailed:(ASIHTTPRequest *)request +{ + NSLog(@"%@",[[request error] localizedDescription]); + [preferencesController loadPreferences:self]; +} + + +- (void)setLocation:(NSString *) place_id { NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@",HALLENPROJEKT_SERVER,@"set_current_place"]]; ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url]; @@ -93,8 +110,9 @@ - (NSError *)setLocation:(NSString *) place_id { [request setPassword:[preferencesController getPassword]]; [request addRequestHeader:@"Accept" value:@"application/json"]; [request setDelegate:self]; - [request start]; - return [request error]; + [request setDidFinishSelector:@selector(settingLocationFinished:)]; + [request setDidFailSelector:@selector(settingLocationFailed:)]; + [request startAsynchronous]; } - (void) updateLocation { @@ -106,24 +124,12 @@ - (void) updateLocation { - (void)selectedItem:(id) sender { NSMenuItem *item = (NSMenuItem *) sender; - NSError *error = [self setLocation: [NSString stringWithFormat:@"%d", [item tag]]]; - if(error){ - NSLog(@"%@",[error localizedDescription]); - [preferencesController loadPreferences:self]; - } - else + if(self.currentlySelectedItem) { - if(self.currentlySelectedItem) - { - [self.currentlySelectedItem setState:NSOffState]; - } - [item setState:NSOnState]; - self.currentlySelectedItem = item; - [self.logoutItem setEnabled:true]; - [self.logoutItem setTitle:[NSString stringWithFormat:@"Check out from %@", [item title]]]; - loggedIn = true; - [self setStatusIcon]; - } + [self.currentlySelectedItem setState:NSOffState]; + } + self.currentlySelectedItem = item; + [self setLocation: [NSString stringWithFormat:@"%d", [item tag]]]; } - (void) updateMenuForLogoutState {