[vlc-commits] [Git][videolan/vlc][master] 13 commits: macosx: Add VLCAbstractMediaLibraryItem class to eliminate duplication of...

Steve Lhomme (@robUx4) gitlab at videolan.org
Tue Feb 14 11:12:27 UTC 2023



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
360bb717 by Claudio Cambra at 2023-02-14T10:43:23+00:00
macosx: Add VLCAbstractMediaLibraryItem class to eliminate duplication of certain protocol property and method implementations

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
d0d6ee05 by Claudio Cambra at 2023-02-14T10:43:23+00:00
macosx: Make media library item classes inherit VLCAbstractMediaLibraryItem, remove duplicated code

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
d07778e8 by Claudio Cambra at 2023-02-14T10:43:23+00:00
macosx: Make VLCLibraryImageCache accept real VLCAbstractMediaLibraryItem rather than protocol

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
fc1ec2eb by Claudio Cambra at 2023-02-14T10:43:23+00:00
macosx: Fix crash on trying to access VLCAbstractMediaLibraryItem smallArtworkMRL property

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
6b16f1ed by Claudio Cambra at 2023-02-14T10:43:23+00:00
macosx: Add VLCLocallyManipulableItemProtocol

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
4a5a1b83 by Claudio Cambra at 2023-02-14T10:43:23+00:00
macosx: Remove unnecessary iterateMediaItemsWithBlock declaration in VLCMediaLibraryGenre

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
bc6b4f5e by Claudio Cambra at 2023-02-14T10:43:23+00:00
macosx: Make VLCMediaLibraryMediaItem conform to VLCLocallyManipulableItemProtocol

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
e7d9b1b8 by Claudio Cambra at 2023-02-14T10:43:23+00:00
macosx: Add VLCAbstractMediaLibraryAudioGroup

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
00757c97 by Claudio Cambra at 2023-02-14T10:43:23+00:00
macosx: Conform VLCAbstractMediaLibraryAudioGroup to VLCLocallyManipulableItemProtocol

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
a0bcafed by Claudio Cambra at 2023-02-14T10:43:23+00:00
macosx: Make VLCMediaLibraryAlbum, VLCMediaLibraryGenre, and VLCMediaLibraryArtist inherit VLCAbstractMediaLibraryAudioGroup

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
74905b62 by Claudio Cambra at 2023-02-14T10:43:23+00:00
macosx: Make VLCMediaLibraryItemProtocol inherit VLCLocallyManipulableItemProtocol

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
2e2f5471 by Claudio Cambra at 2023-02-14T10:43:23+00:00
macosx: Make VLCInputItem conform to VLCLocallyManipulableItemProtocol

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
b3ffbdb6 by Claudio Cambra at 2023-02-14T10:43:23+00:00
macosx: Use reveal in finder methods in data types rather than reimplement in menu controller

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -


9 changed files:

- modules/gui/macosx/library/VLCInputItem.h
- modules/gui/macosx/library/VLCInputItem.m
- modules/gui/macosx/library/VLCLibraryController.h
- modules/gui/macosx/library/VLCLibraryController.m
- modules/gui/macosx/library/VLCLibraryDataTypes.h
- modules/gui/macosx/library/VLCLibraryDataTypes.m
- modules/gui/macosx/library/VLCLibraryImageCache.h
- modules/gui/macosx/library/VLCLibraryImageCache.m
- modules/gui/macosx/library/VLCLibraryMenuController.m


Changes:

=====================================
modules/gui/macosx/library/VLCInputItem.h
=====================================
@@ -22,6 +22,8 @@
 
 #import <Foundation/Foundation.h>
 
+#import "library/VLCLibraryDataTypes.h"
+
 #import <vlc_common.h>
 #import <vlc_input_item.h>
 #import <vlc_tick.h>
@@ -36,7 +38,7 @@ extern NSString *VLCInputItemPreparsingFailed;
 extern NSString *VLCInputItemPreparsingTimeOut;
 extern NSString *VLCInputItemPreparsingSucceeded;
 
- at interface VLCInputItem : NSObject
+ at interface VLCInputItem : NSObject<VLCLocallyManipulableItemProtocol>
 
 - (instancetype)initWithInputItem:(struct input_item_t *)p_inputItem;
 


=====================================
modules/gui/macosx/library/VLCInputItem.m
=====================================
@@ -620,6 +620,36 @@ static const struct input_preparser_callbacks_t preparseCallbacks = {
     return image;
 }
 
