[gnome-music/wip/jfelder/mpris-cleanup: 26/38] mpris: Do not send a signal for unchanged properties
- From: Jean Felder <jfelder src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/mpris-cleanup: 26/38] mpris: Do not send a signal for unchanged properties
- Date: Fri, 31 May 2019 20:31:38 +0000 (UTC)
commit fefe27a79b0e0b01115818538794f359516c67a6
Author: Jean Felder <jfelder src gnome org>
Date: Thu Apr 4 17:33:15 2019 +0200
mpris: Do not send a signal for unchanged properties
According to MPRIS specification a signal should only be sent when a
property value has changed.
Closes: #43
gnomemusic/mpris.py | 52 +++++++++++++++++++++++++++++++++-------------------
1 file changed, 33 insertions(+), 19 deletions(-)
---
diff --git a/gnomemusic/mpris.py b/gnomemusic/mpris.py
index 29bb347d..4691cfad 100644
--- a/gnomemusic/mpris.py
+++ b/gnomemusic/mpris.py
@@ -276,6 +276,10 @@ class MPRIS(DBusInterface):
self._metadata_timeout = None
self._current_thumbnail = None
self._previous_playback_status = "Stopped"
+ self._previous_can_go_next = False
+ self._previous_can_go_previous = False
+ self._first_song_played = False
+ self._previous_loop_status = ""
@log
def _get_playback_status(self):
@@ -456,18 +460,27 @@ class MPRIS(DBusInterface):
@log
def _on_current_song_changed(self, player):
def send_signal():
+ properties = {}
+ properties['Metadata'] = GLib.Variant(
+ 'a{sv}', self._get_metadata())
+
has_next = self.player.props.has_next
+ if self._previous_can_go_next != has_next:
+ properties['CanGoNext'] = GLib.Variant('b', has_next)
+ self._previous_can_go_next = has_next
+
has_previous = self.player.props.has_previous
+ if self._previous_can_go_previous != has_previous:
+ properties['CanGoPrevious'] = GLib.Variant('b', has_previous)
+ self._previous_can_go_previous = has_previous
+
+ if not self._first_song_played:
+ properties['CanPause'] = GLib.Variant('b', True)
+ properties['CanPlay'] = GLib.Variant('b', True)
+ self._first_song_played = True
+
self.PropertiesChanged(
- MPRIS.MEDIA_PLAYER2_PLAYER_IFACE,
- {
- 'CanGoNext': GLib.Variant('b', has_next),
- 'CanGoPrevious': GLib.Variant('b', has_previous),
- 'CanPlay': GLib.Variant('b', True),
- 'CanPause': GLib.Variant('b', True),
- 'Metadata': GLib.Variant('a{sv}', self._get_metadata()),
- },
- [])
+ MPRIS.MEDIA_PLAYER2_PLAYER_IFACE, properties, [])
self._metadata_timeout = None
current_song = self.player.props.current_song
self._current_thumbnail = current_song.get_thumbnail()
@@ -513,16 +526,17 @@ class MPRIS(DBusInterface):
@log
def _on_repeat_mode_changed(self, player, param):
self._update_songs_list()
- has_next = self.player.props.has_next
- has_previous = self.player.props.has_previous
- self.PropertiesChanged(MPRIS.MEDIA_PLAYER2_PLAYER_IFACE,
- {
- 'CanGoNext': GLib.Variant('b', has_next),
- 'CanGoPrevious': GLib.Variant('b', has_previous),
- 'LoopStatus': GLib.Variant('s', self._get_loop_status()),
- 'Shuffle': GLib.Variant('b', self.player.props.repeat_mode ==
RepeatMode.SHUFFLE),
- },
- [])
+ properties = {}
+ is_shuffled = self.player.props.repeat_mode == RepeatMode.SHUFFLE
+ properties['Shuffle'] = GLib.Variant('b', is_shuffled)
+
+ loop_status = self._get_loop_status()
+ if loop_status != self._previous_loop_status:
+ properties['LoopStatus'] = GLib.Variant('s', loop_status)
+ self._previous_loop_status = loop_status
+
+ self.PropertiesChanged(
+ MPRIS.MEDIA_PLAYER2_PLAYER_IFACE, properties, [])
@log
def _on_seek_finished(self, player, position_second):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]