[vlc-commits] [Git][videolan/vlc][master] macosx: Play artists' songs correctly from the collection view

Rémi Denis-Courmont (@Courmisch) gitlab at videolan.org
Thu Jun 30 18:40:49 UTC 2022



Rémi Denis-Courmont pushed to branch master at VideoLAN / VLC


Commits:
95bf8ade by Claudio Cambra at 2022-06-30T18:28:58+00:00
macosx: Play artists' songs correctly from the collection view

Signed-off-by: Claudio Cambra <claudio.cambra at gmail.com>

- - - - -


9 changed files:

- modules/gui/macosx/Makefile.am
- + modules/gui/macosx/UI/VLCLibraryCollectionViewArtistItem.xib
- modules/gui/macosx/library/VLCLibraryAudioDataSource.m
- + modules/gui/macosx/library/VLCLibraryCollectionViewArtistItem.h
- + modules/gui/macosx/library/VLCLibraryCollectionViewArtistItem.m
- modules/gui/macosx/library/VLCLibraryDataTypes.h
- modules/gui/macosx/library/VLCLibraryDataTypes.m
- modules/gui/macosx/library/VLCLibraryMenuController.h
- modules/gui/macosx/library/VLCLibraryMenuController.m


Changes:

=====================================
modules/gui/macosx/Makefile.am
=====================================
@@ -62,6 +62,8 @@ libmacosx_plugin_la_SOURCES = \
 	gui/macosx/library/VLCLibraryCollectionViewItem.m \
 	gui/macosx/library/VLCLibraryCollectionViewAlbumItem.h \
 	gui/macosx/library/VLCLibraryCollectionViewAlbumItem.m \
+	gui/macosx/library/VLCLibraryCollectionViewArtistItem.h \
+	gui/macosx/library/VLCLibraryCollectionViewArtistItem.m \
 	gui/macosx/library/VLCLibraryCollectionViewItemProtocol.h \
 	gui/macosx/library/VLCLibraryCollectionViewSupplementaryElementView.h \
 	gui/macosx/library/VLCLibraryCollectionViewSupplementaryElementView.m \
@@ -299,6 +301,7 @@ libmacosx_plugin_la_XIB_SOURCES = \
 	gui/macosx/UI/VLCPlaylistTableCellView.xib \
 	gui/macosx/UI/VLCLibraryCollectionViewItem.xib \
 	gui/macosx/UI/VLCLibraryCollectionViewAlbumItem.xib \
+	gui/macosx/UI/VLCLibraryCollectionViewArtistItem.xib \
 	gui/macosx/UI/VLCMediaSourceCollectionViewItem.xib \
 	gui/macosx/UI/VLCMediaSourceDeviceCollectionViewItem.xib \
 	gui/macosx/UI/VLCInformationWindow.xib \


