[vlc-devel] [PATCH] macosx: rework renderer menu to match the Qt interface

Felix Paul Kühne fkuehne at videolan.org
Sat Feb 3 14:26:09 CET 2018


From: Felix Paul Kühne <felix at feepk.net>

Discovery automatically runs for 20s when opening the menu and is terminated afterwards. The state is no longer displayed as it is implicit.

Further, this removes the nib object singleton of the renderer menu controller as this way of initialization is discouraged in modern Cocoa.
---
 modules/gui/macosx/UI/MainMenu.xib             | 32 ++++---------------
 modules/gui/macosx/VLCMainMenu.h               |  6 +++-
 modules/gui/macosx/VLCMainMenu.m               | 44 ++++++++++++++++++++++++--
 modules/gui/macosx/VLCRendererDiscovery.m      |  8 +++++
 modules/gui/macosx/VLCRendererMenuController.h | 10 +++---
 modules/gui/macosx/VLCRendererMenuController.m | 21 ++----------
 6 files changed, 70 insertions(+), 51 deletions(-)

diff --git a/modules/gui/macosx/UI/MainMenu.xib b/modules/gui/macosx/UI/MainMenu.xib
index 521b85a07f..7bfc630e91 100644
--- a/modules/gui/macosx/UI/MainMenu.xib
+++ b/modules/gui/macosx/UI/MainMenu.xib
@@ -1,9 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10117" systemVersion="16G1036" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="13771" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
     <dependencies>
         <deployment version="1070" identifier="macosx"/>
-        <development version="7000" identifier="xcode"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10117"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="13771"/>
+        <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
     <objects>
         <customObject id="-2" userLabel="File's Owner" customClass="VLCMainMenu">
@@ -106,6 +106,9 @@
                 <outlet property="rate_slowerLabel" destination="4600" id="vRN-S8-MSb"/>
                 <outlet property="rate_view" destination="4596" id="MPC-hG-6bj"/>
                 <outlet property="record" destination="5137" id="Ka3-jl-auY"/>
+                <outlet property="rendererMenu" destination="ODg-VN-8Tv" id="3Ox-BO-HyW"/>
+                <outlet property="rendererMenuItem" destination="wYl-A2-q30" id="obH-UF-FmA"/>
+                <outlet property="rendererNoneItem" destination="eE8-qf-9x9" id="Ol2-yz-0eF"/>
                 <outlet property="repeat" destination="5143" id="ulG-wD-gtG"/>
                 <outlet property="revealInFinder" destination="3945" id="z7n-A2-K5o"/>
                 <outlet property="save_playlist" destination="1599" id="spC-pk-6W4"/>
@@ -487,26 +490,13 @@
                                 <modifierMask key="keyEquivalentModifierMask"/>
                                 <menu key="submenu" title="Renderer" id="ODg-VN-8Tv">
                                     <items>
-                                        <menuItem title="Renderer discovery off" enabled="NO" id="kZC-S6-b2M">
-                                            <modifierMask key="keyEquivalentModifierMask"/>
-                                        </menuItem>
-                                        <menuItem title="Enable renderer discovery" id="5gR-ec-KSL">
-                                            <modifierMask key="keyEquivalentModifierMask"/>
-                                            <connections>
-                                                <action selector="toggleRendererDiscovery:" target="GfD-zq-JqC" id="tGk-pM-MVQ"/>
-                                            </connections>
-                                        </menuItem>
-                                        <menuItem isSeparatorItem="YES" id="sbF-Ji-lAl"/>
                                         <menuItem title="No Renderer" state="on" id="eE8-qf-9x9">
                                             <modifierMask key="keyEquivalentModifierMask"/>
                                             <connections>
-                                                <action selector="selectRenderer:" target="GfD-zq-JqC" id="JA3-zV-4I0"/>
+                                                <action selector="selectRenderer:" target="-2" id="80x-Dh-S0n"/>
                                             </connections>
                                         </menuItem>
                                     </items>
-                                    <connections>
-                                        <outlet property="delegate" destination="GfD-zq-JqC" id="9Fg-VF-zbg"/>
-                                    </connections>
                                 </menu>
                             </menuItem>
                             <menuItem title="Program" id="5150">
