root / Classes / LogEntryModalViewController.m @ 72744ed1
History | View | Annotate | Download (4.6 kB)
1 |
// |
---|---|
2 |
// LogEntryModalViewController.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 "LogEntryModalViewController.h" |
10 |
#import "APILogEntry.h" |
11 |
#import "TextViewCell.h" |
12 |
|
13 |
#define kRequest 0 |
14 |
#define kResponse 1 |
15 |
|
16 |
@implementation LogEntryModalViewController |
17 |
|
18 |
|
19 |
@synthesize logEntry, requestDescription, responseDescription, requestMethod, url; |
20 |
|
21 |
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { |
22 |
return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) || (toInterfaceOrientation == UIInterfaceOrientationPortrait); |
23 |
} |
24 |
|
25 |
#pragma mark - |
26 |
#pragma mark Button Handlers |
27 |
|
28 |
- (void)cancelButtonPressed:(id)sender { |
29 |
[self dismissModalViewControllerAnimated:YES]; |
30 |
} |
31 |
|
32 |
- (void)emailLogEntryButtonPressed:(id)sender { |
33 |
MFMailComposeViewController *vc = [[MFMailComposeViewController alloc] init]; |
34 |
vc.mailComposeDelegate = self; |
35 |
//[vc setSubject:[NSString stringWithFormat:@"OpenStack Log Entry: %@ %@", logEntry.requestMethod, logEntry.url]]; |
36 |
// [vc setSubject:[NSString stringWithFormat:@"OpenStack Log Entry: %@ %@", requestMethod, url]]; |
37 |
[vc setSubject:[NSString stringWithFormat:@"Rackspace API Call: %@ %@", requestMethod, url]]; |
38 |
//[vc setMessageBody:[NSString stringWithFormat:@"%@\n\n%@", [logEntry requestDescription], [logEntry responseDescription]] isHTML:NO]; |
39 |
[vc setMessageBody:[NSString stringWithFormat:@"%@\n\n%@", requestDescription, responseDescription] isHTML:NO]; |
40 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
41 |
vc.modalPresentationStyle = UIModalPresentationPageSheet; |
42 |
} |
43 |
[self presentModalViewController:vc animated:YES]; |
44 |
[vc release]; |
45 |
} |
46 |
|
47 |
#pragma mark - |
48 |
#pragma mark Table view data source |
49 |
|
50 |
- (CGFloat)findLabelHeight:(NSString*)text font:(UIFont *)font { |
51 |
CGSize textLabelSize = CGSizeMake(280.0, 9000.0f); |
52 |
// pad \n\n to fix layout bug |
53 |
CGSize stringSize = [text sizeWithFont:font constrainedToSize:textLabelSize lineBreakMode:UILineBreakModeCharacterWrap]; |
54 |
return stringSize.height; |
55 |
} |
56 |
|
57 |
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { |
58 |
NSString *text = @""; |
59 |
if (indexPath.section == kRequest) { |
60 |
//text = [logEntry requestDescription]; |
61 |
text = requestDescription; |
62 |
} else if (indexPath.section == kResponse) { |
63 |
//text = [logEntry responseDescription]; |
64 |
text = responseDescription; |
65 |
} |
66 |
return 20.0 + [self findLabelHeight:text font:[UIFont fontWithName:@"Courier" size:12.0]]; |
67 |
} |
68 |
|
69 |
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { |
70 |
if (section == kRequest) { |
71 |
return @"Request"; |
72 |
} else if (section == kResponse) { |
73 |
return @"Response"; |
74 |
} else { |
75 |
return @""; |
76 |
} |
77 |
} |
78 |
|
79 |
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { |
80 |
return 2; |
81 |
} |
82 |
|
83 |
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
84 |
return 1; |
85 |
} |
86 |
|
87 |
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
88 |
|
89 |
static NSString *CellIdentifier = @"Cell"; |
90 |
|
91 |
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
92 |
if (cell == nil) { |
93 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
94 |
cell.selectionStyle = UITableViewCellSelectionStyleNone; |
95 |
cell.textLabel.numberOfLines = 0; |
96 |
cell.textLabel.font = [UIFont fontWithName:@"Courier" size:12.0]; |
97 |
cell.textLabel.lineBreakMode = UILineBreakModeCharacterWrap; |
98 |
} |
99 |
|
100 |
if (indexPath.section == kRequest) { |
101 |
cell.textLabel.text = requestDescription; |
102 |
} else if (indexPath.section == kResponse) { |
103 |
cell.textLabel.text = responseDescription; |
104 |
} |
105 |
|
106 |
return cell; |
107 |
} |
108 |
|
109 |
#pragma mark - |
110 |
#pragma mark Table view delegate |
111 |
|
112 |
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
113 |
} |
114 |
|
115 |
#pragma mark - |
116 |
#pragma mark Mail Composer Delegate |
117 |
|
118 |
// Dismisses the email composition interface when users tap Cancel or Send. |
119 |
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error { |
120 |
[self dismissModalViewControllerAnimated:YES]; |
121 |
} |
122 |
|
123 |
#pragma mark - |
124 |
#pragma mark Memory management |
125 |
|
126 |
- (void)dealloc { |
127 |
[logEntry release]; |
128 |
[requestDescription release]; |
129 |
[responseDescription release]; |
130 |
[requestMethod release]; |
131 |
[url release]; |
132 |
[super dealloc]; |
133 |
} |
134 |
|
135 |
|
136 |
@end |