1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
|
/* HBAddPresetController.m
This file is part of the HandBrake source code.
Homepage: <http://handbrake.fr/>.
It may be used under the terms of the GNU General Public License. */
#import "HBAddPresetController.h"
#import "HBAddCategoryController.h"
#import "HBAudioDefaultsController.h"
#import "HBSubtitlesDefaultsController.h"
@interface HBAddPresetController ()
@property (nonatomic, unsafe_unretained) IBOutlet NSTextField *name;
@property (nonatomic, unsafe_unretained) IBOutlet NSTextField *desc;
@property (nonatomic, unsafe_unretained) IBOutlet NSPopUpButton *categories;
@property (nonatomic, unsafe_unretained) IBOutlet NSPopUpButton *picSettingsPopUp;
@property (nonatomic, unsafe_unretained) IBOutlet NSTextField *picWidth;
@property (nonatomic, unsafe_unretained) IBOutlet NSTextField *picHeight;
@property (nonatomic, unsafe_unretained) IBOutlet NSView *picWidthHeightBox;
@property (nonatomic, strong) HBPreset *preset;
@property (nonatomic, strong) HBMutablePreset *mutablePreset;
@property (nonatomic, strong) HBPreset *selectedCategory;
@property (nonatomic, strong) HBPresetsManager *manager;
@property (nonatomic) int width;
@property (nonatomic) int height;
@property (nonatomic) HBPictureResolutionLimitMode resolutionLimitMode;
@property (nonatomic, readwrite, strong) NSWindowController *defaultsController;
@end
@implementation HBAddPresetController
- (instancetype)initWithPreset:(HBPreset *)preset presetManager:(HBPresetsManager *)manager customWidth:(int)customWidth customHeight:(int)customHeight resolutionLimitMode:(HBPictureResolutionLimitMode)resolutionLimitMode
{
self = [super initWithWindowNibName:@"AddPreset"];
if (self)
{
NSParameterAssert(preset);
_mutablePreset = [preset mutableCopy];
[_mutablePreset resetBuiltInAndDefaultState];
_manager = manager;
_width = customWidth;
_height = customHeight;
_resolutionLimitMode = resolutionLimitMode;
}
return self;
}
- (void)windowDidLoad {
[super windowDidLoad];
// Build the categories menu, and select the first
[self buildCategoriesMenu];
if ([self.categories selectItemWithTag:2] == NO)
{
HBPreset *category = [[HBPreset alloc] initWithCategoryName:@"My Presets" builtIn:NO];
[self.manager addPreset:category];
NSMenuItem *item = [self buildMenuItemWithCategory:category];
[self.categories.menu insertItem:item atIndex:2];
[self.categories selectItemWithTag:2];
}
self.selectedCategory = self.categories.selectedItem.representedObject;
// Populate the preset picture settings popup.
// Use [NSMenuItem tag] to store preset values for each option.
[self.picSettingsPopUp addItemWithTitle:NSLocalizedString(@"None", @"Add preset window -> picture setting")];
[self.picSettingsPopUp.lastItem setTag:HBPictureResolutionLimitModeNone];
[self.picSettingsPopUp addItemWithTitle:NSLocalizedString(@"4320p 8K Ultra HD", @"Add preset window -> picture setting")];
[self.picSettingsPopUp.lastItem setTag:HBPictureResolutionLimitMode8K];
[self.picSettingsPopUp addItemWithTitle:NSLocalizedString(@"2160p 4K Ultra HD", @"Add preset window -> picture setting")];
[self.picSettingsPopUp.lastItem setTag:HBPictureResolutionLimitMode4K];
[self.picSettingsPopUp addItemWithTitle:NSLocalizedString(@"1440p 2.5K Quad HD", @"Add preset window -> picture setting")];
[self.picSettingsPopUp.lastItem setTag:HBPictureResolutionLimitMode1440p];
[self.picSettingsPopUp addItemWithTitle:NSLocalizedString(@"1080p HD", @"Add preset window -> picture setting")];
[self.picSettingsPopUp.lastItem setTag:HBPictureResolutionLimitMode1080p];
[self.picSettingsPopUp addItemWithTitle:NSLocalizedString(@"720p HD", @"Add preset window -> picture setting")];
[self.picSettingsPopUp.lastItem setTag:HBPictureResolutionLimitMode720p];
[self.picSettingsPopUp addItemWithTitle:NSLocalizedString(@"576p PAL SD", @"Add preset window -> picture setting")];
[self.picSettingsPopUp.lastItem setTag:HBPictureResolutionLimitMode576p];
[self.picSettingsPopUp addItemWithTitle:NSLocalizedString(@"480p NTSC SD", @"Add preset window -> picture setting")];
[self.picSettingsPopUp.lastItem setTag:HBPictureResolutionLimitMode480p];
[self.picSettingsPopUp addItemWithTitle:NSLocalizedString(@"Custom", @"Add preset window -> picture setting")];
[self.picSettingsPopUp.lastItem setTag:HBPictureResolutionLimitModeCustom];
[self.picSettingsPopUp selectItemWithTag:self.resolutionLimitMode];
// Initialize custom height and width settings to current values
[self.picWidth setIntValue:self.width];
[self.picHeight setIntValue:self.height];
[self addPresetPicDropdownChanged:nil];
}
/**
* Adds the presets list to the menu.
*/
- (void)buildCategoriesMenu
{
for (HBPreset *preset in self.manager.root.children)
{
if (preset.isBuiltIn == NO && preset.isLeaf == NO)
{
[self.categories.menu addItem:[self buildMenuItemWithCategory:preset]];
}
}
}
- (NSMenuItem *)buildMenuItemWithCategory:(HBPreset *)preset
{
NSMenuItem *item = [[NSMenuItem alloc] init];
item.title = preset.name;
item.toolTip = preset.presetDescription;
item.tag = 2;
item.action = @selector(selectCategoryFromMenu:);
item.representedObject = preset;
return item;
}
- (IBAction)showNewCategoryWindow:(id)sender
{
HBAddCategoryController *addCategoryController = [[HBAddCategoryController alloc] initWithPresetManager:self.manager];
[self.window beginSheet:addCategoryController.window completionHandler:^(NSModalResponse returnCode) {
if (returnCode == NSModalResponseOK)
{
NSMenuItem *item = [self buildMenuItemWithCategory:addCategoryController.category];
[self.categories.menu insertItem:item atIndex:2];
}
[self.categories selectItemWithTag:2];
[self selectCategoryFromMenu:self.categories.selectedItem];
}];
}
- (IBAction)selectCategoryFromMenu:(NSMenuItem *)sender
{
self.selectedCategory = sender.representedObject;
}
- (IBAction)addPresetPicDropdownChanged:(id)sender
{
self.picWidthHeightBox.hidden = self.picSettingsPopUp.selectedItem.tag != HBPictureResolutionLimitModeCustom;
}
- (IBAction)showAudioSettingsSheet:(id)sender
{
HBAudioDefaults *defaults = [[HBAudioDefaults alloc] init];
[defaults applyPreset:self.mutablePreset];
self.defaultsController = [[HBAudioDefaultsController alloc] initWithSettings:defaults];
[self.window beginSheet:self.defaultsController.window completionHandler:^(NSModalResponse returnCode) {
if (returnCode == NSModalResponseOK)
{
[defaults writeToPreset:self.mutablePreset];
}
self.defaultsController = nil;
}];
}
- (IBAction)showSubtitlesSettingsSheet:(id)sender
{
HBSubtitlesDefaults *defaults = [[HBSubtitlesDefaults alloc] init];
[defaults applyPreset:self.mutablePreset];
self.defaultsController = [[HBSubtitlesDefaultsController alloc] initWithSettings:defaults];
[self.window beginSheet:self.defaultsController.window completionHandler:^(NSModalResponse returnCode) {
if (returnCode == NSModalResponseOK)
{
[defaults writeToPreset:self.mutablePreset];
}
self.defaultsController = nil;
}];
}
- (IBAction)add:(id)sender
{
if (self.name.stringValue.length == 0)
{
NSAlert *alert = [[NSAlert alloc] init];
[alert setMessageText:NSLocalizedString(@"The preset name cannot be empty.", @"Add preset window -> name alert message")];
[alert setInformativeText:NSLocalizedString(@"Please enter a name.", @"Add preset window -> name alert informative text")];
[alert runModal];
}
else
{
HBMutablePreset *newPreset = self.mutablePreset;
newPreset.name = self.name.stringValue;
newPreset.presetDescription = self.desc.stringValue;
switch (self.picSettingsPopUp.selectedTag) {
case HBPictureResolutionLimitModeNone:
newPreset[@"PictureWidth"] = @(0);
newPreset[@"PictureHeight"] = @(0);
break;
case HBPictureResolutionLimitMode8K:
newPreset[@"PictureWidth"] = @(7680);
newPreset[@"PictureHeight"] = @(4320);
break;
case HBPictureResolutionLimitMode4K:
newPreset[@"PictureWidth"] = @(3840);
newPreset[@"PictureHeight"] = @(2160);
break;
case HBPictureResolutionLimitMode1440p:
newPreset[@"PictureWidth"] = @(2560);
newPreset[@"PictureHeight"] = @(1440);
break;
case HBPictureResolutionLimitMode1080p:
newPreset[@"PictureWidth"] = @(1920);
newPreset[@"PictureHeight"] = @(1080);
break;
case HBPictureResolutionLimitMode720p:
newPreset[@"PictureWidth"] = @(1280);
newPreset[@"PictureHeight"] = @(720);
break;
case HBPictureResolutionLimitMode576p:
newPreset[@"PictureWidth"] = @(720);
newPreset[@"PictureHeight"] = @(576);
break;
case HBPictureResolutionLimitMode480p:
newPreset[@"PictureWidth"] = @(720);
newPreset[@"PictureHeight"] = @(480);
break;
case HBPictureResolutionLimitModeCustom:
default:
newPreset[@"PictureWidth"] = @(self.picWidth.integerValue);
newPreset[@"PictureHeight"] = @(self.picHeight.integerValue);
break;
}
// Always use Picture Filter settings for the preset
newPreset[@"UsesPictureFilters"] = @YES;
[newPreset cleanUp];
self.preset = [newPreset copy];
[self.selectedCategory insertObject:self.preset inChildrenAtIndex:self.selectedCategory.countOfChildren];
[self.window.sheetParent endSheet:self.window returnCode:NSModalResponseOK];
}
}
- (IBAction)cancel:(id)sender
{
[self.window.sheetParent endSheet:self.window returnCode:NSModalResponseCancel];
}
- (IBAction)openUserGuide:(id)sender
{
[[NSWorkspace sharedWorkspace] openURL:[HBUtilities.documentationURL URLByAppendingPathComponent:@"advanced/custom-presets.html"]];
}
@end
@interface HBAddPresetController (TouchBar) <NSTouchBarProvider, NSTouchBarDelegate>
@end
@implementation HBAddPresetController (TouchBar)
@dynamic touchBar;
static NSTouchBarItemIdentifier HBTouchBarGroup = @"fr.handbrake.buttonsGroup";
static NSTouchBarItemIdentifier HBTouchBarAdd = @"fr.handbrake.openSource";
static NSTouchBarItemIdentifier HBTouchBarCancel = @"fr.handbrake.addToQueue";
- (NSTouchBar *)makeTouchBar
{
NSTouchBar *bar = [[NSTouchBar alloc] init];
bar.delegate = self;
bar.defaultItemIdentifiers = @[NSTouchBarItemIdentifierOtherItemsProxy, HBTouchBarGroup];
bar.principalItemIdentifier = HBTouchBarGroup;
return bar;
}
- (NSTouchBarItem *)touchBar:(NSTouchBar *)touchBar makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier
{
if ([identifier isEqualTo:HBTouchBarGroup])
{
NSCustomTouchBarItem *cancelItem = [[NSCustomTouchBarItem alloc] initWithIdentifier:HBTouchBarAdd];
cancelItem.customizationLabel = NSLocalizedString(@"Cancel", @"Touch bar");
NSButton *cancelButton = [NSButton buttonWithTitle:NSLocalizedString(@"Cancel", @"Touch bar") target:self action:@selector(cancel:)];
[cancelButton.widthAnchor constraintGreaterThanOrEqualToConstant:160].active = YES;
cancelItem.view = cancelButton;
NSCustomTouchBarItem *addItem = [[NSCustomTouchBarItem alloc] initWithIdentifier:HBTouchBarCancel];
addItem.customizationLabel = NSLocalizedString(@"Add Preset", @"Touch bar");
NSButton *addButton = [NSButton buttonWithTitle:NSLocalizedString(@"Add Preset", @"Touch bar") target:self action:@selector(add:)];
[addButton.widthAnchor constraintGreaterThanOrEqualToConstant:160].active = YES;
addButton.keyEquivalent = @"\r";
addItem.view = addButton;
NSGroupTouchBarItem *item = [NSGroupTouchBarItem groupItemWithIdentifier:identifier items:@[cancelItem, addItem]];
return item;
}
return nil;
}
@end
|