From 6d68732784b52b064e74c9fed764ca932c8d8bf9 Mon Sep 17 00:00:00 2001 From: dynaflash Date: Thu, 6 May 2010 18:30:32 +0000 Subject: [PATCH] MacGui: Chapter Title import/export functionality - Saves the chapter list to a .csv file which is compatible with the cli and wingui. - Note: comma's in the chapter name are escaped with a "\" to maintain cli compatibility then if necessary stripped upon re import into macgui. - Original patch by borgclone and added to by realityking. Thanks! - Feature development referenced here http://forum.handbrake.fr/viewtopic.php?f=4&t=4146&start=0 git-svn-id: svn://localhost/HandBrake/trunk@3285 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- macosx/Controller.h | 13 ++- macosx/Controller.m | 150 +++++++++++++++++++++++++++++- macosx/English.lproj/MainMenu.xib | 186 +++++++++++++++++++++++++++++++++----- 3 files changed, 323 insertions(+), 26 deletions(-) diff --git a/macosx/Controller.h b/macosx/Controller.h index d4524169..72b1c6da 100644 --- a/macosx/Controller.h +++ b/macosx/Controller.h @@ -210,6 +210,9 @@ BOOL fIsDragging; /* Chapters box */ IBOutlet NSButton * fCreateChapterMarkers; IBOutlet NSTableView * fChapterTable; + IBOutlet NSButton * fLoadChaptersButton; + IBOutlet NSButton * fSaveChaptersButton; + IBOutlet NSTableColumn * fChapterTableNameColumn; ChapterTitles * fChapterTitlesDelegate; /* Bottom */ @@ -436,7 +439,7 @@ BOOL fIsDragging; - (IBAction)getDefaultPresets:(id)sender; -(void)sendToMetaX:(NSString *) filePath; - // Growl methods +// Growl methods - (NSDictionary *) registrationDictionaryForGrowl; -(void)showGrowlDoneNotification:(NSString *) filePath; - (IBAction)showDebugOutputPanel:(id)sender; @@ -449,8 +452,14 @@ BOOL fIsDragging; - (int) hbInstances; +// Chapter files methods +- (IBAction) browseForChapterFile: (id) sender; +- (void) browseForChapterFileDone: (NSOpenPanel *) sheet + returnCode: (int) returnCode contextInfo: (void *) contextInfo; - +- (IBAction) browseForChapterFileSave: (id) sender; +- (void) browseForChapterFileSaveDone: (NSSavePanel *) sheet + returnCode: (int) returnCode contextInfo: (void *) contextInfo; @end diff --git a/macosx/Controller.m b/macosx/Controller.m index 9d6cd0db..9d76e01c 100644 --- a/macosx/Controller.m +++ b/macosx/Controller.m @@ -514,7 +514,7 @@ static NSString * ChooseSourceIdentifier = @"Choose Source It fQueueStatus,fPresetsAdd,fPresetsDelete,fSrcAngleLabel,fSrcAnglePopUp, fCreateChapterMarkers,fVidTurboPassCheck,fDstMp4LargeFileCheck,fSubForcedCheck,fPresetsOutlineView, fAudDrcLabel,fDstMp4HttpOptFileCheck,fDstMp4iPodFileCheck,fVidQualityRFField,fVidQualityRFLabel, - fEncodeStartStopPopUp,fSrcTimeStartEncodingField,fSrcTimeEndEncodingField,fSrcFrameStartEncodingField,fSrcFrameEndEncodingField}; + fEncodeStartStopPopUp,fSrcTimeStartEncodingField,fSrcTimeEndEncodingField,fSrcFrameStartEncodingField,fSrcFrameEndEncodingField, fLoadChaptersButton, fSaveChaptersButton}; for( unsigned i = 0; i < sizeof( controls ) / sizeof( NSControl * ); i++ ) @@ -7995,6 +7995,154 @@ return YES; } +#pragma mark - +#pragma mark Chapter Files Import / Export + +- (IBAction) browseForChapterFile: (id) sender +{ + /* Open a panel to let the user choose the file */ + NSOpenPanel * panel = [NSOpenPanel openPanel]; + /* We get the current file name and path from the destination field here */ + [panel beginSheetForDirectory: [NSString stringWithFormat:@"%@/", + [[NSUserDefaults standardUserDefaults] stringForKey:@"LastDestinationDirectory"]] + file: NULL + types: [NSArray arrayWithObjects:@"csv",nil] + modalForWindow: fWindow modalDelegate: self + didEndSelector: @selector( browseForChapterFileDone:returnCode:contextInfo: ) + contextInfo: NULL]; +} + +- (void) browseForChapterFileDone: (NSOpenPanel *) sheet + returnCode: (int) returnCode contextInfo: (void *) contextInfo +{ + NSArray *chaptersArray; /* temp array for chapters */ + NSMutableArray *chaptersMutableArray; /* temp array for chapters */ + NSString *chapterName; /* temp string from file */ + int chapters, i; + + if( returnCode == NSOKButton ) /* if they click OK */ + { + chapterName = [[NSString alloc] initWithContentsOfFile:[sheet filename] encoding:NSUTF8StringEncoding error:NULL]; + chaptersArray = [chapterName componentsSeparatedByString:@"\n"]; + chaptersMutableArray= [chaptersArray mutableCopy]; + chapters = [fChapterTitlesDelegate numberOfRowsInTableView:fChapterTable]; + if ([chaptersMutableArray count] > 0) + { + /* if last item is empty remove it */ + if ([[chaptersMutableArray objectAtIndex:[chaptersArray count]-1] length] == 0) + { + [chaptersMutableArray removeLastObject]; + } + } + /* if chapters in table is not equal to array count */ + if ((unsigned int) chapters != [chaptersMutableArray count]) + { + [sheet close]; + [[NSAlert alertWithMessageText:NSLocalizedString(@"Unable to load chapter file", @"Unable to load chapter file") + defaultButton:NSLocalizedString(@"OK", @"OK") + alternateButton:NULL + otherButton:NULL + informativeTextWithFormat:NSLocalizedString(@"%d chapters expected, %d chapters found in %@", @"%d chapters expected, %d chapters found in %@"), + chapters, [chaptersMutableArray count], [[sheet filename] lastPathComponent]] runModal]; + return; + } + /* otherwise, go ahead and populate table with array */ + for (i=0; i 5) + { + /* avoid a segfault */ + /* Get the Range.location of the first comma in the line and then put everything after that into chapterTitle */ + NSRange firstCommaRange = [[chaptersMutableArray objectAtIndex:i] rangeOfString:@","]; + NSString *chapterTitle = [[chaptersMutableArray objectAtIndex:i] substringFromIndex:firstCommaRange.location + 1]; + /* Since we store our chapterTitle commas as "\," for the cli, we now need to remove the escaping "\" from the title */ + chapterTitle = [chapterTitle stringByReplacingOccurrencesOfString:@"\\," withString:@","]; + [fChapterTitlesDelegate tableView:fChapterTable + setObjectValue:chapterTitle + forTableColumn:fChapterTableNameColumn + row:i]; + } + else + { + [sheet close]; + [[NSAlert alertWithMessageText:NSLocalizedString(@"Unable to load chapter file", @"Unable to load chapter file") + defaultButton:NSLocalizedString(@"OK", @"OK") + alternateButton:NULL + otherButton:NULL + informativeTextWithFormat:NSLocalizedString(@"%@ was not formatted as expected.", @"%@ was not formatted as expected."), [[sheet filename] lastPathComponent]] runModal]; + [fChapterTable reloadData]; + return; + } + } + [fChapterTable reloadData]; + } +} + +- (IBAction) browseForChapterFileSave: (id) sender +{ + NSSavePanel *panel = [NSSavePanel savePanel]; + /* Open a panel to let the user save to a file */ + [panel setAllowedFileTypes:[NSArray arrayWithObjects:@"csv",nil]]; + [panel beginSheetForDirectory: [[fDstFile2Field stringValue] stringByDeletingLastPathComponent] + file: [[[[fDstFile2Field stringValue] lastPathComponent] stringByDeletingPathExtension] + stringByAppendingString:@"-chapters.csv"] + modalForWindow: fWindow + modalDelegate: self + didEndSelector: @selector( browseForChapterFileSaveDone:returnCode:contextInfo: ) + contextInfo: NULL]; +} + +- (void) browseForChapterFileSaveDone: (NSSavePanel *) sheet + returnCode: (int) returnCode contextInfo: (void *) contextInfo +{ + NSString *chapterName; /* pointer for string for later file-writing */ + NSString *chapterTitle; + NSError *saveError = [[NSError alloc] init]; + int chapters, i; /* ints for the number of chapters in the table and the loop */ + + if( returnCode == NSOKButton ) /* if they clicked OK */ + { + chapters = [fChapterTitlesDelegate numberOfRowsInTableView:fChapterTable]; + chapterName = [NSString string]; + for (i=0; i 1050 - 10C540 + 10D573 740 - 1038.25 - 458.00 + 1038.29 + 460.00 com.apple.InterfaceBuilder.CocoaPlugin 740 @@ -13,6 +13,7 @@ YES + YES @@ -112,7 +113,7 @@ 1 - + 256 YES @@ -620,7 +621,6 @@ {{10, 25}, {714, 305}} - Video @@ -2489,7 +2489,7 @@ 4 - + 256 YES @@ -2506,7 +2506,7 @@ 256 - {663, 233} + {663, 242} YES @@ -2586,7 +2586,7 @@ 3 2 - + 17 -700448768 @@ -2599,7 +2599,7 @@ 0 - {{1, 17}, {663, 233}} + {{1, 17}, {663, 242}} @@ -2609,7 +2609,7 @@ 256 - {{664, 17}, {15, 233}} + {{664, 17}, {15, 242}} @@ -2643,7 +2643,7 @@ - {{17, 17}, {680, 251}} + {{17, 17}, {680, 260}} 18 @@ -2657,7 +2657,7 @@ 256 - {{14, 274}, {151, 16}} + {{14, 283}, {151, 16}} YES @@ -2676,8 +2676,49 @@ 25 + + + 268 + {{472, 283}, {107, 16}} + + YES + + 67239424 + 134479872 + Import Chapters ... + + + -2038284033 + 129 + + + 200 + 25 + + + + + 268 + {{592, 283}, {106, 16}} + + YES + + 67239424 + 134479872 + Export Chapters ... + + + -2038284033 + 129 + + + 200 + 25 + + {{10, 25}, {714, 305}} + Chapters @@ -2685,14 +2726,14 @@ - + 134217728 YES YES YES - + @@ -4263,7 +4304,7 @@ - + 256 YES @@ -4282,6 +4323,7 @@ 256 {247, 506} + YES @@ -4344,6 +4386,7 @@ {{1, 1}, {247, 506}} + @@ -4354,6 +4397,7 @@ 256 {{248, 1}, {11, 506}} + 256 _doScroller: @@ -4364,6 +4408,7 @@ -2147483392 {{-100, -100}, {183, 15}} + 1 _doScroller: @@ -4372,6 +4417,7 @@ {{4, 31}, {260, 508}} + 18 @@ -4384,6 +4430,7 @@ 292 {{27, 1}, {24, 23}} + YES 67239424 @@ -4412,6 +4459,7 @@ 292 {{4, 1}, {24, 23}} + YES -2080244224 @@ -4436,6 +4484,7 @@ 292 {{59, 1}, {33, 23}} + YES 71433792 @@ -4504,6 +4553,8 @@ {270, 550} + + NSView NSResponder @@ -4520,7 +4571,7 @@ {1.79769e+308, 1.79769e+308} {338, 232} - + 256 YES @@ -4844,6 +4895,7 @@ {338, 318} + {{0, 0}, {1920, 1178}} {338, 254} @@ -6746,6 +6798,46 @@ 5533 + + + browseForChapterFile: + + + + 5538 + + + + browseForChapterFileSave: + + + + 5539 + + + + fLoadChaptersButton + + + + 5540 + + + + fSaveChaptersButton + + + + 5541 + + + + fChapterTableNameColumn + + + + 5544 + @@ -7207,6 +7299,8 @@ YES + + @@ -10159,6 +10253,34 @@ + + 5534 + + + YES + + + + + + 5535 + + + + + 5536 + + + YES + + + + + + 5537 + + + @@ -10941,6 +11063,10 @@ 5523.IBPluginDependency 5523.ImportedFromIB2 5524.IBPluginDependency + 5534.IBPluginDependency + 5535.IBPluginDependency + 5536.IBPluginDependency + 5537.IBPluginDependency 56.IBPluginDependency 56.ImportedFromIB2 57.IBEditorWindowLastContentRect @@ -11197,9 +11323,9 @@ {{720, 261}, {270, 550}} - {{275, 198}, {338, 318}} + {{383, 198}, {338, 318}} com.apple.InterfaceBuilder.CocoaPlugin - {{275, 198}, {338, 318}} + {{383, 198}, {338, 318}} {{421, 536}, {338, 318}} @@ -11286,10 +11412,10 @@ com.apple.InterfaceBuilder.CocoaPlugin - {{20, 306}, {760, 550}} + {{78, 109}, {760, 550}} com.apple.InterfaceBuilder.CocoaPlugin - {{20, 306}, {760, 550}} + {{78, 109}, {760, 550}} {{65, 541}, {760, 550}} @@ -11347,9 +11473,9 @@ com.apple.InterfaceBuilder.CocoaPlugin - {{72, 851}, {392, 144}} + {{72, 712}, {392, 144}} com.apple.InterfaceBuilder.CocoaPlugin - {{72, 851}, {392, 144}} + {{72, 712}, {392, 144}} {{303, 988}, {392, 144}} @@ -11763,6 +11889,10 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin {{337, 663}, {229, 173}} com.apple.InterfaceBuilder.CocoaPlugin @@ -11794,7 +11924,7 @@ - 5533 + 5544 @@ -11822,6 +11952,8 @@ autoSetM4vExtension: browseExportPresetFile: browseFile: + browseForChapterFile: + browseForChapterFileSave: browseImportPresetFile: browseImportSrtFile: browseSources: @@ -11925,6 +12057,8 @@ id id id + id + id @@ -11973,6 +12107,7 @@ fAudTrack4RatePopUp fBrowseSrtFileButton fChapterTable + fChapterTableNameColumn fCreateChapterMarkers fDstBrowseButton fDstFile1Field @@ -11983,6 +12118,7 @@ fDstMp4LargeFileCheck fDstMp4iPodFileCheck fEncodeStartStopPopUp + fLoadChaptersButton fPictureCroppingField fPictureSizeField fPresetDrawer @@ -11998,6 +12134,7 @@ fPresetsOutlineView fQueueStatus fRipIndicator + fSaveChaptersButton fScanIndicator fScanSrcTitleCancelButton fScanSrcTitleNumField @@ -12088,6 +12225,7 @@ NSPopUpButton NSButton NSTableView + NSTableColumn NSButton NSButton NSTextField @@ -12098,6 +12236,7 @@ NSButton NSButton NSPopUpButton + NSButton NSTextField NSTextField NSDrawer @@ -12113,6 +12252,7 @@ HBPresetsOutlineView NSTextField NSProgressIndicator + NSButton NSProgressIndicator NSButton NSTextField -- 2.11.0