@@ -1083,14 +1073,6 @@
             </constraints>
             <point key="canvasLocation" x="296.5" y="285.5"/>
         </customView>
-        <customObject id="GfD-zq-JqC" customClass="VLCRendererMenuController">
-            <connections>
-                <outlet property="rendererDiscoveryState" destination="kZC-S6-b2M" id="Ur7-YL-R4x"/>
-                <outlet property="rendererDiscoveryToggle" destination="5gR-ec-KSL" id="CEI-18-tX4"/>
-                <outlet property="rendererMenu" destination="ODg-VN-8Tv" id="bMa-lk-ryz"/>
-                <outlet property="rendererNoneItem" destination="eE8-qf-9x9" id="p9J-VU-Dg9"/>
-            </connections>
-        </customObject>
         <userDefaultsController representsSharedInstance="YES" id="uFO-sP-uo6"/>
     </objects>
 </document>
diff --git a/modules/gui/macosx/VLCMainMenu.h b/modules/gui/macosx/VLCMainMenu.h
index 2c25d38ad4..777f681448 100644
--- a/modules/gui/macosx/VLCMainMenu.h
+++ b/modules/gui/macosx/VLCMainMenu.h
@@ -1,7 +1,7 @@
 /*****************************************************************************
  *MainMenu.h: MacOS X interface module
  *****************************************************************************
- *Copyright (C) 2011-2015 Felix Paul Kühne
+ *Copyright (C) 2011-2018 Felix Paul Kühne
  *$Id$
  *
  *Authors: Felix Paul Kühne <fkuehne -at- videolan -dot- org>
@@ -93,6 +93,9 @@
 @property (readwrite, weak) IBOutlet NSMenuItem *fwd;
 @property (readwrite, weak) IBOutlet NSMenuItem *bwd;
 @property (readwrite, weak) IBOutlet NSMenuItem *jumpToTime;
+ at property (readwrite, weak) IBOutlet NSMenu *rendererMenu;
+ at property (readwrite, weak) IBOutlet NSMenuItem *rendererMenuItem;
+ at property (readwrite, weak) IBOutlet NSMenuItem *rendererNoneItem;
 @property (readwrite, weak) IBOutlet NSMenuItem *program;
 @property (readwrite, weak) IBOutlet NSMenu *programMenu;
 @property (readwrite, weak) IBOutlet NSMenuItem *title;
@@ -251,6 +254,7 @@
 - (IBAction)setPlaybackRate:(id)sender;
 - (void)updatePlaybackRate;
 - (IBAction)toggleAtoBloop:(id)sender;
+- (IBAction)selectRenderer:(id)sender;
 
 - (IBAction)toggleFullscreen:(id)sender;
 - (IBAction)resizeVideoWindow:(id)sender;
diff --git a/modules/gui/macosx/VLCMainMenu.m b/modules/gui/macosx/VLCMainMenu.m
index 0951662946..80e9565676 100644
--- a/modules/gui/macosx/VLCMainMenu.m
+++ b/modules/gui/macosx/VLCMainMenu.m
@@ -1,7 +1,7 @@
 /*****************************************************************************
  *MainMenu.m: MacOS X interface module
  *****************************************************************************
- *Copyright (C) 2011-2015 Felix Paul Kühne
+ *Copyright (C) 2011-2018 Felix Paul Kühne
  *$Id$
  *
  *Authors: Felix Paul Kühne <fkuehne -at- videolan -dot- org>
@@ -50,21 +50,23 @@
 #import "VLCAddonsWindowController.h"
 #import "VLCTimeSelectionPanelController.h"
 #import "NSScreen+VLCAdditions.h"
+#import "VLCRendererMenuController.h"
 
 #ifdef HAVE_SPARKLE
 #import <Sparkle/Sparkle.h>
 #endif
 
- at interface VLCMainMenu()
+ at interface VLCMainMenu() <NSMenuDelegate>
 {
     VLCAboutWindowController *_aboutWindowController;
     VLCHelpWindowController  *_helpWindowController;
     VLCAddonsWindowController *_addonsController;
+    VLCRendererMenuController *_rendererMenuController;
+    NSTimer *_cancelRendererDiscoveryTimer;
 
     NSMenu *_playlistTableColumnsContextMenu;
 
     __strong VLCTimeSelectionPanelController *_timeSelectionPanel;
-
 }
 @end
 
@@ -206,6 +208,13 @@
 
     [self setSubmenusEnabled: FALSE];
 
+    /* configure playback / controls menu */
+    self.controlsMenu.delegate = self;
+    [_rendererNoneItem setState:NSOnState];
+    _rendererMenuController = [[VLCRendererMenuController alloc] init];
+    _rendererMenuController.rendererNoneItem = _rendererNoneItem;
+    _rendererMenuController.rendererMenu = _rendererMenu;
+
     [[NSNotificationCenter defaultCenter] addObserver: self
                                              selector: @selector(refreshVoutDeviceMenu:)
                                                  name: NSApplicationDidChangeScreenParametersNotification
@@ -394,6 +403,8 @@
     [_fwd setTitle: _NS("Step Forward")];
     [_bwd setTitle: _NS("Step Backward")];
     [_jumpToTime setTitle: _NS("Jump to Time")];
+    [_rendererMenuItem setTitle:_NS("Renderer")];
+    [_rendererNoneItem setTitle:_NS("No renderer")];
     [_program setTitle: _NS("Program")];
     [_programMenu setTitle: _NS("Program")];
     [_title setTitle: _NS("Title")];
@@ -847,6 +858,11 @@
     }
 }
 
