summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorritsuka <[email protected]>2015-01-11 12:18:49 +0000
committerritsuka <[email protected]>2015-01-11 12:18:49 +0000
commit0689343f8dcff22dcd1cf8174aae4641560da078 (patch)
tree87962b6b39a980ec5cb17d4acf277e0d25746f5d
parent3ed0f39d4926cb7ca6b2430c034c1356a52f3a99 (diff)
MacGui: refactored some duplicated code.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6728 b64f7644-9d1e-0410-96f1-a4d463321fa5
-rw-r--r--macosx/English.lproj/OutputPanel.xib11
-rw-r--r--macosx/HBOutputPanelController.m113
2 files changed, 58 insertions, 66 deletions
diff --git a/macosx/English.lproj/OutputPanel.xib b/macosx/English.lproj/OutputPanel.xib
index e578ce5d9..61a123655 100644
--- a/macosx/English.lproj/OutputPanel.xib
+++ b/macosx/English.lproj/OutputPanel.xib
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="5056" systemVersion="13F7" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6724" systemVersion="14C94b" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<dependencies>
- <deployment version="1060" defaultVersion="1090" identifier="macosx"/>
- <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="5056"/>
+ <deployment version="1060" identifier="macosx"/>
+ <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6724"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="HBOutputPanelController">
@@ -12,8 +12,8 @@
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
- <customObject id="-3" userLabel="Application"/>
- <window title="Activity Window - HandBrake" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" hidesOnDeactivate="YES" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" id="5" userLabel="OutputPanel" customClass="NSPanel">
+ <customObject id="-3" userLabel="Application" customClass="NSObject"/>
+ <window title="Activity Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" hidesOnDeactivate="YES" releasedWhenClosed="NO" visibleAtLaunch="NO" frameAutosaveName="OutputPanelFrame" animationBehavior="default" id="5" userLabel="OutputPanel" customClass="NSPanel">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="74" y="449" width="378" height="439"/>
@@ -61,6 +61,7 @@
<connections>
<outlet property="delegate" destination="-2" id="17"/>
</connections>
+ <point key="canvasLocation" x="389" y="440.5"/>
</window>
<menu title="Menu" id="11" userLabel="ContextMenu">
<items>
diff --git a/macosx/HBOutputPanelController.m b/macosx/HBOutputPanelController.m
index d924df80a..8b6e955d7 100644
--- a/macosx/HBOutputPanelController.m
+++ b/macosx/HBOutputPanelController.m
@@ -29,15 +29,17 @@
/// Text storage for the debug output.
NSTextStorage *outputTextStorage;
-
- /// Path to log text file.
- NSString *outputLogFile;
- BOOL encodeLogOn;
}
+/// Path to log text file.
+@property (nonatomic, copy) NSString *outputLogFile;
+
/// Path to individual log text file.
@property (nonatomic, copy) NSString *outputLogFileForEncode;
+/// Whether we are writing an addition log file for the current encode or not.
+@property (nonatomic) BOOL encodeLogOn;
+
@end
@implementation HBOutputPanelController
@@ -73,28 +75,27 @@
* 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 = [[[HBUtilities appSupportPath] stringByAppendingPathComponent:@"HandBrake-activitylog.txt"] retain];
+ _outputLogFile = [[[HBUtilities appSupportPath] stringByAppendingPathComponent:@"HandBrake-activitylog.txt"] retain];
/* We check for an existing output log file here */
- if( [fileManager fileExistsAtPath:outputLogFile] == 0 )
+ if ([fileManager fileExistsAtPath:_outputLogFile] == NO)
{
/* if not, then we create a new blank one */
- [fileManager createFileAtPath:outputLogFile contents:nil attributes:nil];
+ [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 (Cleared): %@\n\n", [[NSDate date] descriptionWithCalendarFormat:nil timeZone:nil locale:nil]];
- [startOutputLogString writeToFile:outputLogFile atomically:YES encoding:NSUTF8StringEncoding error:NULL];
+ NSString *startOutputLogString = [self logHeaderForReason:@"Session (Cleared)"];
+ [startOutputLogString writeToFile:_outputLogFile atomically:YES encoding:NSUTF8StringEncoding error:NULL];
[[HBOutputRedirect stderrRedirect] addListener:self];
[[HBOutputRedirect stdoutRedirect] addListener:self];
- [self setWindowFrameAutosaveName:@"OutputPanelFrame"];
[[textView layoutManager] replaceTextStorage:outputTextStorage];
[[textView enclosingScrollView] setLineScroll:10];
[[textView enclosingScrollView] setPageScroll:20];
- encodeLogOn = NO;
+ _encodeLogOn = NO;
}
return self;
}
@@ -128,9 +129,25 @@
}
}
+- (NSString *)logHeaderForReason:(NSString *)reason
+{
+ return [NSString stringWithFormat:@"HandBrake Activity Log for %@: %@\n%@",
+ reason,
+ [[NSDate date] descriptionWithCalendarFormat:nil timeZone:nil locale:nil],
+ [self handBrakeVersion]];
+}
+
+- (NSString *)handBrakeVersion
+{
+ NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
+ return [NSString stringWithFormat:@"Handbrake Version: %@ (%@)",
+ infoDictionary[@"CFBundleShortVersionString"],
+ infoDictionary[@"CFBundleVersion"]];
+}
+
- (void)startEncodeLog:(NSURL *)logURL
{
- encodeLogOn = YES;
+ self.encodeLogOn = YES;
NSString *outputFileForEncode = logURL.path ;
/* Since the destination path matches the extension of the output file, replace the
* output movie extension and replace it with ".txt"
@@ -167,20 +184,18 @@
[fileManager createFileAtPath:self.outputLogFileForEncode contents:nil attributes:nil];
/* Similar to the regular activity log, we print a header containing the date and time of the encode as well as what directory it was encoded to */
- NSString *versionStringFull = [[NSString stringWithFormat: @"Handbrake Version: %@", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]] stringByAppendingString: [NSString stringWithFormat: @" (%@)\n\n", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]]];
- NSString *startOutputLogString = [NSString stringWithFormat: @"HandBrake Activity Log for %@: %@\n%@",outputFileForEncode, [[NSDate date] descriptionWithCalendarFormat:nil timeZone:nil locale:nil],versionStringFull];
+ NSString *startOutputLogString = [self logHeaderForReason:outputFileForEncode];
[startOutputLogString writeToFile:self.outputLogFileForEncode atomically:YES encoding:NSUTF8StringEncoding error:NULL];
-
-
}
- (void) endEncodeLog
{
- encodeLogOn = NO;
+ self.encodeLogOn = NO;
}
/**
- * Displays text received from HBOutputRedirect in the text view.
+ * Displays text received from HBOutputRedirect in the text view
+ * and write it to the log files.
*/
- (void)stderrRedirect:(NSString *)text
{
@@ -191,42 +206,21 @@
[attributedString release];
/* remove text from outputTextStorage as defined by TextStorageUpperSizeLimit and TextStorageLowerSizeLimit */
- if ([outputTextStorage length] > TextStorageUpperSizeLimit)
+ 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]);
+
+ FILE *f = fopen(_outputLogFile.fileSystemRepresentation, "a");
+ fprintf(f, "%s", text.UTF8String);
fclose(f);
-
- if (encodeLogOn == YES && self.outputLogFileForEncode != nil)
+
+ if (_encodeLogOn == YES && _outputLogFileForEncode != nil)
{
- FILE *e = fopen([self.outputLogFileForEncode UTF8String], "a");
- fprintf(e, "%s", [text UTF8String]);
- fclose(e);
+ FILE *e = fopen(_outputLogFileForEncode.fileSystemRepresentation, "a");
+ fprintf(e, "%s", text.UTF8String);
+ fclose(e);
}
- /* 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]; }
@@ -237,11 +231,9 @@
{
[outputTextStorage deleteCharactersInRange:NSMakeRange(0, [outputTextStorage length])];
/* We want to rewrite the app version info to the top of the activity window so it is always present */
- NSString *versionStringFull = [[NSString stringWithFormat: @"Handbrake Version: %@", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]] stringByAppendingString: [NSString stringWithFormat: @" (%@)\n\n", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]]];
time_t _now = time( NULL );
struct tm * now = localtime( &_now );
- fprintf(stderr, "[%02d:%02d:%02d] macgui: %s\n", now->tm_hour, now->tm_min, now->tm_sec, [versionStringFull UTF8String]);
-
+ fprintf(stderr, "[%02d:%02d:%02d] macgui: %s\n", now->tm_hour, now->tm_min, now->tm_sec, [[self handBrakeVersion] UTF8String]);
}
/**
@@ -261,7 +253,7 @@
- (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, @"\")"]];
+ NSAppleScript *myScript = [[NSAppleScript alloc] initWithSource: [NSString stringWithFormat: @"%@%@%@", @"tell application \"Finder\" to open (POSIX file \"", _outputLogFile, @"\")"]];
[myScript executeAndReturnError: nil];
[myScript release];
}
@@ -289,14 +281,13 @@
- (IBAction)clearActivityLogFile:(id)sender
{
/* We overwrite the existing output log with the new date and time header */
- /* 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:NO encoding:NSUTF8StringEncoding error:NULL];
-
- /* We want to rewrite the app version info to the top of the activity window so it is always present */
- NSString *versionStringFull = [[NSString stringWithFormat: @"macgui: Handbrake Version: %@", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]] stringByAppendingString: [NSString stringWithFormat: @" (%@)\n\n", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]]];
- [versionStringFull writeToFile:outputLogFile atomically:NO encoding:NSUTF8StringEncoding error:NULL];
-
+ /* Use the current date and time for the new output log header */
+ NSString *startOutputLogString = [self logHeaderForReason:@"Session Starting"];
+ [startOutputLogString writeToFile:_outputLogFile atomically:NO encoding:NSUTF8StringEncoding error:NULL];
+
+ /* We want to rewrite the app version info to the top of the activity window so it is always present */
+ NSString *versionStringFull = [self handBrakeVersion];
+ [versionStringFull writeToFile:_outputLogFile atomically:NO encoding:NSUTF8StringEncoding error:NULL];
}
- (void)windowWillClose:(NSNotification *)aNotification