[vlc-commits] macosx/main menu: fix play state display

Felix Paul Kühne git at videolan.org
Mon Mar 11 01:09:04 CET 2019


vlc | branch: master | Felix Paul Kühne <felix at feepk.net> | Sun Mar 10 23:57:08 2019 +0100| [fc5d29fa809af12ff7f0e63c41938028e9a88e05] | committer: Felix Paul Kühne

macosx/main menu: fix play state display

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

 .../gui/macosx/coreinteraction/VLCInputManager.m   | 12 -----
 modules/gui/macosx/menus/VLCMainMenu.h             |  6 ---
 modules/gui/macosx/menus/VLCMainMenu.m             | 52 +++++++++++++++++++---
 3 files changed, 46 insertions(+), 24 deletions(-)

diff --git a/modules/gui/macosx/coreinteraction/VLCInputManager.m b/modules/gui/macosx/coreinteraction/VLCInputManager.m
index 377041b400..9f85211605 100644
--- a/modules/gui/macosx/coreinteraction/VLCInputManager.m
+++ b/modules/gui/macosx/coreinteraction/VLCInputManager.m
@@ -277,12 +277,9 @@ static int InputEvent(vlc_object_t *p_this, const char *psz_var,
 
     if (state == PLAYING_S) {
         [self stopItunesPlayback];
-
-        [[o_main mainMenu] setPause];
         [[o_main mainWindow] setPause];
     } else {
         [[o_main mainMenu] setSubmenusEnabled: FALSE];
-        [[o_main mainMenu] setPlay];
         [[o_main mainWindow] setPlay];
 
         if (state == END_S || state == -1) {
@@ -302,7 +299,6 @@ static int InputEvent(vlc_object_t *p_this, const char *psz_var,
     }
 
     [self updateMainWindow];
-    [self sendDistributedNotificationWithUpdatedPlaybackStatus];
 }
 
 // Called when playback has ended and likely no subsequent media will start playing
@@ -401,14 +397,6 @@ static int InputEvent(vlc_object_t *p_this, const char *psz_var,
     [[VLCCoreInteraction sharedInstance] resetAtoB];
 }
 
-- (void)sendDistributedNotificationWithUpdatedPlaybackStatus
-{
-    [[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"VLCPlayerStateDidChange"
-                                                                   object:nil
-                                                                 userInfo:nil
-                                                       deliverImmediately:YES];
-}
-
 - (BOOL)hasInput
 {
     return p_current_input != NULL;
diff --git a/modules/gui/macosx/menus/VLCMainMenu.h b/modules/gui/macosx/menus/VLCMainMenu.h
index 9ef268fdbe..9fb28fc63c 100644
--- a/modules/gui/macosx/menus/VLCMainMenu.h
+++ b/modules/gui/macosx/menus/VLCMainMenu.h
@@ -284,12 +284,6 @@
 - (IBAction)showMainWindow:(id)sender;
 - (IBAction)showPlaylist:(id)sender;
 
-- (void)setPlay;
-- (void)setPause;
-- (void)setRepeatOne;
-- (void)setRepeatAll;
-- (void)setRepeatOff;
-- (void)setShuffle;
 @end
 
 /*****************************************************************************
diff --git a/modules/gui/macosx/menus/VLCMainMenu.m b/modules/gui/macosx/menus/VLCMainMenu.m
index a92e4770eb..648a2f249b 100644
--- a/modules/gui/macosx/menus/VLCMainMenu.m
+++ b/modules/gui/macosx/menus/VLCMainMenu.m
@@ -236,6 +236,18 @@
                            selector:@selector(updateRecordState)
                                name:VLCPlayerRecordingChanged
                              object:nil];
+    [notificationCenter addObserver:self
+                           selector:@selector(playbackStateChanged:)
+                               name:VLCPlayerStateChanged
+                             object:nil];
+    [notificationCenter addObserver:self
+                           selector:@selector(playModeChanged:)
+                               name:VLCPlaybackRepeatChanged
+                             object:self];
+    [notificationCenter addObserver:self
+                           selector:@selector(playOrderChanged:)
+                               name:VLCPlaybackOrderChanged
+                             object:self];
 
     [self setupVarMenuItem:_add_intf target: (vlc_object_t *)p_intf
                              var:"intf-add" selector: @selector(toggleVar:)];
@@ -1297,7 +1309,40 @@
     [[[VLCMain sharedInstance] currentMediaInfoPanel] toggleWindow:sender];
 }
 
-#pragma mark - convinience stuff for other objects
+#pragma mark - playback state
+
+- (void)playbackStateChanged:(NSNotification *)aNotification
+{
+    enum vlc_player_state playerState = [_playlistController playerController].playerState;
+    if (playerState == VLC_PLAYER_STATE_PLAYING) {
+        [self setPause];
+    } else {
+        [self setPlay];
+    }
+}
+
+- (void)playModeChanged:(NSNotification *)aNotification
+{
+    enum vlc_playlist_playback_repeat repeatState = _playlistController.playbackRepeat;
+    switch (repeatState) {
+        case VLC_PLAYLIST_PLAYBACK_REPEAT_ALL:
+            [self setRepeatAll];
+            break;
+
+        case VLC_PLAYLIST_PLAYBACK_REPEAT_CURRENT:
+            [self setRepeatOne];
+            break;
+
+        default:
+            [self setRepeatOff];
+            break;
+    }
+}
+
+- (void)playOrderChanged:(NSNotification *)aNotification
+{
+    [_random setState:_playlistController.playbackOrder == VLC_PLAYLIST_PLAYBACK_ORDER_RANDOM];
+}
 
 - (void)setPlay
 {
@@ -1331,11 +1376,6 @@
     [_loop setState: NSOffState];
 }
 
-- (void)setShuffle
-{
-    [_random setState:_playlistController.playbackOrder == VLC_PLAYLIST_PLAYBACK_ORDER_RANDOM];
-}
-
 #pragma mark - Dynamic menu creation and validation
 
 - (void)setupVarMenuItem:(NSMenuItem *)mi



More information about the vlc-commits mailing list