]> granicus.if.org Git - handbrake/commitdiff
MacGui: improve touch bar support, add touch bars to the add titles to queue and...
authorDamiano Galassi <damiog@gmail.com>
Tue, 16 Oct 2018 11:57:40 +0000 (13:57 +0200)
committerDamiano Galassi <damiog@gmail.com>
Tue, 16 Oct 2018 11:57:40 +0000 (13:57 +0200)
macosx/HBAddPresetController.m
macosx/HBController.m
macosx/HBCore.h
macosx/HBPresetsViewController.m
macosx/HBPreviewGenerator.m
macosx/HBTitleSelectionController.m

index ab011155b3fdfa81bcca2554410bcd5e8f51c35b..b29c516c539c8b389416db7ab6146a7089a529a8 100644 (file)
@@ -258,3 +258,51 @@ typedef NS_ENUM(NSUInteger, HBAddPresetControllerMode) {
 }
 
 @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
index c4a0c70e5ac08c992c6c5b419460eacae170232d..dec7906ee41c520380a6e1d1b02eb0e7e4d3c230 100644 (file)
@@ -226,8 +226,6 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext;
     fPresetsView = [[HBPresetsViewController alloc] initWithPresetManager:presetManager];
     fPresetsView.delegate = self;
 
-    fPresetsView.showHeader = YES;
-
     // Set up the presets popover
     self.presetsPopover = [[NSPopover alloc] init];
 
@@ -1544,6 +1542,7 @@ static NSTouchBarItemIdentifier HBTouchBarMain = @"fr.handbrake.mainWindowTouchB
 
 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";
@@ -1553,10 +1552,10 @@ 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;
 }
@@ -1583,6 +1582,16 @@ static NSTouchBarItemIdentifier HBTouchBarPreview = @"fr.handbrake.preview";
         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];
index fd802efa24e0b52a67eeaddf06a727e62d9de9f9..eb4d3920b9d7c2d73920c41d45906a6479eda7a1 100644 (file)
@@ -49,6 +49,13 @@ typedef void (^HBCoreCompletionHandler)(HBCoreResult result);
  * 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
 
index 0fe2fa47f9755decc668a217a7f88695f88ec0d7..470776b9b383ba925d6ab7bf96388790e14a8dfb 100644 (file)
@@ -79,6 +79,7 @@ static void *HBPresetsViewControllerContext = &HBPresetsViewControllerContext;
         _selectedPresetInternal = presetManager.defaultPreset;
         _expandedNodes = [[NSArray arrayWithArray:[[NSUserDefaults standardUserDefaults]
                                                    objectForKey:@"HBPreviewViewExpandedStatus"]] mutableCopy];
+        _showHeader = YES;
     }
     return self;
 }
index 6ac4e76bd06a7ea0a504985f3de71fb64d192559..fa486832c53be7ff7c18f5916b5d2379202be34a 100644 (file)
@@ -18,6 +18,7 @@
 @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;
 
@@ -59,6 +60,8 @@
 
 - (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);
index b0bf0a2fdd27747a33eb5c801b543c9d0e15e734..001e9c4d64b83c757e518ff44f45f6c84b196936 100644 (file)
 }
 
 @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