Skip to content

Instantly share code, notes, and snippets.

@dsferruzza
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsferruzza/8e9079a329975f3579e9 to your computer and use it in GitHub Desktop.
Save dsferruzza/8e9079a329975f3579e9 to your computer and use it in GitHub Desktop.
VLC - Stop Atfer Current (#10732)
diff --git a/modules/gui/qt4/input_manager.cpp b/modules/gui/qt4/input_manager.cpp
index f72b3b3..50d1cb3 100644
--- a/modules/gui/qt4/input_manager.cpp
+++ b/modules/gui/qt4/input_manager.cpp
@@ -1205,6 +1205,17 @@ bool MainInputManager::getPlayExitState()
return var_InheritBool( THEPL, "play-and-exit" );
}
+void MainInputManager::activatePlayStop( bool b_exit )
+{
+ var_SetBool( THEPL, "play-and-stop", b_exit );
+ config_PutInt( p_intf, "play-and-stop", b_exit );
+}
+
+bool MainInputManager::getPlayStopState()
+{
+ return var_InheritBool( THEPL, "play-and-stop" );
+}
+
bool MainInputManager::hasEmptyPlaylist()
{
playlist_Lock( THEPL );
diff --git a/modules/gui/qt4/input_manager.hpp b/modules/gui/qt4/input_manager.hpp
index dac3bc3..4511457 100644
--- a/modules/gui/qt4/input_manager.hpp
+++ b/modules/gui/qt4/input_manager.hpp
@@ -268,6 +268,7 @@ public:
audio_output_t *getAout();
bool getPlayExitState();
+ bool getPlayStopState();
bool hasEmptyPlaylist();
void requestVoutUpdate() { return im->UpdateVout(); }
@@ -298,6 +299,7 @@ public slots:
void prev();
void prevOrReset();
void activatePlayQuit( bool );
+ void activatePlayStop( bool );
void loopRepeatLoopStatus();
diff --git a/modules/gui/qt4/menus.cpp b/modules/gui/qt4/menus.cpp
index 0935346..ab1d65b 100644
--- a/modules/gui/qt4/menus.cpp
+++ b/modules/gui/qt4/menus.cpp
@@ -828,6 +828,15 @@ void VLCMenuBar::PopupMenuPlaylistEntries( QMenu *menu,
action->setEnabled( false );
action->setData( ACTION_DELETE_ON_REBUILD );
+ /* Stop after current track */
+ action = addMIMStaticEntry( p_intf, menu, qtr( "Stop &after current track" ),
+ "", SLOT( activatePlayStop( bool ) ), true );
+ action->setCheckable( true );
+ action->setChecked( THEMIM->getPlayStopState() );
+ if( !p_input )
+ action->setEnabled( false );
+ action->setData( ACTION_DELETE_ON_REBUILD );
+
/* Next / Previous */
bool bPlaylistEmpty = THEMIM->hasEmptyPlaylist();
action = addMIMStaticEntry( p_intf, menu, qtr( "Pre&vious" ),

I'm tying to implement #10732

Current problem

With my current implementation (see attached diff), checking Playback > Stop after current track is equivalent to enabling Setting > Playlist > Play and stop.

When quitting VLC, the current state of this boolean is persisted (I checked with grep "play-and-stop" ~/.config/vlc/vlcrc ; this happens when VLC is shutdown, not when the boolean changes) which, I believe, is not the behavior we want for #10732.

If I start VLC with the --play-and-stop argument, the behavior is also similar to enabling Setting > Playlist > Play and stop, but this option is not persisted.

I don't understand why, and I don't know how to imitate this behavior from the GUI.

Future problem (?)

Let's assume the previous problem is solved.

To be user-friendly, I believe that this Stop after current track feature should disable itself when the player is stopped (by the user, or by the feature itself, or for any reason actually). I don't think this is the same use-cases as for --play-and-stop.

For the few I understand, it doesn't seems possible:

  • to have this behaviour AND
  • to reuse the existing --play-and-stop implementation AND
  • to keep the current --play-and-stop behavior (which is "always ON")

I need a wise advice here.


State

We need a boolean variable to remember if the user asked to stop after the current track.

This variable is global to the playlist: it is not a property of each item in the playlist like it is in Amarok/Clementine (at least for now, global is enough).

For now, I'm using a play-and-stop config key, but I'm not convinced that this is the best way to do it.

UI

I focused on the Qt interface. Do I need to implement it in other GUIs?

I added an entry in the Playback context menu. This is enough for testing and I'll worry about UI when the rest is done.

Behaviour

The UI needs to be able to read & write the state.

Also, we need to bind actions to some events:

  • when the currently played item finishes: stop
  • when the player is stopped (manually or not): put the state to false

When the player starts, the state should be false. This is not the case for now, because the state is persisted in the config. Should I implement the state differently, or explicitly set it to false on startup?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment