project_files/HedgewarsMobile/Classes/GameLogViewController.m
branchios-revival
changeset 11181 015596575698
parent 11180 906c1878bc2c
child 12877 00215a7ec5f5
--- a/project_files/HedgewarsMobile/Classes/GameLogViewController.m	Tue Sep 15 04:28:25 2015 +0200
+++ b/project_files/HedgewarsMobile/Classes/GameLogViewController.m	Tue Sep 15 06:05:11 2015 +0200
@@ -18,7 +18,14 @@
 
 #import "GameLogViewController.h"
 
+#ifdef DEBUG
+#import <MessageUI/MFMailComposeViewController.h>
+#endif
+
 @interface GameLogViewController ()
+#ifdef DEBUG
+<MFMailComposeViewControllerDelegate>
+#endif
 
 @end
 
@@ -30,10 +37,21 @@
 {
     [super viewDidLoad];
     
+    self.title = @"Last game log";
+    
     UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithTitle:@"Close" style:UIBarButtonItemStylePlain target:self action:@selector(dismissAction)];
     self.navigationItem.rightBarButtonItem = closeButton;
     [closeButton release];
     
+#ifdef DEBUG
+    if ([self allowSendLogByEmail])
+    {
+        UIBarButtonItem *sendButton = [[UIBarButtonItem alloc] initWithTitle:@"Send" style:UIBarButtonItemStylePlain target:self action:@selector(sendLogByEmailAction)];
+        self.navigationItem.leftBarButtonItem = sendButton;
+        [sendButton release];
+    }
+#endif
+    
     NSString *debugStr = nil;
     if ([[NSFileManager defaultManager] fileExistsAtPath:DEBUG_FILE()])
         debugStr = [[NSString alloc] initWithContentsOfFile:DEBUG_FILE() encoding:NSUTF8StringEncoding error:nil];
@@ -50,13 +68,71 @@
     [logView release];
 }
 
+#pragma mark - Parameters
+
+#ifdef DEBUG
+- (BOOL)allowSendLogByEmail
+{
+    return ([MFMailComposeViewController canSendMail] && [[NSFileManager defaultManager] fileExistsAtPath:DEBUG_FILE()]);
+}
+#endif
+
 #pragma mark - Actions
 
+#ifdef DEBUG
+- (void)sendLogByEmailAction
+{
+    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
+    picker.mailComposeDelegate = self;
+    [picker setSubject:@"Log file of iHedgewars game"];
+    
+    // Attach a log file to the email
+    NSData *logData = [NSData dataWithContentsOfFile:DEBUG_FILE()];
+    [picker addAttachmentData:logData mimeType:@"text/plain" fileName:@"game0.log"];
+    
+    // Fill out the email body text
+    NSString *emailBody = @"Add here description of a problem/log";
+    [picker setMessageBody:emailBody isHTML:NO];
+    
+    [self presentViewController:picker animated:YES completion:nil];
+    [picker release];
+}
+#endif
+
 - (void)dismissAction
 {
     [self dismissViewControllerAnimated:YES completion:nil];
 }
 
+#pragma mark - MailCompose delegate
+
+#ifdef DEBUG
+- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
+{
+    // Notifies users about errors associated with the interface
+    switch (result)
+    {
+        case MFMailComposeResultCancelled:
+            NSLog(@"MailComposeResult: canceled");
+            break;
+        case MFMailComposeResultSaved:
+            NSLog(@"MailComposeResult: saved");
+            break;
+        case MFMailComposeResultSent:
+            NSLog(@"MailComposeResult: sent");
+            break;
+        case MFMailComposeResultFailed:
+            NSLog(@"MailComposeResult: failed");
+            break;
+        default:
+            NSLog(@"MailComposeResult: not sent");
+            break;
+    }
+    
+    [self dismissViewControllerAnimated:YES completion:nil];
+}
+#endif
+
 #pragma mark - Memory warning
 
 - (void)didReceiveMemoryWarning