// // OpenStackViewController.m // OpenStack // // Created by Mike Mayo on 10/21/10. // The OpenStack project is provided under the Apache 2.0 license. // #import "OpenStackViewController.h" #import "LogEntryModalViewController.h" #import "OpenStackRequest.h" #import "OpenStackAccount.h" #import "UIViewController+Conveniences.h" #import "APILogEntry.h" #import "AnimatedProgressView.h" @implementation OpenStackViewController @synthesize toolbar, selectedIndexPath; - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) || (toInterfaceOrientation == UIInterfaceOrientationPortrait); } - (void)viewDidLoad { if (self.navigationController.navigationBar) { if (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPad) { self.toolbar.tintColor = self.navigationController.navigationBar.tintColor; self.toolbar.translucent = self.navigationController.navigationBar.translucent; self.toolbar.opaque = self.navigationController.navigationBar.opaque; self.toolbar.barStyle = self.navigationController.navigationBar.barStyle; } else { self.toolbar.translucent = NO; self.toolbar.opaque = NO; self.toolbar.tintColor = [UIColor blackColor]; } } toolbarProgressView = [[AnimatedProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar]; toolbarProgressView.frame = CGRectMake(0.0, 24.0, 185.0, 10.0); } - (void)showToolbarInfoMessage:(NSString *)text { if (toolbarInfoMessageVisible) { toolbarLabel.text = text; } else { UIFont *font = [UIFont boldSystemFontOfSize:12.0]; CGSize stringSize = [text sizeWithFont:font constrainedToSize:CGSizeMake(226.0, 20.0f) lineBreakMode:UILineBreakModeTailTruncation]; toolbarLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0, 12.0, stringSize.width, 20.0)]; toolbarLabel.textColor = [UIColor whiteColor]; toolbarLabel.textAlignment = UITextAlignmentLeft; toolbarLabel.font = font; toolbarLabel.backgroundColor = [UIColor clearColor]; toolbarLabel.shadowOffset = CGSizeMake(0, -1.0); toolbarLabel.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.4]; toolbarLabel.text = text; NSMutableArray *items; toolbarLabelItem = [[UIBarButtonItem alloc] initWithCustomView:toolbarLabel]; items = [NSMutableArray arrayWithArray:toolbar.items]; [items insertObject:toolbarLabelItem atIndex:2]; toolbar.items = [NSArray arrayWithArray:items]; } toolbarInfoMessageVisible = YES; } - (void)showToolbarActivityMessage:(NSString *)text progress:(BOOL)hasProgress { UIFont *font = [UIFont boldSystemFontOfSize:12.0]; CGSize stringSize = [text sizeWithFont:font constrainedToSize:CGSizeMake(226.0, 20.0f) lineBreakMode:UILineBreakModeTailTruncation]; if (toolbarActivityMessageVisible) { [toolbarLabel setFrame:CGRectMake(10.0, 12.0, stringSize.width, 20.0)]; toolbarLabel.text = text; } else { toolbarLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0, 12.0, stringSize.width, 20.0)]; toolbarLabel.textColor = [UIColor whiteColor]; toolbarLabel.textAlignment = UITextAlignmentLeft; toolbarLabel.font = font; toolbarLabel.backgroundColor = [UIColor clearColor]; toolbarLabel.shadowOffset = CGSizeMake(0, -1.0); toolbarLabel.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.4]; toolbarLabel.text = text; NSMutableArray *items; if (hasProgress) { //toolbarLabel.frame = CGRectMake(0.0, 2.0, stringSize.width, 20.0); toolbarLabel.frame = CGRectMake(0.0, 2.0, 185.0, 20.0); toolbarLabel.textAlignment = UITextAlignmentCenter; UIView *labelWithProgress = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 185.0, 40.0)]; [labelWithProgress addSubview:toolbarLabel]; [labelWithProgress addSubview:toolbarProgressView]; toolbarLabelItem = [[UIBarButtonItem alloc] initWithCustomView:labelWithProgress]; [toolbarProgressView setProgress:0.40 animated:YES]; items = [NSMutableArray arrayWithArray:toolbar.items]; [items insertObject:toolbarLabelItem atIndex:1]; [labelWithProgress release]; } else { toolbarActivityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite]; toolbarActivityIndicatorView.frame = CGRectMake(10.0, 12.0, 20.0, 20.0); [toolbarActivityIndicatorView startAnimating]; toolbarActivityIndicatorItem = [[UIBarButtonItem alloc] initWithCustomView:toolbarActivityIndicatorView]; toolbarLabelItem = [[UIBarButtonItem alloc] initWithCustomView:toolbarLabel]; items = [NSMutableArray arrayWithArray:toolbar.items]; if ([items count] > 2) { [items insertObject:toolbarActivityIndicatorItem atIndex:2]; [items insertObject:toolbarLabelItem atIndex:3]; } else { [items insertObject:toolbarActivityIndicatorItem atIndex:1]; [items insertObject:toolbarLabelItem atIndex:2]; } } toolbar.items = [NSArray arrayWithArray:items]; toolbarActivityMessageVisible = YES; } } - (void)showToolbarActivityMessage:(NSString *)text { [self showToolbarActivityMessage:text progress:NO]; } - (void)hideToolbarInfoMessage { if (toolbarInfoMessageVisible) { NSMutableArray *items = [NSMutableArray arrayWithArray:toolbar.items]; [items removeObject:toolbarLabelItem]; toolbar.items = [NSArray arrayWithArray:items]; [toolbarLabelItem release]; [toolbarLabel removeFromSuperview]; [toolbarLabel release]; toolbarInfoMessageVisible = NO; } } - (void)hideToolbarActivityMessage { if (toolbarActivityMessageVisible) { NSMutableArray *items = [NSMutableArray arrayWithArray:toolbar.items]; [items removeObject:toolbarActivityIndicatorItem]; [items removeObject:toolbarLabelItem]; toolbar.items = [NSArray arrayWithArray:items]; [toolbarActivityIndicatorItem release]; [toolbarLabelItem release]; [toolbarLabel removeFromSuperview]; [toolbarLabel release]; [toolbarActivityIndicatorView removeFromSuperview]; [toolbarActivityIndicatorView release]; toolbarActivityMessageVisible = NO; } } - (void)addHomeButton { UIImage *buttonImage = [UIImage imageNamed:@"HomeFolderIcon.png"]; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button setImage:buttonImage forState:UIControlStateNormal]; button.frame = CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height); [button addTarget:self action:@selector(homeButtonPressed:) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem *customBarItem = [[UIBarButtonItem alloc] initWithCustomView:button]; NSMutableArray *toolbarItems = [NSMutableArray arrayWithArray:self.toolbar.items]; [toolbarItems addObject:customBarItem]; self.toolbar.items = toolbarItems; [customBarItem release]; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { self.selectedIndexPath = indexPath; } - (void)dealloc { if (toolbarActivityMessageVisible) { [self hideToolbarActivityMessage]; } if (toolbarInfoMessageVisible) { [self hideToolbarInfoMessage]; } [toolbarProgressView release]; [selectedIndexPath release]; [super dealloc]; } @end