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)showToolbarInfoMessage:(NSString *)text {
45 if (toolbarInfoMessageVisible) {
46 toolbarLabel.text = text;
50 UIFont *font = [UIFont boldSystemFontOfSize:12.0];
51 CGSize stringSize = [text sizeWithFont:font constrainedToSize:CGSizeMake(226.0, 20.0f) lineBreakMode:UILineBreakModeTailTruncation];
53 toolbarLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0, 12.0, stringSize.width, 20.0)];
54 toolbarLabel.textColor = [UIColor whiteColor];
55 toolbarLabel.textAlignment = UITextAlignmentLeft;
56 toolbarLabel.font = font;
57 toolbarLabel.backgroundColor = [UIColor clearColor];
58 toolbarLabel.shadowOffset = CGSizeMake(0, -1.0);
59 toolbarLabel.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.4];
60 toolbarLabel.text = text;
62 NSMutableArray *items;
64 toolbarLabelItem = [[UIBarButtonItem alloc] initWithCustomView:toolbarLabel];
65 items = [NSMutableArray arrayWithArray:toolbar.items];
66 [items insertObject:toolbarLabelItem atIndex:2];
68 toolbar.items = [NSArray arrayWithArray:items];
71 toolbarInfoMessageVisible = YES;
74 - (void)showToolbarActivityMessage:(NSString *)text progress:(BOOL)hasProgress {
75 UIFont *font = [UIFont boldSystemFontOfSize:12.0];
76 CGSize stringSize = [text sizeWithFont:font constrainedToSize:CGSizeMake(226.0, 20.0f) lineBreakMode:UILineBreakModeTailTruncation];
77 if (toolbarActivityMessageVisible) {
78 //[self hideToolbarActivityMessage];
79 [toolbarLabel setFrame:CGRectMake(10.0, 12.0, stringSize.width, 20.0)];
80 toolbarLabel.text = text;
82 toolbarLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0, 12.0, stringSize.width, 20.0)];
83 toolbarLabel.textColor = [UIColor whiteColor];
84 toolbarLabel.textAlignment = UITextAlignmentLeft;
85 toolbarLabel.font = font;
86 toolbarLabel.backgroundColor = [UIColor clearColor];
87 toolbarLabel.shadowOffset = CGSizeMake(0, -1.0);
88 toolbarLabel.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.4];
89 toolbarLabel.text = text;
91 NSMutableArray *items;
95 //toolbarLabel.frame = CGRectMake(0.0, 2.0, stringSize.width, 20.0);
96 toolbarLabel.frame = CGRectMake(0.0, 2.0, 185.0, 20.0);
97 toolbarLabel.textAlignment = UITextAlignmentCenter;
99 UIView *labelWithProgress = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 185.0, 40.0)];
101 [labelWithProgress addSubview:toolbarLabel];
102 [labelWithProgress addSubview:toolbarProgressView];
104 toolbarLabelItem = [[UIBarButtonItem alloc] initWithCustomView:labelWithProgress];
105 //toolbarLabelItem = [[UIBarButtonItem alloc] initWithCustomView:toolbarProgressView];
107 [toolbarProgressView setProgress:0.40 animated:YES];
109 items = [NSMutableArray arrayWithArray:toolbar.items];
111 [items insertObject:toolbarLabelItem atIndex:1];
113 [labelWithProgress release];
115 toolbarActivityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
116 toolbarActivityIndicatorView.frame = CGRectMake(10.0, 12.0, 20.0, 20.0);
117 [toolbarActivityIndicatorView startAnimating];
119 toolbarActivityIndicatorItem = [[UIBarButtonItem alloc] initWithCustomView:toolbarActivityIndicatorView];
120 toolbarLabelItem = [[UIBarButtonItem alloc] initWithCustomView:toolbarLabel];
122 items = [NSMutableArray arrayWithArray:toolbar.items];
124 if ([items count] > 2) {
125 [items insertObject:toolbarActivityIndicatorItem atIndex:2];
126 [items insertObject:toolbarLabelItem atIndex:3];
128 [items insertObject:toolbarActivityIndicatorItem atIndex:1];
129 [items insertObject:toolbarLabelItem atIndex:2];
133 toolbar.items = [NSArray arrayWithArray:items];
135 toolbarActivityMessageVisible = YES;
139 - (void)showToolbarActivityMessage:(NSString *)text {
140 [self showToolbarActivityMessage:text progress:NO];
143 - (void)hideToolbarInfoMessage {
145 if (toolbarInfoMessageVisible) {
146 NSMutableArray *items = [NSMutableArray arrayWithArray:toolbar.items];
147 [items removeObject:toolbarLabelItem];
148 toolbar.items = [NSArray arrayWithArray:items];
150 [toolbarLabelItem release];
152 [toolbarLabel removeFromSuperview];
153 [toolbarLabel release];
155 toolbarInfoMessageVisible = NO;
161 - (void)hideToolbarActivityMessage {
163 if (toolbarActivityMessageVisible) {
164 NSMutableArray *items = [NSMutableArray arrayWithArray:toolbar.items];
165 [items removeObject:toolbarActivityIndicatorItem];
166 [items removeObject:toolbarLabelItem];
167 toolbar.items = [NSArray arrayWithArray:items];
169 [toolbarActivityIndicatorItem release];
170 [toolbarLabelItem release];
172 [toolbarLabel removeFromSuperview];
173 [toolbarLabel release];
175 [toolbarActivityIndicatorView removeFromSuperview];
176 [toolbarActivityIndicatorView release];
177 toolbarActivityMessageVisible = NO;
181 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
182 selectedIndexPath = indexPath;
185 - (void)viewWillAppear:(BOOL)animated {
186 [super viewWillAppear:animated];
187 // if (selectedIndexPath && [self respondsToSelector:@selector(tableView)]) {
188 // UITableView *tv = [self performSelector:@selector(tableView)];
189 // [tv deselectRowAtIndexPath:selectedIndexPath animated:YES];
194 if (toolbarActivityMessageVisible) {
195 [self hideToolbarActivityMessage];
197 if (toolbarInfoMessageVisible) {
198 [self hideToolbarInfoMessage];
200 [toolbarProgressView release];
201 [selectedIndexPath release];