diff --git a/contrib/mobile/iOS/Onelab/AboutViewController.mm b/contrib/mobile/iOS/Onelab/AboutViewController.mm index 91d0b0def421337c77ba31d5cd692a55d81c031c..d0481a1cdc62fa3d65ba520cbe5a3ac5a844bb09 100644 --- a/contrib/mobile/iOS/Onelab/AboutViewController.mm +++ b/contrib/mobile/iOS/Onelab/AboutViewController.mm @@ -35,7 +35,7 @@ // Do any additional setup after loading the view. self.aboutView.delegate = self; self.aboutView.dataDetectorTypes = UIDataDetectorTypeNone; - + if(self.fileToEdit){ NSData *fileData = [NSData dataWithContentsOfFile:self.fileToEdit]; NSString* aStr = [[NSString alloc] initWithData:fileData encoding:NSUTF8StringEncoding]; @@ -45,13 +45,13 @@ } else{ [self.aboutView loadHTMLString:[NSString stringWithFormat:@"<html><head><style type=\"text/css\"><!--body { background-color: #FFFFFF; color: #252525; margin: 35px 10px 35px 10px; padding: 0; font-family: helvetica-neue,sans-serif; font-size: 1em; }--></style></head><body><center><p><!--img width=32 src=\"icon_onelab.png\"--></p><h3>Onelab/Mobile</h3>Version %@<p>Copyright (C) 2014-2016 Christophe Geuzaine and Maxime Graulich, University of Liège</p><p>Visit <a href=\"http://onelab.info/\">http://onelab.info/</a> for more information</p><p style=\"padding-top: 35px;\">This version of Onelab/Mobile contains:</p><h3>Gmsh</h3>Version %s (<i>Build date:</i> %s)<p>Copyright (C) 1997-2016 Christophe Geuzaine and Jean-François Remacle</p><p><a href=\"http://geuz.org/gmsh/doc/CREDITS.txt\">Credits</a> and <a href=\"http://geuz.org/gmsh/doc/LICENSE.txt\">licensing information</a></p><p><i>Build options:</i> %s</p><p>Visit <a href=\"http://gmsh.info/\">http://gmsh.info</a> for more information</p><h3>GetDP</h3>Version %s (<i>Build date:</i> %s)<p>Copyright (C) 1997-2016 Patrick Dular and Christophe Geuzaine, University of Liège</p><p><a href=\"http://geuz.org/getdp/doc/CREDITS.txt\">Credits</a> and <a href=\"http://geuz.org/getdp/doc/LICENSE.txt\">licensing information</a></p><p><i>Build options:</i> %s</p><p>Visit <a href=\"http://getdp.info\">http://getdp.info</a> for more information</p></center></body>", - [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"], - GMSH_VERSION, - GMSH_DATE, - GMSH_CONFIG_OPTIONS, - GETDP_VERSION, - GETDP_DATE, - GETDP_CONFIG_OPTIONS] + [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"], + GMSH_VERSION, + GMSH_DATE, + GMSH_CONFIG_OPTIONS, + GETDP_VERSION, + GETDP_DATE, + GETDP_CONFIG_OPTIONS] baseURL:[[NSBundle mainBundle] bundleURL]]; } } @@ -59,7 +59,7 @@ -(void)saveFile { NSString *text = [self.aboutView stringByEvaluatingJavaScriptFromString: - @"document.body.innerText"]; + @"document.body.innerText"]; NSLog(@"Saving file %@", self.fileToEdit); NSError *error; [text writeToFile:self.fileToEdit atomically:YES diff --git a/contrib/mobile/iOS/Onelab/ModelListController.h b/contrib/mobile/iOS/Onelab/ModelListController.h index 6ac41aadb1b4f1b39e6f5bfae9a3842c6b568d2f..7d4d76654c25631cc3a219b802d117e69583fbc2 100644 --- a/contrib/mobile/iOS/Onelab/ModelListController.h +++ b/contrib/mobile/iOS/Onelab/ModelListController.h @@ -10,7 +10,7 @@ NSMutableString *currentElementValue; NSString *currentDir; NSString *selectedModel; - NSString *currentFileToEdit; + NSString *currentFileToEdit; } @property (nonatomic, retain) EAGLView *glView; @property (nonatomic, retain) UIActionSheet *longPressActionSheet; diff --git a/contrib/mobile/iOS/Onelab/ModelListController.mm b/contrib/mobile/iOS/Onelab/ModelListController.mm index 78f31fadf2ed4a13a2b18fdb00d28c5c765f105a..75e595c5a9e77fdb2aaf218889a1a6094032f2cd 100644 --- a/contrib/mobile/iOS/Onelab/ModelListController.mm +++ b/contrib/mobile/iOS/Onelab/ModelListController.mm @@ -38,7 +38,7 @@ -(void)showAbout { - currentFileToEdit = nil; + currentFileToEdit = nil; [self performSegueWithIdentifier:@"showAboutSegue" sender:self]; } @@ -118,8 +118,8 @@ completion:nil]; } else{ - [self performSegueWithIdentifier:@"showModelSegue" sender:self]; - } + [self performSegueWithIdentifier:@"showModelSegue" sender:self]; + } } -(void)handleLongPress:(UILongPressGestureRecognizer *)sender @@ -128,154 +128,154 @@ if(sender.state == UIGestureRecognizerStateCancelled) return; NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:p]; if(indexPath == nil) return; - if([[models objectAtIndex:indexPath.row] getUrl]) + if([[models objectAtIndex:indexPath.row] getUrl]) self.longPressActionSheet = [[UIActionSheet alloc] initWithTitle:[[models objectAtIndex:indexPath.row] getName] delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles: @"Open", @"Remove", @"Clear results", @"Edit model files", @"Email model files", @"Visit model website", nil]; else - self.longPressActionSheet = [[UIActionSheet alloc] initWithTitle:[[models objectAtIndex:indexPath.row] getName] delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles: @"Open", @"Remove", @"Clear results", @"Edit model files", @"Email model files", nil]; + self.longPressActionSheet = [[UIActionSheet alloc] initWithTitle:[[models objectAtIndex:indexPath.row] getName] delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles: @"Open", @"Remove", @"Clear results", @"Edit model files", @"Email model files", nil]; self.longPressActionSheet.tag = indexPath.row; [self.longPressActionSheet showInView:self.view]; } -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { - if(actionSheet == self.longPressActionSheet){ + if(actionSheet == self.longPressActionSheet){ switch (buttonIndex) { - case 5: + case 5: [[UIApplication sharedApplication] openURL:[[models objectAtIndex:actionSheet.tag] getUrl]]; break; - case 4: - { - NSString *modelFile = [[models objectAtIndex:actionSheet.tag] getFile]; - NSString *modelPath = [modelFile stringByDeletingLastPathComponent]; - NSArray *modelFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:modelPath error:NULL]; - // TODO: would probably be better to email a zip archive? (this ignores subdirectories) - [self attachFilesToEmail:modelFiles filePath:modelPath]; - } - break; - case 3: - { - NSString *modelFile = [[models objectAtIndex:actionSheet.tag] getFile]; - NSString *modelPath = [modelFile stringByDeletingLastPathComponent]; - NSArray *modelFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:modelPath error:NULL]; - self.editFilesActionSheet = [[UIActionSheet alloc] initWithTitle:@"Model files" delegate:self - cancelButtonTitle: nil - destructiveButtonTitle: nil - otherButtonTitles: nil]; - for(NSString *file in modelFiles) { - NSString *extension = [file pathExtension]; - if([extension isEqualToString:@"txt"] || - [extension isEqualToString:@"geo"] || - [extension isEqualToString:@"pro"] || - [extension isEqualToString:@"dat"]){ - [self.editFilesActionSheet addButtonWithTitle:file]; - } - } - [self.editFilesActionSheet addButtonWithTitle:@"Cancel"]; - self.editFilesActionSheet.cancelButtonIndex = [modelFiles count]; + case 4: + { + NSString *modelFile = [[models objectAtIndex:actionSheet.tag] getFile]; + NSString *modelPath = [modelFile stringByDeletingLastPathComponent]; + NSArray *modelFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:modelPath error:NULL]; + // TODO: would probably be better to email a zip archive? (this ignores subdirectories) + [self attachFilesToEmail:modelFiles filePath:modelPath]; + } + break; + case 3: + { + NSString *modelFile = [[models objectAtIndex:actionSheet.tag] getFile]; + NSString *modelPath = [modelFile stringByDeletingLastPathComponent]; + NSArray *modelFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:modelPath error:NULL]; + self.editFilesActionSheet = [[UIActionSheet alloc] initWithTitle:@"Model files" delegate:self + cancelButtonTitle: nil + destructiveButtonTitle: nil + otherButtonTitles: nil]; + for(NSString *file in modelFiles) { + NSString *extension = [file pathExtension]; + if([extension isEqualToString:@"txt"] || + [extension isEqualToString:@"geo"] || + [extension isEqualToString:@"pro"] || + [extension isEqualToString:@"dat"]){ + [self.editFilesActionSheet addButtonWithTitle:file]; + } + } + self.editFilesActionSheet.cancelButtonIndex = [self.editFilesActionSheet addButtonWithTitle:@"Cancel"]; self.editFilesActionSheet.tag = actionSheet.tag; - [self.editFilesActionSheet showInView:self.view]; - } - break; + [self.editFilesActionSheet showInView:self.view]; + } + break; case 2: { - NSString *modelFile = [[models objectAtIndex:actionSheet.tag] getFile]; - NSString *modelPath = [modelFile stringByDeletingLastPathComponent]; - NSArray *modelFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:modelPath error:NULL]; - for (NSString *obj in modelFiles){ - NSString *extension = [obj pathExtension]; - if([extension isEqualToString:@"msh"] || - [extension isEqualToString:@"pre"] || - [extension isEqualToString:@"res"] || - [extension isEqualToString:@"pos"]){ - NSString *file = [[modelPath stringByAppendingString:@"/"] stringByAppendingString:obj]; - NSLog(@"Removing file %@", file); - [[NSFileManager defaultManager] removeItemAtPath:file error:nil]; - } - } - } + NSString *modelFile = [[models objectAtIndex:actionSheet.tag] getFile]; + NSString *modelPath = [modelFile stringByDeletingLastPathComponent]; + NSArray *modelFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:modelPath error:NULL]; + for (NSString *obj in modelFiles){ + NSString *extension = [obj pathExtension]; + if([extension isEqualToString:@"msh"] || + [extension isEqualToString:@"pre"] || + [extension isEqualToString:@"res"] || + [extension isEqualToString:@"pos"]){ + NSString *file = [[modelPath stringByAppendingString:@"/"] stringByAppendingString:obj]; + NSLog(@"Removing file %@", file); + [[NSFileManager defaultManager] removeItemAtPath:file error:nil]; + } + } + } break; case 1: - { - NSString *file = [[models objectAtIndex:actionSheet.tag] getFile]; - NSString *path = [file stringByDeletingLastPathComponent]; - [[NSFileManager defaultManager] removeItemAtPath:path error:nil]; - [self refreshList]; - } + { + NSString *file = [[models objectAtIndex:actionSheet.tag] getFile]; + NSString *path = [file stringByDeletingLastPathComponent]; + [[NSFileManager defaultManager] removeItemAtPath:path error:nil]; + [self refreshList]; + } break; - case 0: - [self tableView:self.tableView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:actionSheet.tag inSection:0]]; + case 0: + [self tableView:self.tableView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:actionSheet.tag inSection:0]]; break; } - } - else{ - NSString *modelFile = [[models objectAtIndex:actionSheet.tag] getFile]; - NSString *modelPath = [modelFile stringByDeletingLastPathComponent]; - currentFileToEdit = [[modelPath stringByAppendingString:@"/"] - stringByAppendingString:[actionSheet buttonTitleAtIndex:buttonIndex]]; - [self performSegueWithIdentifier:@"showAboutSegue" sender:self]; - } + } + else{ + if(buttonIndex != actionSheet.cancelButtonIndex){ + NSString *modelFile = [[models objectAtIndex:actionSheet.tag] getFile]; + NSString *modelPath = [modelFile stringByDeletingLastPathComponent]; + NSString *file = [actionSheet buttonTitleAtIndex:buttonIndex]; + currentFileToEdit = [[modelPath stringByAppendingString:@"/"] stringByAppendingString:file]; + [self performSegueWithIdentifier:@"showAboutSegue" sender:self]; + } + } } - (void)attachFilesToEmail:(NSArray*)files filePath:(NSString*)path { - if([MFMailComposeViewController canSendMail] == NO) return; - - MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init]; - mc.mailComposeDelegate = self; - [mc setSubject:@"My ONELAB model"]; - - // Add attachments - for (NSString *file in files){ - NSString *extension = [file pathExtension]; - NSString *filePath = [[path stringByAppendingString:@"/"] stringByAppendingString:file]; - NSData *fileData = [NSData dataWithContentsOfFile:filePath]; - if(fileData){ - NSString *mimeType; - if ([extension isEqualToString:@"jpg"]) { - mimeType = @"image/jpeg"; - } - else if([extension isEqualToString:@"png"]) { - mimeType = @"image/png"; - } - else if([extension isEqualToString:@"doc"]) { - mimeType = @"application/msword"; - } - else if([extension isEqualToString:@"ppt"]) { - mimeType = @"application/vnd.ms-powerpoint"; - } - else if([extension isEqualToString:@"html"]) { - mimeType = @"text/html"; - } - else if([extension isEqualToString:@"pdf"]) { - mimeType = @"application/pdf"; - } - else{ - mimeType = @"text/plain"; - } + if([MFMailComposeViewController canSendMail] == NO) return; + + MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init]; + mc.mailComposeDelegate = self; + [mc setSubject:@"My ONELAB model"]; + + // Add attachments + for (NSString *file in files){ + NSString *extension = [file pathExtension]; + NSString *filePath = [[path stringByAppendingString:@"/"] stringByAppendingString:file]; + NSData *fileData = [NSData dataWithContentsOfFile:filePath]; + if(fileData){ + NSString *mimeType; + if ([extension isEqualToString:@"jpg"]) { + mimeType = @"image/jpeg"; + } + else if([extension isEqualToString:@"png"]) { + mimeType = @"image/png"; + } + else if([extension isEqualToString:@"doc"]) { + mimeType = @"application/msword"; + } + else if([extension isEqualToString:@"ppt"]) { + mimeType = @"application/vnd.ms-powerpoint"; + } + else if([extension isEqualToString:@"html"]) { + mimeType = @"text/html"; + } + else if([extension isEqualToString:@"pdf"]) { + mimeType = @"application/pdf"; + } + else{ + mimeType = @"text/plain"; + } + + [mc addAttachmentData:fileData mimeType:@"" fileName:file]; + } + } + + // Present mail view controller on screen + [self presentViewController:mc animated:YES completion:NULL]; - [mc addAttachmentData:fileData mimeType:@"" fileName:file]; - } - } - - // Present mail view controller on screen - [self presentViewController:mc animated:YES completion:NULL]; - } - (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error { - switch (result){ - case MFMailComposeResultCancelled: NSLog(@"Mail cancelled"); break; - case MFMailComposeResultSaved: NSLog(@"Mail saved"); break; - case MFMailComposeResultSent: NSLog(@"Mail sent"); break; - case MFMailComposeResultFailed: NSLog(@"Mail sent failure: %@", [error localizedDescription]); break; + switch (result){ + case MFMailComposeResultCancelled: NSLog(@"Mail cancelled"); break; + case MFMailComposeResultSaved: NSLog(@"Mail saved"); break; + case MFMailComposeResultSent: NSLog(@"Mail sent"); break; + case MFMailComposeResultFailed: NSLog(@"Mail sent failure: %@", [error localizedDescription]); break; default: break; - } - // Close the Mail Interface - [self dismissViewControllerAnimated:YES completion:NULL]; + } + // Close the Mail Interface + [self dismissViewControllerAnimated:YES completion:NULL]; } - - (BOOL) parseInfosFile:(NSString *)file { NSData *xmlFile = [[NSFileManager defaultManager] contentsAtPath:file]; @@ -347,9 +347,9 @@ ModelViewController *modelViewController = [segue destinationViewController]; modelViewController.initialModel = selectedModel; } - else if ([[segue identifier] isEqualToString:@"showAboutSegue"]) { - AboutViewController *aboutViewController = [segue destinationViewController]; - aboutViewController.fileToEdit = currentFileToEdit; - } + else if ([[segue identifier] isEqualToString:@"showAboutSegue"]) { + AboutViewController *aboutViewController = [segue destinationViewController]; + aboutViewController.fileToEdit = currentFileToEdit; + } } @end diff --git a/contrib/mobile/iOS/Onelab/ModelViewController.mm b/contrib/mobile/iOS/Onelab/ModelViewController.mm index 097e0bc8b3aba6025fbb5623064d7d22ece16fbe..cd7d5c051f62c61d3ad18df1b27298f1de17ce56 100644 --- a/contrib/mobile/iOS/Onelab/ModelViewController.mm +++ b/contrib/mobile/iOS/Onelab/ModelViewController.mm @@ -187,7 +187,7 @@ [_progressIndicator stopAnimating]; [_progressIndicator setHidden:YES]; if(_errors.count > 0) { - _errorAlert = [[UIErrorAlertView alloc] initWithTitle:@"Gmsh/GetDP error" message:[_errors lastObject] delegate:self cancelButtonTitle:@"Hide" otherButtonTitles:@"Show more", nil]; + _errorAlert = [[UIErrorAlertView alloc] initWithTitle:@"Error" message:[_errors lastObject] delegate:self cancelButtonTitle:@"Hide" otherButtonTitles:@"Show more", nil]; [_errorAlert show]; } } @@ -328,9 +328,9 @@ } else [_errors removeLastObject]; if(_errors.count > 1) - _errorAlert = [[UIErrorAlertView alloc] initWithTitle:@"Gmsh/GetDP error" message:[_errors lastObject] delegate:self cancelButtonTitle:@"Hide" otherButtonTitles:@"Show more", nil]; + _errorAlert = [[UIErrorAlertView alloc] initWithTitle:@"Error" message:[_errors lastObject] delegate:self cancelButtonTitle:@"Hide" otherButtonTitles:@"Show more", nil]; else - _errorAlert = [[UIErrorAlertView alloc] initWithTitle:@"Gmsh/GetDP error" message:[_errors lastObject] delegate:self cancelButtonTitle:@"Hide" otherButtonTitles: nil]; + _errorAlert = [[UIErrorAlertView alloc] initWithTitle:@"Error" message:[_errors lastObject] delegate:self cancelButtonTitle:@"Hide" otherButtonTitles: nil]; [_errorAlert show]; }