[vlc-commits] macosx / playlist controller: expose the remaining playlist states

Felix Paul Kühne git at videolan.org
Thu Jan 31 19:07:27 CET 2019


vlc | branch: master | Felix Paul Kühne <felix at feepk.net> | Thu Jan 31 18:59:19 2019 +0100| [04ad7d7b73ba214232fe7427132a1ab362e82676] | committer: Felix Paul Kühne

macosx / playlist controller: expose the remaining playlist states

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

 modules/gui/macosx/VLCPlaylistController.h | 19 ++++++++
 modules/gui/macosx/VLCPlaylistController.m | 69 ++++++++++++++++++++++++++----
 2 files changed, 79 insertions(+), 9 deletions(-)

diff --git a/modules/gui/macosx/VLCPlaylistController.h b/modules/gui/macosx/VLCPlaylistController.h
index ced07666d6..3cda3a77b7 100644
--- a/modules/gui/macosx/VLCPlaylistController.h
+++ b/modules/gui/macosx/VLCPlaylistController.h
@@ -28,6 +28,11 @@ NS_ASSUME_NONNULL_BEGIN
 @class VLCPlaylistModel;
 @class VLCPlaylistDataSource;
 
+extern NSString *VLCPlaybackOrderChanged;
+extern NSString *VLCPlaybackRepeatChanged;
+extern NSString *VLCPlaybackHasPreviousChanged;
+extern NSString *VLCPlaybackHasNextChanged;
+
 @interface VLCPlaylistController : NSObject
 
 /**
@@ -54,15 +59,29 @@ NS_ASSUME_NONNULL_BEGIN
 
 /**
  * indicates whether there is a previous item in the list the user could go back to
+ * @note Subscribe to the VLCPlaybackHasPreviousChanged notification to be notified about changes
  */
 @property (readonly) BOOL hasPreviousPlaylistItem;
 
 /**
  * indicates whether there is a next item in the list the user could move on to
+ * @note Subscribe to the VLCPlaybackHasNextChanged notification to be notified about changes
  */
 @property (readonly) BOOL hasNextPlaylistItem;
 
 /**
+ * sets and gets the playback repeat mode according to the enum defined in the core
+ * @note Subscribe to the VLCPlaybackRepeatChanged notification to be notified about changes
+ */
+ at property (readwrite) enum vlc_playlist_playback_repeat playbackRepeat;
+
+/**
+ * sets and gets the playback order according to the enum defined in the core
+ * @note Subscribe to the VLCPlaybackOrderChanged notification to be notified about changes
+ */
+ at property (readwrite) enum vlc_playlist_playback_order playbackOrder;
+
+/**
  * Simplified version to add new items to the end of the current playlist
  * @param array array of items. Each item is a Dictionary with meta info.
  */
diff --git a/modules/gui/macosx/VLCPlaylistController.m b/modules/gui/macosx/VLCPlaylistController.m
index 8237c1d93d..47f00d3c00 100644
--- a/modules/gui/macosx/VLCPlaylistController.m
+++ b/modules/gui/macosx/VLCPlaylistController.m
@@ -26,6 +26,11 @@
 #import "VLCMain.h"
 #import <vlc_interface.h>
 
