From 8e7fdbaed7f2ece531fee19ebc6c3f0f284b795d Mon Sep 17 00:00:00 2001 From: ritsuka Date: Sun, 25 Jan 2015 08:02:47 +0000 Subject: [PATCH] =?utf8?q?MacGui:=20add=20a=20"Add=20Titles=20to=20Queue?= =?utf8?q?=E2=80=A6"=20menu=20item=20that=20let=20select=20which=20titles?= =?utf8?q?=20are=20added=20to=20the=20queue.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6810 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- macosx/English.lproj/HBTitleSelection.xib | 141 +++++++++++++++++++++ macosx/English.lproj/MainMenu.xib | 10 +- macosx/HBController.m | 132 +++++++++++++------ macosx/HBTitleSelectionController.h | 19 +++ macosx/HBTitleSelectionController.m | 112 ++++++++++++++++ macosx/HandBrake.xcodeproj/project.pbxproj | 30 ++++- 6 files changed, 396 insertions(+), 48 deletions(-) create mode 100644 macosx/English.lproj/HBTitleSelection.xib create mode 100644 macosx/HBTitleSelectionController.h create mode 100644 macosx/HBTitleSelectionController.m diff --git a/macosx/English.lproj/HBTitleSelection.xib b/macosx/English.lproj/HBTitleSelection.xib new file mode 100644 index 000000000..c1ddb8235 --- /dev/null +++ b/macosx/English.lproj/HBTitleSelection.xib @@ -0,0 +1,141 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/macosx/English.lproj/MainMenu.xib b/macosx/English.lproj/MainMenu.xib index 112c27a1f..486f503f0 100644 --- a/macosx/English.lproj/MainMenu.xib +++ b/macosx/English.lproj/MainMenu.xib @@ -97,9 +97,15 @@ - + - + + + + + + + diff --git a/macosx/HBController.m b/macosx/HBController.m index e9a884c98..9de07ef23 100644 --- a/macosx/HBController.m +++ b/macosx/HBController.m @@ -7,6 +7,7 @@ #import "HBController.h" #import "HBQueueController.h" +#import "HBTitleSelectionController.h" #import "HBPresetsManager.h" #import "HBPreset.h" @@ -27,12 +28,14 @@ #import "HBCore.h" #import "HBJob.h" -@interface HBController () +@interface HBController () @property (assign) IBOutlet NSView *openTitleView; @property (nonatomic, readwrite) BOOL scanSpecificTitle; @property (nonatomic, readwrite) NSInteger scanSpecificTitleIdx; +@property (nonatomic, readwrite, retain) HBTitleSelectionController *titlesSelectionController; + /** * The name of the source, it might differ from the source * last path component if it's a package or a folder. @@ -373,7 +376,7 @@ { SEL action = [menuItem action]; - if (action == @selector(addToQueue:) || action == @selector(addAllTitlesToQueue:) || + if (action == @selector(addToQueue:) || action == @selector(addAllTitlesToQueue:) || action == @selector(addTitlesToQueue:) || action == @selector(showPicturePanel:) || action == @selector(showAddPresetPanel:) || action == @selector(showPreviewWindow:)) { @@ -516,12 +519,22 @@ { if (result == NSOKButton) { - NSURL *scanURL = panel.URL; - // we set the last searched source directory in the prefs here - [[NSUserDefaults standardUserDefaults] setURL:scanURL.URLByDeletingLastPathComponent forKey:@"HBLastSourceDirectoryURL"]; - NSURL *url = panel.URL; + // Check if we selected a folder or not + id outValue = nil; + [url getResourceValue:&outValue forKey:NSURLIsDirectoryKey error:NULL]; + + // we set the last searched source directory in the prefs here + if ([outValue boolValue]) + { + [[NSUserDefaults standardUserDefaults] setURL:url forKey:@"HBLastSourceDirectoryURL"]; + } + else + { + [[NSUserDefaults standardUserDefaults] setURL:url.URLByDeletingLastPathComponent forKey:@"HBLastSourceDirectoryURL"]; + } + // We check to see if the chosen file at path is a package if ([[NSWorkspace sharedWorkspace] isFilePackageAtPath:url.path]) { @@ -592,7 +605,9 @@ }]; } -/* Here we actually tell hb_scan to perform the source scan, using the path to source and title number*/ +/** + * Here we actually tell hb_scan to perform the source scan, using the path to source and title number + */ - (void)performScan:(NSURL *)scanURL scanTitleNum:(NSInteger)scanTitleNum { // Save the current settings @@ -1145,56 +1160,93 @@ - (IBAction)pause:(id)sender { - if (fQueueController.core.state == HBStatePaused) - { - [fQueueController.core resume]; - } - else - { - [fQueueController.core pause]; - } + [fQueueController togglePauseResume:sender]; } #pragma mark - #pragma mark Batch Queue Titles Methods -- (IBAction)addAllTitlesToQueue:(id)sender +- (IBAction)addTitlesToQueue:(id)sender { - NSAlert *alert = [[NSAlert alloc] init]; - [alert setMessageText:NSLocalizedString(@"You are about to add ALL titles to the queue!", @"")]; - [alert setInformativeText:[NSString stringWithFormat:NSLocalizedString(@"Current preset will be applied to all %ld titles. Are you sure you want to do this?", @""), self.core.titles.count]]; - [alert addButtonWithTitle:NSLocalizedString(@"Cancel", @"")]; - [alert addButtonWithTitle:NSLocalizedString(@"Yes, I want to add all titles to the queue", @"")]; - [alert setAlertStyle:NSCriticalAlertStyle]; - - [alert beginSheetModalForWindow:self.window modalDelegate:self didEndSelector:@selector(addAllTitlesToQueueAlertDone:returnCode:contextInfo:) contextInfo:NULL]; - [alert release]; + self.titlesSelectionController = [[[HBTitleSelectionController alloc] initWithTitles:self.core.titles delegate:self] autorelease]; + + [NSApp beginSheet:self.titlesSelectionController.window + modalForWindow:self.window + modalDelegate:nil + didEndSelector:NULL + contextInfo:NULL]; } -- (void)addAllTitlesToQueueAlertDone:(NSAlert *)alert - returnCode:(NSInteger)returnCode - contextInfo:(void *)contextInfo +- (void)didSelectIndexes:(NSIndexSet *)indexes { - if (returnCode == NSAlertSecondButtonReturn) - { - [self doAddAllTitlesToQueue]; - } + [self.titlesSelectionController.window orderOut:nil]; + [NSApp endSheet:self.titlesSelectionController.window]; + + [self doAddTitlesAtIndexesToQueue:indexes]; } -- (void)doAddAllTitlesToQueue +- (void)doAddTitlesAtIndexesToQueue:(NSIndexSet *)indexes; { NSMutableArray *jobs = [[NSMutableArray alloc] init]; + BOOL fileExists = NO; for (HBTitle *title in self.core.titles) { - HBJob *job = [[HBJob alloc] initWithTitle:title andPreset:self.selectedPreset]; - job.destURL = [self destURLForJob:job]; - [jobs addObject:job]; - [job release]; + if ([indexes containsIndex:title.index]) + { + HBJob *job = [[HBJob alloc] initWithTitle:title andPreset:self.selectedPreset]; + job.destURL = [self destURLForJob:job]; + job.title = nil; + [jobs addObject:job]; + [job release]; + + if ([[NSFileManager defaultManager] fileExistsAtPath:job.destURL.path] || [fQueueController jobExistAtURL:job.destURL]) + { + fileExists = YES; + } + } + } + + if (fileExists) + { + // File exist, warn user + NSAlert *alert = [[NSAlert alloc] init]; + [alert setMessageText:NSLocalizedString(@"File already exists.", nil)]; + [alert setInformativeText:NSLocalizedString(@"One or more file already exists. Do you want to overwrite?", nil)]; + [alert addButtonWithTitle:NSLocalizedString(@"Cancel", nil)]; + [alert addButtonWithTitle:NSLocalizedString(@"Overwrite", nil)]; + [alert setAlertStyle:NSCriticalAlertStyle]; + + [alert beginSheetModalForWindow:self.window modalDelegate:self didEndSelector:@selector(overwriteAddTitlesToQueueAlertDone:returnCode:contextInfo:) contextInfo:jobs]; + [alert release]; } + else + { + [fQueueController addJobsFromArray:jobs]; + [jobs release]; + } +} - [fQueueController addJobsFromArray:jobs]; - [jobs release]; +- (void)overwriteAddTitlesToQueueAlertDone:(NSAlert *)alert + returnCode:(NSInteger)returnCode + contextInfo:(void *)contextInfo +{ + if (returnCode == NSAlertSecondButtonReturn) + { + NSArray *jobs = (NSArray *)contextInfo; + [fQueueController addJobsFromArray:jobs]; + [jobs release]; + } +} + +- (IBAction)addAllTitlesToQueue:(id)sender +{ + NSMutableIndexSet *indexes = [NSMutableIndexSet indexSet]; + for (HBTitle *title in self.core.titles) + { + [indexes addIndex:title.index]; + } + [self doAddTitlesAtIndexesToQueue:indexes]; } #pragma mark - Picture @@ -1374,7 +1426,7 @@ [panel beginSheetModalForWindow:self.window completionHandler:^(NSInteger result) { NSURL *importPresetsFile = [panel URL]; - NSURL *importPresetsDirectory = nil;//[importPresetsFile URLByDeletingLastPathComponent]; + NSURL *importPresetsDirectory = [importPresetsFile URLByDeletingLastPathComponent]; [[NSUserDefaults standardUserDefaults] setURL:importPresetsDirectory forKey:@"LastPresetImportDirectoryURL"]; // NOTE: here we need to do some sanity checking to verify we do not hose up our presets file diff --git a/macosx/HBTitleSelectionController.h b/macosx/HBTitleSelectionController.h new file mode 100644 index 000000000..3dda1984b --- /dev/null +++ b/macosx/HBTitleSelectionController.h @@ -0,0 +1,19 @@ +/* HBTitleSelectionController.h + + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +#import + +@protocol HBTitleSelectionDelegate + +- (void)didSelectIndexes:(NSIndexSet *)indexes; + +@end + +@interface HBTitleSelectionController : NSWindowController + +- (instancetype)initWithTitles:(NSArray *)titles delegate:(id)delegate; + +@end diff --git a/macosx/HBTitleSelectionController.m b/macosx/HBTitleSelectionController.m new file mode 100644 index 000000000..814c78991 --- /dev/null +++ b/macosx/HBTitleSelectionController.m @@ -0,0 +1,112 @@ +/* HBTitleSelectionController.h + + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +#import "HBTitleSelectionController.h" +#import "HBTitle.h" + +@interface HBTitleSelectionController () + +@property (nonatomic, readonly) NSArray *titles; +@property (nonatomic, readonly) NSMutableArray *selection; + +@property (nonatomic, readonly) id delegate; + +@end + +@implementation HBTitleSelectionController + +- (instancetype)initWithTitles:(NSArray *)titles delegate:(id)delegate +{ + self = [super initWithWindowNibName:@"HBTitleSelection"]; + if (self) + { + _titles = [titles retain]; + _selection = [[NSMutableArray alloc] initWithCapacity:titles.count]; + _delegate = delegate; + + for (NSUInteger i = 0; i < titles.count; i++) + { + _selection[i] = @YES; + } + } + + return self; +} + +- (void)dealloc +{ + [_titles release]; + _titles = nil; + + [_selection release]; + _selection = nil; + + [super dealloc]; +} + +- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView +{ + return self.titles.count; +} + +- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row +{ + HBTitle *title = self.titles[row]; + + if ([tableColumn.identifier isEqualTo:@"index"]) + { + return @(title.index); + } + else if ([tableColumn.identifier isEqualTo:@"title"]) + { + return self.selection[row]; + } + else if ([tableColumn.identifier isEqualTo:@"duration"]) + { + return title.timeCode; + } + + return nil; +} + +- (void)tableView:(NSTableView *)tableView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row; +{ + if ([tableColumn.identifier isEqualTo:@"title"]) + { + self.selection[row] = object; + } +} + +- (void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row +{ + if ([tableColumn.identifier isEqualTo:@"title"]) + { + HBTitle *title = self.titles[row]; + [aCell setTitle:title.name]; + } +} + +- (IBAction)add:(id)sender +{ + NSMutableIndexSet *indexes = [NSMutableIndexSet indexSet]; + + [self.selection enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { + if ([obj boolValue]) + { + HBTitle *title = self.titles[idx]; + [indexes addIndex:title.index]; + } + + }]; + [self.delegate didSelectIndexes:indexes]; +} + +- (IBAction)cancel:(id)sender +{ + [self.delegate didSelectIndexes:[NSIndexSet indexSet]]; +} + +@end diff --git a/macosx/HandBrake.xcodeproj/project.pbxproj b/macosx/HandBrake.xcodeproj/project.pbxproj index 05fa21643..f052c27ae 100644 --- a/macosx/HandBrake.xcodeproj/project.pbxproj +++ b/macosx/HandBrake.xcodeproj/project.pbxproj @@ -157,6 +157,8 @@ A9BB0F2719A0ECE40079F1C1 /* HBHUDButtonCell.m in Sources */ = {isa = PBXBuildFile; fileRef = A9BB0F2619A0ECE40079F1C1 /* HBHUDButtonCell.m */; }; A9BC24C91A69293E007DC41A /* HBAttributedStringAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = A9BC24C81A69293E007DC41A /* HBAttributedStringAdditions.m */; }; A9C0DB85197E7B0000DF55B3 /* SubtitlesDefaults.xib in Resources */ = {isa = PBXBuildFile; fileRef = A9C0DB83197E7B0000DF55B3 /* SubtitlesDefaults.xib */; }; + A9C183961A716B8F00C897C2 /* HBTitleSelectionController.m in Sources */ = {isa = PBXBuildFile; fileRef = A9C183941A716B8F00C897C2 /* HBTitleSelectionController.m */; }; + A9C1839D1A716BCC00C897C2 /* HBTitleSelection.xib in Resources */ = {isa = PBXBuildFile; fileRef = A9C1839B1A716BCC00C897C2 /* HBTitleSelection.xib */; }; A9C9F88919A733FE00DC8923 /* HBHUDView.m in Sources */ = {isa = PBXBuildFile; fileRef = A9C9F88819A733FE00DC8923 /* HBHUDView.m */; }; A9CF25F11990D62C0023F727 /* Presets.xib in Resources */ = {isa = PBXBuildFile; fileRef = A9CF25EF1990D62C0023F727 /* Presets.xib */; }; A9CF25F41990D64E0023F727 /* HBPreset.m in Sources */ = {isa = PBXBuildFile; fileRef = A9CF25F31990D64E0023F727 /* HBPreset.m */; }; @@ -429,6 +431,9 @@ A9BC24C71A69293E007DC41A /* HBAttributedStringAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HBAttributedStringAdditions.h; sourceTree = ""; }; A9BC24C81A69293E007DC41A /* HBAttributedStringAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HBAttributedStringAdditions.m; sourceTree = ""; }; A9C0DB84197E7B0000DF55B3 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = SubtitlesDefaults.xib; sourceTree = ""; }; + A9C183931A716B8F00C897C2 /* HBTitleSelectionController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HBTitleSelectionController.h; sourceTree = ""; }; + A9C183941A716B8F00C897C2 /* HBTitleSelectionController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HBTitleSelectionController.m; sourceTree = ""; }; + A9C1839C1A716BCC00C897C2 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = HBTitleSelection.xib; sourceTree = ""; }; A9C9F88719A733FE00DC8923 /* HBHUDView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HBHUDView.h; sourceTree = ""; }; A9C9F88819A733FE00DC8923 /* HBHUDView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HBHUDView.m; sourceTree = ""; }; A9CF25F01990D62C0023F727 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = Presets.xib; sourceTree = ""; }; @@ -795,6 +800,7 @@ 273F217C14ADDDA10021BE6D /* InfoPlist.strings */, 273F217E14ADDDA10021BE6D /* MainMenu.xib */, A92268791A6E569B00A8D5C5 /* MainWindow.xib */, + A9C1839B1A716BCC00C897C2 /* HBTitleSelection.xib */, A9CF25EF1990D62C0023F727 /* Presets.xib */, A9E2FD291A21BC6F000E8D3F /* AddPreset.xib */, A93E0ED51972958C00FD67FB /* Video.xib */, @@ -971,16 +977,18 @@ A9B34D701976841800871B7D /* Main Window View Controllers */, A9AA447C1970726500D7DEFC /* HBQueueController.h */, A9906B2B1A710920001D82D5 /* HBQueueController.m */, - 273F209B14ADBE670021BE6D /* HBOutputPanelController.h */, - 273F209C14ADBE670021BE6D /* HBOutputPanelController.m */, - 273F209F14ADBE670021BE6D /* HBPreferencesController.h */, - 273F20A014ADBE670021BE6D /* HBPreferencesController.m */, + A9C183931A716B8F00C897C2 /* HBTitleSelectionController.h */, + A9C183941A716B8F00C897C2 /* HBTitleSelectionController.m */, + A9E2FD241A21BC4A000E8D3F /* HBAddPresetController.h */, + A9E2FD251A21BC4A000E8D3F /* HBAddPresetController.m */, 273F20A914ADBE670021BE6D /* HBPictureController.h */, 273F20AA14ADBE670021BE6D /* HBPictureController.m */, 273F20A314ADBE670021BE6D /* HBPreviewController.h */, 273F20A414ADBE670021BE6D /* HBPreviewController.m */, - A9E2FD241A21BC4A000E8D3F /* HBAddPresetController.h */, - A9E2FD251A21BC4A000E8D3F /* HBAddPresetController.m */, + 273F209B14ADBE670021BE6D /* HBOutputPanelController.h */, + 273F209C14ADBE670021BE6D /* HBOutputPanelController.m */, + 273F209F14ADBE670021BE6D /* HBPreferencesController.h */, + 273F20A014ADBE670021BE6D /* HBPreferencesController.m */, ); name = Controllers; sourceTree = ""; @@ -1142,6 +1150,7 @@ A9CF25F11990D62C0023F727 /* Presets.xib in Resources */, 273F216114ADCBF80021BE6D /* JobSmall.png in Resources */, 273F216714ADCBF80021BE6D /* Reveal.png in Resources */, + A9C1839D1A716BCC00C897C2 /* HBTitleSelection.xib in Resources */, 273F216814ADCBF80021BE6D /* RevealHighlight.png in Resources */, A91C02521A165EA200DEA6F3 /* EncodeComplete.png in Resources */, 273F216914ADCBF80021BE6D /* RevealHighlightPressed.png in Resources */, @@ -1272,6 +1281,7 @@ 273F20BE14ADC09F0021BE6D /* main.mm in Sources */, A9537BF01A48A85C00141102 /* HBJob+UIAdditions.m in Sources */, A9EA43681A2210C400785E95 /* HBQueueOutlineView.m in Sources */, + A9C183961A716B8F00C897C2 /* HBTitleSelectionController.m in Sources */, A91726E7197291BC00D1AFEF /* HBChapterTitlesController.m in Sources */, A9C9F88919A733FE00DC8923 /* HBHUDView.m in Sources */, A932E26F198833920047D13E /* HBAudioDefaultsController.m in Sources */, @@ -1403,6 +1413,14 @@ name = SubtitlesDefaults.xib; sourceTree = ""; }; + A9C1839B1A716BCC00C897C2 /* HBTitleSelection.xib */ = { + isa = PBXVariantGroup; + children = ( + A9C1839C1A716BCC00C897C2 /* English */, + ); + name = HBTitleSelection.xib; + sourceTree = ""; + }; A9CF25EF1990D62C0023F727 /* Presets.xib */ = { isa = PBXVariantGroup; children = ( -- 2.40.0