Skip to content

Commit

Permalink
made request run asynchronously
Browse files Browse the repository at this point in the history
  • Loading branch information
phuesler committed Dec 11, 2009
1 parent db07c44 commit ef6a9d8
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions HallenprojektStatusAppDelegate.m
Expand Up @@ -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];
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit ef6a9d8

Please sign in to comment.