From 06fef0372d05a55bb9a145407dd81da8103a3e1e Mon Sep 17 00:00:00 2001 From: Maxime Graulich <maxime.graulich@gmail.com> Date: Fri, 9 Aug 2013 09:54:37 +0000 Subject: [PATCH] Fix run/stop on iPhone --- contrib/mobile/iOS/Onelab/AppDelegate.h | 1 + contrib/mobile/iOS/Onelab/AppDelegate.mm | 6 ++-- .../mobile/iOS/Onelab/DetailViewController.mm | 6 ++++ .../mobile/iOS/Onelab/MasterViewController.mm | 33 ++++++++++++++----- 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/contrib/mobile/iOS/Onelab/AppDelegate.h b/contrib/mobile/iOS/Onelab/AppDelegate.h index e3292f2be7..2fd35b8dd9 100644 --- a/contrib/mobile/iOS/Onelab/AppDelegate.h +++ b/contrib/mobile/iOS/Onelab/AppDelegate.h @@ -12,6 +12,7 @@ @interface AppDelegate : UIResponder <UIApplicationDelegate>{ @public + bool compute; } @property (strong, nonatomic) UIWindow *window; diff --git a/contrib/mobile/iOS/Onelab/AppDelegate.mm b/contrib/mobile/iOS/Onelab/AppDelegate.mm index e7dce44313..f4dc901f95 100644 --- a/contrib/mobile/iOS/Onelab/AppDelegate.mm +++ b/contrib/mobile/iOS/Onelab/AppDelegate.mm @@ -14,10 +14,12 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. - UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"iPadStoryboard" bundle:nil]; self.modelListController = (ModelListController *)self.window.rootViewController; - if([[UIDevice currentDevice].model isEqualToString:@"iPad"] || [[UIDevice currentDevice].model isEqualToString:@"iPad Simulator"]) + if([[UIDevice currentDevice].model isEqualToString:@"iPad"] || [[UIDevice currentDevice].model isEqualToString:@"iPad Simulator"]) { + UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"iPadStoryboard" bundle:nil]; self.splitViewController = [storyboard instantiateViewControllerWithIdentifier:@"SplitViewController"]; + } + compute = false; return YES; } diff --git a/contrib/mobile/iOS/Onelab/DetailViewController.mm b/contrib/mobile/iOS/Onelab/DetailViewController.mm index de42265e17..77364f12dc 100644 --- a/contrib/mobile/iOS/Onelab/DetailViewController.mm +++ b/contrib/mobile/iOS/Onelab/DetailViewController.mm @@ -125,6 +125,12 @@ - (void) showModelsList { + if(((AppDelegate *)[UIApplication sharedApplication].delegate)->compute) { + UIAlertView *alert; + alert = [[UIAlertView alloc] initWithTitle:@"Can't show the models list" message:@"The compute have to be finished before you can select an other model." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil]; + [alert show]; + return; + } if([[UIDevice currentDevice].model isEqualToString:@"iPad"] || [[UIDevice currentDevice].model isEqualToString:@"iPad Simulator"]){ AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; [UIView transitionWithView:appDelegate.window diff --git a/contrib/mobile/iOS/Onelab/MasterViewController.mm b/contrib/mobile/iOS/Onelab/MasterViewController.mm index 3b2b5dac98..0780bdb765 100644 --- a/contrib/mobile/iOS/Onelab/MasterViewController.mm +++ b/contrib/mobile/iOS/Onelab/MasterViewController.mm @@ -8,6 +8,7 @@ #import "MasterViewController.h" #import "DetailViewController.h" +#import "AppDelegate.h" #import "parameter.h" @interface MasterViewController () { @@ -30,8 +31,16 @@ // Do any additional setup after loading the view, typically from a nib. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshParameters:) name:@"refreshParameters" object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resetParameters:) name:@"resetParameters" object:nil]; - runButton = [[UIBarButtonItem alloc] initWithTitle:@"Run" style:UIBarButtonItemStyleBordered target:self action:@selector(runWithNewParameter)]; - [runButton setTitle:@"Run"]; + if(((AppDelegate *)[UIApplication sharedApplication].delegate)->compute){ // Only on iPhone/iPod + runButton = [[UIBarButtonItem alloc] initWithTitle:@"Stop" style:UIBarButtonItemStyleBordered target:self action:@selector(stopRunning)]; + [runButton setTitle:@"Stop"]; + + } + else { + runButton = [[UIBarButtonItem alloc] initWithTitle:@"Run" style:UIBarButtonItemStyleBordered target:self action:@selector(runWithNewParameter)]; + [runButton setTitle:@"Run"]; + } + self.navigationItem.leftItemsSupplementBackButton = YES; // Only on iPhone/iPod self.navigationItem.leftBarButtonItem = runButton; UIBarButtonItem *refresh = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(resetParameters:)]; @@ -175,17 +184,21 @@ - (void)runWithNewParameter { - dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ // TODO fix Run/Stop for iPhone + dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; + appDelegate->compute = YES; [runButton setTitle:@"Stop"]; [self.view setNeedsDisplay]; [runButton setAction:@selector(stopRunning)]; self.navigationItem.rightBarButtonItem.enabled = NO; onelab_cb("compute"); - [runButton setTitle:@"Run"]; - [self.view setNeedsDisplay]; - [runButton setAction:@selector(runWithNewParameter)]; - self.navigationItem.rightBarButtonItem.enabled = YES; - //[[NSNotificationCenter defaultCenter] postNotificationName:@"refreshParameters" object:nil]; + if([[UIDevice currentDevice].model isEqualToString:@"iPad"] || [[UIDevice currentDevice].model isEqualToString:@"iPad Simulator"]){ + [runButton setTitle:@"Run"]; + [self.view setNeedsDisplay]; + [runButton setAction:@selector(runWithNewParameter)]; + self.navigationItem.rightBarButtonItem.enabled = YES; + } + appDelegate->compute = NO; }); if(![[UIDevice currentDevice].model isEqualToString:@"iPad"] && ![[UIDevice currentDevice].model isEqualToString:@"iPad Simulator"]) [self.navigationController popViewControllerAnimated:YES]; @@ -194,6 +207,10 @@ - (void)stopRunning { onelab_cb("stop"); + if(![[UIDevice currentDevice].model isEqualToString:@"iPad"] && ![[UIDevice currentDevice].model isEqualToString:@"iPad Simulator"]){ + ((AppDelegate *)[UIApplication sharedApplication].delegate)->compute = NO; + [self.navigationController popViewControllerAnimated:YES]; + } } #pragma mark - Table View -- GitLab