+- (void)moveToTrash
+{
+    if (self.isStream) {
+        return;
+    }
+    
+    NSURL *pathUrl = [NSURL URLWithString:self.path];
+    if (pathUrl == nil) {
+        return;
+    }
+
+    [NSFileManager.defaultManager trashItemAtURL:pathUrl
+                                resultingItemURL:nil
+                                           error:nil];
+}
+
+- (void)revealInFinder
+{
+    if (self.isStream) {
+        return;
+    }
+
+    NSURL *pathUrl = [NSURL URLWithString:self.path];
+    if (pathUrl == nil) {
+        return;
+    }
+
+    [NSWorkspace.sharedWorkspace activateFileViewerSelectingURLs:@[pathUrl]];
+}
+
 @end
 
 


=====================================
modules/gui/macosx/library/VLCLibraryController.h
=====================================
@@ -35,7 +35,6 @@ NS_ASSUME_NONNULL_BEGIN
 
 - (int)appendItemToPlaylist:(VLCMediaLibraryMediaItem *)mediaItem playImmediately:(BOOL)playImmediately;
 - (int)appendItemsToPlaylist:(NSArray <VLCMediaLibraryMediaItem *> *)mediaItemArray playFirstItemImmediately:(BOOL)playFirstItemImmediately;
-- (void)showItemInFinder:(VLCMediaLibraryMediaItem *)mediaItem;
 
 - (int)addFolderWithFileURL:(NSURL *)fileURL;
 - (int)banFolderWithFileURL:(NSURL *)fileURL;


=====================================
modules/gui/macosx/library/VLCLibraryController.m
=====================================
@@ -118,21 +118,6 @@
     return ret;
 }
 