+- (IBAction)selectRenderer:(id)sender
+{
+    [_rendererMenuController selectRenderer:sender];
+}
+
 #pragma mark - audio menu
 
 - (void)refreshAudioDeviceList
@@ -1561,6 +1577,28 @@
     }
 }
 
+#pragma mark - menu delegation
+
+- (void)menuWillOpen:(NSMenu *)menu
+{
+    [_cancelRendererDiscoveryTimer invalidate];
+    [_rendererMenuController startRendererDiscoveries];
+}
+
+- (void)menuDidClose:(NSMenu *)menu
+{
+    _cancelRendererDiscoveryTimer = [NSTimer scheduledTimerWithTimeInterval:20.
+                                                                     target:self
+                                                                   selector:@selector(cancelRendererDiscovery)
+                                                                   userInfo:nil
+                                                                    repeats:NO];
+}
+
+- (void)cancelRendererDiscovery
+{
+    [_rendererMenuController stopRendererDiscoveries];
+}
+
 @end
 
 @implementation VLCMainMenu (NSMenuValidation)
diff --git a/modules/gui/macosx/VLCRendererDiscovery.m b/modules/gui/macosx/VLCRendererDiscovery.m
index ff00f12609..198ca8ce4a 100644
--- a/modules/gui/macosx/VLCRendererDiscovery.m
+++ b/modules/gui/macosx/VLCRendererDiscovery.m
@@ -32,6 +32,7 @@
 {
     intf_thread_t               *p_intf;
     vlc_renderer_discovery_t    *p_rd;
+    BOOL                        _isRunning;
 }
 
 - (void)handleItemAdded:(vlc_renderer_item_t *)item;
