[gnome-music/wip/jfelder/mpris-cleanup: 97/117] mpris: Simplify GetPlaylists method



commit ac2d7c04ef8b93e17c193c040437d0f05d761c1d
Author: Jean Felder <jfelder src gnome org>
Date:   Thu Mar 21 08:56:20 2019 +0100

    mpris: Simplify GetPlaylists method

 gnomemusic/mpris.py | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)
---
diff --git a/gnomemusic/mpris.py b/gnomemusic/mpris.py
index 3c178ff0..29e11b6a 100644
--- a/gnomemusic/mpris.py
+++ b/gnomemusic/mpris.py
@@ -453,12 +453,12 @@ class MPRIS(DBusInterface):
         has_previous = self.player.props.has_previous
         self.PropertiesChanged(MPRIS.MEDIA_PLAYER2_PLAYER_IFACE,
                                {
+                                   'Metadata': GLib.Variant('a{sv}', self._get_metadata()),
                                    '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()),
                                },
                                [])
 
@@ -659,13 +659,29 @@ class MPRIS(DBusInterface):
         self.app._window.views[View.PLAYLIST].activate_playlist(playlist_id)
 
     def GetPlaylists(self, index, max_count, order, reverse):
+        """Gets a set of playlists (MPRIS Method).
+
+        GNOME Music only handles playlists with the Alphabetical order.
+
+        :param int index: the index of the first playlist to be fetched
+        :param int max_count: the maximum number of playlists to fetch.
+        :param str order: the ordering that should be used.
+        :param bool reverse: whether the order should be reversed.
+        """
         if order != 'Alphabetical':
             return []
+
         playlists = [(self._get_playlist_dbus_path(playlist),
-                      utils.get_media_title(playlist) or '', '')
+                      utils.get_media_title(playlist), '')
                      for playlist in self.playlists]
-        return playlists[index:index + max_count] if not reverse \
-            else playlists[index + max_count - 1:index - 1 if index - 1 >= 0 else None:-1]
+
+        if not reverse:
+            return playlists[index:index + max_count]
+
+        first_index = index - 1
+        if first_index < 0:
+            first_index = None
+        return playlists[index + max_count - 1:first_index:-1]
 
     def PlaylistChanged(self, playlist):
         self.con.emit_signal(None,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]