[vlc-commits] [Git][videolan/vlc][master] macosx: Make all library audio items use the artwork image cache
Jean-Baptiste Kempf (@jbk)
gitlab at videolan.org
Mon Jul 25 11:08:45 UTC 2022
Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC
Commits:
61556384 by Claudio Cambra at 2022-07-25T11:08:35+00:00
macosx: Make all library audio items use the artwork image cache
- - - - -
7 changed files:
- modules/gui/macosx/Makefile.am
- â modules/gui/macosx/extensions/NSImage+Helpers.h
- â modules/gui/macosx/extensions/NSImage+Helpers.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
Changes:
=====================================
modules/gui/macosx/Makefile.am
=====================================
@@ -36,8 +36,6 @@ libmacosx_plugin_la_SOURCES = \
gui/macosx/extensions/NSColor+VLCAdditions.m \
gui/macosx/extensions/NSFont+VLCAdditions.h \
gui/macosx/extensions/NSFont+VLCAdditions.m \
- gui/macosx/extensions/NSImage+Helpers.h \
- gui/macosx/extensions/NSImage+Helpers.m \
gui/macosx/extensions/NSMenu+VLCAdditions.h \
gui/macosx/extensions/NSMenu+VLCAdditions.m \
gui/macosx/extensions/NSScreen+VLCAdditions.h \
=====================================
modules/gui/macosx/extensions/NSImage+Helpers.h deleted
=====================================
@@ -1,33 +0,0 @@
-/*****************************************************************************
- * NSImage+Helpers.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>
-
-NS_ASSUME_NONNULL_BEGIN
-
- at interface NSImage (Helpers)
-
-+ (instancetype)artworkOrPlaceholderFromMrl:(NSString *)artworkMRL;
-
- at end
-
-NS_ASSUME_NONNULL_END
\ No newline at end of file
=====================================
modules/gui/macosx/extensions/NSImage+Helpers.m deleted
=====================================
@@ -1,43 +0,0 @@
-/*****************************************************************************
- * NSImage+Helpers.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 "NSImage+Helpers.h"
-
-NS_ASSUME_NONNULL_BEGIN
-
- at implementation NSImage (Helpers)
-
-+ (instancetype)artworkOrPlaceholderFromMrl:(NSString *)artworkMRL
-{
- NSImage *image = nil;
- if (artworkMRL.length > 0) {
- image = [[NSImage alloc] initWithContentsOfURL:[NSURL URLWithString:artworkMRL]];
- }
- if (!image) {
- image = [NSImage imageNamed: @"noart.png"];
- }
- return image;
-}
-
- at end
-
-NS_ASSUME_NONNULL_END
\ No newline at end of file
=====================================
modules/gui/macosx/library/VLCLibraryDataTypes.h
=====================================
@@ -99,6 +99,7 @@ extern const long long int VLCMediaLibraryMediaItemDurationDenominator;
@protocol VLCMediaLibraryItemProtocol <NSObject>
+ at property (readonly) BOOL smallArtworkGenerated;
@property (readonly) NSImage *smallArtworkImage;
@property (readonly) NSString *smallArtworkMRL;
@property (readonly) NSString *displayString;
@@ -182,10 +183,6 @@ extern const long long int VLCMediaLibraryMediaItemDurationDenominator;
@property (readonly) float progress;
@property (readonly) NSString *title;
- at property (readonly, nullable) NSString *smallArtworkMRL;
- at property (readonly, nullable) NSImage *smallArtworkImage;
-
- at property (readonly) BOOL smallArtworkGenerated;
@property (readonly) BOOL favorited;
@property (readonly, nullable) VLCMediaLibraryShowEpisode *showEpisode;
=====================================
modules/gui/macosx/library/VLCLibraryDataTypes.m
=====================================
@@ -23,7 +23,6 @@
#import "VLCLibraryDataTypes.h"
#import "main/VLCMain.h"
-#import "extensions/NSImage+Helpers.h"
#import "extensions/NSString+Helpers.h"
#import "library/VLCInputItem.h"
#import "library/VLCLibraryImageCache.h"
@@ -183,6 +182,7 @@ NSString *VLCMediaLibraryMediaItemLibraryID = @"VLCMediaLibraryMediaItemLibraryI
@implementation VLCMediaLibraryArtist
+ at synthesize smallArtworkGenerated = _smallArtworkGenerated;
@synthesize smallArtworkMRL = _smallArtworkMRL;
+ (nullable instancetype)artistWithID:(int64_t)artistID
@@ -210,7 +210,8 @@ NSString *VLCMediaLibraryMediaItemLibraryID = @"VLCMediaLibraryMediaItemLibraryI
_artistID = p_artist->i_id;
_name = toNSStr(p_artist->psz_name);
_shortBiography = toNSStr(p_artist->psz_shortbio);
- _smallArtworkMRL = toNSStr(p_artist->thumbnails[VLC_ML_THUMBNAIL_SMALL].psz_mrl);
+ _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;
@@ -220,7 +221,11 @@ NSString *VLCMediaLibraryMediaItemLibraryID = @"VLCMediaLibraryMediaItemLibraryI
- (NSImage *)smallArtworkImage
{
- return [NSImage artworkOrPlaceholderFromMrl:_smallArtworkMRL];
+ NSImage *image = [VLCLibraryImageCache thumbnailForLibraryItem:self];
+ if (!image) {
+ image = [NSImage imageNamed:@"noart.png"];
+ }
+ return image;
}
- (NSString *)displayString
@@ -301,6 +306,7 @@ NSString *VLCMediaLibraryMediaItemLibraryID = @"VLCMediaLibraryMediaItemLibraryI
@implementation VLCMediaLibraryAlbum
+ at synthesize smallArtworkGenerated = _smallArtworkGenerated;
@synthesize smallArtworkMRL = _smallArtworkMRL;
- (instancetype)initWithAlbum:(struct vlc_ml_album_t *)p_album
@@ -310,7 +316,8 @@ NSString *VLCMediaLibraryMediaItemLibraryID = @"VLCMediaLibraryMediaItemLibraryI
_albumID = p_album->i_id;
_title = toNSStr(p_album->psz_title);
_summary = toNSStr(p_album->psz_summary);
- _smallArtworkMRL = toNSStr(p_album->thumbnails[VLC_ML_THUMBNAIL_SMALL].psz_mrl);
+ _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;
@@ -322,7 +329,11 @@ NSString *VLCMediaLibraryMediaItemLibraryID = @"VLCMediaLibraryMediaItemLibraryI
- (NSImage *)smallArtworkImage
{
- return [NSImage artworkOrPlaceholderFromMrl:_smallArtworkMRL];
+ NSImage *image = [VLCLibraryImageCache thumbnailForLibraryItem:self];
+ if (!image) {
+ image = [NSImage imageNamed:@"noart.png"];
+ }
+ return image;
}
@@ -372,6 +383,7 @@ NSString *VLCMediaLibraryMediaItemLibraryID = @"VLCMediaLibraryMediaItemLibraryI
@implementation VLCMediaLibraryGenre
+ at synthesize smallArtworkGenerated = _smallArtworkGenerated;
@synthesize smallArtworkMRL = _smallArtworkMRL;
- (instancetype)initWithGenre:(struct vlc_ml_genre_t *)p_genre
@@ -381,13 +393,19 @@ NSString *VLCMediaLibraryMediaItemLibraryID = @"VLCMediaLibraryMediaItemLibraryI
_genreID = p_genre->i_id;
_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;
}
- (NSImage *)smallArtworkImage
{
- return [NSImage artworkOrPlaceholderFromMrl:_smallArtworkMRL];
+ NSImage *image = [VLCLibraryImageCache thumbnailForLibraryItem:self];
+ if (!image) {
+ image = [NSImage imageNamed:@"noart.png"];
+ }
+ return image;
}
- (NSString *)displayString
@@ -508,6 +526,7 @@ NSString *VLCMediaLibraryMediaItemLibraryID = @"VLCMediaLibraryMediaItemLibraryI
#pragma mark - initialization
+ at synthesize smallArtworkGenerated = _smallArtworkGenerated;
@synthesize smallArtworkMRL = _smallArtworkMRL;
+ (nullable instancetype)mediaItemForLibraryID:(int64_t)libraryID
@@ -597,11 +616,7 @@ NSString *VLCMediaLibraryMediaItemLibraryID = @"VLCMediaLibraryMediaItemLibraryI
_progress = p_mediaItem->f_progress;
_title = toNSStr(p_mediaItem->psz_title);
_smallArtworkGenerated = p_mediaItem->thumbnails[VLC_ML_THUMBNAIL_SMALL].psz_mrl != NULL;
- if (_smallArtworkGenerated) {
- _smallArtworkMRL = toNSStr(p_mediaItem->thumbnails[VLC_ML_THUMBNAIL_SMALL].psz_mrl);
- } else {
- _smallArtworkMRL = nil;
- }
+ _smallArtworkMRL = _smallArtworkGenerated ? toNSStr(p_mediaItem->thumbnails[VLC_ML_THUMBNAIL_SMALL].psz_mrl) : nil;
_favorited = p_mediaItem->b_is_favorite;
switch (p_mediaItem->i_subtype) {
@@ -732,7 +747,7 @@ NSString *VLCMediaLibraryMediaItemLibraryID = @"VLCMediaLibraryMediaItemLibraryI
- (NSImage *)smallArtworkImage
{
- NSImage *image = [VLCLibraryImageCache thumbnailForMediaItem:self];
+ NSImage *image = [VLCLibraryImageCache thumbnailForLibraryItem:self];
if (!image) {
image = [NSImage imageNamed:@"noart.png"];
}
=====================================
modules/gui/macosx/library/VLCLibraryImageCache.h
=====================================
@@ -24,11 +24,11 @@
NS_ASSUME_NONNULL_BEGIN
- at class VLCMediaLibraryMediaItem;
+ at protocol VLCMediaLibraryItemProtocol;
@interface VLCLibraryImageCache : NSObject
-+ (nullable NSImage *)thumbnailForMediaItem:(VLCMediaLibraryMediaItem *)mediaItem;
++ (nullable NSImage *)thumbnailForLibraryItem:(id<VLCMediaLibraryItemProtocol>)libraryItem;
@end
=====================================
modules/gui/macosx/library/VLCLibraryImageCache.m
=====================================
@@ -59,27 +59,29 @@ float kVLCDefaultThumbnailPosition = .15;
return sharedImageCache;
}
-+ (NSImage *)thumbnailForMediaItem:(VLCMediaLibraryMediaItem *)mediaItem
++ (NSImage *)thumbnailForLibraryItem:(id<VLCMediaLibraryItemProtocol>)libraryItem
{
- return [[VLCLibraryImageCache sharedImageCache] imageForMediaItem:mediaItem];
+ return [[VLCLibraryImageCache sharedImageCache] imageForLibraryItem:libraryItem];
}
-- (NSImage *)imageForMediaItem:(VLCMediaLibraryMediaItem *)mediaItem
+- (NSImage *)imageForLibraryItem:(id<VLCMediaLibraryItemProtocol>)libraryItem
{
- NSImage *cachedImage = [_imageCache objectForKey:mediaItem.smallArtworkMRL];
+ NSImage *cachedImage = [_imageCache objectForKey:libraryItem.smallArtworkMRL];
if (cachedImage) {
return cachedImage;
}
- return [self smallThumbnailForMediaItem:mediaItem];
+ return [self smallThumbnailForLibraryItem:libraryItem];
}
-- (NSImage *)smallThumbnailForMediaItem:(VLCMediaLibraryMediaItem *)mediaItem
+- (NSImage *)smallThumbnailForLibraryItem:(id<VLCMediaLibraryItemProtocol>)libraryItem
{
NSImage *image;
- NSString *artworkMRL = mediaItem.smallArtworkMRL;
- if (mediaItem.smallArtworkGenerated) {
+ NSString *artworkMRL = libraryItem.smallArtworkMRL;
+ if (libraryItem.smallArtworkGenerated) {
image = [[NSImage alloc] initWithContentsOfURL:[NSURL URLWithString:artworkMRL]];
- } else {
+ } else if ([libraryItem isKindOfClass:[VLCMediaLibraryMediaItem class]]) {
+ VLCMediaLibraryMediaItem* mediaItem = (VLCMediaLibraryMediaItem*)libraryItem;
+
if (mediaItem.mediaType != VLC_ML_MEDIA_TYPE_AUDIO) {
[self generateThumbnailForMediaItem:mediaItem.libraryID];
}
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/61556384147016a0a43351af9c13f1a898c85a89
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/61556384147016a0a43351af9c13f1a898c85a89
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