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;
94 //toolbarLabel.frame = CGRectMake(0.0, 2.0, stringSize.width, 20.0);
95 toolbarLabel.frame = CGRectMake(0.0, 2.0, 185.0, 20.0);
96 toolbarLabel.textAlignment = UITextAlignmentCenter;
98 UIView *labelWithProgress = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 185.0, 40.0)];
100 [labelWithProgress addSubview:toolbarLabel];
101 [labelWithProgress addSubview:toolbarProgressView];
103 toolbarLabelItem = [[UIBarButtonItem alloc] initWithCustomView:labelWithProgress];
104 //toolbarLabelItem = [[UIBarButtonItem alloc] initWithCustomView:toolbarProgressView];
106 [toolbarProgressView setProgress:0.40 animated:YES];
108 items = [NSMutableArray arrayWithArray:toolbar.items];
110 [items insertObject:toolbarLabelItem atIndex:1];
112 [labelWithProgress release];
114 toolbarActivityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
115 toolbarActivityIndicatorView.frame = CGRectMake(10.0, 12.0, 20.0, 20.0);
116 [toolbarActivityIndicatorView startAnimating];
118 toolbarActivityIndicatorItem = [[UIBarButtonItem alloc] initWithCustomView:toolbarActivityIndicatorView];
119 toolbarLabelItem = [[UIBarButtonItem alloc] initWithCustomView:toolbarLabel];
121 items = [NSMutableArray arrayWithArray:toolbar.items];
122 if ([items count] > 2) {
123 [items insertObject:toolbarActivityIndicatorItem atIndex:2];
124 [items insertObject:toolbarLabelItem atIndex:3];
126 [items insertObject:toolbarActivityIndicatorItem atIndex:1];
127 [items insertObject:toolbarLabelItem atIndex:2];
131 toolbar.items = [NSArray arrayWithArray:items];
133 toolbarActivityMessageVisible = YES;
137 - (void)showToolbarActivityMessage:(NSString *)text {
138 [self showToolbarActivityMessage:text progress:NO];
141 - (void)hideToolbarInfoMessage {
143 if (toolbarInfoMessageVisible) {
144 NSMutableArray *items = [NSMutableArray arrayWithArray:toolbar.items];
145 [items removeObject:toolbarLabelItem];
146 toolbar.items = [NSArray arrayWithArray:items];
148 [toolbarLabelItem release];
150 [toolbarLabel removeFromSuperview];
151 [toolbarLabel release];
153 toolbarInfoMessageVisible = NO;
159 - (void)hideToolbarActivityMessage {
161 if (toolbarActivityMessageVisible) {
162 NSMutableArray *items = [NSMutableArray arrayWithArray:toolbar.items];
163 [items removeObject:toolbarActivityIndicatorItem];
164 [items removeObject:toolbarLabelItem];
165 toolbar.items = [NSArray arrayWithArray:items];
167 [toolbarActivityIndicatorItem release];
168 [toolbarLabelItem release];
170 [toolbarLabel removeFromSuperview];
171 [toolbarLabel release];
173 [toolbarActivityIndicatorView removeFromSuperview];
174 [toolbarActivityIndicatorView release];
175 toolbarActivityMessageVisible = NO;
180 - (void)addHomeButton {
181 UIImage *buttonImage = [UIImage imageNamed:@"HomeFolderIcon.png"];
183 UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
184 [button setImage:buttonImage forState:UIControlStateNormal];
185 button.frame = CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height);
186 [button addTarget:self action:@selector(homeButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
187 UIBarButtonItem *customBarItem = [[UIBarButtonItem alloc] initWithCustomView:button];
188 NSMutableArray *toolbarItems = [NSMutableArray arrayWithArray:self.toolbar.items];
189 [toolbarItems addObject:customBarItem];
190 self.toolbar.items = toolbarItems;
191 [customBarItem release];
196 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
197 self.selectedIndexPath = indexPath;
201 if (toolbarActivityMessageVisible) {
202 [self hideToolbarActivityMessage];
204 if (toolbarInfoMessageVisible) {
205 [self hideToolbarInfoMessage];
208 [toolbarProgressView release];
209 [selectedIndexPath release];