Fix compile errors
[pithos-ios] / Classes / APILogsViewController.m
1 //
2 //  APILogsViewController.m
3 //  OpenStack
4 //
5 //  Created by Mike Mayo on 10/11/10.
6 //  The OpenStack project is provided under the Apache 2.0 license.
7 //
8
9 #import "APILogsViewController.h"
10 #import "OpenStackAccount.h"
11 #import "APILogger.h"
12 #import "APILogEntry.h"
13 #import "UIViewController+Conveniences.h"
14 #import "ActivityIndicatorView.h"
15 #import "LogEntryViewController.h"
16
17
18 @implementation APILogsViewController
19
20 @synthesize account;
21
22 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
23     return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) || (toInterfaceOrientation == UIInterfaceOrientationPortrait);
24 }
25
26 #pragma mark -
27 #pragma mark Button Handlers
28
29 - (void)refreshButtonPressed:(id)sender {
30     activityIndicatorView = [[ActivityIndicatorView alloc] initWithFrame:[ActivityIndicatorView frameForText:@"Loading..."] text:@"Loading..."];
31     [activityIndicatorView addToView:self.view];
32     
33     loggerEntries = [APILogger loggerEntries];
34     
35     [activityIndicatorView removeFromSuperviewAndRelease];
36     entriesLoaded = YES;
37     [self.tableView reloadData];    
38 }
39
40 #pragma mark -
41 #pragma mark View lifecycle
42
43 - (void)viewDidLoad {
44     [super viewDidLoad];
45
46     self.navigationItem.title = @"API Logs";
47     
48     UIBarButtonItem *refreshButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refreshButtonPressed:)];
49     self.navigationItem.rightBarButtonItem = refreshButton;
50     [refreshButton release];
51 }
52
53 - (void)viewWillAppear:(BOOL)animated {
54     [super viewWillAppear:animated];
55     [self refreshButtonPressed:nil];
56 }
57
58 /*
59 - (void)viewDidAppear:(BOOL)animated {
60     [super viewDidAppear:animated];
61 }
62 */
63 /*
64 - (void)viewWillDisappear:(BOOL)animated {
65     [super viewWillDisappear:animated];
66 }
67 */
68 /*
69 - (void)viewDidDisappear:(BOOL)animated {
70     [super viewDidDisappear:animated];
71 }
72 */
73
74 #pragma mark -
75 #pragma mark Table view data source
76
77 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
78     // Return the number of sections.
79     return 1;
80 }
81
82
83 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
84     // Return the number of rows in the section.
85     return entriesLoaded ? [loggerEntries count] : 0;
86 }
87
88
89 // Customize the appearance of table view cells.
90 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
91     
92     static NSString *CellIdentifier = @"Cell";
93     
94     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
95     if (cell == nil) {
96         cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
97         cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
98     }
99     
100     // Configure the cell...
101     
102     APILogEntry *entry = [loggerEntries objectAtIndex:indexPath.row];    
103     cell.textLabel.text = [NSString stringWithFormat:@"%@ %@", entry.requestMethod, [entry.url path]];
104     cell.detailTextLabel.text = [NSString stringWithFormat:@"%@", entry.responseStatusMessage];
105     
106     if (entry.responseStatusCode == 0) {
107         cell.detailTextLabel.text = @"No response";
108     }
109     
110     if (entry.responseStatusCode < 200 || entry.responseStatusCode >= 300) {
111         cell.textLabel.textColor = [UIColor redColor];
112         cell.detailTextLabel.textColor = [UIColor redColor];
113     } else {
114         cell.textLabel.textColor = [UIColor blackColor];
115         cell.detailTextLabel.textColor = [UIColor grayColor];
116     }
117     
118     return cell;
119 }
120
121 #pragma mark -
122 #pragma mark Table view delegate
123
124 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
125     LogEntryViewController *vc = [[LogEntryViewController alloc] initWithNibName:@"LogEntryViewController" bundle:nil];
126     vc.logEntry = [loggerEntries objectAtIndex:indexPath.row];
127     [self.navigationController pushViewController:vc animated:YES];
128     [vc release];
129 }
130
131
132 #pragma mark -
133 #pragma mark Memory management
134
135 - (void)didReceiveMemoryWarning {
136     // Releases the view if it doesn't have a superview.
137     [super didReceiveMemoryWarning];
138     
139     // Relinquish ownership any cached data, images, etc that aren't in use.
140 }
141
142 - (void)viewDidUnload {
143     // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
144     // For example: self.myOutlet = nil;
145 }
146
147
148 - (void)dealloc {
149     [account release];
150     [super dealloc];
151 }
152
153
154 @end
155