Commit 9f935c4c authored by Marvin Scholz's avatar Marvin Scholz

macosx: Implement renderer discovery as NSMenu

parent 03e2e638
......@@ -57,7 +57,7 @@
1C3113ED1E508C6900D4DD76 /* VLCTimeSelectionPanelController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1CD3667A1B7A242E0054E39F /* VLCTimeSelectionPanelController.m */; };
1C3113EF1E508C7600D4DD76 /* VLCRendererDiscovery.m in Sources */ = {isa = PBXBuildFile; fileRef = 6BBBB8B61D114628001BD9BA /* VLCRendererDiscovery.m */; };
1C3113F11E508C7600D4DD76 /* VLCRendererItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 6BBBB8B11D10A994001BD9BA /* VLCRendererItem.m */; };
1C3113F31E508C7600D4DD76 /* VLCRendererDialog.m in Sources */ = {isa = PBXBuildFile; fileRef = 6BBBB8A81D108A17001BD9BA /* VLCRendererDialog.m */; };
1C3113F31E508C7600D4DD76 /* VLCRendererMenuController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6BBBB8A81D108A17001BD9BA /* VLCRendererMenuController.m */; };
1C3113F51E508C7600D4DD76 /* VLCHUDTextFieldCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B846FEA1CF5DBFF00112E54 /* VLCHUDTextFieldCell.m */; };
1C3113F71E508C7600D4DD76 /* VLCHUDButtonCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B846FDD1CF5D88C00112E54 /* VLCHUDButtonCell.m */; };
1C3113F91E508C7600D4DD76 /* VLCHUDCheckboxCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B846FDF1CF5D88C00112E54 /* VLCHUDCheckboxCell.m */; };
......@@ -695,8 +695,8 @@
6BBB05DF1EEFF165003A1019 /* VLCHUDTableCornerView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCHUDTableCornerView.m; sourceTree = "<group>"; };
6BBB05E11EF08181003A1019 /* VLCHUDSegmentedCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCHUDSegmentedCell.h; sourceTree = "<group>"; };
6BBB05E21EF08181003A1019 /* VLCHUDSegmentedCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCHUDSegmentedCell.m; sourceTree = "<group>"; };
6BBBB8A71D108A17001BD9BA /* VLCRendererDialog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCRendererDialog.h; sourceTree = "<group>"; };
6BBBB8A81D108A17001BD9BA /* VLCRendererDialog.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCRendererDialog.m; sourceTree = "<group>"; };
6BBBB8A71D108A17001BD9BA /* VLCRendererMenuController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCRendererMenuController.h; sourceTree = "<group>"; };
6BBBB8A81D108A17001BD9BA /* VLCRendererMenuController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCRendererMenuController.m; sourceTree = "<group>"; };
6BBBB8B01D10A994001BD9BA /* VLCRendererItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCRendererItem.h; sourceTree = "<group>"; };
6BBBB8B11D10A994001BD9BA /* VLCRendererItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCRendererItem.m; sourceTree = "<group>"; };
6BBBB8B51D114628001BD9BA /* VLCRendererDiscovery.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCRendererDiscovery.h; sourceTree = "<group>"; };
......@@ -1640,8 +1640,8 @@
6BBBB8B61D114628001BD9BA /* VLCRendererDiscovery.m */,
6BBBB8B01D10A994001BD9BA /* VLCRendererItem.h */,
6BBBB8B11D10A994001BD9BA /* VLCRendererItem.m */,
6BBBB8A71D108A17001BD9BA /* VLCRendererDialog.h */,
6BBBB8A81D108A17001BD9BA /* VLCRendererDialog.m */,
6BBBB8A71D108A17001BD9BA /* VLCRendererMenuController.h */,
6BBBB8A81D108A17001BD9BA /* VLCRendererMenuController.m */,
);
name = Renderers;
sourceTree = "<group>";
......@@ -1886,7 +1886,7 @@
1C31140D1E508C8800D4DD76 /* SPMediaKeyTap.m in Sources */,
1C3113EF1E508C7600D4DD76 /* VLCRendererDiscovery.m in Sources */,
1C3113F11E508C7600D4DD76 /* VLCRendererItem.m in Sources */,
1C3113F31E508C7600D4DD76 /* VLCRendererDialog.m in Sources */,
1C3113F31E508C7600D4DD76 /* VLCRendererMenuController.m in Sources */,
1C3113F51E508C7600D4DD76 /* VLCHUDTextFieldCell.m in Sources */,
1C3113F71E508C7600D4DD76 /* VLCHUDButtonCell.m in Sources */,
6B4D50931E7979CB004479B5 /* VLCSimplePrefsWindow.m in Sources */,
......
......@@ -87,7 +87,7 @@ libmacosx_plugin_la_SOURCES = \
gui/macosx/VLCMainWindow.h gui/macosx/VLCMainWindow.m \
gui/macosx/VLCRendererDiscovery.h gui/macosx/VLCRendererDiscovery.m \
gui/macosx/VLCRendererItem.h gui/macosx/VLCRendererItem.m \
gui/macosx/VLCRendererDialog.h gui/macosx/VLCRendererDialog.m \
gui/macosx/VLCRendererMenuController.h gui/macosx/VLCRendererMenuController.m \
gui/macosx/VLCResumeDialogController.h gui/macosx/VLCResumeDialogController.m \
gui/macosx/VLCTrackSynchronizationWindowController.h gui/macosx/VLCTrackSynchronizationWindowController.m \
gui/macosx/VLCVideoEffectsWindowController.h gui/macosx/VLCVideoEffectsWindowController.m \
......
......@@ -106,7 +106,6 @@
<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="renderer" destination="Rf6-Uj-7Ja" id="Nzc-Qb-SnK"/>
<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"/>
......@@ -484,11 +483,31 @@
<menuItem isSeparatorItem="YES" id="5154">
<modifierMask key="keyEquivalentModifierMask" command="YES"/>
</menuItem>
<menuItem title="Select Renderer…" id="Rf6-Uj-7Ja">
<menuItem title="Renderer" id="wYl-A2-q30">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="showRenderers:" target="-2" id="Y9L-YQ-3RJ"/>
</connections>
<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"/>
</connections>
</menuItem>
</items>
<connections>
<outlet property="delegate" destination="GfD-zq-JqC" id="9Fg-VF-zbg"/>
</connections>
</menu>
</menuItem>
<menuItem title="Program" id="5150">
<menu key="submenu" title="Program" id="5157"/>
......@@ -1060,6 +1079,14 @@
</constraints>
<point key="canvasLocation" x="479.5" y="564.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>
......@@ -99,7 +99,6 @@
@property (readwrite, weak) IBOutlet NSMenu *titleMenu;
@property (readwrite, weak) IBOutlet NSMenuItem *chapter;
@property (readwrite, weak) IBOutlet NSMenu *chapterMenu;
@property (readwrite, weak) IBOutlet NSMenuItem *renderer;
@property (readwrite, weak) IBOutlet NSMenu *audioMenu;
@property (readwrite, weak) IBOutlet NSMenuItem *vol_up;
......
......@@ -49,7 +49,6 @@
#import "VLCDebugMessageWindowController.h"
#import "VLCAddonsWindowController.h"
#import "VLCTimeSelectionPanelController.h"
#import "VLCRendererDialog.h"
#import "NSScreen+VLCAdditions.h"
#ifdef HAVE_SPARKLE
......@@ -61,7 +60,6 @@
VLCAboutWindowController *_aboutWindowController;
VLCHelpWindowController *_helpWindowController;
VLCAddonsWindowController *_addonsController;
VLCRendererDialog *_rendererDialog;
NSMenu *_playlistTableColumnsContextMenu;
......@@ -401,7 +399,6 @@
[_titleMenu setTitle: _NS("Title")];
[_chapter setTitle: _NS("Chapter")];
[_chapterMenu setTitle: _NS("Chapter")];
[_renderer setTitle: _NS("Select Renderer…")];
[_audioMenu setTitle: _NS("Audio")];
[_vol_up setTitle: _NS("Increase Volume")];
......@@ -1282,14 +1279,6 @@
[_helpWindowController showHelp];
}
- (IBAction)showRenderers:(id)sender
{
if (!_rendererDialog)
_rendererDialog = [[VLCRendererDialog alloc] init];
[_rendererDialog showWindow:self];
}
- (IBAction)openDocumentation:(id)sender
{
NSURL *url = [NSURL URLWithString: @"http://www.videolan.org/doc/"];
......
/*****************************************************************************
* VLCRendererDialog.h: View controller class for the renderer dialog
* VLCRendererDialog.h: Controller class for the renderer menu
*****************************************************************************
* Copyright (C) 2016 VLC authors and VideoLAN
* $Id$
......@@ -26,14 +26,11 @@
#import "VLCRendererItem.h"
#import "VLCRendererDiscovery.h"
@interface VLCRendererDialog : NSWindowController <VLCRendererDiscoveryDelegate, NSWindowDelegate>
@interface VLCRendererMenuController : NSObject <VLCRendererDiscoveryDelegate>
#ifdef MAC_OS_X_VERSION_10_11
@property NSMutableArray<VLCRendererItem*> *rendererItems;
#else
@property NSMutableArray *rendererItems;
#endif
- (IBAction)selectRenderer:(id)sender;
@property (readwrite, weak) IBOutlet NSMenu *rendererMenu;
@property (readwrite, weak) IBOutlet NSMenuItem *rendererDiscoveryState;
@property (readwrite, weak) IBOutlet NSMenuItem *rendererDiscoveryToggle;
@property (readwrite, weak) IBOutlet NSMenuItem *rendererNoneItem;
@end
/*****************************************************************************
* VLCRendererDialog.m: View controller class for the renderer dialog
* VLCRendererDialog.m: Controller class for the renderer menu
*****************************************************************************
* Copyright (C) 2016 VLC authors and VideoLAN
* $Id$
......@@ -21,69 +21,61 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#import "VLCRendererDialog.h"
#import "VLCRendererMenuController.h"
#import "VLCRendererItem.h"
#import "VLCMain.h"
#include <vlc_renderer_discovery.h>
@interface VLCRendererDialog ()
@interface VLCRendererMenuController ()
{
IBOutlet NSTableView *tableView;
IBOutlet NSArrayController *arrayController;
#ifdef MAC_OS_X_VERSION_10_11
NSMutableArray<VLCRendererDiscovery*> *renderer_discoveries;
#else
NSMutableArray *renderer_discoveries;
#endif
NSMutableDictionary *_rendererItems;
NSMutableArray *_rendererDiscoveries;
BOOL _isDiscoveryEnabled;
NSMenuItem *_selectedItem;
intf_thread_t *p_intf;
vlc_renderer_discovery_t *p_rd;
intf_thread_t *p_intf;
vlc_renderer_discovery_t *p_rd;
}
@end
@implementation VLCRendererDialog
@implementation VLCRendererMenuController
- (id)init
- (instancetype)init
{
self = [super initWithWindowNibName:@"VLCRendererDialog"];
self = [super init];
if (self) {
_rendererItems = [[NSMutableArray alloc] init];
renderer_discoveries = [[NSMutableArray alloc] initWithCapacity:1];
_rendererItems = [NSMutableDictionary dictionary];
_rendererDiscoveries = [NSMutableArray array];
_isDiscoveryEnabled = NO;
p_intf = getIntf();
[self loadRendererDiscoveries];
}
return self;
}
- (void)dealloc
- (void)awakeFromNib
{
[self stopRendererDiscoveries];
[self clearRendererDiscoveries];
_selectedItem = _rendererNoneItem;
[self setupMenu];
}
- (void)windowDidLoad
{
[super windowDidLoad];
[self.window setDelegate:self];
[self.window setTitle:_NS("Renderer selection")];
[self loadRendererDiscoveries];
}
- (void)windowWillClose:(NSNotification *)notification
- (void)dealloc
{
// Stop all renderer discoveries here!
[self stopRendererDiscoveries];
}
- (void)showWindow:(id)sender
- (void)setupMenu
{
// Start all renderer discoveries here!
[self startRendererDiscoveries];
return [super showWindow:sender];
[_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
......@@ -103,8 +95,7 @@
for( ; *ppsz_name; ppsz_name++, ppsz_longname++) {
VLCRendererDiscovery *dc = [[VLCRendererDiscovery alloc] initWithName:*ppsz_name andLongname:*ppsz_longname];
[dc setDelegate:self];
[dc startDiscovery];
[renderer_discoveries addObject:dc];
[_rendererDiscoveries addObject:dc];
free(*ppsz_name);
free(*ppsz_longnames);
}
......@@ -112,29 +103,71 @@
free(ppsz_longnames);
}
- (void)clearRendererDiscoveries
#pragma mark - Renderer item management
- (void)addRendererItem:(VLCRendererItem *)item
{
[renderer_discoveries removeAllObjects];
// Create a menu item
NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle:item.name
action:@selector(selectRenderer:)
keyEquivalent:@""];
[menuItem setTarget:self];
[menuItem setRepresentedObject:item];
[_rendererMenu insertItem:menuItem atIndex:[_rendererMenu indexOfItem:_rendererNoneItem] + 1];
}
- (void)removeRendererItem:(VLCRendererItem *)item
{
NSInteger index = [_rendererMenu indexOfItemWithRepresentedObject:item];
if (index != NSNotFound) {
NSMenuItem *menuItem = [_rendererMenu itemAtIndex:index];
if (menuItem == _selectedItem) {
[self selectRenderer:_rendererNoneItem];
}
[_rendererMenu removeItemAtIndex:index];
}
}
- (void)startRendererDiscoveries
{
for (VLCRendererDiscovery *dc in renderer_discoveries) {
_isDiscoveryEnabled = YES;
[_rendererDiscoveryState setTitle:_NS("Renderer discovery on")];
[_rendererDiscoveryToggle setTitle:_NS("Disable renderer discovery")];
for (VLCRendererDiscovery *dc in _rendererDiscoveries) {
[dc startDiscovery];
}
}
- (void)stopRendererDiscoveries
{
for (VLCRendererDiscovery *dc in renderer_discoveries) {
_isDiscoveryEnabled = NO;
[_rendererDiscoveryState setTitle:_NS("Renderer discovery off")];
[_rendererDiscoveryToggle setTitle:_NS("Enable renderer discovery")];
for (VLCRendererDiscovery *dc in _rendererDiscoveries) {
[dc stopDiscovery];
}
}
- (IBAction)selectRenderer:(id)sender
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem {
if (menuItem == _rendererNoneItem ||
[[menuItem representedObject] isKindOfClass:[VLCRendererItem class]]) {
return _isDiscoveryEnabled;
}
return [menuItem isEnabled];
}
- (IBAction)selectRenderer:(NSMenuItem *)sender
{
[_selectedItem setState:NSOffState];
[sender setState:NSOnState];
_selectedItem = sender;
VLCRendererItem* item = [sender representedObject];
playlist_t *playlist = pl_Get(p_intf);
VLCRendererItem* item = [arrayController.selectedObjects firstObject];
if (!playlist)
return;
if (item) {
[item setSoutForPlaylist:playlist];
} else {
......@@ -147,15 +180,24 @@
var_SetString(playlist, "sout", "");
}
#pragma mark VLCRendererDiscoveryDelegate methods
#pragma mark VLCRendererDiscovery delegate methods
- (void)addedRendererItem:(VLCRendererItem *)item from:(VLCRendererDiscovery *)sender
{
[arrayController addObject:item];
[self addRendererItem:item];
}
- (void)removedRendererItem:(VLCRendererItem *)item from:(VLCRendererDiscovery *)sender
{
[arrayController removeObject:item];
[self removeRendererItem:item];
}
#pragma mark Menu actions
- (IBAction)toggleRendererDiscovery:(id)sender {
if (_isDiscoveryEnabled) {
[self stopRendererDiscoveries];
} else {
[self startRendererDiscoveries];
}
}
@end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment