Fix compile errors
[pithos-ios] / Classes / OpenStackViewController.m
1 //
2 //  OpenStackViewController.m
3 //  OpenStack
4 //
5 //  Created by Mike Mayo on 10/21/10.
6 //  The OpenStack project is provided under the Apache 2.0 license.
7 //
8
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"
16
17
18 @implementation OpenStackViewController
19
20 @synthesize toolbar, selectedIndexPath;
21
22 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
23     return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) || (toInterfaceOrientation == UIInterfaceOrientationPortrait);
24 }
25
26 - (void)viewDidLoad {
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;
33         } else {
34             self.toolbar.translucent = NO;
35             self.toolbar.opaque = NO;            
36             self.toolbar.tintColor = [UIColor blackColor];
37         }
38     }
39     
40     toolbarProgressView = [[AnimatedProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
41     toolbarProgressView.frame = CGRectMake(0.0, 24.0, 185.0, 10.0);
42 }
43
44 - (void)showToolbarInfoMessage:(NSString *)text {    
45     if (toolbarInfoMessageVisible) {
46         toolbarLabel.text = text;
47         
48     }
49     else {
50         UIFont *font = [UIFont boldSystemFontOfSize:12.0];
51         CGSize stringSize = [text sizeWithFont:font constrainedToSize:CGSizeMake(226.0, 20.0f) lineBreakMode:UILineBreakModeTailTruncation];
52
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;
61     
62         NSMutableArray *items;
63     
64         toolbarLabelItem = [[UIBarButtonItem alloc] initWithCustomView:toolbarLabel];
65         items = [NSMutableArray arrayWithArray:toolbar.items];
66         [items insertObject:toolbarLabelItem atIndex:2];
67     
68         toolbar.items = [NSArray arrayWithArray:items];
69     }
70     
71     toolbarInfoMessageVisible = YES;
72 }
73
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;        
81     } else {
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;
90         
91         NSMutableArray *items;
92         
93         if (hasProgress) {
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;
97             
98             UIView *labelWithProgress = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 185.0, 40.0)];
99             
100             [labelWithProgress addSubview:toolbarLabel];
101             [labelWithProgress addSubview:toolbarProgressView];
102             
103             toolbarLabelItem = [[UIBarButtonItem alloc] initWithCustomView:labelWithProgress];
104             //toolbarLabelItem = [[UIBarButtonItem alloc] initWithCustomView:toolbarProgressView];
105             
106             [toolbarProgressView setProgress:0.40 animated:YES];
107             
108             items = [NSMutableArray arrayWithArray:toolbar.items];
109             
110             [items insertObject:toolbarLabelItem atIndex:1];
111             
112             [labelWithProgress release];
113         } else {
114             toolbarActivityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
115             toolbarActivityIndicatorView.frame = CGRectMake(10.0, 12.0, 20.0, 20.0);
116             [toolbarActivityIndicatorView startAnimating];
117             
118             toolbarActivityIndicatorItem = [[UIBarButtonItem alloc] initWithCustomView:toolbarActivityIndicatorView];
119             toolbarLabelItem = [[UIBarButtonItem alloc] initWithCustomView:toolbarLabel];
120             
121             items = [NSMutableArray arrayWithArray:toolbar.items];
122             if ([items count] > 2) {
123                 [items insertObject:toolbarActivityIndicatorItem atIndex:2];
124                 [items insertObject:toolbarLabelItem atIndex:3];
125             } else {
126                 [items insertObject:toolbarActivityIndicatorItem atIndex:1];
127                 [items insertObject:toolbarLabelItem atIndex:2];
128             }
129         }
130         
131         toolbar.items = [NSArray arrayWithArray:items];
132         
133         toolbarActivityMessageVisible = YES;
134     }    
135 }
136
137 - (void)showToolbarActivityMessage:(NSString *)text {
138     [self showToolbarActivityMessage:text progress:NO];
139 }
140
141 - (void)hideToolbarInfoMessage {
142     
143     if (toolbarInfoMessageVisible) {
144         NSMutableArray *items = [NSMutableArray arrayWithArray:toolbar.items];
145         [items removeObject:toolbarLabelItem];
146         toolbar.items = [NSArray arrayWithArray:items];    
147     
148         [toolbarLabelItem release];
149         
150         [toolbarLabel removeFromSuperview];
151         [toolbarLabel release];
152         
153         toolbarInfoMessageVisible = NO;
154     }
155     
156 }
157
158
159 - (void)hideToolbarActivityMessage {
160     
161     if (toolbarActivityMessageVisible) {
162         NSMutableArray *items = [NSMutableArray arrayWithArray:toolbar.items];
163         [items removeObject:toolbarActivityIndicatorItem];
164         [items removeObject:toolbarLabelItem];
165         toolbar.items = [NSArray arrayWithArray:items];    
166
167         [toolbarActivityIndicatorItem release];
168         [toolbarLabelItem release];
169         
170         [toolbarLabel removeFromSuperview];
171         [toolbarLabel release];
172         
173         [toolbarActivityIndicatorView removeFromSuperview];
174         [toolbarActivityIndicatorView release];
175         toolbarActivityMessageVisible = NO;
176     }
177 }
178
179
180 - (void)addHomeButton {
181     UIImage *buttonImage = [UIImage imageNamed:@"HomeFolderIcon.png"];
182         
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];
192     
193 }
194
195
196 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
197     self.selectedIndexPath = indexPath;
198 }
199
200 - (void)dealloc {
201     if (toolbarActivityMessageVisible) {
202         [self hideToolbarActivityMessage];
203     }
204     if (toolbarInfoMessageVisible) {
205         [self hideToolbarInfoMessage];
206     }
207     
208     [toolbarProgressView release];
209     [selectedIndexPath release];
210     [super dealloc];
211 }
212
213 @end