-- (void)showItemInFinder:(VLCMediaLibraryMediaItem *)mediaItem;
-{
-    if (mediaItem == nil) {
-        return;
-    }
-    VLCMediaLibraryFile *firstFile = mediaItem.files.firstObject;
-
-    if (firstFile) {
-        NSURL *URL = [NSURL URLWithString:firstFile.MRL];
-        if (URL) {
-            [[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:@[URL]];
-        }
-    }
-}
-
 #pragma mark - folder management
 
 - (int)addFolderWithFileURL:(NSURL *)fileURL


=====================================
modules/gui/macosx/library/VLCLibraryDataTypes.h
=====================================
@@ -97,9 +97,17 @@ extern const long long int VLCMediaLibraryMediaItemDurationDenominator;
 
 @end
 
-#pragma mark - Audio media library classes
+#pragma mark - Media library classes
 
- at protocol VLCMediaLibraryItemProtocol <NSObject>
+ at protocol VLCLocallyManipulableItemProtocol <NSObject>
+
+- (void)revealInFinder;
+- (void)moveToTrash;
+
+ at end
+
+// Protocol with common methods and properties expected for media library items
+ at protocol VLCMediaLibraryItemProtocol <VLCLocallyManipulableItemProtocol>
 
 @property (readonly) int64_t libraryID;
 @property (readonly) BOOL smallArtworkGenerated;
@@ -114,6 +122,8 @@ extern const long long int VLCMediaLibraryMediaItemDurationDenominator;
 
 @end
 
+// Extended VLCMediaLibraryItemProtocol that includes additional properties for media library item
+// audio groups (i.e. artists, genres, etc.)
 @protocol VLCMediaLibraryAudioGroupProtocol <VLCMediaLibraryItemProtocol>
 
 @property (readonly) unsigned int numberOfTracks;
@@ -123,7 +133,29 @@ extern const long long int VLCMediaLibraryMediaItemDurationDenominator;
 
 @end
 
- at interface VLCMediaLibraryArtist : NSObject<VLCMediaLibraryAudioGroupProtocol>
+// Base abstract class with common implementations of properties used by media library items.
+// Do not use directly -- subclass to create new media library item types.
+ at interface VLCAbstractMediaLibraryItem : NSObject
+
+ at property (readonly) int64_t libraryID;
+ at property (readonly) BOOL smallArtworkGenerated;
+ at property (readonly) NSImage *smallArtworkImage;
+ at property (readonly, strong, atomic) NSString *smallArtworkMRL;
+
+ at end
+
+// Like VLCAbstractMediaLibraryItem but with some additional functionality for audio groupings
+// such as artists and genres. Do not use directly, subclass instead.
+ at interface VLCAbstractMediaLibraryAudioGroup : VLCAbstractMediaLibraryItem<VLCLocallyManipulableItemProtocol>
+
+ at property (readonly) NSArray <VLCMediaLibraryMediaItem *> *tracksAsMediaItems;
+ at property (readonly) VLCMediaLibraryMediaItem *firstMediaItem;
+
+- (void)iterateMediaItemsWithBlock:(void (^)(VLCMediaLibraryMediaItem*))mediaItemBlock;
+
+ at end
+
+ at interface VLCMediaLibraryArtist : VLCAbstractMediaLibraryAudioGroup<VLCMediaLibraryAudioGroupProtocol>
 
 + (nullable instancetype)artistWithID:(int64_t)artistID;
 - (instancetype)initWithArtist:(struct vlc_ml_artist_t *)p_artist;
@@ -135,7 +167,7 @@ extern const long long int VLCMediaLibraryMediaItemDurationDenominator;
 
 @end
 
- at interface VLCMediaLibraryAlbum : NSObject<VLCMediaLibraryAudioGroupProtocol>
+ at interface VLCMediaLibraryAlbum : VLCAbstractMediaLibraryAudioGroup<VLCMediaLibraryAudioGroupProtocol>
 
 + (nullable instancetype)albumWithID:(int64_t)albumID;
 - (instancetype)initWithAlbum:(struct vlc_ml_album_t *)p_album;
@@ -149,18 +181,16 @@ extern const long long int VLCMediaLibraryMediaItemDurationDenominator;
 
 @end
 
- at interface VLCMediaLibraryGenre : NSObject<VLCMediaLibraryAudioGroupProtocol>
+ at interface VLCMediaLibraryGenre : VLCAbstractMediaLibraryAudioGroup<VLCMediaLibraryAudioGroupProtocol>
 
 + (nullable instancetype)genreWithID:(int64_t)genreID;
 - (instancetype)initWithGenre:(struct vlc_ml_genre_t *)p_genre;
 
 @property (readonly) NSString *name;
 
-- (void)iterateMediaItemsWithBlock:(void (^)(VLCMediaLibraryMediaItem*))mediaItemBlock orderedBy:(int)mediaItemParentType;
-
 @end
 
- at interface VLCMediaLibraryMediaItem : NSObject<VLCMediaLibraryItemProtocol>
+ at interface VLCMediaLibraryMediaItem : VLCAbstractMediaLibraryItem<VLCMediaLibraryItemProtocol>
 
 + (nullable instancetype)mediaItemForLibraryID:(int64_t)libraryID;
 + (nullable instancetype)mediaItemForURL:(NSURL *)url;
@@ -214,7 +244,6 @@ extern const long long int VLCMediaLibraryMediaItemDurationDenominator;
 @property (readonly) int trackNumber;
 @property (readonly) int discNumber;
 
-
 @end
 
 @interface VLCMediaLibraryEntryPoint : NSObject


=====================================
modules/gui/macosx/library/VLCLibraryDataTypes.m
=====================================
@@ -252,13 +252,63 @@ static NSArray<VLCMediaLibraryArtist *> *fetchArtistsForLibraryItem(library_arti
 
 @end
 
-#pragma mark - Audio media library classes
+#pragma mark - Media library item classes
+
+ at interface VLCAbstractMediaLibraryItem ()
+
+ at property (readwrite, assign) int64_t libraryID;
+ at property (readwrite, assign) BOOL smallArtworkGenerated;
+ at property (readwrite, atomic, strong) NSString *smallArtworkMRL;
+
+ at end
+
+ at implementation VLCAbstractMediaLibraryItem
+
+- (NSImage *)smallArtworkImage
+{
+    NSImage *image = [VLCLibraryImageCache thumbnailForLibraryItem:self];
+    if (!image) {
+        image = [NSImage imageNamed:@"noart.png"];
+    }
+    return image;
+}
+
+ at end
+
+ at implementation VLCAbstractMediaLibraryAudioGroup
+
+- (NSArray <VLCMediaLibraryMediaItem *> *)tracksAsMediaItems
+{
+    [self doesNotRecognizeSelector:_cmd];
+    return nil;
+}
+
+- (void)iterateMediaItemsWithBlock:(void (^)(VLCMediaLibraryMediaItem*))mediaItemBlock
+{
+    [self doesNotRecognizeSelector:_cmd];
+}
+
+- (VLCMediaLibraryMediaItem *)firstMediaItem
+{
+    return [[self tracksAsMediaItems] firstObject];
+}
+
+- (void)moveToTrash
+{
+    [self iterateMediaItemsWithBlock:^(VLCMediaLibraryMediaItem* childMediaItem) {
+        [childMediaItem moveToTrash];
+    }];
+}
+
+- (void)revealInFinder
+{
+    [self.firstMediaItem revealInFinder];
+}
+
+ at end
 
 @implementation VLCMediaLibraryArtist
 
- at synthesize libraryID = _libraryID;
- at synthesize smallArtworkGenerated = _smallArtworkGenerated;
- at synthesize smallArtworkMRL = _smallArtworkMRL;
 @synthesize numberOfTracks = _numberOfTracks;
 
 + (nullable instancetype)artistWithID:(int64_t)artistID
@@ -279,11 +329,12 @@ static NSArray<VLCMediaLibraryArtist *> *fetchArtistsForLibraryItem(library_arti
 {
     self = [super init];
     if (self && p_artist != NULL) {
-        _libraryID = p_artist->i_id;
+        self.libraryID = p_artist->i_id;
+        self.smallArtworkGenerated = p_artist->thumbnails[VLC_ML_THUMBNAIL_SMALL].psz_mrl != NULL;
+        self.smallArtworkMRL = self.smallArtworkGenerated ? toNSStr(p_artist->thumbnails[VLC_ML_THUMBNAIL_SMALL].psz_mrl) : nil;
+
         _name = toNSStr(p_artist->psz_name);
         _shortBiography = toNSStr(p_artist->psz_shortbio);
-        _smallArtworkGenerated = p_artist->thumbnails[VLC_ML_THUMBNAIL_SMALL].psz_mrl != NULL;
-        _smallArtworkMRL = _smallArtworkGenerated ? toNSStr(p_artist->thumbnails[VLC_ML_THUMBNAIL_SMALL].psz_mrl) : nil;
         _musicBrainzID = toNSStr(p_artist->psz_mb_id);
         _numberOfAlbums = p_artist->i_nb_album;
         _numberOfTracks = p_artist->i_nb_tracks;
@@ -291,15 +342,6 @@ static NSArray<VLCMediaLibraryArtist *> *fetchArtistsForLibraryItem(library_arti
     return self;
 }
 
-- (NSImage *)smallArtworkImage
-{
-    NSImage *image = [VLCLibraryImageCache thumbnailForLibraryItem:self];
-    if (!image) {
-        image = [NSImage imageNamed:@"noart.png"];
-    }
-    return image;
-}
-
 - (NSString *)displayString
 {
     return _name;
@@ -334,17 +376,12 @@ static NSArray<VLCMediaLibraryArtist *> *fetchArtistsForLibraryItem(library_arti
 
 - (NSArray<VLCMediaLibraryAlbum *> *)albums
 {
-    return fetchAlbumsForLibraryItem(vlc_ml_list_artist_albums, _libraryID);
+    return fetchAlbumsForLibraryItem(vlc_ml_list_artist_albums, self.libraryID);
 }
 
 - (NSArray<VLCMediaLibraryMediaItem *> *)tracksAsMediaItems
 {
-    return fetchMediaItemsForLibraryItem(vlc_ml_list_artist_tracks, _libraryID);
-}
-
-- (VLCMediaLibraryMediaItem *)firstMediaItem
-{
-    return [[self tracksAsMediaItems] firstObject];
+    return fetchMediaItemsForLibraryItem(vlc_ml_list_artist_tracks, self.libraryID);
 }
 
 - (void)iterateMediaItemsWithBlock:(void (^)(VLCMediaLibraryMediaItem*))mediaItemBlock;
@@ -358,9 +395,6 @@ static NSArray<VLCMediaLibraryArtist *> *fetchArtistsForLibraryItem(library_arti
 
 @implementation VLCMediaLibraryAlbum
 
- at synthesize libraryID = _libraryID;
- at synthesize smallArtworkGenerated = _smallArtworkGenerated;
- at synthesize smallArtworkMRL = _smallArtworkMRL;
 @synthesize numberOfTracks = _numberOfTracks;
 
 + (nullable instancetype)albumWithID:(int64_t)albumID
@@ -381,11 +415,12 @@ static NSArray<VLCMediaLibraryArtist *> *fetchArtistsForLibraryItem(library_arti
 {
     self = [super init];
     if (self && p_album != NULL) {
-        _libraryID = p_album->i_id;
+        self.libraryID = p_album->i_id;
+        self.smallArtworkGenerated = p_album->thumbnails[VLC_ML_THUMBNAIL_SMALL].psz_mrl != NULL;
+        self.smallArtworkMRL = self.smallArtworkGenerated ? toNSStr(p_album->thumbnails[VLC_ML_THUMBNAIL_SMALL].psz_mrl) : nil;
+
         _title = toNSStr(p_album->psz_title);
         _summary = toNSStr(p_album->psz_summary);
-        _smallArtworkGenerated = p_album->thumbnails[VLC_ML_THUMBNAIL_SMALL].psz_mrl != NULL;
-        _smallArtworkMRL = _smallArtworkGenerated ? toNSStr(p_album->thumbnails[VLC_ML_THUMBNAIL_SMALL].psz_mrl) : nil;
         _artistName = toNSStr(p_album->psz_artist);
         _artistID = p_album->i_artist_id;
         _numberOfTracks = p_album->i_nb_tracks;
@@ -395,15 +430,6 @@ static NSArray<VLCMediaLibraryArtist *> *fetchArtistsForLibraryItem(library_arti
     return self;
 }
 
-- (NSImage *)smallArtworkImage
-{
-    NSImage *image = [VLCLibraryImageCache thumbnailForLibraryItem:self];
-    if (!image) {
-        image = [NSImage imageNamed:@"noart.png"];
-    }
-    return image;
-}
-
 - (NSString *)displayString
 {
     return _title;
@@ -431,12 +457,7 @@ static NSArray<VLCMediaLibraryArtist *> *fetchArtistsForLibraryItem(library_arti
 
 - (NSArray<VLCMediaLibraryMediaItem *> *)tracksAsMediaItems
 {
-    return fetchMediaItemsForLibraryItem(vlc_ml_list_album_tracks, _libraryID);
-}
-
-- (VLCMediaLibraryMediaItem *)firstMediaItem
-{
-    return [[self tracksAsMediaItems] firstObject];
+    return fetchMediaItemsForLibraryItem(vlc_ml_list_album_tracks, self.libraryID);
 }
 
 - (void)iterateMediaItemsWithBlock:(void (^)(VLCMediaLibraryMediaItem*))mediaItemBlock
@@ -450,20 +471,18 @@ static NSArray<VLCMediaLibraryArtist *> *fetchArtistsForLibraryItem(library_arti
 
 @implementation VLCMediaLibraryGenre
 
- at synthesize libraryID = _libraryID;
- at synthesize smallArtworkGenerated = _smallArtworkGenerated;
- at synthesize smallArtworkMRL = _smallArtworkMRL;
 @synthesize numberOfTracks = _numberOfTracks;
 
 - (instancetype)initWithGenre:(struct vlc_ml_genre_t *)p_genre
 {
     self = [super init];
     if (self && p_genre != NULL) {
-        _libraryID = p_genre->i_id;
+        self.libraryID = p_genre->i_id;
+        self.smallArtworkGenerated = p_genre->thumbnails[VLC_ML_THUMBNAIL_SMALL].psz_mrl != NULL;
+        self.smallArtworkMRL = self.smallArtworkGenerated ? toNSStr(p_genre->thumbnails[VLC_ML_THUMBNAIL_SMALL].psz_mrl) : nil;
+
         _name = toNSStr(p_genre->psz_name);
         _numberOfTracks = p_genre->i_nb_tracks;
-        _smallArtworkGenerated = p_genre->thumbnails[VLC_ML_THUMBNAIL_SMALL].psz_mrl != NULL;
-        _smallArtworkMRL = _smallArtworkGenerated ? toNSStr(p_genre->thumbnails[VLC_ML_THUMBNAIL_SMALL].psz_mrl) : nil;
     }
     return self;
 }
@@ -482,15 +501,6 @@ static NSArray<VLCMediaLibraryArtist *> *fetchArtistsForLibraryItem(library_arti
     return genre;
 }
 
-- (NSImage *)smallArtworkImage
-{
-    NSImage *image = [VLCLibraryImageCache thumbnailForLibraryItem:self];
-    if (!image) {
-        image = [NSImage imageNamed:@"noart.png"];
-    }
-    return image;
-}
-
 - (NSString *)displayString
 {
     return _name;
@@ -512,23 +522,18 @@ static NSArray<VLCMediaLibraryArtist *> *fetchArtistsForLibraryItem(library_arti
 
 - (NSArray<VLCMediaLibraryAlbum *> *)albums
 {
-    return fetchAlbumsForLibraryItem(vlc_ml_list_genre_albums, _libraryID);
+    return fetchAlbumsForLibraryItem(vlc_ml_list_genre_albums, self.libraryID);
 }
 
 - (NSArray<VLCMediaLibraryArtist *> *)artists
 {
 
-    return fetchArtistsForLibraryItem(vlc_ml_list_genre_artists, _libraryID);
+    return fetchArtistsForLibraryItem(vlc_ml_list_genre_artists, self.libraryID);
 }
 
 - (NSArray<VLCMediaLibraryMediaItem *> *)tracksAsMediaItems
 {
-    return fetchMediaItemsForLibraryItem(vlc_ml_list_genre_tracks, _libraryID);
-}
-
-- (VLCMediaLibraryMediaItem *)firstMediaItem
-{
-    return [[self tracksAsMediaItems] firstObject];
+    return fetchMediaItemsForLibraryItem(vlc_ml_list_genre_tracks, self.libraryID);
 }
 
 - (void)iterateMediaItemsWithBlock:(void (^)(VLCMediaLibraryMediaItem*))mediaItemBlock
@@ -570,10 +575,6 @@ static NSArray<VLCMediaLibraryArtist *> *fetchArtistsForLibraryItem(library_arti
 
 #pragma mark - initialization
 
- at synthesize libraryID = _libraryID;
- at synthesize smallArtworkGenerated = _smallArtworkGenerated;
- at synthesize smallArtworkMRL = _smallArtworkMRL;
-
 + (nullable instancetype)mediaItemForLibraryID:(int64_t)libraryID
 {
     vlc_medialibrary_t *p_mediaLibrary = getMediaLibrary();
@@ -627,8 +628,11 @@ static NSArray<VLCMediaLibraryArtist *> *fetchArtistsForLibraryItem(library_arti
 {
     self = [super init];
     if (self && p_mediaItem != NULL && p_mediaLibrary != NULL) {
+        self.libraryID = p_mediaItem->i_id;
+        self.smallArtworkGenerated = p_mediaItem->thumbnails[VLC_ML_THUMBNAIL_SMALL].psz_mrl != NULL;
+        self.smallArtworkMRL = self.smallArtworkGenerated ? toNSStr(p_mediaItem->thumbnails[VLC_ML_THUMBNAIL_SMALL].psz_mrl) : nil;
+
         _p_mediaLibrary = p_mediaLibrary;
-        _libraryID = p_mediaItem->i_id;
         _mediaType = p_mediaItem->i_type;
         _mediaSubType = p_mediaItem->i_subtype;
         NSMutableArray *mutArray = [[NSMutableArray alloc] initWithCapacity:p_mediaItem->p_files->i_nb_items];
@@ -656,8 +660,6 @@ static NSArray<VLCMediaLibraryArtist *> *fetchArtistsForLibraryItem(library_arti
         _lastPlayedDate = p_mediaItem->i_last_played_date;
         _progress = p_mediaItem->f_progress;
         _title = toNSStr(p_mediaItem->psz_title);
-        _smallArtworkGenerated = p_mediaItem->thumbnails[VLC_ML_THUMBNAIL_SMALL].psz_mrl != NULL;
-        _smallArtworkMRL = _smallArtworkGenerated ? toNSStr(p_mediaItem->thumbnails[VLC_ML_THUMBNAIL_SMALL].psz_mrl) : nil;
         _favorited = p_mediaItem->b_is_favorite;
 
         switch (p_mediaItem->i_subtype) {
@@ -747,13 +749,13 @@ static NSArray<VLCMediaLibraryArtist *> *fetchArtistsForLibraryItem(library_arti
         return;
     }
 
-    [aCoder encodeInt64:_libraryID forKey:VLCMediaLibraryMediaItemLibraryID];
+    [aCoder encodeInt64:self.libraryID forKey:VLCMediaLibraryMediaItemLibraryID];
 }
 
 - (NSString *)description
 {
     return [NSString stringWithFormat:@"%@ — title: %@, ID: %lli, type: %i, artwork: %@",
-            NSStringFromClass([self class]), _title, _libraryID, _mediaType, _smallArtworkMRL];
+            NSStringFromClass([self class]), _title, self.libraryID, _mediaType, self.smallArtworkMRL];
 }
 
 - (NSString *)readableMediaType
@@ -794,15 +796,6 @@ static NSArray<VLCMediaLibraryArtist *> *fetchArtistsForLibraryItem(library_arti
     }
 }
 
-- (NSImage *)smallArtworkImage
-{
-    NSImage *image = [VLCLibraryImageCache thumbnailForLibraryItem:self];
-    if (!image) {
-        image = [NSImage imageNamed:@"noart.png"];
-    }
-    return image;
-}
-
 - (NSString *)displayString
 {
     return _title;
@@ -841,7 +834,7 @@ static NSArray<VLCMediaLibraryArtist *> *fetchArtistsForLibraryItem(library_arti
 
 - (VLCInputItem *)inputItem
 {
-    input_item_t *p_inputItem = vlc_ml_get_input_item(_p_mediaLibrary, _libraryID);
+    input_item_t *p_inputItem = vlc_ml_get_input_item(_p_mediaLibrary, self.libraryID);
     VLCInputItem *inputItem = nil;
     if (p_inputItem) {
         inputItem = [[VLCInputItem alloc] initWithInputItem:p_inputItem];
@@ -864,7 +857,7 @@ static NSArray<VLCMediaLibraryArtist *> *fetchArtistsForLibraryItem(library_arti
 
 - (int)setIntegerPreference:(int)value forKey:(enum vlc_ml_playback_state)key
 {
-    return vlc_ml_media_set_playback_state(_p_mediaLibrary, _libraryID, key, [[[NSNumber numberWithInt:value] stringValue] UTF8String]);
+    return vlc_ml_media_set_playback_state(_p_mediaLibrary, self.libraryID, key, [[[NSNumber numberWithInt:value] stringValue] UTF8String]);
 }
 
 - (int)integerPreferenceForKey:(enum vlc_ml_playback_state)key
@@ -872,7 +865,7 @@ static NSArray<VLCMediaLibraryArtist *> *fetchArtistsForLibraryItem(library_arti
     int ret = 0;
     char *psz_value;
 
-    if (vlc_ml_media_get_playback_state(_p_mediaLibrary, _libraryID, key, &psz_value) == VLC_SUCCESS && psz_value != NULL) {
+    if (vlc_ml_media_get_playback_state(_p_mediaLibrary, self.libraryID, key, &psz_value) == VLC_SUCCESS && psz_value != NULL) {
         ret = atoi(psz_value);
         free(psz_value);
     }
@@ -882,7 +875,7 @@ static NSArray<VLCMediaLibraryArtist *> *fetchArtistsForLibraryItem(library_arti
 
 - (int)setFloatPreference:(float)value forKey:(enum vlc_ml_playback_state)key
 {
-    return vlc_ml_media_set_playback_state(_p_mediaLibrary, _libraryID, key, [[[NSNumber numberWithFloat:value] stringValue] UTF8String]);
+    return vlc_ml_media_set_playback_state(_p_mediaLibrary, self.libraryID, key, [[[NSNumber numberWithFloat:value] stringValue] UTF8String]);
 }
 
 - (float)floatPreferenceForKey:(enum vlc_ml_playback_state)key
@@ -890,7 +883,7 @@ static NSArray<VLCMediaLibraryArtist *> *fetchArtistsForLibraryItem(library_arti
     float ret = .0;
     char *psz_value;
 
-    if (vlc_ml_media_get_playback_state(_p_mediaLibrary, _libraryID, key, &psz_value) == VLC_SUCCESS && psz_value != NULL) {
+    if (vlc_ml_media_get_playback_state(_p_mediaLibrary, self.libraryID, key, &psz_value) == VLC_SUCCESS && psz_value != NULL) {
         ret = atof(psz_value);
         free(psz_value);
     }
@@ -900,7 +893,7 @@ static NSArray<VLCMediaLibraryArtist *> *fetchArtistsForLibraryItem(library_arti
 
 - (int)setStringPreference:(NSString *)value forKey:(enum vlc_ml_playback_state)key
 {
-    return vlc_ml_media_set_playback_state(_p_mediaLibrary, _libraryID, key, [value UTF8String]);
+    return vlc_ml_media_set_playback_state(_p_mediaLibrary, self.libraryID, key, [value UTF8String]);
 }
 
 - (NSString *)stringPreferenceForKey:(enum vlc_ml_playback_state)key
@@ -908,7 +901,7 @@ static NSArray<VLCMediaLibraryArtist *> *fetchArtistsForLibraryItem(library_arti
     NSString *ret = @"";
     char *psz_value;
 
-    if (vlc_ml_media_get_playback_state(_p_mediaLibrary, _libraryID, key, &psz_value) == VLC_SUCCESS && psz_value != NULL) {
+    if (vlc_ml_media_get_playback_state(_p_mediaLibrary, self.libraryID, key, &psz_value) == VLC_SUCCESS && psz_value != NULL) {
         ret = toNSStr(psz_value);
         free(psz_value);
     }
@@ -1078,6 +1071,28 @@ static NSArray<VLCMediaLibraryArtist *> *fetchArtistsForLibraryItem(library_arti
     [self setIntegerPreference:lastSubtitleDelay forKey:VLC_ML_PLAYBACK_STATE_SUBTITLE_DELAY];
 }
 
+- (void)revealInFinder
+{
+    VLCMediaLibraryFile *firstFile = _files.firstObject;
+
+    if (firstFile) {
+        NSURL *URL = [NSURL URLWithString:firstFile.MRL];
+        if (URL) {
+            [[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:@[URL]];
+        }
+    }
+}
+
+- (void)moveToTrash
+{
+    NSFileManager *fileManager = [NSFileManager defaultManager];
+    for (VLCMediaLibraryFile *fileToTrash in _files) {
+        [fileManager trashItemAtURL:fileToTrash.fileURL
+                   resultingItemURL:nil
+                              error:nil];
+    }
+}
+
 @end
 
 @implementation VLCMediaLibraryEntryPoint


=====================================
modules/gui/macosx/library/VLCLibraryImageCache.h
=====================================
@@ -26,11 +26,11 @@ NS_ASSUME_NONNULL_BEGIN
 
 @class VLCInputItem;
 @class VLCPlaylistItem;
- at protocol VLCMediaLibraryItemProtocol;
+ at class VLCAbstractMediaLibraryItem;
 
 @interface VLCLibraryImageCache : NSObject
 
-+ (nullable NSImage *)thumbnailForLibraryItem:(id<VLCMediaLibraryItemProtocol>)libraryItem;
++ (nullable NSImage *)thumbnailForLibraryItem:(VLCAbstractMediaLibraryItem*)libraryItem;
 + (nullable NSImage *)thumbnailForInputItem:(VLCInputItem*)inputItem;
 + (nullable NSImage *)thumbnailForPlaylistItem:(VLCPlaylistItem*)playlistItem;
 


=====================================
modules/gui/macosx/library/VLCLibraryImageCache.m
=====================================
@@ -64,12 +64,12 @@ float kVLCDefaultThumbnailPosition = .15;
     return sharedImageCache;
 }
 
-+ (NSImage *)thumbnailForLibraryItem:(id<VLCMediaLibraryItemProtocol>)libraryItem
++ (NSImage *)thumbnailForLibraryItem:(VLCAbstractMediaLibraryItem*)libraryItem
 {
     return [[VLCLibraryImageCache sharedImageCache] imageForLibraryItem:libraryItem];
 }
 
-- (NSImage *)imageForLibraryItem:(id<VLCMediaLibraryItemProtocol>)libraryItem
+- (NSImage *)imageForLibraryItem:(VLCAbstractMediaLibraryItem*)libraryItem
 {
     NSImage *cachedImage = [_imageCache objectForKey:libraryItem.smallArtworkMRL];
     if (cachedImage) {
@@ -78,7 +78,7 @@ float kVLCDefaultThumbnailPosition = .15;
     return [self smallThumbnailForLibraryItem:libraryItem];
 }
 
-- (NSImage *)smallThumbnailForLibraryItem:(id<VLCMediaLibraryItemProtocol>)libraryItem
+- (NSImage *)smallThumbnailForLibraryItem:(VLCAbstractMediaLibraryItem*)libraryItem
 {
     NSImage *image;
     NSString *artworkMRL = libraryItem.smallArtworkMRL;


=====================================
modules/gui/macosx/library/VLCLibraryMenuController.m
=====================================
@@ -195,73 +195,19 @@
 - (void)revealInFinder:(id)sender
 {
     if (_representedItem != nil) {
-        [self revealMediaLibraryItemInFinder:_representedItem];
-    } else if (_representedInputItem != nil && (!_representedInputItem.isStream)) {
-        [self revealInputItemInFinder:_representedInputItem];
-    }
-}
-
-- (void)revealMediaLibraryItemInFinder:(id<VLCMediaLibraryItemProtocol>)mediaLibraryItem
-{
-    NSParameterAssert(mediaLibraryItem);
-    VLCMediaLibraryMediaItem *firstMediaItem = mediaLibraryItem.firstMediaItem;
-
-    if(firstMediaItem) {
-        [VLCMain.sharedInstance.libraryController showItemInFinder:firstMediaItem];
-    }
-}
-
-- (void)revealInputItemInFinder:(VLCInputItem*)inputItem
-{
-    NSParameterAssert(inputItem);
-    NSAssert(!inputItem.isStream, @"Cannot reveal a stream input item in Finder");
-    
-    NSString *path = inputItem.path;
-
-    if (!path || path.length == 0) {
-        return;
+        [_representedItem revealInFinder];
+    } else if (_representedInputItem != nil) {
+        [_representedInputItem revealInFinder];
     }
-
-    [NSWorkspace.sharedWorkspace selectFile:path inFileViewerRootedAtPath:path];
 }
 
 - (void)moveToTrash:(id)sender
 {
     if (_representedItem != nil) {
-        [self moveMediaLibraryItemToTrash:_representedItem];
-    } else if (_representedInputItem != nil && (!_representedInputItem.isStream)) {
-        [self moveInputItemToTrash:_representedInputItem];
-    }
-}
-
-- (void)moveMediaLibraryItemToTrash:(id<VLCMediaLibraryItemProtocol>)mediaLibraryItem
-{
-    NSParameterAssert(mediaLibraryItem);
-
-    NSFileManager *fileManager = [NSFileManager defaultManager];
-    [mediaLibraryItem iterateMediaItemsWithBlock:^(VLCMediaLibraryMediaItem* childMediaItem) {
-        for (VLCMediaLibraryFile *fileToTrash in childMediaItem.files) {
-            [fileManager trashItemAtURL:fileToTrash.fileURL
-                       resultingItemURL:nil
-                                  error:nil];
-        }
-    }];
-}
-
-- (void)moveInputItemToTrash:(VLCInputItem*)inputItem
-{
-    NSParameterAssert(inputItem);
-    NSAssert(!inputItem.isStream, @"Cannot move a stream input item to trash");
-
-    NSString *path = inputItem.path;
-
-    if (!path || path.length == 0) {
-        return;
+        [_representedItem moveToTrash];
+    } else if (_representedInputItem != nil) {
+        [_representedInputItem moveToTrash];
     }
-
-    [NSFileManager.defaultManager trashItemAtURL:[NSURL URLWithString:path]
-                                resultingItemURL:nil
-                                           error:nil];
 }
 
 - (void)showInformation:(id)sender



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/ff1316724f3520ae0220fd693b6b589d56240561...b3ffbdb67d0f185f2995795527d24bb0f2bc3ba9

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/ff1316724f3520ae0220fd693b6b589d56240561...b3ffbdb67d0f185f2995795527d24bb0f2bc3ba9
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