+- (void)dealloc {
+ if (fileDownloading) {
+ OpenStackAppDelegate *app = [[UIApplication sharedApplication] delegate];
+ OpenStackRequest *request = [app objectDownloadRequestForAccount:account container:container object:object];
+ request.downloadProgressDelegate = nil;
+ }
+ [account release];
+ [downloadProgressView release];
+ [cdnURLActionSheet release];
+ [folderViewController release];
+ [oldPublicURI release];
+ [permissions release];
+ [objectIsPublicSwitch release];
+ [documentInteractionController release];
+ [versionID release];
+ [super dealloc];
+}
+
+#pragma mark - Internal
+
+- (void)objectIsPublicSwitchChanged:(id)sender {
+ NSString *activityMessage = [NSString stringWithFormat:@"Enabling public link.."];
+ self.oldPublicURI = object.publicURI;
+
+ if (objectIsPublic) {
+ activityMessage = [NSString stringWithFormat:@"Disabling public link.."];
+ object.publicURI = @"";
+ } else {
+ object.publicURI = @"TRUE";
+ }
+ __block ActivityIndicatorView *activityIndicatorView = [ActivityIndicatorView activityIndicatorViewWithText:activityMessage
+ andAddToView:self.view
+ scrollOffset:self.tableView.contentOffset.y];
+ objectIsPublic = !objectIsPublic;
+ [[self.account.manager writeObjectMetadata:container object:object]
+ success:^(OpenStackRequest *request) {
+ NSIndexPath *publicURICellIndexPath = [NSIndexPath indexPathForRow:1 inSection:publicLinkSection];
+ if (objectIsPublic) {
+ [[self.account.manager getObjectInfo:container object:object version:versionID]
+ success:^(OpenStackRequest *request) {
+ [activityIndicatorView stopAnimatingAndRemoveFromSuperview];
+ object.publicURI = [request.responseHeaders objectForKey:@"X-Object-Public"];
+ NSIndexPath *publicURICellIndexPath = [NSIndexPath indexPathForRow:1 inSection:publicLinkSection];
+ [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:publicURICellIndexPath]
+ withRowAnimation:UITableViewRowAnimationBottom];
+ }
+ failure:^(OpenStackRequest *request) {
+ [activityIndicatorView stopAnimatingAndRemoveFromSuperview];
+ [self alert:@"There was a problem retrieving the public link from the server." request:request];
+ }];
+ } else {
+ [activityIndicatorView stopAnimatingAndRemoveFromSuperview];
+ [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:publicURICellIndexPath]
+ withRowAnimation:UITableViewRowAnimationTop];
+ }
+ }
+ failure:^(OpenStackRequest *request) {
+ [activityIndicatorView stopAnimatingAndRemoveFromSuperview];
+ objectIsPublic = !objectIsPublic;
+ objectIsPublicSwitch.on = !objectIsPublicSwitch.on;
+ object.publicURI = oldPublicURI;
+ [self alert:@"There was a problem enabling the public link." request:request];
+ }];
+}
+
+- (void)openFile {
+ OpenStackAppDelegate *app = [[UIApplication sharedApplication] delegate];
+ NSString *filePath = [app cacheFilePathForHash:object.hash];
+ self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
+ self.documentInteractionController.delegate = self;
+ self.documentInteractionController.name = object.name;
+
+ CGRect frameToPresentMenuFrom;
+ if ([[UIDevice currentDevice].systemVersion hasPrefix:@"6"]) {
+ frameToPresentMenuFrom = CGRectMake(0.0,
+ self.tableView.contentOffset.y,
+ self.view.frame.size.width,
+ 1.0);
+ } else {
+ UITableViewCell *openFileCell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:kActions]];
+ frameToPresentMenuFrom = CGRectMake(openFileCell.frame.origin.x,
+ openFileCell.frame.origin.y - self.tableView.contentOffset.y,
+ openFileCell.frame.size.width,
+ openFileCell.frame.size.height);
+ }
+ if (![self.documentInteractionController presentOptionsMenuFromRect:frameToPresentMenuFrom inView:self.view animated:YES]) {
+ if ([self.object isPlayableMedia]) {
+ MediaViewController *vc = [[MediaViewController alloc] initWithNibName:@"MediaViewController" bundle:nil];
+ vc.container = self.container;
+ vc.object = self.object;
+ [self.navigationController pushViewController:vc animated:YES];
+ [vc release];
+ } else {
+ [self alert:@"Error" message:@"This file could not be opened."];
+ }
+ }
+}
+
+- (void)mailFile {
+ if (![MFMailComposeViewController canSendMail]) {
+ [self alert:@"Cannot send mail" message:@"Your device has not been configured for sending mail"];
+ } else {
+ OpenStackAppDelegate *app = [[UIApplication sharedApplication] delegate];
+ NSString *filePath = [app cacheFilePathForHash:object.hash];
+ NSData *data = [NSData dataWithContentsOfURL:[NSURL fileURLWithPath:filePath]];
+
+ MFMailComposeViewController *vc = [[MFMailComposeViewController alloc] init];
+ vc.mailComposeDelegate = self;
+ [vc setSubject:object.name];
+ [vc addAttachmentData:data mimeType:object.contentType fileName:object.name];
+ [vc setMessageBody:@"" isHTML:NO];
+ if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)
+ vc.modalPresentationStyle = UIModalPresentationPageSheet;
+ [self presentModalViewController:vc animated:YES];
+ [vc release];
+ }
+}
+
+- (void)updatePermissionsUserCatalog {
+ NSMutableArray *UUIDs = [NSMutableArray arrayWithCapacity:permissions.count];
+ for (NSString *user in permissions) {
+ NSRange rangeOfColumn = [user rangeOfString:@":"];
+ NSString *UUID = (rangeOfColumn.location == NSNotFound) ? user : [user substringToIndex:rangeOfColumn.location];
+ if (![UUID isEqualToString:@"*"]) {
+ [UUIDs addObject:UUID];
+ }
+ }
+ if (UUIDs.count) {
+ __block ActivityIndicatorView *activityIndicatorView = [ActivityIndicatorView activityIndicatorViewWithText:@"Loading permissions..."
+ andAddToView:self.view];
+ [[self.account.manager userCatalogForDisplaynames:nil UUIDs:UUIDs]
+ success:^(OpenStackRequest *request) {
+ [activityIndicatorView stopAnimatingAndRemoveFromSuperview];
+ [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:permissionsSection] withRowAnimation:UITableViewRowAnimationNone];
+ }
+ failure:^(OpenStackRequest *request) {
+ [activityIndicatorView stopAnimatingAndRemoveFromSuperview];
+ if (request.responseStatusCode != 404) {
+ // Don't show alert on 404, since it can be a pre-UUID server.
+ [self alert:@"Failed to translate sharing UUIDs." request:request];
+ }
+ }];
+ }
+}
+
+- (void)delete {
+ if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone) {
+ folderViewController.deletedObject = object;
+ [self.navigationController popViewControllerAnimated:YES];
+ } else {
+ [folderViewController deleteAnimatedObject:object];
+ [folderViewController setDetailViewController];
+ }
+}