diff options
author | ritsuka <[email protected]> | 2014-11-23 12:54:31 +0000 |
---|---|---|
committer | ritsuka <[email protected]> | 2014-11-23 12:54:31 +0000 |
commit | 9e0dcb82bdbf0801b79b84241ab67088c2fb0553 (patch) | |
tree | 7eb8845516a8e3bb091e07a0eaa40e8459c1a93e /macosx/HBAddPresetController.m | |
parent | 20e1a9b2e253fe2d59dbf64a878e735a8d4d7c91 (diff) |
MacGui: moved the "add preset" window to its own window controller class. Keep the current settings when changing title or scanning a new file.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6538 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'macosx/HBAddPresetController.m')
-rw-r--r-- | macosx/HBAddPresetController.m | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/macosx/HBAddPresetController.m b/macosx/HBAddPresetController.m new file mode 100644 index 000000000..c33610496 --- /dev/null +++ b/macosx/HBAddPresetController.m @@ -0,0 +1,138 @@ +// +// HBAddPresetController.m +// HandBrake +// +// Created by Damiano Galassi on 23/11/14. +// +// + +#import "HBAddPresetController.h" +#import "HBPreset.h" + +@interface HBAddPresetController () + +@property (assign) IBOutlet NSTextField *name; +@property (assign) IBOutlet NSTextField *desc; + +@property (assign) IBOutlet NSPopUpButton *picSettingsPopUp; +@property (assign) IBOutlet NSTextField *picWidth; +@property (assign) IBOutlet NSTextField *picHeight; +@property (assign) IBOutlet NSBox *picWidthHeightBox; + +@property (assign) IBOutlet NSButton *picFilters; + +@property (retain) HBPreset *preset; +@property NSSize size; + +@end + +@implementation HBAddPresetController + +- (instancetype)initWithPreset:(HBPreset *)preset videoSize:(NSSize)size; +{ + self = [super initWithWindowNibName:@"AddPreset"]; + if (self) + { + NSParameterAssert(preset); + _preset = [preset retain]; + _size = size; + } + return self; +} + +- (void)dealloc +{ + self.preset = nil;; + [super dealloc]; +} + +- (void)windowDidLoad { + [super windowDidLoad]; + + /* + * Populate the preset picture settings popup. + * + * Custom is not applicable when the anamorphic mode is Strict. + * + * Use [NSMenuItem tag] to store preset values for each option. + */ + [self.picSettingsPopUp addItemWithTitle:NSLocalizedString(@"None", @"")]; + [[self.picSettingsPopUp lastItem] setTag: 0]; + + if ([self.preset.content[@"PicturePAR"] integerValue] != HB_ANAMORPHIC_STRICT) + { + // not Strict, Custom is applicable + [self.picSettingsPopUp addItemWithTitle:NSLocalizedString(@"Custom", @"")]; + [[self.picSettingsPopUp lastItem] setTag: 1]; + } + [self.picSettingsPopUp addItemWithTitle:NSLocalizedString(@"Source Maximum (post source scan)", @"")]; + [[self.picSettingsPopUp lastItem] setTag: 2]; + + /* + * Default to Source Maximum for anamorphic Strict + * Default to Custom for all other anamorphic modes + */ + [self.picSettingsPopUp selectItemWithTag: (1 + ([self.preset.content[@"PicturePAR"] integerValue] == HB_ANAMORPHIC_STRICT))]; + /* Save the current filters in the preset by default */ + [self.picFilters setState:NSOnState]; + + /* Initialize custom height and width settings to current values */ + + [self.picWidth setStringValue: [NSString stringWithFormat:@"%d", (int)self.size.width]]; + [self.picHeight setStringValue: [NSString stringWithFormat:@"%d",(int)self.size.height]]; + [self addPresetPicDropdownChanged:nil]; +} + +- (IBAction)addPresetPicDropdownChanged:(id)sender +{ + if (self.picSettingsPopUp.selectedItem.tag == 1) + { + self.picWidthHeightBox.hidden = NO; + } + else + { + self.picWidthHeightBox.hidden = YES; + } +} + +- (IBAction)add:(id)sender +{ + if (self.name.stringValue.length == 0) + { + NSAlert *alert = [[NSAlert alloc] init]; + [alert setMessageText:NSLocalizedString(@"Warning!", @"")]; + [alert setInformativeText:NSLocalizedString(@"You need to insert a name for the preset.", @"")]; + [alert runModal]; + [alert release]; + } + else + { + self.preset.name = self.name.stringValue; + self.preset.presetDescription = self.name.stringValue; + + NSMutableDictionary *dict = [[self.preset.content mutableCopy] autorelease]; + + // Get the picture size + dict[@"PictureWidth"] = @(self.picWidth.integerValue); + dict[@"PictureHeight"] = @(self.picHeight.integerValue); + + //Get the whether or not to apply pic Size and Cropping (includes Anamorphic) + dict[@"UsesPictureSettings"] = @(self.picSettingsPopUp.selectedItem.tag); + + // Get whether or not to use the current Picture Filter settings for the preset + dict[@"UsesPictureFilters"] = @(self.picFilters.state); + + self.preset.content = [[dict copy] autorelease]; + + [[self window] orderOut:nil]; + [NSApp endSheet:[self window] returnCode:NSModalResponseContinue]; + } +} + +- (IBAction)cancel:(id)sender +{ + [[self window] orderOut:nil]; + [NSApp endSheet:[self window] returnCode:NSModalResponseAbort]; +} + +@end |