+NSString *VLCPlaybackOrderChanged = @"VLCPlaybackOrderChanged";
+NSString *VLCPlaybackRepeatChanged = @"VLCPlaybackRepeatChanged";
+NSString *VLCPlaybackHasPreviousChanged = @"VLCPlaybackHasPreviousChanged";
+NSString *VLCPlaybackHasNextChanged = @"VLCPlaybackHasNextChanged";
+
 @interface VLCPlaylistController ()
 {
     vlc_playlist_t *_p_playlist;
@@ -35,8 +40,12 @@
 - (void)playlistResetWithItems:(vlc_playlist_item_t *const *)items count:(size_t)numberOfItems;
 - (void)playlistAdded:(vlc_playlist_item_t *const *)items atIndex:(size_t)insertionIndex count:(size_t)numberOfItems;
 - (void)playlistRemovedItemsAtIndex:(size_t)index count:(size_t)numberOfItems;
-- (void)currentPlaylistItemChanged:(ssize_t)index;
 - (void)playlistUpdatedForIndex:(size_t)firstUpdatedIndex items:(vlc_playlist_item_t *const *)items count:(size_t)numberOfItems;
+- (void)playlistPlaybackRepeatUpdated:(enum vlc_playlist_playback_repeat)currentRepeatMode;
+- (void)playlistPlaybackOrderUpdated:(enum vlc_playlist_playback_order)currentOrder;
+- (void)currentPlaylistItemChanged:(size_t)index;
+- (void)playlistHasPreviousItem:(BOOL)hasPrevious;
+- (void)playlistHasNextItem:(BOOL)hasNext;
 
 @end
 
@@ -110,6 +119,24 @@ cb_playlist_current_item_changed(vlc_playlist_t *playlist,
     [playlistController currentPlaylistItemChanged:index];
 }
 
+static void
+cb_playlist_has_prev_changed(vlc_playlist_t *playlist,
+                             bool has_prev,
+                             void *p_data)
+{
+    VLCPlaylistController *playlistController = (__bridge VLCPlaylistController *)p_data;
+    [playlistController playlistHasPreviousItem:has_prev];
+}
+
+static void
+cb_playlist_has_next_changed(vlc_playlist_t *playlist,
+                             bool has_next,
+                             void *p_data)
+{
+    VLCPlaylistController *playlistController = (__bridge VLCPlaylistController *)p_data;
+    [playlistController playlistHasNextItem:has_next];
+}
+
 static const struct vlc_playlist_callbacks playlist_callbacks = {
     cb_playlist_items_reset,
     cb_playlist_items_added,
@@ -119,8 +146,8 @@ static const struct vlc_playlist_callbacks playlist_callbacks = {
     cb_playlist_playback_repeat_changed,
     cb_playlist_playback_order_changed,
     cb_playlist_current_item_changed,
-    NULL,
-    NULL,
+    cb_playlist_has_prev_changed,
+    cb_playlist_has_next_changed,
 };
 
 #pragma mark -
@@ -183,12 +210,6 @@ static const struct vlc_playlist_callbacks playlist_callbacks = {
     [_playlistDataSource performSelectorOnMainThread:@selector(playlistUpdated) withObject:nil waitUntilDone:NO];
 }
 
-- (void)currentPlaylistItemChanged:(ssize_t)index
-{
-    _currentPlaylistIndex = index;
-    [_playlistDataSource performSelectorOnMainThread:@selector(playlistUpdated) withObject:nil waitUntilDone:NO];
-}
-
 - (void)playlistUpdatedForIndex:(size_t)firstUpdatedIndex items:(vlc_playlist_item_t *const *)items count:(size_t)numberOfItems
 {
     VLC_UNUSED(items);
@@ -198,6 +219,36 @@ static const struct vlc_playlist_callbacks playlist_callbacks = {
     [_playlistDataSource performSelectorOnMainThread:@selector(playlistUpdated) withObject:nil waitUntilDone:NO];
 }
 
+- (void)playlistPlaybackRepeatUpdated:(enum vlc_playlist_playback_repeat)currentRepeatMode
+{
+    _playbackRepeat = currentRepeatMode;
+    [[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackRepeatChanged object:nil];
+}
+
+- (void)playlistPlaybackOrderUpdated:(enum vlc_playlist_playback_order)currentOrder
+{
+    _playbackOrder = currentOrder;
+    [[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackOrderChanged object:nil];
+}
+
+- (void)currentPlaylistItemChanged:(size_t)index
+{
+    _currentPlaylistIndex = index;
+    [_playlistDataSource performSelectorOnMainThread:@selector(playlistUpdated) withObject:nil waitUntilDone:NO];
+}
+
+- (void)playlistHasPreviousItem:(BOOL)hasPrevious
+{
+    _hasPreviousPlaylistItem = hasPrevious;
+    [[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackHasPreviousChanged object:nil];
+}
+
+- (void)playlistHasNextItem:(BOOL)hasNext
+{
+    _hasNextPlaylistItem = hasNext;
+    [[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackHasNextChanged object:nil];
+}
+
 #pragma mark - controller functions for use within the UI
 
 - (void)addPlaylistItems:(NSArray*)array



More information about the vlc-commits mailing list