}
@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 = @[HBTouchBarGroup, NSTouchBarItemIdentifierOtherItemsProxy];
+ 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:200].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:200].active = YES;
+ addButton.keyEquivalent = @"\r";
+ addItem.view = addButton;
+
+ NSGroupTouchBarItem *item = [NSGroupTouchBarItem groupItemWithIdentifier:identifier items:@[cancelItem, addItem]];
+ return item;
+ }
+
+ return nil;
+}
+
+@end
fPresetsView = [[HBPresetsViewController alloc] initWithPresetManager:presetManager];
fPresetsView.delegate = self;
- fPresetsView.showHeader = YES;
-
// Set up the presets popover
self.presetsPopover = [[NSPopover alloc] init];
static NSTouchBarItemIdentifier HBTouchBarOpen = @"fr.handbrake.openSource";
static NSTouchBarItemIdentifier HBTouchBarAddToQueue = @"fr.handbrake.addToQueue";
+static NSTouchBarItemIdentifier HBTouchBarAddTitlesToQueue = @"fr.handbrake.addTitlesToQueue";
static NSTouchBarItemIdentifier HBTouchBarRip = @"fr.handbrake.rip";
static NSTouchBarItemIdentifier HBTouchBarPause = @"fr.handbrake.pause";
static NSTouchBarItemIdentifier HBTouchBarPreview = @"fr.handbrake.preview";
NSTouchBar *bar = [[NSTouchBar alloc] init];
bar.delegate = self;
- bar.defaultItemIdentifiers = @[HBTouchBarOpen, NSTouchBarItemIdentifierFixedSpaceSmall, HBTouchBarAddToQueue, NSTouchBarItemIdentifierFixedSpaceLarge, HBTouchBarRip, HBTouchBarPause, NSTouchBarItemIdentifierFixedSpaceLarge, HBTouchBarPreview];
+ bar.defaultItemIdentifiers = @[HBTouchBarOpen, NSTouchBarItemIdentifierFixedSpaceSmall, HBTouchBarAddToQueue, NSTouchBarItemIdentifierFixedSpaceLarge, HBTouchBarRip, HBTouchBarPause, NSTouchBarItemIdentifierFixedSpaceLarge, HBTouchBarPreview, NSTouchBarItemIdentifierOtherItemsProxy];
bar.customizationIdentifier = HBTouchBarMain;
- bar.customizationAllowedItemIdentifiers = @[HBTouchBarOpen, HBTouchBarAddToQueue, HBTouchBarRip, HBTouchBarPause, HBTouchBarPreview, NSTouchBarItemIdentifierFixedSpaceSmall, NSTouchBarItemIdentifierFixedSpaceLarge, NSTouchBarItemIdentifierFlexibleSpace];
+ bar.customizationAllowedItemIdentifiers = @[HBTouchBarOpen, HBTouchBarAddToQueue, HBTouchBarAddTitlesToQueue, HBTouchBarRip, HBTouchBarPause, HBTouchBarPreview, NSTouchBarItemIdentifierFixedSpaceSmall, NSTouchBarItemIdentifierFixedSpaceLarge, NSTouchBarItemIdentifierFlexibleSpace];
return bar;
}
item.view = button;
return item;
}
+ else if ([identifier isEqualTo:HBTouchBarAddTitlesToQueue])
+ {
+ NSCustomTouchBarItem *item = [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier];
+ item.customizationLabel = NSLocalizedString(@"Add Titles To Queue", @"Touch bar");
+
+ NSButton *button = [NSButton buttonWithTitle:NSLocalizedString(@"Add Titles To Queue", @"Touch bar") target:self action:@selector(addTitlesToQueue:)];
+
+ item.view = button;
+ return item;
+ }
else if ([identifier isEqualTo:HBTouchBarRip])
{
NSCustomTouchBarItem *item = [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier];
* HBCore is an Objective-C interface to the low-level HandBrake library.
* HBCore monitors state changes of libhb. It can also be used
* to implement properties that can be directly bound to elements of the gui.
+ *
+ * Instance methods must be called on the same queue as the queue
+ * passed to initWithLogLevel:queue:
+ * Convenience inits use the main queue by default.
+ *
+ * copyImageAtIndex: can be called on a different queue,
+ * but the caller must ensure the validity of the title.
*/
@interface HBCore : NSObject
_selectedPresetInternal = presetManager.defaultPreset;
_expandedNodes = [[NSArray arrayWithArray:[[NSUserDefaults standardUserDefaults]
objectForKey:@"HBPreviewViewExpandedStatus"]] mutableCopy];
+ _showHeader = YES;
}
return self;
}
@property (nonatomic, readonly) NSCache<NSNumber *, id> *smallPreviewsCache;
@property (nonatomic, readonly) dispatch_semaphore_t sem;
+@property (nonatomic, readonly) _Atomic bool invalidated;
@property (nonatomic, strong) HBCore *core;
- (void)dealloc
{
+ _invalidated = true;
+
[[NSNotificationCenter defaultCenter] removeObserver:self];
[[NSRunLoop mainRunLoop] cancelPerformSelectorsWithTarget:self];
[self.core cancelEncode];
- (void)copySmallImageAtIndex:(NSUInteger)index completionHandler:(void (^)(__nullable CGImageRef result))handler
{
dispatch_semaphore_wait(_sem, DISPATCH_TIME_FOREVER);
- if (index >= self.imagesCount)
+
+ if (_invalidated || index >= self.imagesCount)
{
handler(NULL);
dispatch_semaphore_signal(_sem);
}
@end
+
+@interface HBTitleSelectionController (TouchBar) <NSTouchBarProvider, NSTouchBarDelegate>
+@end
+
+@implementation HBTitleSelectionController (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 = @[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:200].active = YES;
+ cancelItem.view = cancelButton;
+
+ NSCustomTouchBarItem *addItem = [[NSCustomTouchBarItem alloc] initWithIdentifier:HBTouchBarCancel];
+ addItem.customizationLabel = NSLocalizedString(@"Add To Queue", @"Touch bar");
+ NSButton *addButton = [NSButton buttonWithTitle:NSLocalizedString(@"Add To Queue", @"Touch bar") target:self action:@selector(add:)];
+ [addButton.widthAnchor constraintGreaterThanOrEqualToConstant:200].active = YES;
+ addButton.keyEquivalent = @"\r";
+ addItem.view = addButton;
+
+ NSGroupTouchBarItem *item = [NSGroupTouchBarItem groupItemWithIdentifier:identifier items:@[cancelItem, addItem]];
+ return item;
+ }
+
+ return nil;
+}
+
+@end