[vlc-commits] [Git][videolan/vlc][master] macosx: Unify and refactor VLCLibraryTableCellView representation setting

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Thu Aug 4 06:24:05 UTC 2022



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
993a7b87 by Claudio Cambra at 2022-08-04T06:05:52+00:00
macosx: Unify and refactor VLCLibraryTableCellView representation setting

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

- - - - -


6 changed files:

- modules/gui/macosx/library/VLCLibraryAlbumTracksDataSource.m
- modules/gui/macosx/library/VLCLibraryAudioDataSource.m
- modules/gui/macosx/library/VLCLibraryDataTypes.h
- modules/gui/macosx/library/VLCLibraryDataTypes.m
- modules/gui/macosx/library/VLCLibraryTableCellView.h
- modules/gui/macosx/library/VLCLibraryTableCellView.m


Changes:

=====================================
modules/gui/macosx/library/VLCLibraryAlbumTracksDataSource.m
=====================================
@@ -77,21 +77,7 @@
         cellView.identifier = VLCAudioLibraryCellIdentifier;
     }
 
-    VLCMediaLibraryMediaItem *mediaItem = _tracks[row];
-
-    NSImage *image = mediaItem.smallArtworkImage;
-    if (!image) {
-        image = [NSImage imageNamed: @"noart.png"];
-    }
-    cellView.representedImageView.image = image;
-    cellView.representedMediaItem = mediaItem;
-
-    NSString *title = mediaItem.title;
-    cellView.primaryTitleTextField.hidden = NO;
-    cellView.secondaryTitleTextField.hidden = NO;
-    cellView.primaryTitleTextField.stringValue = title;
-    cellView.secondaryTitleTextField.stringValue = [NSString stringWithTime:mediaItem.duration / 1000];
-
+    [cellView setRepresentedItem:_tracks[row]];
     return cellView;
 }
 


=====================================
modules/gui/macosx/library/VLCLibraryAudioDataSource.m
=====================================
@@ -255,69 +255,7 @@
         cellView.identifier = VLCAudioLibraryCellIdentifier;
     }
 
-    switch (_currentParentType) {
-        case VLC_ML_PARENT_ARTIST:
-        {
-            VLCMediaLibraryArtist *artist = _displayedCollection[row];
-
-            cellView.singlePrimaryTitleTextField.hidden = NO;
-            cellView.singlePrimaryTitleTextField.stringValue = artist.name;
-            cellView.representedImageView.image = artist.smallArtworkImage;
-            break;
-        }
-        case VLC_ML_PARENT_ALBUM:
-        {
-            VLCMediaLibraryAlbum *album = _displayedCollection[row];
-
-            cellView.primaryTitleTextField.hidden = NO;
-            cellView.secondaryTitleTextField.hidden = NO;
-            cellView.primaryTitleTextField.stringValue = album.title;
-            cellView.secondaryTitleTextField.stringValue = album.artistName;
-            cellView.representedImageView.image = album.smallArtworkImage;
-            break;
-        }
-        case VLC_ML_PARENT_UNKNOWN:
-        {
-            VLCMediaLibraryMediaItem *mediaItem = _displayedCollection[row];
-
-            cellView.representedImageView.image = mediaItem.smallArtworkImage;
-            cellView.representedMediaItem = mediaItem;
-
-            NSString *title = mediaItem.title;
-            NSString *nameOfArtist;
-
-            VLCMediaLibraryArtist *artist = [VLCMediaLibraryArtist artistWithID:mediaItem.artistID];
-            if (artist) {
-                nameOfArtist = artist.name;
-            }
-
-            if (title && nameOfArtist) {
-                cellView.primaryTitleTextField.hidden = NO;
-                cellView.secondaryTitleTextField.hidden = NO;
-                cellView.primaryTitleTextField.stringValue = title;
-                cellView.secondaryTitleTextField.stringValue = nameOfArtist;
-            } else {
-                cellView.singlePrimaryTitleTextField.hidden = NO;
-                cellView.singlePrimaryTitleTextField.stringValue = title;
-            }
-            break;
-        }
-        case VLC_ML_PARENT_GENRE:
-        {
-            VLCMediaLibraryGenre *genre = _displayedCollection[row];
-
-            cellView.primaryTitleTextField.hidden = NO;
-            cellView.secondaryTitleTextField.hidden = NO;
-            cellView.primaryTitleTextField.stringValue = genre.name;
-            cellView.secondaryTitleTextField.stringValue = [NSString stringWithFormat:_NS("%lli items"), genre.numberOfTracks];
-            cellView.representedImageView.image = genre.smallArtworkImage;
-            break;
-        }
-        default:
-            NSAssert(1, @"reached the unreachable");
-            break;
-    }
-
+    [cellView setRepresentedItem:_displayedCollection[row]];
     return cellView;
 }
 


=====================================
modules/gui/macosx/library/VLCLibraryDataTypes.h
=====================================
@@ -104,6 +104,7 @@ extern const long long int VLCMediaLibraryMediaItemDurationDenominator;
 @property (readonly) NSImage *smallArtworkImage;
 @property (readonly) NSString *smallArtworkMRL;
 @property (readonly) NSString *displayString;
