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


Commits:
73a248c0 by Claudio Cambra at 2022-06-21T15:20:03+00:00
macosx: Play albums works correctly from the collection view

Signed-off-by: Claudio Cambra <claudio.cam...@gmail.com>

- - - - -


10 changed files:

- modules/gui/macosx/Makefile.am
- + modules/gui/macosx/UI/VLCLibraryCollectionViewAlbumItem.xib
- modules/gui/macosx/library/VLCLibraryAudioDataSource.m
- + modules/gui/macosx/library/VLCLibraryCollectionViewAlbumItem.h
- + modules/gui/macosx/library/VLCLibraryCollectionViewAlbumItem.m
- modules/gui/macosx/library/VLCLibraryCollectionViewItem.h
- modules/gui/macosx/library/VLCLibraryCollectionViewItem.m
- + modules/gui/macosx/library/VLCLibraryCollectionViewItemProtocol.h
- modules/gui/macosx/library/VLCLibraryMenuController.h
- modules/gui/macosx/library/VLCLibraryMenuController.m


Changes:

=====================================
modules/gui/macosx/Makefile.am
=====================================
@@ -60,6 +60,9 @@ libmacosx_plugin_la_SOURCES = \
        gui/macosx/library/VLCLibraryAudioDataSource.m \
        gui/macosx/library/VLCLibraryCollectionViewItem.h \
        gui/macosx/library/VLCLibraryCollectionViewItem.m \
+       gui/macosx/library/VLCLibraryCollectionViewAlbumItem.h \
+       gui/macosx/library/VLCLibraryCollectionViewAlbumItem.m \
+       gui/macosx/library/VLCLibraryCollectionViewItemProtocol.h \
        gui/macosx/library/VLCLibraryCollectionViewSupplementaryElementView.h \
        gui/macosx/library/VLCLibraryCollectionViewSupplementaryElementView.m \
        gui/macosx/library/VLCLibraryController.h \
@@ -293,6 +296,7 @@ libmacosx_plugin_la_XIB_SOURCES = \
        gui/macosx/UI/VLCLibraryTableCellView.xib \
        gui/macosx/UI/VLCPlaylistTableCellView.xib \
        gui/macosx/UI/VLCLibraryCollectionViewItem.xib \
+       gui/macosx/UI/VLCLibraryCollectionViewAlbumItem.xib \
        gui/macosx/UI/VLCMediaSourceCollectionViewItem.xib \
        gui/macosx/UI/VLCMediaSourceDeviceCollectionViewItem.xib \
        gui/macosx/UI/VLCInformationWindow.xib \


=====================================
modules/gui/macosx/UI/VLCLibraryCollectionViewAlbumItem.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="VLCLibraryCollectionViewAlbumItem">
+            <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
=====================================
@@ -30,6 +30,7 @@
 #import "library/VLCLibraryTableCellView.h"
 #import "library/VLCLibraryAlbumTableCellView.h"
 #import "library/VLCLibraryCollectionViewItem.h"
+#import "library/VLCLibraryCollectionViewAlbumItem.h"
 
 #import "extensions/NSString+Helpers.h"
 #import "views/VLCImageView.h"
@@ -65,7 +66,10 @@ static NSString *VLCAudioLibraryCellIdentifier = 
@"VLCAudioLibraryCellIdentifier
 
     _collectionView.dataSource = self;
     _collectionView.delegate = self;
+
     [_collectionView registerClass:[VLCLibraryCollectionViewItem class] 
forItemWithIdentifier:VLCLibraryCellIdentifier];
+    [_collectionView registerClass:[VLCLibraryCollectionViewAlbumItem class] 
forItemWithIdentifier:VLCLibraryAlbumCellIdentifier];
+    
     NSCollectionViewFlowLayout *flowLayout = 
_collectionView.collectionViewLayout;
     flowLayout.itemSize = CGSizeMake(214., 260.);
     flowLayout.sectionInset = NSEdgeInsetsMake(20., 20., 20., 20.);
