From 5a20ab2751a20962fe523e8418be6ae886dd68cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Paul=20K=C3=BChne?= <felix@feepk.net> Date: Sun, 30 Jun 2019 16:31:21 +0200 Subject: [PATCH] macosx: add custom cell to list media source contents --- .../macosx/VLC.xcodeproj/project.pbxproj | 8 + modules/gui/macosx/Makefile.am | 3 + .../UI/VLCMediaSourceCollectionViewItem.xib | 96 +++++++++ .../VLCMediaSourceBaseDataSource.m | 2 + .../VLCMediaSourceCollectionViewItem.h | 47 +++++ .../VLCMediaSourceCollectionViewItem.m | 188 ++++++++++++++++++ .../media-source/VLCMediaSourceDataSource.m | 13 +- po/POTFILES.in | 2 + 8 files changed, 349 insertions(+), 10 deletions(-) create mode 100644 modules/gui/macosx/UI/VLCMediaSourceCollectionViewItem.xib create mode 100644 modules/gui/macosx/media-source/VLCMediaSourceCollectionViewItem.h create mode 100644 modules/gui/macosx/media-source/VLCMediaSourceCollectionViewItem.m diff --git a/extras/package/macosx/VLC.xcodeproj/project.pbxproj b/extras/package/macosx/VLC.xcodeproj/project.pbxproj index bde06554ef1c..d72b5e6ecd44 100644 --- a/extras/package/macosx/VLC.xcodeproj/project.pbxproj +++ b/extras/package/macosx/VLC.xcodeproj/project.pbxproj @@ -123,6 +123,7 @@ 7D66D4362200BC340040D04A /* VLCClickerManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D66D4352200BC340040D04A /* VLCClickerManager.m */; }; 7D66D4392200C5B80040D04A /* VLCVideoFilterHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D66D4382200C5B80040D04A /* VLCVideoFilterHelper.m */; }; 7D66D43C2200D6090040D04A /* VLCDetachedVideoWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D66D43B2200D6090040D04A /* VLCDetachedVideoWindow.m */; }; + 7D67318622C8F4060000AD40 /* VLCMediaSourceCollectionViewItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D67318422C8F4050000AD40 /* VLCMediaSourceCollectionViewItem.m */; }; 7D713D322201AE350042BEB7 /* VLCLibraryWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D713D312201AE350042BEB7 /* VLCLibraryWindow.m */; }; 7D713D362201DC640042BEB7 /* VLCLibraryWindow.xib in Sources */ = {isa = PBXBuildFile; fileRef = 7D713D332201BB130042BEB7 /* VLCLibraryWindow.xib */; }; 7D903E0E22438F8F00917358 /* error.c in Sources */ = {isa = PBXBuildFile; fileRef = 1C64E331223DB3B60046F895 /* error.c */; }; @@ -509,6 +510,9 @@ 7D66D4382200C5B80040D04A /* VLCVideoFilterHelper.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCVideoFilterHelper.m; sourceTree = "<group>"; }; 7D66D43A2200D6090040D04A /* VLCDetachedVideoWindow.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCDetachedVideoWindow.h; sourceTree = "<group>"; }; 7D66D43B2200D6090040D04A /* VLCDetachedVideoWindow.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCDetachedVideoWindow.m; sourceTree = "<group>"; }; + 7D67318322C8F3F60000AD40 /* VLCMediaSourceCollectionViewItem.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = VLCMediaSourceCollectionViewItem.xib; sourceTree = "<group>"; }; + 7D67318422C8F4050000AD40 /* VLCMediaSourceCollectionViewItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCMediaSourceCollectionViewItem.m; sourceTree = "<group>"; }; + 7D67318522C8F4050000AD40 /* VLCMediaSourceCollectionViewItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCMediaSourceCollectionViewItem.h; sourceTree = "<group>"; }; 7D713D302201AE350042BEB7 /* VLCLibraryWindow.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCLibraryWindow.h; sourceTree = "<group>"; }; 7D713D312201AE350042BEB7 /* VLCLibraryWindow.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCLibraryWindow.m; sourceTree = "<group>"; }; 7D713D332201BB130042BEB7 /* VLCLibraryWindow.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = VLCLibraryWindow.xib; sourceTree = "<group>"; }; @@ -1423,6 +1427,8 @@ 7DFBDCC3226E445500B700A5 /* VLCMediaSourceBaseDataSource.m */, 7D2554C022C8A39300F2D9C2 /* VLCMediaSourceDataSource.h */, 7D2554C122C8A39300F2D9C2 /* VLCMediaSourceDataSource.m */, + 7D67318522C8F4050000AD40 /* VLCMediaSourceCollectionViewItem.h */, + 7D67318422C8F4050000AD40 /* VLCMediaSourceCollectionViewItem.m */, 7D2554C422C8E8B500F2D9C2 /* VLCMediaSourceDeviceCollectionViewItem.h */, 7D2554C322C8E8B400F2D9C2 /* VLCMediaSourceDeviceCollectionViewItem.m */, ); @@ -1535,6 +1541,7 @@ 7D0F64052202047900FDB91F /* VLCLibraryCollectionViewItem.xib */, 7DE2F0482282D7980040DD0A /* VLCLibraryTableCellView.xib */, 7DE82E7A228437AA002D341A /* VLCLibraryAlbumTableCellView.xib */, + 7D67318322C8F3F60000AD40 /* VLCMediaSourceCollectionViewItem.xib */, 7DF14FBC2270CB1C0008ABE4 /* VLCMediaSourceDeviceCollectionViewItem.xib */, 6B82241A1E4D2A9000833BE1 /* VLCStatusBarIconMainMenu.xib */, 6B8224181E4D2A9000833BE1 /* VLCFullScreenPanel.xib */, @@ -1677,6 +1684,7 @@ 7DE7232E22A51F8D00D72616 /* VLCPositionFormatter.m in Sources */, 1CCC89032078A3D500E5626F /* SimplePreferences.xib in Sources */, 7DE82E7922843781002D341A /* VLCLibraryAlbumTableCellView.m in Sources */, + 7D67318622C8F4060000AD40 /* VLCMediaSourceCollectionViewItem.m in Sources */, 1CCC89042078A3D500E5626F /* StreamOutput.xib in Sources */, 1CCC89052078A3D500E5626F /* TextfieldPanel.xib in Sources */, 1CCC89062078A3D500E5626F /* TimeSelectionPanel.xib in Sources */, diff --git a/modules/gui/macosx/Makefile.am b/modules/gui/macosx/Makefile.am index 953812c175e0..1ba4d436b270 100644 --- a/modules/gui/macosx/Makefile.am +++ b/modules/gui/macosx/Makefile.am @@ -91,6 +91,8 @@ libmacosx_plugin_la_SOURCES = \ gui/macosx/media-source/VLCMediaSource.m \ gui/macosx/media-source/VLCMediaSourceBaseDataSource.h \ gui/macosx/media-source/VLCMediaSourceBaseDataSource.m \ + gui/macosx/media-source/VLCMediaSourceCollectionViewItem.h \ + gui/macosx/media-source/VLCMediaSourceCollectionViewItem.m \ gui/macosx/media-source/VLCMediaSourceDataSource.h \ gui/macosx/media-source/VLCMediaSourceDataSource.m \ gui/macosx/media-source/VLCMediaSourceDeviceCollectionViewItem.h \ @@ -274,6 +276,7 @@ libmacosx_plugin_la_XIB_SOURCES = \ gui/macosx/UI/VLCLibraryTableCellView.xib \ gui/macosx/UI/VLCPlaylistTableCellView.xib \ gui/macosx/UI/VLCLibraryCollectionViewItem.xib \ + gui/macosx/UI/VLCMediaSourceCollectionViewItem.xib \ gui/macosx/UI/VLCMediaSourceDeviceCollectionViewItem.xib \ gui/macosx/UI/MediaInfo.xib \ gui/macosx/UI/Open.xib \ diff --git a/modules/gui/macosx/UI/VLCMediaSourceCollectionViewItem.xib b/modules/gui/macosx/UI/VLCMediaSourceCollectionViewItem.xib new file mode 100644 index 000000000000..c0f3941db81b --- /dev/null +++ b/modules/gui/macosx/UI/VLCMediaSourceCollectionViewItem.xib @@ -0,0 +1,96 @@ +<?xml version="1.0" encoding="UTF-8"?> +<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct"> + <dependencies> + <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14490.70"/> + <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> + </dependencies> + <objects> + <customObject id="-2" userLabel="File's Owner" customClass="VLCMediaSourceCollectionViewItem"> + <connections> + <outlet property="addToPlaylistButton" destination="Ubz-8I-W2F" id="ywN-PH-QZt"/> + <outlet property="annotationTextField" destination="kHQ-HZ-YIi" id="XX9-Sc-oam"/> + <outlet property="mediaImageView" destination="2aB-sB-hfY" id="Sv0-G1-KNm"/> + <outlet property="mediaTitleTextField" destination="OBS-Eh-1mT" id="h1n-PU-IAx"/> + <outlet property="playInstantlyButton" destination="S3I-5Z-qgS" id="VV4-Lu-IMq"/> + <outlet property="view" destination="Hz6-mo-xeY" id="0bl-1N-x8E"/> + </connections> + </customObject> + <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/> + <customObject id="-3" userLabel="Application" customClass="NSObject"/> + <customView id="Hz6-mo-xeY" customClass="VLCTrackingView"> + <rect key="frame" x="0.0" y="0.0" width="256" height="214"/> + <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> + <subviews> + <customView translatesAutoresizingMaskIntoConstraints="NO" id="2aB-sB-hfY" customClass="VLCImageView"> + <rect key="frame" x="0.0" y="32" width="256" height="182"/> + <subviews> + <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="S3I-5Z-qgS"> + <rect key="frame" x="96" y="59" width="64" height="64"/> + <buttonCell key="cell" type="square" bezelStyle="shadowlessSquare" image="libraryPlay" imagePosition="only" alignment="center" inset="2" id="IHP-p1-d0R"> + <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/> + <font key="font" metaFont="system"/> + </buttonCell> + <connections> + <action selector="playInstantly:" target="-2" id="fi3-0G-oEM"/> + </connections> + </button> + <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="kHQ-HZ-YIi" customClass="VLCRoundedCornerTextField"> + <rect key="frame" x="5" y="155" width="37" height="17"/> + <textFieldCell key="cell" lineBreakMode="clipping" title="Label" id="F0j-LH-r6g"> + <font key="font" metaFont="system"/> + <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/> + <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/> + </textFieldCell> + </textField> + </subviews> + <constraints> + <constraint firstItem="kHQ-HZ-YIi" firstAttribute="top" secondItem="2aB-sB-hfY" secondAttribute="top" constant="10" id="1we-Fw-12H"/> + <constraint firstItem="S3I-5Z-qgS" firstAttribute="centerX" secondItem="2aB-sB-hfY" secondAttribute="centerX" id="Seo-tS-piW"/> + <constraint firstItem="S3I-5Z-qgS" firstAttribute="centerY" secondItem="2aB-sB-hfY" secondAttribute="centerY" id="ZWU-oW-OVa"/> + <constraint firstItem="kHQ-HZ-YIi" firstAttribute="leading" secondItem="2aB-sB-hfY" secondAttribute="leading" constant="7" id="s9g-G1-oCF"/> + </constraints> + </customView> + <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="OBS-Eh-1mT"> + <rect key="frame" x="-2" y="4" width="52" height="24"/> + <constraints> + <constraint firstAttribute="height" constant="24" id="wMC-00-Vuv"/> + </constraints> + <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" title="Label" usesSingleLineMode="YES" id="7Hy-o3-LvX"> + <font key="font" size="20" name=".AppleSystemUIFont"/> + <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/> + <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/> + </textFieldCell> + </textField> + <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Ubz-8I-W2F"> + <rect key="frame" x="222" y="187" width="20" height="20"/> + <constraints> + <constraint firstAttribute="width" constant="20" id="XhX-7U-Nxj"/> + <constraint firstAttribute="height" constant="20" id="ZDT-YM-Cbr"/> + </constraints> + <buttonCell key="cell" type="square" bezelStyle="shadowlessSquare" image="ellipsis" imagePosition="only" alignment="center" inset="2" id="6ko-MM-ds0"> + <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/> + <font key="font" metaFont="system"/> + </buttonCell> + <connections> + <action selector="addToPlaylist:" target="-2" id="Lxc-A8-UMA"/> + </connections> + </button> + </subviews> + <constraints> + <constraint firstItem="2aB-sB-hfY" firstAttribute="top" secondItem="Hz6-mo-xeY" secondAttribute="top" id="3Ah-0T-rA9"/> + <constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="OBS-Eh-1mT" secondAttribute="trailing" id="457-oy-EbD"/> + <constraint firstItem="Ubz-8I-W2F" firstAttribute="top" secondItem="Hz6-mo-xeY" secondAttribute="top" constant="7" id="8Qf-Un-Gdl"/> + <constraint firstAttribute="trailing" secondItem="Ubz-8I-W2F" secondAttribute="trailing" constant="14" id="ZVz-SL-rxZ"/> + <constraint firstAttribute="bottom" secondItem="OBS-Eh-1mT" secondAttribute="bottom" constant="4" id="d6E-7J-S2d"/> + <constraint firstAttribute="trailing" secondItem="2aB-sB-hfY" secondAttribute="trailing" id="oZw-Ab-83p"/> + <constraint firstItem="2aB-sB-hfY" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" id="t9g-tX-AQX"/> + <constraint firstItem="OBS-Eh-1mT" firstAttribute="top" secondItem="2aB-sB-hfY" secondAttribute="bottom" constant="4" id="vJy-Kf-4Jh"/> + <constraint firstItem="OBS-Eh-1mT" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" id="yvp-xr-geN"/> + </constraints> + </customView> + </objects> + <resources> + <image name="ellipsis" width="17" height="3"/> + <image name="libraryPlay" width="64" height="64"/> + </resources> +</document> diff --git a/modules/gui/macosx/media-source/VLCMediaSourceBaseDataSource.m b/modules/gui/macosx/media-source/VLCMediaSourceBaseDataSource.m index 47a73009fab1..e574912f4a4e 100644 --- a/modules/gui/macosx/media-source/VLCMediaSourceBaseDataSource.m +++ b/modules/gui/macosx/media-source/VLCMediaSourceBaseDataSource.m @@ -25,6 +25,7 @@ #import "media-source/VLCMediaSourceProvider.h" #import "media-source/VLCMediaSource.h" #import "media-source/VLCMediaSourceDeviceCollectionViewItem.h" +#import "media-source/VLCMediaSourceCollectionViewItem.h" #import "media-source/VLCMediaSourceDataSource.h" #import "main/VLCMain.h" @@ -73,6 +74,7 @@ self.collectionView.dataSource = self; self.collectionView.delegate = self; [self.collectionView registerClass:[VLCMediaSourceDeviceCollectionViewItem class] forItemWithIdentifier:VLCMediaSourceDeviceCellIdentifier]; + [self.collectionView registerClass:[VLCMediaSourceCollectionViewItem class] forItemWithIdentifier:VLCMediaSourceCellIdentifier]; self.homeButton.action = @selector(homeButtonAction:); self.homeButton.target = self; diff --git a/modules/gui/macosx/media-source/VLCMediaSourceCollectionViewItem.h b/modules/gui/macosx/media-source/VLCMediaSourceCollectionViewItem.h new file mode 100644 index 000000000000..30dac451ce08 --- /dev/null +++ b/modules/gui/macosx/media-source/VLCMediaSourceCollectionViewItem.h @@ -0,0 +1,47 @@ +/***************************************************************************** + * VLCMediaSourceCollectionViewItem.h: MacOS X interface module + ***************************************************************************** + * Copyright (C) 2019 VLC authors and VideoLAN + * + * Authors: Felix Paul Kühne <fkuehne # 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + *****************************************************************************/ + +#import <Cocoa/Cocoa.h> + +NS_ASSUME_NONNULL_BEGIN + +extern NSString *VLCMediaSourceCellIdentifier; + +@class VLCImageView; +@class VLCInputItem; + +@interface VLCMediaSourceCollectionViewItem : NSCollectionViewItem + +@property (readwrite, assign) IBOutlet NSTextField *mediaTitleTextField; +@property (readwrite, assign) IBOutlet NSTextField *annotationTextField; +@property (readwrite, assign) IBOutlet VLCImageView *mediaImageView; +@property (readwrite, assign) IBOutlet NSButton *playInstantlyButton; +@property (readwrite, assign) IBOutlet NSButton *addToPlaylistButton; + +@property (readwrite, strong, nonatomic) VLCInputItem *representedInputItem; + +- (IBAction)playInstantly:(id)sender; +- (IBAction)addToPlaylist:(id)sender; + +@end + +NS_ASSUME_NONNULL_END diff --git a/modules/gui/macosx/media-source/VLCMediaSourceCollectionViewItem.m b/modules/gui/macosx/media-source/VLCMediaSourceCollectionViewItem.m new file mode 100644 index 000000000000..a90d68d62862 --- /dev/null +++ b/modules/gui/macosx/media-source/VLCMediaSourceCollectionViewItem.m @@ -0,0 +1,188 @@ +/***************************************************************************** + * VLCMediaSourceCollectionViewItem.m: MacOS X interface module + ***************************************************************************** + * Copyright (C) 2019 VLC authors and VideoLAN + * + * Authors: Felix Paul Kühne <fkuehne # 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + *****************************************************************************/ + +#import "VLCMediaSourceCollectionViewItem.h" + +#import "main/VLCMain.h" +#import "views/VLCImageView.h" +#import "views/VLCTrackingView.h" +#import "extensions/NSString+Helpers.h" +#import "extensions/NSFont+VLCAdditions.h" +#import "extensions/NSColor+VLCAdditions.h" +#import "extensions/NSView+VLCAdditions.h" +#import "library/VLCInputItem.h" +#import "playlist/VLCPlaylistController.h" + +NSString *VLCMediaSourceCellIdentifier = @"VLCLibraryCellIdentifier"; + +@implementation VLCMediaSourceCollectionViewItem + +- (instancetype)initWithNibName:(NSNibName)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil +{ + self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; + if (self) { + NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; + [notificationCenter addObserver:self + selector:@selector(updateFontBasedOnSetting:) + name:VLCConfigurationChangedNotification + object:nil]; + } + return self; +} + +- (void)dealloc +{ + [[NSNotificationCenter defaultCenter] removeObserver:self]; + if (@available(macOS 10_14, *)) { + [[NSApplication sharedApplication] removeObserver:self forKeyPath:@"effectiveAppearance"]; + } +} + +- (void)awakeFromNib +{ + [(VLCTrackingView *)self.view setViewToHide:self.playInstantlyButton]; + self.annotationTextField.font = [NSFont VLClibraryCellAnnotationFont]; + self.annotationTextField.textColor = [NSColor VLClibraryAnnotationColor]; + self.annotationTextField.backgroundColor = [NSColor VLClibraryAnnotationBackgroundColor]; + + if (@available(macOS 10_14, *)) { + [[NSApplication sharedApplication] addObserver:self + forKeyPath:@"effectiveAppearance" + options:0 + context:nil]; + } + + [self updateColoredAppearance]; + [self updateFontBasedOnSetting:nil]; + [self prepareForReuse]; +} + +#pragma mark - dynamic appearance + +- (void)observeValueForKeyPath:(NSString *)keyPath + ofObject:(id)object + change:(NSDictionary<NSKeyValueChangeKey,id> *)change + context:(void *)context +{ + [self updateColoredAppearance]; +} + +- (void)updateColoredAppearance +{ + self.mediaTitleTextField.textColor = self.view.shouldShowDarkAppearance ? [NSColor VLClibraryDarkTitleColor] : [NSColor VLClibraryLightTitleColor]; +} + +- (void)updateFontBasedOnSetting:(NSNotification *)aNotification +{ + if (config_GetInt("macosx-large-text")) { + self.mediaTitleTextField.font = [NSFont VLClibraryLargeCellTitleFont]; + } else { + self.mediaTitleTextField.font = [NSFont VLClibrarySmallCellTitleFont]; + } +} + +#pragma mark - view representation + +- (void)prepareForReuse +{ + [super prepareForReuse]; + _playInstantlyButton.hidden = YES; + _mediaTitleTextField.stringValue = @""; + _annotationTextField.hidden = YES; + _mediaImageView.image = nil; + _addToPlaylistButton.hidden = NO; +} + +- (void)setRepresentedInputItem:(VLCInputItem *)representedInputItem +{ + _representedInputItem = representedInputItem; + [self updateRepresentation]; +} + +- (void)updateRepresentation +{ + if (_representedInputItem == nil) { + NSAssert(1, @"no input item assigned for collection view item", nil); + return; + } + + _mediaTitleTextField.stringValue = _representedInputItem.name; + NSURL *artworkURL = _representedInputItem.artworkURL; + NSImage *placeholderImage = [self imageForInputItem]; + if (artworkURL) { + [_mediaImageView setImageURL:artworkURL placeholderImage:placeholderImage]; + } else { + _mediaImageView.image = placeholderImage; + } + + switch (_representedInputItem.inputType) { + case ITEM_TYPE_DIRECTORY: + _annotationTextField.stringValue = _NS("Folder"); + _annotationTextField.hidden = NO; + break; + + case ITEM_TYPE_STREAM: + _annotationTextField.stringValue = _NS("Stream"); + _annotationTextField.hidden = NO; + break; + + case ITEM_TYPE_PLAYLIST: + _annotationTextField.stringValue = _NS("Playlist"); + _annotationTextField.hidden = NO; + break; + + case ITEM_TYPE_DISC: + _annotationTextField.stringValue = _NS("Disk"); + _annotationTextField.hidden = NO; + break; + + default: + break; + } +} + +- (NSImage *)imageForInputItem +{ + NSImage *image; + if (_representedInputItem.inputType == ITEM_TYPE_DIRECTORY) { + image = [NSImage imageNamed:NSImageNameFolder]; + } + + if (!image) { + image = [NSImage imageNamed: @"noart.png"]; + } + return image; +} + +#pragma mark - actions + +- (IBAction)playInstantly:(id)sender +{ + [[[VLCMain sharedInstance] playlistController] addInputItem:_representedInputItem.vlcInputItem atPosition:-1 startPlayback:YES]; +} + +- (IBAction)addToPlaylist:(id)sender +{ + [[[VLCMain sharedInstance] playlistController] addInputItem:_representedInputItem.vlcInputItem atPosition:-1 startPlayback:NO]; +} + +@end diff --git a/modules/gui/macosx/media-source/VLCMediaSourceDataSource.m b/modules/gui/macosx/media-source/VLCMediaSourceDataSource.m index 664af0434050..2e5db5609731 100644 --- a/modules/gui/macosx/media-source/VLCMediaSourceDataSource.m +++ b/modules/gui/macosx/media-source/VLCMediaSourceDataSource.m @@ -23,7 +23,7 @@ #import "VLCMediaSourceDataSource.h" #import "library/VLCInputItem.h" -#import "media-source/VLCMediaSourceDeviceCollectionViewItem.h" +#import "media-source/VLCMediaSourceCollectionViewItem.h" #import "media-source/VLCMediaSource.h" #import "main/VLCMain.h" #import "playlist/VLCPlaylistController.h" @@ -65,21 +65,14 @@ - (NSCollectionViewItem *)collectionView:(NSCollectionView *)collectionView itemForRepresentedObjectAtIndexPath:(NSIndexPath *)indexPath { - VLCMediaSourceDeviceCollectionViewItem *viewItem = [collectionView makeItemWithIdentifier:VLCMediaSourceDeviceCellIdentifier forIndexPath:indexPath]; + VLCMediaSourceCollectionViewItem *viewItem = [collectionView makeItemWithIdentifier:VLCMediaSourceCellIdentifier forIndexPath:indexPath]; VLCInputNode *rootNode = _nodeToDisplay; NSArray *nodeChildren = rootNode.children; VLCInputNode *childNode = nodeChildren[indexPath.item]; VLCInputItem *childRootInput = childNode.inputItem; - viewItem.titleTextField.stringValue = childRootInput.name; - NSURL *artworkURL = childRootInput.artworkURL; - NSImage *placeholder = [NSImage imageNamed:@"NSApplicationIcon"]; - if (artworkURL) { - [viewItem.mediaImageView setImageURL:artworkURL placeholderImage:placeholder]; - } else { - viewItem.mediaImageView.image = placeholder; - } + viewItem.representedInputItem = childRootInput; return viewItem; } diff --git a/po/POTFILES.in b/po/POTFILES.in index 78f5e3625b8a..b461a495deef 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -496,6 +496,8 @@ modules/gui/macosx/media-source/VLCMediaSource.h modules/gui/macosx/media-source/VLCMediaSource.m modules/gui/macosx/media-source/VLCMediaSourceBaseDataSource.h modules/gui/macosx/media-source/VLCMediaSourceBaseDataSource.m +modules/gui/macosx/media-source/VLCMediaSourceCollectionViewItem.h +modules/gui/macosx/media-source/VLCMediaSourceCollectionViewItem.m modules/gui/macosx/media-source/VLCMediaSourceDataSource.h modules/gui/macosx/media-source/VLCMediaSourceDataSource.m modules/gui/macosx/media-source/VLCMediaSourceDeviceCollectionViewItem.h -- GitLab