diff options
Diffstat (limited to 'macosx')
-rw-r--r-- | macosx/English.lproj/OutputPanel.nib/classes.nib | 7 | ||||
-rw-r--r-- | macosx/English.lproj/OutputPanel.nib/info.nib | 4 | ||||
-rw-r--r-- | macosx/English.lproj/OutputPanel.nib/keyedobjects.nib | bin | 6081 -> 6282 bytes | |||
-rw-r--r-- | macosx/HBOutputPanelController.h | 4 | ||||
-rw-r--r-- | macosx/HBOutputPanelController.m | 92 |
5 files changed, 97 insertions, 10 deletions
diff --git a/macosx/English.lproj/OutputPanel.nib/classes.nib b/macosx/English.lproj/OutputPanel.nib/classes.nib index f9f53db9e..cadaf1e67 100644 --- a/macosx/English.lproj/OutputPanel.nib/classes.nib +++ b/macosx/English.lproj/OutputPanel.nib/classes.nib @@ -2,7 +2,12 @@ IBClasses = ( {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, { - ACTIONS = {clearOutput = id; copyAllOutputToPasteboard = id; showOutputPanel = id; }; + ACTIONS = { + clearOutput = id; + copyAllOutputToPasteboard = id; + openActivityLogFile = id; + showOutputPanel = id; + }; CLASS = HBOutputPanelController; LANGUAGE = ObjC; OUTLETS = {outputPanel = NSPanel; textView = NSTextView; }; diff --git a/macosx/English.lproj/OutputPanel.nib/info.nib b/macosx/English.lproj/OutputPanel.nib/info.nib index c4028233f..6f50f595a 100644 --- a/macosx/English.lproj/OutputPanel.nib/info.nib +++ b/macosx/English.lproj/OutputPanel.nib/info.nib @@ -3,7 +3,7 @@ <plist version="1.0"> <dict> <key>IBDocumentLocation</key> - <string>81 82 356 240 0 0 1440 878 </string> + <string>107 409 356 240 0 0 1440 878 </string> <key>IBEditorPositions</key> <dict> <key>11</key> @@ -13,8 +13,8 @@ <string>446.1</string> <key>IBOpenObjects</key> <array> - <integer>5</integer> <integer>11</integer> + <integer>5</integer> </array> <key>IBSystem Version</key> <string>8R2218</string> diff --git a/macosx/English.lproj/OutputPanel.nib/keyedobjects.nib b/macosx/English.lproj/OutputPanel.nib/keyedobjects.nib Binary files differindex 60e034726..09f7dd7d2 100644 --- a/macosx/English.lproj/OutputPanel.nib/keyedobjects.nib +++ b/macosx/English.lproj/OutputPanel.nib/keyedobjects.nib diff --git a/macosx/HBOutputPanelController.h b/macosx/HBOutputPanelController.h index c2b6bd75d..b61fa20ff 100644 --- a/macosx/HBOutputPanelController.h +++ b/macosx/HBOutputPanelController.h @@ -21,10 +21,14 @@ /// Text storage for the debug output. NSTextStorage *outputTextStorage; + + /// Path to log text file. + NSString *outputLogFile; } - (IBAction)showOutputPanel:(id)sender; - (IBAction)clearOutput:(id)sender; - (IBAction)copyAllOutputToPasteboard:(id)sender; +- (IBAction)openActivityLogFile:(id)sender; @end diff --git a/macosx/HBOutputPanelController.m b/macosx/HBOutputPanelController.m index d60490a32..deb15d5fd 100644 --- a/macosx/HBOutputPanelController.m +++ b/macosx/HBOutputPanelController.m @@ -30,9 +30,46 @@ { if (self = [super init]) { - outputTextStorage = [[NSTextStorage alloc] init]; + /* We initialize the outputTextStorage object for the activity window */ + outputTextStorage = [[NSTextStorage alloc] init]; + + /* We declare the default NSFileManager into fileManager */ + NSFileManager * fileManager = [NSFileManager defaultManager]; + /* we set the files and support paths here */ + NSString *AppSupportDirectory = @"~/Library/Application Support/HandBrake"; + AppSupportDirectory = [AppSupportDirectory stringByExpandingTildeInPath]; + /* First, lets verify that the app support directory exists */ + if ([fileManager fileExistsAtPath:AppSupportDirectory] == 0) + { + /* If it doesnt exist yet, we create it here */ + [fileManager createDirectoryAtPath:AppSupportDirectory attributes:nil]; + } + + /* Establish the log file and location to write to */ + /* We are initially using a .txt file as opposed to a .log file since it will open by + * default with the users text editor instead of the .log default Console.app, should + * create less confusion for less experienced users when we ask them to paste the log for support + */ + outputLogFile = @"~/Library/Application Support/HandBrake/HandBrake-activitylog.txt"; + outputLogFile = [[outputLogFile stringByExpandingTildeInPath]retain]; + + /* We check for an existing output log file here */ + if ([fileManager fileExistsAtPath:outputLogFile] == 0) + { + /* if not, then we create a new blank one */ + [fileManager createFileAtPath:outputLogFile contents:nil attributes:nil]; + } + + /* We overwrite the existing output log with the date for starters the output log to start fresh with the new session */ + /* Use the current date and time for the new output log header */ + NSString *startOutputLogString = [NSString stringWithFormat: @"HandBrake Activity Log for Session Starting: %@\n\n", [[NSDate date] descriptionWithCalendarFormat:nil timeZone:nil locale:nil]]; + [startOutputLogString writeToFile:outputLogFile atomically:YES encoding:NSUTF8StringEncoding error:NULL]; + + [[HBOutputRedirect stderrRedirect] addListener:self]; [[HBOutputRedirect stdoutRedirect] addListener:self]; + + } return self; } @@ -76,14 +113,44 @@ */ - (void)stderrRedirect:(NSString *)text { - NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:text]; - [outputTextStorage appendAttributedString:attributedString]; - [attributedString release]; - - if ([outputTextStorage length] > TextStorageUpperSizeLimit) + + NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:text]; + /* Actually write the libhb output to the text view (outputTextStorage) */ + [outputTextStorage appendAttributedString:attributedString]; + [attributedString release]; + + /* remove text from outputTextStorage as defined by TextStorageUpperSizeLimit and TextStorageLowerSizeLimit */ + if ([outputTextStorage length] > TextStorageUpperSizeLimit) [outputTextStorage deleteCharactersInRange:NSMakeRange(0, [outputTextStorage length] - TextStorageLowerSizeLimit)]; - + [textView scrollRangeToVisible:NSMakeRange([outputTextStorage length], 0)]; + + /* We use a c function to write to the log file without reading it into memory + * as it should be faster and easier on memory than using cocoa's writeToFile + * thanks ritsuka !!*/ + FILE *f = fopen([outputLogFile UTF8String], "a"); + fprintf(f, "%s", [text UTF8String]); + fclose(f); + + + /* Below uses Objective-C to write to the file, though it is slow and uses + * more memory than the c function above. For now, leaving this in here + * just in case and commented out. + */ + /* Put the new incoming string from libhb into an nsstring for appending to our log file */ + //NSString *newOutputString = [[NSString alloc] initWithString:text]; + /*get the current log file and put it into an NSString */ + /* HACK ALERT: must be a way to do it without reading the whole log into memory + Performance note: could batch write to the log, but want to get each line as it comes out of + libhb in case of a crash or freeze so we see exactly what the last thing was before crash*/ + //NSString *currentOutputLogString = [[NSString alloc]initWithContentsOfFile:outputLogFile encoding:NSUTF8StringEncoding error:NULL]; + + /* Append the new libhb output string to the existing log file string */ + //currentOutputLogString = [currentOutputLogString stringByAppendingString:newOutputString]; + /* Save the new modified log file string back to disk */ + //[currentOutputLogString writeToFile:outputLogFile atomically:YES encoding:NSUTF8StringEncoding error:NULL]; + /* Release the new libhb output string */ + //[newOutputString release]; } - (void)stdoutRedirect:(NSString *)text { [self stderrRedirect:text]; } @@ -105,6 +172,17 @@ [pboard setString:[outputTextStorage string] forType:NSStringPboardType]; } +/** + * Opens the activity log txt file in users default editor. + */ +- (IBAction)openActivityLogFile:(id)sender +{ + /* Opens the activity window log file in the users default text editor */ + NSAppleScript *myScript = [[NSAppleScript alloc] initWithSource: [NSString stringWithFormat: @"%@%@%@", @"tell application \"Finder\" to open (POSIX file \"", outputLogFile, @"\")"]]; + [myScript executeAndReturnError: nil]; + [myScript release]; +} + - (void)windowWillClose:(NSNotification *)aNotification { [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"OutputPanelIsOpen"]; |