[gnome-music/wip/jfelder/simplify-playlistdialog: 26/28] grilo: Add function to populate user playlists



commit 7d8db2936d3a93507e87054a133fa129a414b0a5
Author: Jean Felder <jfelder src gnome org>
Date:   Mon Mar 12 18:59:48 2018 +0100

    grilo: Add function to populate user playlists
    
    This function will be used by PlaylistDialog which does not need
    smart playlists.

 gnomemusic/grilo.py | 24 ++++++++++++++++++++++--
 gnomemusic/query.py | 11 ++++++++++-
 2 files changed, 32 insertions(+), 3 deletions(-)
---
diff --git a/gnomemusic/grilo.py b/gnomemusic/grilo.py
index add7520a..d77a6938 100644
--- a/gnomemusic/grilo.py
+++ b/gnomemusic/grilo.py
@@ -259,9 +259,29 @@ class Grilo(GObject.GObject):
 
     @log
     def populate_playlists(self, offset, callback, count=-1):
+        """Asynchronously get playlists (user and smart ones)
+
+        :param int offset: start index
+        :param function callback: callback function
+        :param int count: limit number of results
+        """
         if self.tracker:
-            GLib.idle_add(self.populate_items, Query.all_playlists(), offset,
-                                                callback, count)
+            GLib.idle_add(
+                self.populate_items, Query.all_playlists(), offset, callback,
+                count)
+
+    @log
+    def populate_user_playlists(self, offset, callback, count=-1):
+        """Asynchronously get user playlists
+
+        :param int offset: start index
+        :param function callback: callback function
+        :param int count: limit number of results
+        """
+        if self.tracker:
+            GLib.idle_add(
+                self.populate_items, Query.all_user_playlists(), offset,
+                callback, count)
 
     @log
     def populate_album_songs(self, album, callback, count=-1):
diff --git a/gnomemusic/query.py b/gnomemusic/query.py
index 89bfd622..c7554378 100644
--- a/gnomemusic/query.py
+++ b/gnomemusic/query.py
@@ -89,8 +89,15 @@ class Query():
 
     @staticmethod
     def all_playlists():
+        """Query to retrieve all playlists (user and smart ones)."""
         return Query.playlists('?playlist a nmm:Playlist .')
 
+    @staticmethod
+    def all_user_playlists():
+        """Query to retrieve playlists created by user."""
+        return Query.playlists(
+            '?playlist a nmm:Playlist .', 'FILTER (!BOUND(?tag))')
+
     @staticmethod
     def all_songs_count():
         query = """
@@ -222,7 +229,7 @@ class Query():
         return query
 
     @staticmethod
-    def playlists(where_clause):
+    def playlists(where_clause, filter_clause=None):
         query = """
     SELECT DISTINCT
         rdf:type(?playlist)
@@ -239,11 +246,13 @@ class Query():
                      && !STRENDS(LCASE(?url), '.m3u8')
                      && !STRENDS(LCASE(?url), '.pls')
                      || !BOUND(nfo:belongsToContainer(?playlist)) )
+            %(filter_clause)s
             OPTIONAL { ?playlist nao:hasTag ?tag }
         }
     ORDER BY DESC(tracker:added(?playlist)) !BOUND(?tag) LCASE(?title)
     """.replace('\n', ' ').strip() % {
             'where_clause': where_clause.replace('\n', ' ').strip(),
+            'filter_clause': filter_clause or '',
             'music_dir': Query.MUSIC_URI
         }
 


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