=====================================
modules/gui/macosx/UI/VLCLibraryCollectionViewArtistItem.xib
=====================================
@@ -0,0 +1,125 @@
+<?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="VLCLibraryCollectionViewArtistItem">
+            <connections>
+                <outlet property="addToPlaylistButton" destination="Ubz-8I-W2F" id="k0q-b1-PZi"/>
+                <outlet property="annotationTextField" destination="tm2-NW-WsZ" id="Miy-RS-Rol"/>
+                <outlet property="durationTextField" destination="VAn-gF-QiZ" id="U8T-Cs-HaL"/>
+                <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="JlC-bE-i5Y"/>
+                <outlet property="progressIndicator" destination="dFt-oZ-h9P" id="JC6-gk-Mid"/>
+                <outlet property="unplayedIndicatorTextField" destination="u2r-zy-XEW" id="56s-K4-Kxr"/>
+                <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="49" width="256" height="165"/>
+                    <subviews>
+                        <customView translatesAutoresizingMaskIntoConstraints="NO" id="dFt-oZ-h9P" customClass="VLCLinearProgressIndicator">
+                            <rect key="frame" x="0.0" y="0.0" width="256" height="4"/>
+                            <constraints>
+                                <constraint firstAttribute="height" constant="4" id="lyQ-kl-gVk"/>
+                            </constraints>
+                        </customView>
+                        <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="S3I-5Z-qgS">
+                            <rect key="frame" x="96" y="51" 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="E2B-oj-rx3"/>
+                            </connections>
+                        </button>
+                        <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="tm2-NW-WsZ" customClass="VLCRoundedCornerTextField">
+                            <rect key="frame" x="8" y="141" width="37" height="17"/>
+                            <textFieldCell key="cell" lineBreakMode="clipping" title="Label" id="tyb-Ur-7J9">
+                                <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 firstAttribute="bottom" secondItem="dFt-oZ-h9P" secondAttribute="bottom" id="4q3-3S-7PA"/>
+                        <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="dFt-oZ-h9P" firstAttribute="leading" secondItem="2aB-sB-hfY" secondAttribute="leading" id="gTe-sx-hdP"/>
+                        <constraint firstAttribute="trailing" secondItem="dFt-oZ-h9P" secondAttribute="trailing" id="kBI-UU-vnc"/>
+                    </constraints>
+                </customView>
+                <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="OBS-Eh-1mT">
+                    <rect key="frame" x="-2" y="21" width="52" height="24"/>
+                    <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>
+                <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="u2r-zy-XEW">
+                    <rect key="frame" x="224" y="1" width="34" height="17"/>
+                    <textFieldCell key="cell" lineBreakMode="clipping" title="NEW" id="NeT-5U-eZn">
+                        <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>
+                <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="2C9-Rn-VAb"/>
+                    </connections>
+                </button>
+                <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="VAn-gF-QiZ">
+                    <rect key="frame" x="-2" y="0.0" width="42" height="19"/>
+                    <textFieldCell key="cell" lineBreakMode="clipping" title="Label" id="LSS-jh-llZ">
+                        <font key="font" size="15" name=".AppleSystemUIFont"/>
+                        <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
+                        <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
+                    </textFieldCell>
+                </textField>
+            </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 firstItem="VAn-gF-QiZ" firstAttribute="top" secondItem="OBS-Eh-1mT" secondAttribute="bottom" constant="2" id="ALi-0z-Mza"/>
+                <constraint firstAttribute="trailing" secondItem="u2r-zy-XEW" secondAttribute="trailing" id="Dd7-va-0UJ"/>
+                <constraint firstItem="u2r-zy-XEW" firstAttribute="centerY" secondItem="VAn-gF-QiZ" secondAttribute="centerY" id="H5N-j9-THf"/>
+                <constraint firstAttribute="bottom" secondItem="VAn-gF-QiZ" secondAttribute="bottom" id="Kp0-Hx-3Ek"/>
+                <constraint firstItem="VAn-gF-QiZ" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" id="QUW-dn-Fbc"/>
+                <constraint firstAttribute="trailing" secondItem="Ubz-8I-W2F" secondAttribute="trailing" constant="14" id="ZVz-SL-rxZ"/>
+                <constraint firstItem="tm2-NW-WsZ" firstAttribute="top" secondItem="Hz6-mo-xeY" secondAttribute="top" constant="7" id="cvk-A5-enS"/>
+                <constraint firstItem="tm2-NW-WsZ" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" constant="10" id="fH0-Om-7gV"/>
+                <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>


=====================================
modules/gui/macosx/library/VLCLibraryAudioDataSource.m
=====================================
@@ -31,6 +31,7 @@
 #import "library/VLCLibraryAlbumTableCellView.h"
 #import "library/VLCLibraryCollectionViewItem.h"
 #import "library/VLCLibraryCollectionViewAlbumItem.h"
+#import "library/VLCLibraryCollectionViewArtistItem.h"
 
 #import "extensions/NSString+Helpers.h"
 #import "views/VLCImageView.h"
@@ -69,6 +70,7 @@ static NSString *VLCAudioLibraryCellIdentifier = @"VLCAudioLibraryCellIdentifier
 
     [_collectionView registerClass:[VLCLibraryCollectionViewItem class] forItemWithIdentifier:VLCLibraryCellIdentifier];
     [_collectionView registerClass:[VLCLibraryCollectionViewAlbumItem class] forItemWithIdentifier:VLCLibraryAlbumCellIdentifier];
+    [_collectionView registerClass:[VLCLibraryCollectionViewArtistItem class] forItemWithIdentifier:VLCLibraryArtistCellIdentifier];
     
     NSCollectionViewFlowLayout *flowLayout = _collectionView.collectionViewLayout;
     flowLayout.itemSize = CGSizeMake(214., 260.);
