[vlc-commits] macosx/library: implement playmode controls

Felix Paul Kühne git at videolan.org
Mon Apr 29 19:27:11 CEST 2019


vlc | branch: master | Felix Paul Kühne <felix at feepk.net> | Sun Apr 28 18:40:49 2019 +0200| [f07cd5f7b76ee3b7c1e6f50b680ea3a68f4bf162] | committer: Felix Paul Kühne

macosx/library: implement playmode controls

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f07cd5f7b76ee3b7c1e6f50b680ea3a68f4bf162
---

 modules/gui/macosx/UI/VLCLibraryWindow.xib    |  9 +++
 modules/gui/macosx/library/VLCLibraryWindow.h |  3 +
 modules/gui/macosx/library/VLCLibraryWindow.m | 89 ++++++++++++++++++++++++---
 3 files changed, 94 insertions(+), 7 deletions(-)

diff --git a/modules/gui/macosx/UI/VLCLibraryWindow.xib b/modules/gui/macosx/UI/VLCLibraryWindow.xib
index 00d19278ec..a1d180f1be 100644
--- a/modules/gui/macosx/UI/VLCLibraryWindow.xib
+++ b/modules/gui/macosx/UI/VLCLibraryWindow.xib
@@ -195,6 +195,9 @@
                                             <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
                                             <font key="font" metaFont="system"/>
                                         </buttonCell>
+                                        <connections>
+                                            <action selector="shuffleAction:" target="QvC-M9-y7g" id="IPl-lr-hFA"/>
+                                        </connections>
                                     </button>
                                     <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="8zF-Wo-H79">
                                         <rect key="frame" x="64" y="15" width="24" height="24"/>
@@ -202,6 +205,9 @@
                                             <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
                                             <font key="font" metaFont="system"/>
                                         </buttonCell>
+                                        <connections>
+                                            <action selector="repeatAction:" target="QvC-M9-y7g" id="zpd-jv-1v1"/>
+                                        </connections>
                                     </button>
                                     <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="cih-xp-HmY">
                                         <rect key="frame" x="133" y="15" width="84" height="17"/>
@@ -209,6 +215,9 @@
                                             <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
                                             <font key="font" metaFont="system"/>
                                         </buttonCell>
+                                        <connections>
+                                            <action selector="clearPlaylist:" target="QvC-M9-y7g" id="tzd-mR-sDu"/>
+                                        </connections>
                                     </button>
                                 </subviews>
                                 <constraints>
diff --git a/modules/gui/macosx/library/VLCLibraryWindow.h b/modules/gui/macosx/library/VLCLibraryWindow.h
index 096ab4aeca..18f5f7b7a3 100644
--- a/modules/gui/macosx/library/VLCLibraryWindow.h
+++ b/modules/gui/macosx/library/VLCLibraryWindow.h
@@ -55,6 +55,9 @@ NS_ASSUME_NONNULL_BEGIN
 - (void)disableVideoPlaybackAppearance;
 
 - (IBAction)playlistDoubleClickAction:(id)sender;
+- (IBAction)shuffleAction:(id)sender;
+- (IBAction)repeatAction:(id)sender;
+- (IBAction)clearPlaylist:(id)sender;
 
 @end
 
diff --git a/modules/gui/macosx/library/VLCLibraryWindow.m b/modules/gui/macosx/library/VLCLibraryWindow.m
index b160244c7b..033189d9cc 100644
--- a/modules/gui/macosx/library/VLCLibraryWindow.m
+++ b/modules/gui/macosx/library/VLCLibraryWindow.m
@@ -53,6 +53,8 @@ static const float f_playlist_row_height = 72.;
     VLCLibraryDataSource *_libraryDataSource;
     VLCMediaSourceDataSource *_mediaSourceDataSource;
 
+    VLCPlaylistController *_playlistController;
+
     NSRect _windowFrameBeforePlayback;
 
     VLCFSPanelController *_fspanel;
