[gnome-music/wip/gbsneto/contained-playlists: 7/29] playlists: Manage playlists internally
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/gbsneto/contained-playlists: 7/29] playlists: Manage playlists internally
- Date: Thu, 1 Dec 2016 23:26:09 +0000 (UTC)
commit 56e658bdc0b588d414667f9f68a715303aeedf7b
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Mon Nov 28 19:38:58 2016 +0100
playlists: Manage playlists internally
This commit makes the Playlists class load and maintain
an internal list of playlists available.
Next commits will make the potential consumers of this
API use it.
gnomemusic/playlists.py | 37 +++++++++++++++++++++++++++++++++++++
1 files changed, 37 insertions(+), 0 deletions(-)
---
diff --git a/gnomemusic/playlists.py b/gnomemusic/playlists.py
index 82e8f5a..2e9cf58 100644
--- a/gnomemusic/playlists.py
+++ b/gnomemusic/playlists.py
@@ -30,6 +30,7 @@ from gi.repository import Grl, GLib, GObject
from gnomemusic import TrackerWrapper
from gnomemusic.grilo import grilo
from gnomemusic.query import Query
+import gnomemusic.utils as utils
from gettext import gettext as _
import inspect
import time
@@ -190,6 +191,7 @@ class Playlists(GObject.GObject):
GObject.GObject.__init__(self)
self.tracker = TrackerWrapper().tracker
self._static_playlists = StaticPlaylists()
+ self.playlists = []
grilo.connect('ready', self._on_grilo_ready)
@@ -231,6 +233,21 @@ class Playlists(GObject.GObject):
Query.get_playlist_with_tag(playlist.tag_text), None,
callback, playlist)
+ # Gather the available playlists too
+ grilo.populate_playlists(0, self._populate_playlists_finish_cb)
+
+ @log
+ def _populate_playlists_finish_cb(self, source, param, item, remaining=0, data=None):
+ """Fill in the list of playlists currently available"""
+ if not item:
+ return
+
+ playlist = Playlist(item.get_id(), utils.get_media_title(item))
+ playlist.grilo_item = item
+
+ self.playlists.append(playlist)
+ self.emit('playlist-added', playlist)
+
@log
def _create_static_playlist(self, playlist):
""" Create the tag and the static playlist, and fetch the newly created
@@ -352,6 +369,11 @@ class Playlists(GObject.GObject):
# tell system we updated the playlist so playlist is reloaded
self.emit('playlist-updated', playlist.id)
+ # Add the playlist to the cache
+ if not playlist in self.playlists:
+ self.playlists.append(playlist)
+ self.emit('playlist-added', playlist)
+
# Asynchronously form the playlist's final query
cursor.next_async(None, callback, final_query)
@@ -364,6 +386,12 @@ class Playlists(GObject.GObject):
def create_playlist(self, title):
def get_callback(source, param, item, count, data, error):
if item:
+ new_playlist = Playlist(item.get_id(), utils.get_media_title(item))
+ new_playlist.grilo_item = item
+
+ self.playlists.append(new_playlist)
+ self.emit('playlist-added', playlist)
+
self.emit('playlist-created', item)
def cursor_callback(cursor, res, data):
@@ -463,6 +491,15 @@ class Playlists(GObject.GObject):
)
@log
+ def get_playlists(self):
+ """Retrieves the currently loaded playlists.
+
+ :return: a list of Playlists
+ :rtype: list
+ """
+ return self.playlists.copy()
+
+ @log
def is_static_playlist(self, playlist):
"""Checks whether the given playlist is static or not
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]