@@ -395,31 +397,10 @@ static NSString *VLCAudioLibraryCellIdentifier = @"VLCAudioLibraryCellIdentifier
     switch (_currentParentType) {
         case VLC_ML_PARENT_ARTIST:
         {
-            // TODO: Have artist-specific view item
+            VLCLibraryCollectionViewArtistItem *viewArtistItem = [collectionView makeItemWithIdentifier:VLCLibraryArtistCellIdentifier forIndexPath:indexPath];
             VLCMediaLibraryArtist *artist = _displayedCollection[indexPath.item];
-            viewItem.mediaTitleTextField.stringValue = artist.name;
-            NSString *countMetadataString;
-            if (artist.numberOfAlbums > 1) {
-                countMetadataString = [NSString stringWithFormat:_NS("%u albums"), artist.numberOfAlbums];
-            } else {
-                countMetadataString = _NS("1 album");
-            }
-            if (artist.numberOfTracks > 1) {
-                countMetadataString = [countMetadataString stringByAppendingFormat:@", %@", [NSString stringWithFormat:_NS("%u songs"), artist.numberOfTracks]];
-            } else {
-                countMetadataString = [countMetadataString stringByAppendingFormat:@", %@", _NS("1 song")];
-            }
-            viewItem.durationTextField.stringValue = countMetadataString;
-
-            NSImage *image;
-            if (artist.artworkMRL.length > 0) {
-                image = [[NSImage alloc] initWithContentsOfURL:[NSURL URLWithString:artist.artworkMRL]];
-            }
-            if (!image) {
-                image = [NSImage imageNamed: @"noart.png"];
-            }
-            viewItem.mediaImageView.image = image;
-            break;
+            viewArtistItem.representedArtist = artist;
+            return viewArtistItem;
         }
         case VLC_ML_PARENT_ALBUM:
         {


=====================================
modules/gui/macosx/library/VLCLibraryCollectionViewArtistItem.h
=====================================
@@ -0,0 +1,39 @@
+/*****************************************************************************
+ * VLCLibraryCollectionViewArtistItem.h: MacOS X interface module
+ *****************************************************************************
+ * Copyright (C) 2022 VLC authors and VideoLAN
+ *
+ * Authors: Claudio Cambra <claudio.cambra at gmail.com>
+ *
+ * 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>
+#import "VLCLibraryCollectionViewItemProtocol.h"
+
+NS_ASSUME_NONNULL_BEGIN
+
+ at class VLCMediaLibraryArtist;
+
+extern NSString *VLCLibraryArtistCellIdentifier;
+
+ at interface VLCLibraryCollectionViewArtistItem : NSCollectionViewItem<VLCLibraryCollectionViewItemProtocol>
+
+ at property (readwrite, retain, nonatomic) VLCMediaLibraryArtist *representedArtist;
+
+ at end
+
+NS_ASSUME_NONNULL_END
+


=====================================
modules/gui/macosx/library/VLCLibraryCollectionViewArtistItem.m
=====================================
@@ -0,0 +1,263 @@
+/*****************************************************************************
+ * VLCLibraryCollectionViewArtistItem.m: MacOS X interface module
+ *****************************************************************************
+ * Copyright (C) 2022 VLC authors and VideoLAN
+ *
+ * Authors: Claudio Cambra <claudio.cambra at gmail.com>
+ *
+ * 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 "VLCLibraryCollectionViewArtistItem.h"
+
+#import "main/VLCMain.h"
+#import "library/VLCLibraryController.h"
+#import "library/VLCLibraryDataTypes.h"
+#import "library/VLCLibraryModel.h"
+#import "library/VLCLibraryMenuController.h"
+#import "views/VLCImageView.h"
+#import "views/VLCLinearProgressIndicator.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"
+
+NSString *VLCLibraryArtistCellIdentifier = @"VLCLibraryArtistCellIdentifier";
+
+ at interface VLCLibraryCollectionViewArtistItem()
+{
+    VLCLibraryController *_libraryController;
+    VLCLibraryMenuController *_menuController;
+}
+ at end
+
+ at implementation VLCLibraryCollectionViewArtistItem
+
+ at synthesize mediaTitleTextField = _mediaTitleTextField;
+ at synthesize annotationTextField = _annotationTextField;
+ at synthesize unplayedIndicatorTextField = _unplayedIndicatorTextField;
+ at synthesize durationTextField = _durationTextField;
+ at synthesize mediaImageView = _mediaImageView;
+ at synthesize playInstantlyButton = _playInstantlyButton;
+ at synthesize addToPlaylistButton = _addToPlaylistButton;
+ at synthesize progressIndicator = _progressIndicator;
+
+- (instancetype)initWithNibName:(NSNibName)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
+{
+    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
+    if (self) {
+        NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
+        // TODO: Update artist on a VLCLibraryModelArtistUpdated signal
+        [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.durationTextField.textColor = [NSColor VLClibrarySubtitleColor];
+    self.annotationTextField.font = [NSFont VLClibraryCellAnnotationFont];
+    self.annotationTextField.textColor = [NSColor VLClibraryAnnotationColor];
+    self.annotationTextField.backgroundColor = [NSColor VLClibraryAnnotationBackgroundColor];
+    self.unplayedIndicatorTextField.stringValue = _NS("NEW");
+    self.unplayedIndicatorTextField.font = [NSFont VLClibraryHighlightCellHighlightLabelFont];
+    self.unplayedIndicatorTextField.textColor = [NSColor VLClibraryHighlightColor];
+
+    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];
+        self.durationTextField.font = [NSFont VLClibraryLargeCellSubtitleFont];
+    } else {
+        self.mediaTitleTextField.font = [NSFont VLClibrarySmallCellTitleFont];
+        self.durationTextField.font = [NSFont VLClibrarySmallCellSubtitleFont];
+    }
+}
+
+#pragma mark - view representation
+
+- (void)prepareForReuse
+{
+    [super prepareForReuse];
+    _playInstantlyButton.hidden = YES;
+    _mediaTitleTextField.stringValue = @"";
+    _durationTextField.stringValue = [NSString stringWithTime:0];
+    _mediaImageView.image = nil;
+    _annotationTextField.hidden = YES;
+    _progressIndicator.hidden = YES;
+    _unplayedIndicatorTextField.hidden = YES;
+}
+
+- (void)setRepresentedArtist:(VLCMediaLibraryArtist *)representedArtist
+{
+    if (!_libraryController) {
+        _libraryController = [[VLCMain sharedInstance] libraryController];
+    }
+
+    _representedArtist = representedArtist;
+    [self updateRepresentation];
+}
+
+- (void)artistUpdated:(NSNotification *)aNotification
+{
+    VLCMediaLibraryArtist *updatedArtist = aNotification.object;
+    if (updatedArtist == nil || _representedArtist == nil) {
+        return;
+    }
+    if (updatedArtist.artistID == _representedArtist.artistID) {
+        [self updateRepresentation];
+    }
+}
+
+- (void)updateRepresentation
+{
+    if (_representedArtist == nil) {
+        NSAssert(1, @"no artist assigned for collection view item", nil);
+        return;
+    }
+
+    _mediaTitleTextField.stringValue = _representedArtist.name;
+
+    NSString *countMetadataString;
+    if (_representedArtist.numberOfAlbums > 1) {
+        countMetadataString = [NSString stringWithFormat:_NS("%u albums"), _representedArtist.numberOfAlbums];
+    } else {
+        countMetadataString = _NS("1 album");
+    }
+    if (_representedArtist.numberOfTracks > 1) {
+        countMetadataString = [countMetadataString stringByAppendingFormat:@", %@", [NSString stringWithFormat:_NS("%u songs"), _representedArtist.numberOfTracks]];
+    } else {
+        countMetadataString = [countMetadataString stringByAppendingFormat:@", %@", _NS("1 song")];
+    }
+
+    _durationTextField.stringValue = countMetadataString;
+
+    _mediaImageView.image = [self imageForMedia];
+
+    // TODO: Show artist tracks progress with progress indicator
+}
+
+- (NSImage *)imageForMedia
+{
+    NSImage *image = nil;
+    if (_representedArtist.artworkMRL.length > 0) {
+        image = [[NSImage alloc] initWithContentsOfURL:[NSURL URLWithString:_representedArtist.artworkMRL]];
+    }
+    if (!image) {
+        image = [NSImage imageNamed: @"noart.png"];
+    }
+    return image;
+}
+
+#pragma mark - actions
+
+- (IBAction)playInstantly:(id)sender
+{
+    if (!_libraryController) {
+        _libraryController = [[VLCMain sharedInstance] libraryController];
+    }
+
+    // We want to add all the tracks to the playlist but only play the first one immediately,
+    // otherwise we will skip straight to the last track of the last album from the artist
+    BOOL playImmediately = YES;
+    for(VLCMediaLibraryAlbum* album in _representedArtist.albums) {
+        for(VLCMediaLibraryMediaItem* mediaItem in album.tracksAsMediaItems) {
+            [_libraryController appendItemToPlaylist:mediaItem playImmediately:playImmediately];
+
+            if(playImmediately) {
+                playImmediately = NO;
+            }
+        }
+    }
+}
+
+- (IBAction)addToPlaylist:(id)sender
+{
+    if (!_libraryController) {
+        _libraryController = [[VLCMain sharedInstance] libraryController];
+    }
+
+    for(VLCMediaLibraryAlbum* album in _representedArtist.albums) {
+        for(VLCMediaLibraryMediaItem* mediaItem in album.tracksAsMediaItems) {
+            [_libraryController appendItemToPlaylist:mediaItem playImmediately:NO];
+        }
+    }
+}
+
+-(void)mouseDown:(NSEvent *)theEvent
+{
+    if (theEvent.modifierFlags & NSControlKeyMask) {
+        if (!_menuController) {
+            _menuController = [[VLCLibraryMenuController alloc] init];
+        }
+        [_menuController setRepresentedArtist:self.representedArtist];
+        [_menuController popupMenuWithEvent:theEvent forView:self.view];
+    }
+
+    [super mouseDown:theEvent];
+}
+
+- (void)rightMouseDown:(NSEvent *)theEvent
+{
+    if (!_menuController) {
+        _menuController = [[VLCLibraryMenuController alloc] init];
+    }
+    [_menuController setRepresentedArtist:self.representedArtist];
+    [_menuController popupMenuWithEvent:theEvent forView:self.view];
+
+    [super rightMouseDown:theEvent];
+}
+
+ at end


=====================================
modules/gui/macosx/library/VLCLibraryDataTypes.h
=====================================
@@ -28,6 +28,7 @@ NS_ASSUME_NONNULL_BEGIN
 extern NSString *VLCMediaLibraryMediaItemPasteboardType;
 
 @class VLCMediaLibraryMediaItem;
+ at class VLCMediaLibraryAlbum;
 @class VLCInputItem;
 
 extern const CGFloat VLCMediaLibrary4KWidth;
@@ -106,6 +107,7 @@ extern const long long int VLCMediaLibraryMediaItemDurationDenominator;
 @property (readonly) NSString *musicBrainzID;
 @property (readonly) unsigned int numberOfAlbums;
 @property (readonly) unsigned int numberOfTracks;
+ at property (readonly) NSArray <VLCMediaLibraryAlbum *> *albums;
 
 @end
 


=====================================
modules/gui/macosx/library/VLCLibraryDataTypes.m
=====================================
@@ -213,6 +213,26 @@ NSString *VLCMediaLibraryMediaItemLibraryID = @"VLCMediaLibraryMediaItemLibraryI
     return self;
 }
 
+- (NSArray<VLCMediaLibraryAlbum *> *)albums
+{
+    intf_thread_t *p_intf = getIntf();
+    if (!p_intf) {
+        return @[];
+    }
+    vlc_medialibrary_t *p_mediaLibrary = vlc_ml_instance_get(p_intf);
+    if (!p_mediaLibrary) {
+        return @[];
+    }
+    vlc_ml_album_list_t *p_albumList = vlc_ml_list_artist_albums(p_mediaLibrary, NULL, _artistID);
+    NSMutableArray *mutableArray = [[NSMutableArray alloc] initWithCapacity:p_albumList->i_nb_items];
+    for (size_t x = 0; x < p_albumList->i_nb_items; x++) {
+        VLCMediaLibraryAlbum *album = [[VLCMediaLibraryAlbum alloc] initWithAlbum:&p_albumList->p_items[x]];
+        [mutableArray addObject:album];
+    }
+    vlc_ml_album_list_release(p_albumList);
+    return [mutableArray copy];
+}
+
 @end
 
 @implementation VLCMediaLibraryAlbum


=====================================
modules/gui/macosx/library/VLCLibraryMenuController.h
=====================================
@@ -26,12 +26,14 @@ NS_ASSUME_NONNULL_BEGIN
 
 @class VLCMediaLibraryMediaItem;
 @class VLCMediaLibraryAlbum;
+ at class VLCMediaLibraryArtist;
 
 @interface VLCLibraryMenuController : NSObject
 
 - (void)popupMenuWithEvent:(NSEvent *)theEvent forView:(NSView *)theView;
 - (void)setRepresentedMediaItem:(VLCMediaLibraryMediaItem *)mediaItem;
 - (void)setRepresentedAlbum:(VLCMediaLibraryAlbum *)album;
+- (void)setRepresentedArtist:(VLCMediaLibraryArtist *)artist;
 
 @end
 


=====================================
modules/gui/macosx/library/VLCLibraryMenuController.m
=====================================
@@ -37,6 +37,7 @@
     enum vlc_ml_parent_type _currentRepresentedType;
     VLCMediaLibraryMediaItem *_representedMediaItem;
     VLCMediaLibraryAlbum *_representedAlbum;
+    VLCMediaLibraryArtist *_representedArtist;
 }
 @end
 
@@ -88,6 +89,15 @@
 - (void)addToPlaylist:(BOOL)playImmediately
 {
     switch(_currentRepresentedType) {
+        case VLC_ML_PARENT_ARTIST:
+        {
+            for(VLCMediaLibraryAlbum* album in _representedArtist.albums) {
+                for(VLCMediaLibraryMediaItem* mediaItem in album.tracksAsMediaItems) {
+                    [[[VLCMain sharedInstance] libraryController] appendItemToPlaylist:mediaItem playImmediately:playImmediately];
+                }
+            }
+            break;
+        }
         case VLC_ML_PARENT_ALBUM:
         {
             for(VLCMediaLibraryMediaItem* mediaItem in _representedAlbum.tracksAsMediaItems) {
@@ -135,6 +145,11 @@
 - (void)revealInFinder:(id)sender
 {
     switch(_currentRepresentedType) {
+        case VLC_ML_PARENT_ARTIST:
+        {
+            [[[VLCMain sharedInstance] libraryController] showItemInFinder:_representedArtist.albums.firstObject.tracksAsMediaItems.firstObject];
+            break;
+        }
         case VLC_ML_PARENT_ALBUM:
         {
             [[[VLCMain sharedInstance] libraryController] showItemInFinder:_representedAlbum.tracksAsMediaItems.firstObject];
@@ -155,6 +170,18 @@
     NSArray *filesToTrash;
 
     switch(_currentRepresentedType) {
+        case VLC_ML_PARENT_ARTIST:
+        {
+            NSMutableArray *allMediaItemFiles = [[NSMutableArray alloc] init];
+            for(VLCMediaLibraryAlbum* album in _representedArtist.albums) {
+                for(VLCMediaLibraryMediaItem* mediaItem in album.tracksAsMediaItems) {
+                    [allMediaItemFiles addObjectsFromArray: mediaItem.files];
+                }
+            }
+
+            filesToTrash = [allMediaItemFiles copy];
+            break;
+        }
         case VLC_ML_PARENT_ALBUM:
         {
             NSMutableArray *allMediaItemFiles = [[NSMutableArray alloc] init];
@@ -199,6 +226,8 @@
 {
     _representedMediaItem = nil;
     _representedAlbum = nil;
+    _representedArtist = nil;
+    _currentRepresentedType = VLC_ML_PARENT_UNKNOWN;
 }
 
 - (void)setRepresentedMediaItem:(VLCMediaLibraryMediaItem *)mediaItem
@@ -215,4 +244,11 @@
     _currentRepresentedType = VLC_ML_PARENT_ALBUM;
 }
 
+- (void)setRepresentedArtist:(VLCMediaLibraryArtist *)artist
+{
+    [self clearRepresentedMedia];
+    _representedArtist = artist;
+    _currentRepresentedType = VLC_ML_PARENT_ARTIST;
+}
+
 @end



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/95bf8adefa671f3b9556648f0a6cbdc699408e50

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/95bf8adefa671f3b9556648f0a6cbdc699408e50
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list