@@ -63,6 +65,9 @@ static const float f_playlist_row_height = 72.;
 
 - (void)awakeFromNib
 {
+    VLCMain *mainInstance = [VLCMain sharedInstance];
+    _playlistController = [mainInstance playlistController];
+
     NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
     [notificationCenter addObserver:self
                            selector:@selector(shouldShowFullscreenController:)
@@ -76,6 +81,15 @@ static const float f_playlist_row_height = 72.;
                            selector:@selector(updateLibraryRepresentation:)
                                name:VLCLibraryModelVideoMediaListUpdated
                              object:nil];
+    [notificationCenter addObserver:self
+                           selector:@selector(shuffleStateUpdated:)
+                               name:VLCPlaybackOrderChanged
+                             object:nil];
+    [notificationCenter addObserver:self
+                           selector:@selector(repeatStateUpdated:)
+                               name:VLCPlaybackRepeatChanged
+                             object:nil];
+
     if (@available(macOS 10_14, *)) {
         [[NSApplication sharedApplication] addObserver:self
                                             forKeyPath:@"effectiveAppearance"
@@ -95,13 +109,10 @@ static const float f_playlist_row_height = 72.;
     [_segmentedTitleControl setLabel:_NS("Internet") forSegment:3];
     [_segmentedTitleControl sizeToFit];
 
-    VLCMain *mainInstance = [VLCMain sharedInstance];
-
-    VLCPlaylistController *playlistController = [mainInstance playlistController];
     _playlistDataSource = [[VLCPlaylistDataSource alloc] init];
-    _playlistDataSource.playlistController = playlistController;
+    _playlistDataSource.playlistController = _playlistController;
     _playlistDataSource.tableView = _playlistTableView;
-    playlistController.playlistDataSource = _playlistDataSource;
+    _playlistController.playlistDataSource = _playlistDataSource;
 
     _playlistTableView.dataSource = _playlistDataSource;
     _playlistTableView.delegate = _playlistDataSource;
@@ -128,6 +139,8 @@ static const float f_playlist_row_height = 72.;
     [self updateColorsBasedOnAppearance];
 
     [self segmentedControlAction:nil];
+    [self repeatStateUpdated:nil];
+    [self shuffleStateUpdated:nil];
 }
 
 - (void)dealloc
@@ -138,7 +151,6 @@ static const float f_playlist_row_height = 72.;
     }
 }
 
-
 - (void)observeValueForKeyPath:(NSString *)keyPath
                       ofObject:(id)object
                         change:(NSDictionary<NSKeyValueChangeKey,id> *)change
@@ -166,6 +178,62 @@ static const float f_playlist_row_height = 72.;
     }
 }
 
+#pragma mark - playmode state display and interaction
+
+- (IBAction)shuffleAction:(id)sender
+{
+    if (_playlistController.playbackOrder == VLC_PLAYLIST_PLAYBACK_ORDER_NORMAL) {
+        _playlistController.playbackOrder = VLC_PLAYLIST_PLAYBACK_ORDER_RANDOM;
+    } else {
+        _playlistController.playbackOrder = VLC_PLAYLIST_PLAYBACK_ORDER_NORMAL;
+    }
+}
+
+- (void)shuffleStateUpdated:(NSNotification *)aNotification
+{
+    if (_playlistController.playbackOrder == VLC_PLAYLIST_PLAYBACK_ORDER_NORMAL) {
+        self.shufflePlaylistButton.image = [NSImage imageNamed:@"shuffleOff"];
+    } else {
+        self.shufflePlaylistButton.image = [NSImage imageNamed:@"shuffleOn"];
+    }
+}
+
+- (IBAction)repeatAction:(id)sender
+{
+    enum vlc_playlist_playback_repeat currentRepeatState = _playlistController.playbackRepeat;
+    switch (currentRepeatState) {
+        case VLC_PLAYLIST_PLAYBACK_REPEAT_ALL:
+            _playlistController.playbackRepeat = VLC_PLAYLIST_PLAYBACK_REPEAT_NONE;
+            break;
+        case VLC_PLAYLIST_PLAYBACK_REPEAT_CURRENT:
+            _playlistController.playbackRepeat = VLC_PLAYLIST_PLAYBACK_REPEAT_ALL;
+            break;
+
+        default:
+            _playlistController.playbackRepeat = VLC_PLAYLIST_PLAYBACK_REPEAT_CURRENT;
+            break;
+    }
+}
+
+- (void)repeatStateUpdated:(NSNotification *)aNotification
+{
+    enum vlc_playlist_playback_repeat currentRepeatState = _playlistController.playbackRepeat;
+    switch (currentRepeatState) {
+        case VLC_PLAYLIST_PLAYBACK_REPEAT_ALL:
+            self.repeatPlaylistButton.image = [NSImage imageNamed:@"repeatAll"];
+            break;
+        case VLC_PLAYLIST_PLAYBACK_REPEAT_CURRENT:
+            self.repeatPlaylistButton.image = [NSImage imageNamed:@"repeatOne"];
+            break;
+
+        default:
+            self.repeatPlaylistButton.image = [NSImage imageNamed:@"repeatOff"];
+            break;
+    }
+}
+
+#pragma mark - misc. user interactions
+
 - (void)segmentedControlAction:(id)sender
 {
     switch (_segmentedTitleControl.selectedSegment) {
@@ -191,7 +259,7 @@ static const float f_playlist_row_height = 72.;
     }
 }
 
-- (void)playlistDoubleClickAction:(id)sender
+- (IBAction)playlistDoubleClickAction:(id)sender
 {
     NSInteger selectedRow = self.playlistTableView.selectedRow;
     if (selectedRow == -1)
@@ -200,6 +268,13 @@ static const float f_playlist_row_height = 72.;
     [[[VLCMain sharedInstance] playlistController] playItemAtIndex:selectedRow];
 }
 
+- (IBAction)clearPlaylist:(id)sender
+{
+    [_playlistController clearPlaylist];
+}
+
+#pragma mark - video output controlling
+
 - (void)videoPlaybackWillBeStarted
 {
     if (!self.fullscreen)



More information about the vlc-commits mailing list