Skip to content

Commit

Permalink
disable inappropriate mpd action on empty playlist
Browse files Browse the repository at this point in the history
  • Loading branch information
SoongNoonien committed Nov 2, 2024
1 parent 1aa3129 commit d9deae2
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/plattenalbum.py
Original file line number Diff line number Diff line change
Expand Up @@ -2726,8 +2726,9 @@ def __init__(self, client):
# actions
self._disable_on_stop_data=["next","prev","seek-forward","seek-backward","a-b-loop"]
self._disable_no_song_data=["tidy","enqueue"]
self._enable_on_reconnect_data=["toggle-play","stop","clear","update","disconnect"]
self._data=self._disable_on_stop_data+self._disable_no_song_data+self._enable_on_reconnect_data
self._enable_disable_on_playlist_data=["toggle-play","clear"]
self._enable_on_reconnect_data=["stop","update","disconnect"]
self._data=self._disable_on_stop_data+self._disable_no_song_data+self._enable_on_reconnect_data+self._enable_disable_on_playlist_data
for name in self._data:
action=Gio.SimpleAction.new(name, None)
action.connect("activate", getattr(self, ("_on_"+name.replace("-","_"))))
Expand All @@ -2747,6 +2748,7 @@ def __init__(self, client):
# connect
self._client.emitter.connect("state", self._on_state)
self._client.emitter.connect("current-song", self._on_song_changed)
self._client.emitter.connect("playlist", self._on_playlist_changed)
self._client.emitter.connect("disconnected", self._on_disconnected)
self._client.emitter.connect("connected", self._on_connected)

Expand Down Expand Up @@ -2810,6 +2812,10 @@ def _on_song_changed(self, emitter, song, songid, state):
for action in self._disable_no_song_data:
self.lookup_action(action).set_enabled(song is not None)

def _on_playlist_changed(self, emitter, version, length, song_pos):
for action in self._enable_disable_on_playlist_data:
self.lookup_action(action).set_enabled(length > 0)

def _on_disconnected(self, *args):
self._connect_action.set_enabled(True)
for action in self._data:
Expand Down

0 comments on commit d9deae2

Please sign in to comment.