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
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;
48 UIFont *font = [UIFont boldSystemFontOfSize:12.0];
49 CGSize stringSize = [text sizeWithFont:font constrainedToSize:CGSizeMake(226.0, 20.0f) lineBreakMode:UILineBreakModeTailTruncation];
51 toolbarLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0, 12.0, stringSize.width, 20.0)];
52 toolbarLabel.textColor = [UIColor whiteColor];
53 toolbarLabel.textAlignment = UITextAlignmentLeft;
54 toolbarLabel.font = font;
55 toolbarLabel.backgroundColor = [UIColor clearColor];
56 toolbarLabel.shadowOffset = CGSizeMake(0, -1.0);
57 toolbarLabel.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.4];
58 toolbarLabel.text = text;
60 NSMutableArray *items;
62 toolbarLabelItem = [[UIBarButtonItem alloc] initWithCustomView:toolbarLabel];
63 items = [NSMutableArray arrayWithArray:toolbar.items];
64 [items insertObject:toolbarLabelItem atIndex:2];
66 toolbar.items = [NSArray arrayWithArray:items];
69 toolbarInfoMessageVisible = YES;
72 - (void)showToolbarActivityMessage:(NSString *)text progress:(BOOL)hasProgress {
73 UIFont *font = [UIFont boldSystemFontOfSize:12.0];
74 CGSize stringSize = [text sizeWithFont:font constrainedToSize:CGSizeMake(226.0, 20.0f) lineBreakMode:UILineBreakModeTailTruncation];
75 if (toolbarActivityMessageVisible) {
76 [toolbarLabel setFrame:CGRectMake(10.0, 12.0, stringSize.width, 20.0)];
77 toolbarLabel.text = text;
79 toolbarLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0, 12.0, stringSize.width, 20.0)];
80 toolbarLabel.textColor = [UIColor whiteColor];
81 toolbarLabel.textAlignment = UITextAlignmentLeft;
82 toolbarLabel.font = font;
83 toolbarLabel.backgroundColor = [UIColor clearColor];
84 toolbarLabel.shadowOffset = CGSizeMake(0, -1.0);
85 toolbarLabel.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.4];
86 toolbarLabel.text = text;
88 NSMutableArray *items;
91 //toolbarLabel.frame = CGRectMake(0.0, 2.0, stringSize.width, 20.0);
92 toolbarLabel.frame = CGRectMake(0.0, 2.0, 185.0, 20.0);
93 toolbarLabel.textAlignment = UITextAlignmentCenter;
95 UIView *labelWithProgress = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 185.0, 40.0)];
97 [labelWithProgress addSubview:toolbarLabel];
98 [labelWithProgress addSubview:toolbarProgressView];
100 toolbarLabelItem = [[UIBarButtonItem alloc] initWithCustomView:labelWithProgress];
102 [toolbarProgressView setProgress:0.40 animated:YES];
104 items = [NSMutableArray arrayWithArray:toolbar.items];
106 [items insertObject:toolbarLabelItem atIndex:1];
108 [labelWithProgress release];
110 toolbarActivityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
111 toolbarActivityIndicatorView.frame = CGRectMake(10.0, 12.0, 20.0, 20.0);
112 [toolbarActivityIndicatorView startAnimating];
114 toolbarActivityIndicatorItem = [[UIBarButtonItem alloc] initWithCustomView:toolbarActivityIndicatorView];
115 toolbarLabelItem = [[UIBarButtonItem alloc] initWithCustomView:toolbarLabel];
117 items = [NSMutableArray arrayWithArray:toolbar.items];
118 if ([items count] > 2) {
119 [items insertObject:toolbarActivityIndicatorItem atIndex:2];
120 [items insertObject:toolbarLabelItem atIndex:3];
122 [items insertObject:toolbarActivityIndicatorItem atIndex:1];
123 [items insertObject:toolbarLabelItem atIndex:2];
127 toolbar.items = [NSArray arrayWithArray:items];
129 toolbarActivityMessageVisible = YES;
133 - (void)showToolbarActivityMessage:(NSString *)text {
134 [self showToolbarActivityMessage:text progress:NO];
137 - (void)hideToolbarInfoMessage {
138 if (toolbarInfoMessageVisible) {
139 NSMutableArray *items = [NSMutableArray arrayWithArray:toolbar.items];
140 [items removeObject:toolbarLabelItem];
141 toolbar.items = [NSArray arrayWithArray:items];
143 [toolbarLabelItem release];
145 [toolbarLabel removeFromSuperview];
146 [toolbarLabel release];
148 toolbarInfoMessageVisible = NO;
152 - (void)hideToolbarActivityMessage {
153 if (toolbarActivityMessageVisible) {
154 NSMutableArray *items = [NSMutableArray arrayWithArray:toolbar.items];
155 [items removeObject:toolbarActivityIndicatorItem];
156 [items removeObject:toolbarLabelItem];
157 toolbar.items = [NSArray arrayWithArray:items];
159 [toolbarActivityIndicatorItem release];
160 [toolbarLabelItem release];
162 [toolbarLabel removeFromSuperview];
163 [toolbarLabel release];
165 [toolbarActivityIndicatorView removeFromSuperview];
166 [toolbarActivityIndicatorView release];
168 toolbarActivityMessageVisible = NO;
172 - (void)addHomeButton {
173 UIImage *buttonImage = [UIImage imageNamed:@"HomeFolderIcon.png"];
175 UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
176 [button setImage:buttonImage forState:UIControlStateNormal];
177 button.frame = CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height);
178 [button addTarget:self action:@selector(homeButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
179 UIBarButtonItem *customBarItem = [[UIBarButtonItem alloc] initWithCustomView:button];
180 NSMutableArray *toolbarItems = [NSMutableArray arrayWithArray:self.toolbar.items];
181 [toolbarItems addObject:customBarItem];
182 self.toolbar.items = toolbarItems;
183 [customBarItem release];
187 if (toolbarActivityMessageVisible) {
188 [self hideToolbarActivityMessage];
190 if (toolbarInfoMessageVisible) {
191 [self hideToolbarInfoMessage];
194 [toolbarProgressView release];