+ at property (readonly) NSString *detailString;
 @property (readonly) NSString *durationString;
 @property (readonly) VLCMediaLibraryMediaItem *firstMediaItem;
 


=====================================
modules/gui/macosx/library/VLCLibraryDataTypes.m
=====================================
@@ -303,6 +303,11 @@ static NSArray<VLCMediaLibraryArtist *> *fetchArtistsForLibraryItem(library_arti
     return _name;
 }
 
+- (NSString *)detailString
+{
+    return nil;
+}
+
 - (NSString *)durationString
 {
     NSString *countMetadataString;
@@ -377,12 +382,16 @@ static NSArray<VLCMediaLibraryArtist *> *fetchArtistsForLibraryItem(library_arti
     return image;
 }
 
-
 - (NSString *)displayString
 {
     return _title;
 }
 
+- (NSString *)detailString
+{
+    return _artistName;
+}
+
 - (NSString *)durationString
 {
     return [NSString stringWithTime:_duration / VLCMediaLibraryMediaItemDurationDenominator];
@@ -440,6 +449,11 @@ static NSArray<VLCMediaLibraryArtist *> *fetchArtistsForLibraryItem(library_arti
     return _name;
 }
 
+- (NSString *)detailString
+{
+    return [NSString stringWithFormat:_NS("%lli items"), _numberOfTracks];
+}
+
 - (NSString *)durationString
 {
     if (_numberOfTracks > 1) {
@@ -723,6 +737,16 @@ static NSArray<VLCMediaLibraryArtist *> *fetchArtistsForLibraryItem(library_arti
     return _title;
 }
 
+- (NSString *)detailString
+{
+    VLCMediaLibraryArtist *artist = [VLCMediaLibraryArtist artistWithID:_artistID];
+    if (artist) {
+        return artist.name;
+    }
+
+    return nil;
+}
+
 - (NSString *)durationString
 {
     return [NSString stringWithTime:_duration / VLCMediaLibraryMediaItemDurationDenominator];


=====================================
modules/gui/macosx/library/VLCLibraryTableCellView.h
=====================================
@@ -26,7 +26,7 @@ NS_ASSUME_NONNULL_BEGIN
 
 @class VLCImageView;
 @class VLCTrackingView;
- at class VLCMediaLibraryMediaItem;
+ at protocol VLCMediaLibraryItemProtocol;
 @class VLCInputItem;
 
 @interface VLCLibraryTableCellView : NSTableCellView
@@ -37,7 +37,8 @@ NS_ASSUME_NONNULL_BEGIN
 @property (readwrite, assign) IBOutlet NSTextField *primaryTitleTextField;
 @property (readwrite, assign) IBOutlet VLCImageView *representedImageView;
 @property (readwrite, assign) IBOutlet NSButton *playInstantlyButton;
- at property (readwrite, strong, nonatomic) VLCMediaLibraryMediaItem *representedMediaItem;
+
+ at property (readwrite, strong, nonatomic) id<VLCMediaLibraryItemProtocol> representedItem;
 @property (readwrite, strong, nonatomic) VLCInputItem *representedInputItem;
 
 @end


=====================================
modules/gui/macosx/library/VLCLibraryTableCellView.m
=====================================
@@ -51,13 +51,25 @@
     self.playInstantlyButton.hidden = YES;
 }
 
-- (void)setRepresentedMediaItem:(VLCMediaLibraryMediaItem *)representedMediaItem
+- (void)setRepresentedItem:(id<VLCMediaLibraryItemProtocol>)representedItem
 {
-    _representedMediaItem = representedMediaItem;
+    _representedItem = representedItem;
 
     self.trackingView.viewToHide = self.playInstantlyButton;
     self.playInstantlyButton.action = @selector(playMediaItemInstantly:);
     self.playInstantlyButton.target = self;
+
+    self.representedImageView.image = representedItem.smallArtworkImage;
+
+    if(representedItem.detailString.length > 0) {
+        self.primaryTitleTextField.hidden = NO;
+        self.primaryTitleTextField.stringValue = representedItem.displayString;
+        self.secondaryTitleTextField.hidden = NO;
+        self.secondaryTitleTextField.stringValue = representedItem.detailString;
+    } else {
+        self.singlePrimaryTitleTextField.hidden = NO;
+        self.singlePrimaryTitleTextField.stringValue = representedItem.displayString;
+    }
 }
 
 - (void)setRepresentedInputItem:(VLCInputItem *)representedInputItem
@@ -95,7 +107,7 @@
 
 - (void)playMediaItemInstantly:(id)sender
 {
-    [[[VLCMain sharedInstance] libraryController] appendItemToPlaylist:_representedMediaItem playImmediately:YES];
+    [[[VLCMain sharedInstance] libraryController] appendItemToPlaylist:_representedItem playImmediately:YES];
 }
 
 - (void)playInputItemInstantly:(id)sender



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/993a7b8762168df69adc7ccae83f555c1568f7fb

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/993a7b8762168df69adc7ccae83f555c1568f7fb
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