[vlc-commits] [Git][videolan/vlc][master] macosx: Stop using magic numbers for segmented control segments
Jean-Baptiste Kempf (@jbk)
gitlab at videolan.org
Wed Aug 17 17:01:00 UTC 2022
Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC
Commits:
452d9f86 by Claudio Cambra at 2022-08-17T17:00:50+00:00
macosx: Stop using magic numbers for segmented control segments
- - - - -
7 changed files:
- modules/gui/macosx/library/VLCLibraryAudioDataSource.h
- modules/gui/macosx/library/VLCLibraryAudioDataSource.m
- modules/gui/macosx/library/VLCLibraryModel.h
- modules/gui/macosx/library/VLCLibraryModel.m
- modules/gui/macosx/library/VLCLibraryWindow.h
- modules/gui/macosx/library/VLCLibraryWindow.m
- modules/gui/macosx/media-source/VLCMediaSourceBaseDataSource.m
Changes:
=====================================
modules/gui/macosx/library/VLCLibraryAudioDataSource.h
=====================================
@@ -30,6 +30,13 @@ NS_ASSUME_NONNULL_BEGIN
@class VLCLibraryGroupDataSource;
@class VLCMediaLibraryAlbum;
+typedef NS_ENUM(NSUInteger, VLCAudioLibrarySegment) {
+ VLCAudioLibraryArtistsSegment = 0,
+ VLCAudioLibraryAlbumsSegment,
+ VLCAudioLibrarySongsSegment,
+ VLCAudioLibraryGenresSegment
+};
+
@interface VLCLibraryAudioDataSource : NSObject <VLCLibraryTableViewDataSource, NSTableViewDelegate>
@property (readwrite, assign) VLCLibraryModel *libraryModel;
=====================================
modules/gui/macosx/library/VLCLibraryAudioDataSource.m
=====================================
@@ -119,12 +119,11 @@
- (void)setupAppearance
{
- NSArray *availableCollections = [VLCLibraryModel availableAudioCollections];
- NSUInteger availableCollectionsCount = availableCollections.count;
- self.segmentedControl.segmentCount = availableCollectionsCount;
- for (NSUInteger x = 0; x < availableCollectionsCount; x++) {
- [self.segmentedControl setLabel:availableCollections[x] forSegment:x];
- }
+ self.segmentedControl.segmentCount = 4;
+ [self.segmentedControl setLabel:_NS("Artists") forSegment:VLCAudioLibraryArtistsSegment];
+ [self.segmentedControl setLabel:_NS("Albums") forSegment:VLCAudioLibraryAlbumsSegment];
+ [self.segmentedControl setLabel:_NS("Songs") forSegment:VLCAudioLibrarySongsSegment];
+ [self.segmentedControl setLabel:_NS("Genres") forSegment:VLCAudioLibraryGenresSegment];
_collectionView.dataSource = self;
_collectionView.delegate = self;
@@ -200,19 +199,19 @@
_currentSelectedSegment = _segmentedControl.selectedSegment;
switch (_currentSelectedSegment) {
- case 0:
+ case VLCAudioLibraryArtistsSegment:
_displayedCollection = [self.libraryModel listOfArtists];
_currentParentType = VLC_ML_PARENT_ARTIST;
break;
- case 1:
+ case VLCAudioLibraryAlbumsSegment:
_displayedCollection = [self.libraryModel listOfAlbums];
_currentParentType = VLC_ML_PARENT_ALBUM;
break;
- case 2:
+ case VLCAudioLibrarySongsSegment:
_displayedCollection = [self.libraryModel listOfAudioMedia];
_currentParentType = VLC_ML_PARENT_UNKNOWN;
break;
- case 3:
+ case VLCAudioLibraryGenresSegment:
_displayedCollection = [self.libraryModel listOfGenres];
_currentParentType = VLC_ML_PARENT_GENRE;
break;
=====================================
modules/gui/macosx/library/VLCLibraryModel.h
=====================================
@@ -42,8 +42,6 @@ extern NSString *VLCLibraryModelMediaItemUpdated;
@interface VLCLibraryModel : NSObject
-+ (NSArray *)availableAudioCollections;
-
- (instancetype)initWithLibrary:(vlc_medialibrary_t *)library;
@property (readonly) size_t numberOfAudioMedia;
=====================================
modules/gui/macosx/library/VLCLibraryModel.m
=====================================
@@ -166,11 +166,6 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
[_defaultNotificationCenter removeObserver:self];
}
-+ (NSArray *)availableAudioCollections
-{
- return @[_NS("Artists"), _NS("Albums"), _NS("Songs"), _NS("Genres")];
-}
-
- (void)mediaItemWasUpdated:(VLCMediaLibraryMediaItem *)mediaItem
{
[_defaultNotificationCenter postNotificationName:VLCLibraryModelMediaItemUpdated object:mediaItem];
=====================================
modules/gui/macosx/library/VLCLibraryWindow.h
=====================================
@@ -37,6 +37,18 @@ NS_ASSUME_NONNULL_BEGIN
@class VLCPlaylistSortingMenuController;
@class VLCFSPanelController;
+typedef NS_ENUM(NSUInteger, VLCLibrarySegment) {
+ VLCLibraryVideoSegment = 0,
+ VLCLibraryMusicSegment,
+ VLCLibraryBrowseSegment,
+ VLCLibraryStreamsSegment
+};
+
+typedef NS_ENUM(NSUInteger, VLCViewModeSegment) {
+ VLCGridViewModeSegment = 0,
+ VLCListViewModeSegment
+};
+
@interface VLCLibraryWindowController : NSWindowController<NSWindowRestoration>
- (instancetype)initWithLibraryWindow;
=====================================
modules/gui/macosx/library/VLCLibraryWindow.m
=====================================
@@ -252,10 +252,10 @@ static void addShadow(NSImageView *__unsafe_unretained imageView)
_currentSelectedSegment = -1; // To enforce action on the selected segment
_segmentedTitleControl.segmentCount = 4;
[_segmentedTitleControl setTarget:self];
- [_segmentedTitleControl setLabel:_NS("Video") forSegment:0];
- [_segmentedTitleControl setLabel:_NS("Music") forSegment:1];
- [_segmentedTitleControl setLabel:_NS("Browse") forSegment:2];
- [_segmentedTitleControl setLabel:_NS("Streams") forSegment:3];
+ [_segmentedTitleControl setLabel:_NS("Video") forSegment:VLCLibraryVideoSegment];
+ [_segmentedTitleControl setLabel:_NS("Music") forSegment:VLCLibraryMusicSegment];
+ [_segmentedTitleControl setLabel:_NS("Browse") forSegment:VLCLibraryBrowseSegment];
+ [_segmentedTitleControl setLabel:_NS("Streams") forSegment:VLCLibraryStreamsSegment];
[_segmentedTitleControl sizeToFit];
_playlistDragDropView.dropTarget = self;
@@ -533,17 +533,18 @@ static void addShadow(NSImageView *__unsafe_unretained imageView)
_currentSelectedViewModeSegment = _gridVsListSegmentedControl.selectedSegment;
switch (_segmentedTitleControl.selectedSegment) {
- case 0:
+ case VLCLibraryVideoSegment:
[self showVideoLibrary];
break;
-
- case 1:
+ case VLCLibraryMusicSegment:
[self showAudioLibrary];
break;
-
- default:
+ case VLCLibraryBrowseSegment:
+ case VLCLibraryStreamsSegment:
[self showMediaSourceAppearance];
break;
+ default:
+ break;
}
}
@@ -635,7 +636,7 @@ static void addShadow(NSImageView *__unsafe_unretained imageView)
[_libraryTargetView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[_audioLibraryView(>=444.)]|" options:0 metrics:0 views:dict]];
- if (self.gridVsListSegmentedControl.selectedSegment == 0) {
+ if (self.gridVsListSegmentedControl.selectedSegment == VLCGridViewModeSegment) {
_audioLibrarySplitView.hidden = YES;
_audioCollectionViewScrollView.hidden = NO;
[_libraryAudioDataSource reloadAppearance];
=====================================
modules/gui/macosx/media-source/VLCMediaSourceBaseDataSource.m
=====================================
@@ -102,7 +102,7 @@ NSString *VLCMediaSourceTableViewCellIdentifier = @"VLCMediaSourceTableViewCellI
self.tableView.dataSource = self;
self.tableView.delegate = self;
self.tableView.hidden = YES;
- _gridViewMode = self.gridVsListSegmentedControl.selectedSegment == 0;
+ _gridViewMode = self.gridVsListSegmentedControl.selectedSegment == VLCGridViewModeSegment;
}
- (void)reloadViews
@@ -420,7 +420,7 @@ referenceSizeForHeaderInSection:(NSInteger)section
- (void)setGridOrListMode:(id)sender
{
- _gridViewMode = self.gridVsListSegmentedControl.selectedSegment == 0;
+ _gridViewMode = self.gridVsListSegmentedControl.selectedSegment == VLCGridViewModeSegment;
_childDataSource.gridViewMode = _gridViewMode;
[self setCurrentViewMode];
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/452d9f86cfa20b3495b76665af4b6967ad68eac9
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/452d9f86cfa20b3495b76665af4b6967ad68eac9
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