@@ -387,9 +391,11 @@ static NSString *VLCAudioLibraryCellIdentifier = 
@"VLCAudioLibraryCellIdentifier
      itemForRepresentedObjectAtIndexPath:(NSIndexPath *)indexPath
 {
     VLCLibraryCollectionViewItem *viewItem = [collectionView 
makeItemWithIdentifier:VLCLibraryCellIdentifier forIndexPath:indexPath];
+
     switch (_currentParentType) {
         case VLC_ML_PARENT_ARTIST:
         {
+            // TODO: Have artist-specific view item
             VLCMediaLibraryArtist *artist = 
_displayedCollection[indexPath.item];
             viewItem.mediaTitleTextField.stringValue = artist.name;
             NSString *countMetadataString;
@@ -417,22 +423,10 @@ static NSString *VLCAudioLibraryCellIdentifier = 
@"VLCAudioLibraryCellIdentifier
         }
         case VLC_ML_PARENT_ALBUM:
         {
+            VLCLibraryCollectionViewAlbumItem *viewAlbumItem = [collectionView 
makeItemWithIdentifier:VLCLibraryAlbumCellIdentifier forIndexPath:indexPath];
             VLCMediaLibraryAlbum *album = _displayedCollection[indexPath.item];
-            viewItem.mediaTitleTextField.stringValue = album.title;
-            if (album.numberOfTracks > 1) {
-                viewItem.durationTextField.stringValue = [NSString 
stringWithFormat:_NS("%u songs"), album.numberOfTracks];
-            } else {
-                viewItem.durationTextField.stringValue = _NS("1 song");
-            }
-            NSImage *image;
-            if (album.artworkMRL.length > 0) {
-                image = [[NSImage alloc] initWithContentsOfURL:[NSURL 
URLWithString:album.artworkMRL]];
-            }
-            if (!image) {
-                image = [NSImage imageNamed: @"noart.png"];
-            }
-            viewItem.mediaImageView.image = image;
-            break;
+            viewAlbumItem.representedAlbum = album;
+            return viewAlbumItem;
         }
         case VLC_ML_PARENT_UNKNOWN:
         {
@@ -442,6 +436,7 @@ static NSString *VLCAudioLibraryCellIdentifier = 
@"VLCAudioLibraryCellIdentifier
         }
         case VLC_ML_PARENT_GENRE:
         {
+            // TODO: Have genre-specific view item
             VLCMediaLibraryGenre *genre = _displayedCollection[indexPath.item];
             viewItem.mediaTitleTextField.stringValue = genre.name;
             if (genre.numberOfTracks > 1) {
@@ -450,8 +445,8 @@ static NSString *VLCAudioLibraryCellIdentifier = 
@"VLCAudioLibraryCellIdentifier
                 viewItem.durationTextField.stringValue = _NS("1 song");
             }
             viewItem.mediaImageView.image = [NSImage imageNamed: @"noart.png"];
+            break;
         }
-
         default:
             break;
     }


=====================================
modules/gui/macosx/library/VLCLibraryCollectionViewAlbumItem.h
=====================================
@@ -0,0 +1,39 @@
+/*****************************************************************************
+ * VLCLibraryCollectionViewAlbumItem.h: MacOS X interface module
+ *****************************************************************************
+ * Copyright (C) 2022 VLC authors and VideoLAN
+ *
+ * Authors: Claudio Cambra <claudio.cam...@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
+
+@class VLCMediaLibraryAlbum;
+
+extern NSString *VLCLibraryAlbumCellIdentifier;
+
+@interface VLCLibraryCollectionViewAlbumItem : 
NSCollectionViewItem<VLCLibraryCollectionViewItemProtocol>
+
+@property (readwrite, retain, nonatomic) VLCMediaLibraryAlbum 
*representedAlbum;
+
+@end
+
+NS_ASSUME_NONNULL_END
+


=====================================
modules/gui/macosx/library/VLCLibraryCollectionViewAlbumItem.m
=====================================
@@ -0,0 +1,246 @@
+/*****************************************************************************
+ * VLCLibraryCollectionViewAlbumItem.m: MacOS X interface module
+ *****************************************************************************
+ * Copyright (C) 2019 VLC authors and VideoLAN
+ *
+ * Authors: Claudio Cambra <claudio.cam...@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 "VLCLibraryCollectionViewAlbumItem.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 *VLCLibraryAlbumCellIdentifier = @"VLCLibraryAlbumCellIdentifier";
+
+@interface VLCLibraryCollectionViewAlbumItem()
+{
+    VLCLibraryController *_libraryController;
+    VLCLibraryMenuController *_menuController;
+}
+@end
+
+@implementation VLCLibraryCollectionViewAlbumItem
+
+@synthesize mediaTitleTextField = _mediaTitleTextField;
+@synthesize annotationTextField = _annotationTextField;
+@synthesize unplayedIndicatorTextField = _unplayedIndicatorTextField;
+@synthesize durationTextField = _durationTextField;
+@synthesize mediaImageView = _mediaImageView;
+@synthesize playInstantlyButton = _playInstantlyButton;
+@synthesize addToPlaylistButton = _addToPlaylistButton;
+@synthesize progressIndicator = _progressIndicator;
+
+- (instancetype)initWithNibName:(NSNibName)nibNameOrNil bundle:(NSBundle 
*)nibBundleOrNil
+{
+    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
+    if (self) {
+        NSNotificationCenter *notificationCenter = [NSNotificationCenter 
defaultCenter];
+        // TODO: Update album on a VLCLibraryModelAlbumUpdated 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)setRepresentedAlbum:(VLCMediaLibraryAlbum *)representedAlbum
+{
+    if (!_libraryController) {
+        _libraryController = [[VLCMain sharedInstance] libraryController];
+    }
+
+    _representedAlbum = representedAlbum;
+    [self updateRepresentation];
+}
+
+- (void)albumUpdated:(NSNotification *)aNotification
+{
+    VLCMediaLibraryAlbum *updatedAlbum = aNotification.object;
+    if (updatedAlbum == nil || _representedAlbum == nil) {
+        return;
+    }
+    if (updatedAlbum.albumID == _representedAlbum.albumID) {
+        [self updateRepresentation];
+    }
+}
+
+- (void)updateRepresentation
+{
+    if (_representedAlbum == nil) {
+        NSAssert(1, @"no media item assigned for collection view item", nil);
+        return;
+    }
+
+    _mediaTitleTextField.stringValue = _representedAlbum.title;
+    _durationTextField.stringValue = [NSString 
stringWithTime:_representedAlbum.duration / 
VLCMediaLibraryMediaItemDurationDenominator];
+
+    _mediaImageView.image = [self imageForMedia];
+
+    // TODO: Show album progress with progress indicator
+}
+
+- (NSImage *)imageForMedia
+{
+    NSImage *image;
+    if (_representedAlbum.artworkMRL.length > 0) {
+        image = [[NSImage alloc] initWithContentsOfURL:[NSURL 
URLWithString:_representedAlbum.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 album
+    BOOL playImmediately = YES;
+    for(VLCMediaLibraryMediaItem* mediaItem in 
_representedAlbum.tracksAsMediaItems) {
+        [_libraryController appendItemToPlaylist:mediaItem 
playImmediately:playImmediately];
+
+        if(playImmediately) {
+            playImmediately = NO;
+        }
+    }
+}
+
+- (IBAction)addToPlaylist:(id)sender
+{
+    if (!_libraryController) {
+        _libraryController = [[VLCMain sharedInstance] libraryController];
+    }
+
+    for(VLCMediaLibraryMediaItem* mediaItem in 
_representedAlbum.tracksAsMediaItems) {
+        [_libraryController appendItemToPlaylist:mediaItem playImmediately:NO];
+    }
+}
+
+-(void)mouseDown:(NSEvent *)theEvent
+{
+    if (theEvent.modifierFlags & NSControlKeyMask) {
+        if (!_menuController) {
+            _menuController = [[VLCLibraryMenuController alloc] init];
+        }
+        [_menuController setRepresentedAlbum:self.representedAlbum];
+        [_menuController popupMenuWithEvent:theEvent forView:self.view];
+    }
+
+    [super mouseDown:theEvent];
+}
+
+- (void)rightMouseDown:(NSEvent *)theEvent
+{
+    if (!_menuController) {
+        _menuController = [[VLCLibraryMenuController alloc] init];
+    }
+    [_menuController setRepresentedAlbum:self.representedAlbum];
+    [_menuController popupMenuWithEvent:theEvent forView:self.view];
+
+    [super rightMouseDown:theEvent];
+}
+
+@end


=====================================
modules/gui/macosx/library/VLCLibraryCollectionViewItem.h
=====================================
@@ -21,31 +21,18 @@
  *****************************************************************************/
 
 #import <Cocoa/Cocoa.h>
+#import "VLCLibraryCollectionViewItemProtocol.h"
 
 NS_ASSUME_NONNULL_BEGIN
 
-extern NSString *VLCLibraryCellIdentifier;
-
-@class VLCImageView;
-@class VLCLinearProgressIndicator;
 @class VLCMediaLibraryMediaItem;
 
-@interface VLCLibraryCollectionViewItem : NSCollectionViewItem
+extern NSString *VLCLibraryCellIdentifier;
 
-@property (readwrite, assign) IBOutlet NSTextField *mediaTitleTextField;
-@property (readwrite, assign) IBOutlet NSTextField *annotationTextField;
-@property (readwrite, assign) IBOutlet NSTextField *unplayedIndicatorTextField;
-@property (readwrite, assign) IBOutlet NSTextField *durationTextField;
-@property (readwrite, assign) IBOutlet VLCImageView *mediaImageView;
-@property (readwrite, assign) IBOutlet NSButton *playInstantlyButton;
-@property (readwrite, assign) IBOutlet NSButton *addToPlaylistButton;
-@property (readwrite, assign) IBOutlet VLCLinearProgressIndicator 
*progressIndicator;
+@interface VLCLibraryCollectionViewItem : 
NSCollectionViewItem<VLCLibraryCollectionViewItemProtocol>
 
 @property (readwrite, retain, nonatomic) VLCMediaLibraryMediaItem 
*representedMediaItem;
 
-- (IBAction)playInstantly:(id)sender;
-- (IBAction)addToPlaylist:(id)sender;
-
 @end
 
 NS_ASSUME_NONNULL_END


=====================================
modules/gui/macosx/library/VLCLibraryCollectionViewItem.m
=====================================
@@ -48,6 +48,15 @@ const CGFloat 
VLCLibraryCollectionViewItemMaximumDisplayedProgress = 0.95;
 
 @implementation VLCLibraryCollectionViewItem
 
+@synthesize mediaTitleTextField = _mediaTitleTextField;
+@synthesize annotationTextField = _annotationTextField;
+@synthesize unplayedIndicatorTextField = _unplayedIndicatorTextField;
+@synthesize durationTextField = _durationTextField;
+@synthesize mediaImageView = _mediaImageView;
+@synthesize playInstantlyButton = _playInstantlyButton;
+@synthesize addToPlaylistButton = _addToPlaylistButton;
+@synthesize progressIndicator = _progressIndicator;
+
 - (instancetype)initWithNibName:(NSNibName)nibNameOrNil bundle:(NSBundle 
*)nibBundleOrNil
 {
     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
@@ -229,7 +238,7 @@ const CGFloat 
VLCLibraryCollectionViewItemMaximumDisplayedProgress = 0.95;
         if (!_menuController) {
             _menuController = [[VLCLibraryMenuController alloc] init];
         }
-        _menuController.representedMediaItem = self.representedMediaItem;
+        [_menuController setRepresentedMediaItem:self.representedMediaItem];
         [_menuController popupMenuWithEvent:theEvent forView:self.view];
     }
 
@@ -241,7 +250,7 @@ const CGFloat 
VLCLibraryCollectionViewItemMaximumDisplayedProgress = 0.95;
     if (!_menuController) {
         _menuController = [[VLCLibraryMenuController alloc] init];
     }
-    _menuController.representedMediaItem = self.representedMediaItem;
+    [_menuController setRepresentedMediaItem:self.representedMediaItem];
     [_menuController popupMenuWithEvent:theEvent forView:self.view];
 
     [super rightMouseDown:theEvent];


=====================================
modules/gui/macosx/library/VLCLibraryCollectionViewItemProtocol.h
=====================================
@@ -0,0 +1,48 @@
+/*****************************************************************************
+ * VLCLibraryCollectionViewItemProtocl.h: MacOS X interface module
+ *****************************************************************************
+ * Copyright (C) 2022 VLC authors and VideoLAN
+ *
+ * Authors: Felix Paul Kühne <fkuehne # videolan -dot- org>
+ *          Claudio Cambra <claudio.cam...@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>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@class VLCImageView;
+@class VLCLinearProgressIndicator;
+
+@protocol VLCLibraryCollectionViewItemProtocol
+@required
+
+@property (readwrite, assign) IBOutlet NSTextField *mediaTitleTextField;
+@property (readwrite, assign) IBOutlet NSTextField *annotationTextField;
+@property (readwrite, assign) IBOutlet NSTextField *unplayedIndicatorTextField;
+@property (readwrite, assign) IBOutlet NSTextField *durationTextField;
+@property (readwrite, assign) IBOutlet VLCImageView *mediaImageView;
+@property (readwrite, assign) IBOutlet NSButton *playInstantlyButton;
+@property (readwrite, assign) IBOutlet NSButton *addToPlaylistButton;
+@property (readwrite, assign) IBOutlet VLCLinearProgressIndicator 
*progressIndicator;
+
+- (IBAction)playInstantly:(id)sender;
+- (IBAction)addToPlaylist:(id)sender;
+
+@end
+
+NS_ASSUME_NONNULL_END


=====================================
modules/gui/macosx/library/VLCLibraryMenuController.h
=====================================
@@ -25,12 +25,13 @@
 NS_ASSUME_NONNULL_BEGIN
 
 @class VLCMediaLibraryMediaItem;
+@class VLCMediaLibraryAlbum;
 
 @interface VLCLibraryMenuController : NSObject
 
-@property (readwrite, weak) VLCMediaLibraryMediaItem *representedMediaItem;
-
 - (void)popupMenuWithEvent:(NSEvent *)theEvent forView:(NSView *)theView;
+- (void)setRepresentedMediaItem:(VLCMediaLibraryMediaItem *)mediaItem;
+- (void)setRepresentedAlbum:(VLCMediaLibraryAlbum *)album;
 
 @end
 


=====================================
modules/gui/macosx/library/VLCLibraryMenuController.m
=====================================
@@ -34,6 +34,9 @@
 {
     NSMenu *_libraryMenu;
     VLCLibraryInformationPanel *_informationPanel;
+    enum vlc_ml_parent_type _currentRepresentedType;
+    VLCMediaLibraryMediaItem *_representedMediaItem;
+    VLCMediaLibraryAlbum *_representedAlbum;
 }
 @end
 
@@ -69,7 +72,7 @@
 
 - (void)popupMenuWithEvent:(NSEvent *)theEvent forView:(NSView *)theView
 {
-    if (self.representedMediaItem != nil) {
+    if (_representedMediaItem != nil) {
         [NSMenu popUpContextMenu:_libraryMenu withEvent:theEvent 
forView:theView];
     } else {
         NSMenu *minimalMenu = [[NSMenu alloc] initWithTitle:@""];
@@ -82,14 +85,34 @@
 
 #pragma mark - actions
 
+- (void)addToPlaylist:(BOOL)playImmediately
+{
+    switch(_currentRepresentedType) {
+        case VLC_ML_PARENT_ALBUM:
+        {
+            for(VLCMediaLibraryMediaItem* mediaItem in 
_representedAlbum.tracksAsMediaItems) {
+                [[[VLCMain sharedInstance] libraryController] 
appendItemToPlaylist:mediaItem playImmediately:playImmediately];
+            }
+            break;
+        }
+        case VLC_ML_PARENT_UNKNOWN:
+        {
+            [[[VLCMain sharedInstance] libraryController] 
appendItemToPlaylist:_representedMediaItem playImmediately:playImmediately];
+            break;
+        }
+        default:
+            NSLog(@"No represented media type, cannot append nothing to 
playlist.");
+    }
+}
+
 - (void)play:(id)sender
 {
-    [[[VLCMain sharedInstance] libraryController] 
appendItemToPlaylist:self.representedMediaItem playImmediately:YES];
+    [self addToPlaylist:YES];
 }
 
 - (void)appendToPlaylist:(id)sender
 {
-    [[[VLCMain sharedInstance] libraryController] 
appendItemToPlaylist:self.representedMediaItem playImmediately:NO];
+    [self addToPlaylist:NO];
 }
 
 - (void)addMedia:(id)sender
@@ -111,12 +134,47 @@
 
 - (void)revealInFinder:(id)sender
 {
-    [[[VLCMain sharedInstance] libraryController] 
showItemInFinder:self.representedMediaItem];
+    switch(_currentRepresentedType) {
+        case VLC_ML_PARENT_ALBUM:
+        {
+            [[[VLCMain sharedInstance] libraryController] 
showItemInFinder:_representedAlbum.tracksAsMediaItems.firstObject];
+            break;
+        }
+        case VLC_ML_PARENT_UNKNOWN:
+        {
+            [[[VLCMain sharedInstance] libraryController] 
showItemInFinder:_representedMediaItem];
+            break;
+        }
+        default:
+            NSLog(@"No represented media type, nothing to show in Finder.");
+    }
 }
 
 - (void)moveToTrash:(id)sender
 {
-    NSArray *filesToTrash = self.representedMediaItem.files;
+    NSArray *filesToTrash;
+
+    switch(_currentRepresentedType) {
+        case VLC_ML_PARENT_ALBUM:
+        {
+            NSMutableArray *allMediaItemFiles = [[NSMutableArray alloc] init];
+            for(VLCMediaLibraryMediaItem* mediaItem in 
_representedAlbum.tracksAsMediaItems) {
+                [allMediaItemFiles addObjectsFromArray: mediaItem.files];
+            }
+
+            filesToTrash = [allMediaItemFiles copy];
+            break;
+        }
+        case VLC_ML_PARENT_UNKNOWN:
+        {
+            filesToTrash = _representedMediaItem.files;
+            break;
+        }
+        default:
+            NSLog(@"No represented media type, not moving anything to trash.");
+            return;
+    }
+
     NSFileManager *fileManager = [NSFileManager defaultManager];
 
     for (VLCMediaLibraryFile *fileToTrash in filesToTrash) {
@@ -130,8 +188,31 @@
         _informationPanel = [[VLCLibraryInformationPanel alloc] 
initWithWindowNibName:@"VLCLibraryInformationPanel"];
     }
 
-    [_informationPanel setRepresentedMediaItem:self.representedMediaItem];
-    [_informationPanel showWindow:self];
+    if(_currentRepresentedType == VLC_ML_PARENT_UNKNOWN) {
+        [_informationPanel setRepresentedMediaItem:_representedMediaItem];
+        [_informationPanel showWindow:self];
+    }
+    
+}
+
+- (void)clearRepresentedMedia
+{
+    _representedMediaItem = nil;
+    _representedAlbum = nil;
+}
+
+- (void)setRepresentedMediaItem:(VLCMediaLibraryMediaItem *)mediaItem
+{
+    [self clearRepresentedMedia];
+    _representedMediaItem = mediaItem;
+    _currentRepresentedType = VLC_ML_PARENT_UNKNOWN;
+}
+
+- (void)setRepresentedAlbum:(VLCMediaLibraryAlbum *)album
+{
+    [self clearRepresentedMedia];
+    _representedAlbum = album;
+    _currentRepresentedType = VLC_ML_PARENT_ALBUM;
 }
 
 @end



View it on GitLab: 
https://code.videolan.org/videolan/vlc/-/commit/73a248c0592c0793709303bc451eb26d2e2c9408

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


VideoLAN code repository instance
_______________________________________________
vlc-commits mailing list
vlc-commits@videolan.org
https://mailman.videolan.org/listinfo/vlc-commits

Reply via email to