@@ -77,6 +78,10 @@ static void renderer_event_item_removed(vlc_renderer_discovery_t *rd,
 
 - (bool)startDiscovery
 {
+    if (_isRunning) {
+        return YES;
+    }
+
     struct vlc_renderer_discovery_owner owner =
     {
         (__bridge void *) self,
@@ -91,10 +96,12 @@ static void renderer_event_item_removed(vlc_renderer_discovery_t *rd,
     p_rd = vlc_rd_new(VLC_OBJECT(p_intf), _name.UTF8String, &owner);
 
     if (!p_rd) {
+        _isRunning = NO;
         msg_Err(p_intf, "Could not create '%s' renderer discovery service", _name.UTF8String);
         return false;
     }
 
+    _isRunning = YES;
     return true;
 }
 
@@ -103,6 +110,7 @@ static void renderer_event_item_removed(vlc_renderer_discovery_t *rd,
     if (p_rd != NULL) {
         vlc_rd_release(p_rd);
         p_rd = NULL;
+        _isRunning = NO;
     }
 }
 
diff --git a/modules/gui/macosx/VLCRendererMenuController.h b/modules/gui/macosx/VLCRendererMenuController.h
index ae3d6df7f8..081264022a 100644
--- a/modules/gui/macosx/VLCRendererMenuController.h
+++ b/modules/gui/macosx/VLCRendererMenuController.h
@@ -28,9 +28,11 @@
 
 @interface VLCRendererMenuController : NSObject <VLCRendererDiscoveryDelegate>
 
- at property (readwrite, weak) IBOutlet NSMenu     *rendererMenu;
- at property (readwrite, weak) IBOutlet NSMenuItem *rendererDiscoveryState;
- at property (readwrite, weak) IBOutlet NSMenuItem *rendererDiscoveryToggle;
- at property (readwrite, weak) IBOutlet NSMenuItem *rendererNoneItem;
+ at property (readwrite, weak) NSMenu *rendererMenu;
+ at property (readwrite, weak) NSMenuItem *rendererNoneItem;
+
+- (void)startRendererDiscoveries;
+- (void)stopRendererDiscoveries;
+- (void)selectRenderer:(NSMenuItem *)sender;
 
 @end
diff --git a/modules/gui/macosx/VLCRendererMenuController.m b/modules/gui/macosx/VLCRendererMenuController.m
index bedfb38fa9..411a5b9125 100644
--- a/modules/gui/macosx/VLCRendererMenuController.m
+++ b/modules/gui/macosx/VLCRendererMenuController.m
@@ -1,10 +1,11 @@
 /*****************************************************************************
  * VLCRendererMenuController.m: Controller class for the renderer menu
  *****************************************************************************
- * Copyright (C) 2016 VLC authors and VideoLAN
+ * Copyright (C) 2016-2018 VLC authors and VideoLAN
  * $Id$
  *
  * Authors: Marvin Scholz <epirat07 at gmail dot com>
+ *          Felix Paul Kühne <fkuehne -at- videolan -dot- org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -59,7 +60,6 @@
 - (void)awakeFromNib
 {
     _selectedItem = _rendererNoneItem;
-    [self setupMenu];
 }
 
 - (void)dealloc
@@ -67,17 +67,6 @@
     [self stopRendererDiscoveries];
 }
 
-- (void)setupMenu
-{
-    [_rendererDiscoveryState setTitle:_NS("Renderer discovery off")];
-    [_rendererDiscoveryState setEnabled:NO];
-
-    [_rendererDiscoveryToggle setTitle:_NS("Enable renderer discovery")];
-
-    [_rendererNoneItem setTitle:_NS("No renderer")];
-    [_rendererNoneItem setState:NSOnState];
-}
-
 - (void)loadRendererDiscoveries
 {
     playlist_t *playlist = pl_Get(p_intf);
@@ -131,8 +120,6 @@
 - (void)startRendererDiscoveries
 {
     _isDiscoveryEnabled = YES;
-    [_rendererDiscoveryState setTitle:_NS("Renderer discovery on")];
-    [_rendererDiscoveryToggle setTitle:_NS("Disable renderer discovery")];
     for (VLCRendererDiscovery *dc in _rendererDiscoveries) {
         [dc startDiscovery];
     }
@@ -141,8 +128,6 @@
 - (void)stopRendererDiscoveries
 {
     _isDiscoveryEnabled = NO;
-    [_rendererDiscoveryState setTitle:_NS("Renderer discovery off")];
-    [_rendererDiscoveryToggle setTitle:_NS("Enable renderer discovery")];
     for (VLCRendererDiscovery *dc in _rendererDiscoveries) {
         [dc stopDiscovery];
     }
@@ -156,7 +141,7 @@
     return [menuItem isEnabled];
 }
 
-- (IBAction)selectRenderer:(NSMenuItem *)sender
+- (void)selectRenderer:(NSMenuItem *)sender
 {
     [_selectedItem setState:NSOffState];
     [sender setState:NSOnState];
-- 
2.16.1



More information about the vlc-devel mailing list