16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
17 */ |
17 */ |
18 |
18 |
19 #import "GameLogViewController.h" |
19 #import "GameLogViewController.h" |
20 |
20 |
|
21 #ifdef DEBUG |
|
22 #import <MessageUI/MFMailComposeViewController.h> |
|
23 #endif |
|
24 |
21 @interface GameLogViewController () |
25 @interface GameLogViewController () |
|
26 #ifdef DEBUG |
|
27 <MFMailComposeViewControllerDelegate> |
|
28 #endif |
22 |
29 |
23 @end |
30 @end |
24 |
31 |
25 @implementation GameLogViewController |
32 @implementation GameLogViewController |
26 |
33 |
28 |
35 |
29 - (void)viewDidLoad |
36 - (void)viewDidLoad |
30 { |
37 { |
31 [super viewDidLoad]; |
38 [super viewDidLoad]; |
32 |
39 |
|
40 self.title = @"Last game log"; |
|
41 |
33 UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithTitle:@"Close" style:UIBarButtonItemStylePlain target:self action:@selector(dismissAction)]; |
42 UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithTitle:@"Close" style:UIBarButtonItemStylePlain target:self action:@selector(dismissAction)]; |
34 self.navigationItem.rightBarButtonItem = closeButton; |
43 self.navigationItem.rightBarButtonItem = closeButton; |
35 [closeButton release]; |
44 [closeButton release]; |
|
45 |
|
46 #ifdef DEBUG |
|
47 if ([self allowSendLogByEmail]) |
|
48 { |
|
49 UIBarButtonItem *sendButton = [[UIBarButtonItem alloc] initWithTitle:@"Send" style:UIBarButtonItemStylePlain target:self action:@selector(sendLogByEmailAction)]; |
|
50 self.navigationItem.leftBarButtonItem = sendButton; |
|
51 [sendButton release]; |
|
52 } |
|
53 #endif |
36 |
54 |
37 NSString *debugStr = nil; |
55 NSString *debugStr = nil; |
38 if ([[NSFileManager defaultManager] fileExistsAtPath:DEBUG_FILE()]) |
56 if ([[NSFileManager defaultManager] fileExistsAtPath:DEBUG_FILE()]) |
39 debugStr = [[NSString alloc] initWithContentsOfFile:DEBUG_FILE() encoding:NSUTF8StringEncoding error:nil]; |
57 debugStr = [[NSString alloc] initWithContentsOfFile:DEBUG_FILE() encoding:NSUTF8StringEncoding error:nil]; |
40 else |
58 else |
48 |
66 |
49 [self.view addSubview:logView]; |
67 [self.view addSubview:logView]; |
50 [logView release]; |
68 [logView release]; |
51 } |
69 } |
52 |
70 |
|
71 #pragma mark - Parameters |
|
72 |
|
73 #ifdef DEBUG |
|
74 - (BOOL)allowSendLogByEmail |
|
75 { |
|
76 return ([MFMailComposeViewController canSendMail] && [[NSFileManager defaultManager] fileExistsAtPath:DEBUG_FILE()]); |
|
77 } |
|
78 #endif |
|
79 |
53 #pragma mark - Actions |
80 #pragma mark - Actions |
|
81 |
|
82 #ifdef DEBUG |
|
83 - (void)sendLogByEmailAction |
|
84 { |
|
85 MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; |
|
86 picker.mailComposeDelegate = self; |
|
87 [picker setSubject:@"Log file of iHedgewars game"]; |
|
88 |
|
89 // Attach a log file to the email |
|
90 NSData *logData = [NSData dataWithContentsOfFile:DEBUG_FILE()]; |
|
91 [picker addAttachmentData:logData mimeType:@"text/plain" fileName:@"game0.log"]; |
|
92 |
|
93 // Fill out the email body text |
|
94 NSString *emailBody = @"Add here description of a problem/log"; |
|
95 [picker setMessageBody:emailBody isHTML:NO]; |
|
96 |
|
97 [self presentViewController:picker animated:YES completion:nil]; |
|
98 [picker release]; |
|
99 } |
|
100 #endif |
54 |
101 |
55 - (void)dismissAction |
102 - (void)dismissAction |
56 { |
103 { |
57 [self dismissViewControllerAnimated:YES completion:nil]; |
104 [self dismissViewControllerAnimated:YES completion:nil]; |
58 } |
105 } |
|
106 |
|
107 #pragma mark - MailCompose delegate |
|
108 |
|
109 #ifdef DEBUG |
|
110 - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error |
|
111 { |
|
112 // Notifies users about errors associated with the interface |
|
113 switch (result) |
|
114 { |
|
115 case MFMailComposeResultCancelled: |
|
116 NSLog(@"MailComposeResult: canceled"); |
|
117 break; |
|
118 case MFMailComposeResultSaved: |
|
119 NSLog(@"MailComposeResult: saved"); |
|
120 break; |
|
121 case MFMailComposeResultSent: |
|
122 NSLog(@"MailComposeResult: sent"); |
|
123 break; |
|
124 case MFMailComposeResultFailed: |
|
125 NSLog(@"MailComposeResult: failed"); |
|
126 break; |
|
127 default: |
|
128 NSLog(@"MailComposeResult: not sent"); |
|
129 break; |
|
130 } |
|
131 |
|
132 [self dismissViewControllerAnimated:YES completion:nil]; |
|
133 } |
|
134 #endif |
59 |
135 |
60 #pragma mark - Memory warning |
136 #pragma mark - Memory warning |
61 |
137 |
62 - (void)didReceiveMemoryWarning |
138 - (void)didReceiveMemoryWarning |
63 { |
139 { |