2 // OpenStackViewController.m
5 // Created by Mike Mayo on 10/21/10.
6 // The OpenStack project is provided under the Apache 2.0 license.
9 #import "OpenStackViewController.h"
10 #import "LogEntryModalViewController.h"
11 #import "OpenStackRequest.h"
12 #import "OpenStackAccount.h"
13 #import "UIViewController+Conveniences.h"
14 #import "APILogEntry.h"
15 #import "AnimatedProgressView.h"
18 @implementation OpenStackViewController
20 @synthesize toolbar, selectedIndexPath;
22 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
23 return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) || (toInterfaceOrientation == UIInterfaceOrientationPortrait);
27 if (self.navigationController.navigationBar) {
28 if (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPad) {
29 self.toolbar.tintColor = self.navigationController.navigationBar.tintColor;
30 self.toolbar.translucent = self.navigationController.navigationBar.translucent;
31 self.toolbar.opaque = self.navigationController.navigationBar.opaque;
32 self.toolbar.barStyle = self.navigationController.navigationBar.barStyle;
34 self.toolbar.translucent = NO;
35 self.toolbar.opaque = NO;
36 self.toolbar.tintColor = [UIColor blackColor];
40 toolbarProgressView = [[AnimatedProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
41 toolbarProgressView.frame = CGRectMake(0.0, 24.0, 185.0, 10.0);
44 - (void)showToolbarActivityMessage:(NSString *)text progress:(BOOL)hasProgress {
46 if (toolbarMessageVisible) {
47 //[self hideToolbarActivityMessage];
48 toolbarLabel.text = text;
50 UIFont *font = [UIFont boldSystemFontOfSize:12.0];
51 CGSize stringSize = [text sizeWithFont:font constrainedToSize:CGSizeMake(226.0, 20.0f) lineBreakMode:UILineBreakModeTailTruncation];
52 toolbarLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0, 12.0, stringSize.width, 20.0)];
53 toolbarLabel.textColor = [UIColor whiteColor];
54 toolbarLabel.textAlignment = UITextAlignmentLeft;
55 toolbarLabel.font = font;
56 toolbarLabel.backgroundColor = [UIColor clearColor];
57 toolbarLabel.shadowOffset = CGSizeMake(0, -1.0);
58 toolbarLabel.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.4];
59 toolbarLabel.text = text;
61 NSMutableArray *items;
65 //toolbarLabel.frame = CGRectMake(0.0, 2.0, stringSize.width, 20.0);
66 toolbarLabel.frame = CGRectMake(0.0, 2.0, 185.0, 20.0);
67 toolbarLabel.textAlignment = UITextAlignmentCenter;
69 UIView *labelWithProgress = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 185.0, 40.0)];
71 [labelWithProgress addSubview:toolbarLabel];
72 [labelWithProgress addSubview:toolbarProgressView];
74 toolbarLabelItem = [[UIBarButtonItem alloc] initWithCustomView:labelWithProgress];
75 //toolbarLabelItem = [[UIBarButtonItem alloc] initWithCustomView:toolbarProgressView];
77 [toolbarProgressView setProgress:0.40 animated:YES];
79 items = [NSMutableArray arrayWithArray:toolbar.items];
81 [items insertObject:toolbarLabelItem atIndex:1];
83 [labelWithProgress release];
85 toolbarActivityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
86 toolbarActivityIndicatorView.frame = CGRectMake(10.0, 12.0, 20.0, 20.0);
87 [toolbarActivityIndicatorView startAnimating];
89 toolbarActivityIndicatorItem = [[UIBarButtonItem alloc] initWithCustomView:toolbarActivityIndicatorView];
90 toolbarLabelItem = [[UIBarButtonItem alloc] initWithCustomView:toolbarLabel];
92 items = [NSMutableArray arrayWithArray:toolbar.items];
94 if ([items count] > 2) {
95 [items insertObject:toolbarActivityIndicatorItem atIndex:2];
96 [items insertObject:toolbarLabelItem atIndex:3];
98 [items insertObject:toolbarActivityIndicatorItem atIndex:1];
99 [items insertObject:toolbarLabelItem atIndex:2];
103 toolbar.items = [NSArray arrayWithArray:items];
105 toolbarMessageVisible = YES;
109 - (void)showToolbarActivityMessage:(NSString *)text {
110 [self showToolbarActivityMessage:text progress:NO];
113 - (void)hideToolbarActivityMessage {
115 if (toolbarMessageVisible) {
116 NSMutableArray *items = [NSMutableArray arrayWithArray:toolbar.items];
117 [items removeObject:toolbarActivityIndicatorItem];
118 [items removeObject:toolbarLabelItem];
119 toolbar.items = [NSArray arrayWithArray:items];
121 [toolbarActivityIndicatorItem release];
122 [toolbarLabelItem release];
124 [toolbarLabel removeFromSuperview];
125 [toolbarLabel release];
127 [toolbarActivityIndicatorView removeFromSuperview];
128 [toolbarActivityIndicatorView release];
130 toolbarMessageVisible = NO;
134 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
135 selectedIndexPath = indexPath;
138 - (void)viewWillAppear:(BOOL)animated {
139 [super viewWillAppear:animated];
140 // if (selectedIndexPath && [self respondsToSelector:@selector(tableView)]) {
141 // UITableView *tv = [self performSelector:@selector(tableView)];
142 // [tv deselectRowAtIndexPath:selectedIndexPath animated:YES];
147 if (toolbarMessageVisible) {
148 [self hideToolbarActivityMessage];
150 [toolbarProgressView release];
151 [selectedIndexPath release];