Remove unnecessary code and resources
[pithos-ios] / Classes / ErrorAlerter.m
1 //
2 //  ErrorAlerter.m
3 //  OpenStack
4 //
5 //  Created by Mike Mayo on 1/17/11.
6 //  Copyright 2011 __MyCompanyName__. All rights reserved.
7 //
8
9 #import "ErrorAlerter.h"
10 #import "LogEntryModalViewController.h"
11 #import "OpenStackRequest.h"
12 #import "UIViewController+Conveniences.h"
13 #import "APILogEntry.h"
14
15
16 @implementation ErrorAlerter
17
18 @synthesize failedRequest, logEntryModalViewController, viewController;
19
20 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
21     if (buttonIndex == 1) { // details button
22         if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
23             self.logEntryModalViewController.modalPresentationStyle = UIModalPresentationFormSheet;
24         }                
25         [self.viewController presentModalViewController:self.logEntryModalViewController animated:YES];
26     }
27 }
28
29 - (void)alert:(NSString *)message request:(OpenStackRequest *)request viewController:(UIViewController *)aViewController {
30     
31     self.viewController = aViewController;
32
33     NSString *title = @"Error";
34     if (request.responseStatusCode == 0) {
35         title = @"Connection Error";
36         message = @"Please check your connection or API URL and try again.";
37     }
38
39     self.logEntryModalViewController = [[LogEntryModalViewController alloc] initWithNibName:@"LogEntryModalViewController" bundle:nil];
40     self.logEntryModalViewController.logEntry = [[[APILogEntry alloc] initWithRequest:request] autorelease];
41     self.logEntryModalViewController.requestDescription = [logEntryModalViewController.logEntry requestDescription];
42     self.logEntryModalViewController.responseDescription = [logEntryModalViewController.logEntry responseDescription];
43     self.logEntryModalViewController.requestMethod = [logEntryModalViewController.logEntry requestMethod];
44     self.logEntryModalViewController.url = [[logEntryModalViewController.logEntry url] description];
45     
46     // present an alert with a Details button to show the API log entry
47     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:message delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Details", nil];
48     [alert show];
49     [alert release];        
50 }
51
52 - (void)dealloc {
53     [failedRequest release];
54     [logEntryModalViewController release];
55     [viewController release];
56     [super dealloc];
57 }
58
59
60 @end