[gnome-music/wip/jfelder/playlists-core-rewrite-prep-work: 10/19] playlistdialog: Use the playlists managed by Playlists
- From: Jean Felder <jfelder src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/playlists-core-rewrite-prep-work: 10/19] playlistdialog: Use the playlists managed by Playlists
- Date: Tue, 2 Jul 2019 13:28:48 +0000 (UTC)
commit 861b456050c284d021cef49a1f3618f2639c9f00
Author: Jean Felder <jfelder src gnome org>
Date: Mon Jul 1 23:37:17 2019 +0200
playlistdialog: Use the playlists managed by Playlists
Instead of relying on grilo to populate the dialog with playlists, use
the new API from Playlists class.
It is based on some work done by Georges Basile Stavracas Neto.
gnomemusic/playlists.py | 27 ++++++++++-------
gnomemusic/views/playlistsview.py | 3 +-
gnomemusic/widgets/playlistdialog.py | 51 +++++++++++----------------------
gnomemusic/widgets/playlistdialogrow.py | 10 +++----
4 files changed, 40 insertions(+), 51 deletions(-)
---
diff --git a/gnomemusic/playlists.py b/gnomemusic/playlists.py
index 7ca7d1d7..b91c0870 100644
--- a/gnomemusic/playlists.py
+++ b/gnomemusic/playlists.py
@@ -169,7 +169,7 @@ class Playlists(GObject.GObject):
GObject.SignalFlags.RUN_FIRST, None, (Grl.Media,)
),
'song-added-to-playlist': (
- GObject.SignalFlags.RUN_FIRST, None, (Grl.Media, Grl.Media)
+ GObject.SignalFlags.RUN_FIRST, None, (Playlist, Grl.Media)
),
}
@@ -393,7 +393,12 @@ class Playlists(GObject.GObject):
self.update_smart_playlist(playlist)
@log
- def create_playlist(self, title):
+ def create_playlist(self, title, callback):
+ """Creates an user playlist.
+
+ :param str title: new playlist title
+ :param function callback: called once the playlist is created
+ """
def get_callback(source, param, item, count, data, error):
if not item:
return
@@ -404,6 +409,7 @@ class Playlists(GObject.GObject):
self._playlists_model.insert_sorted(
new_playlist, Playlist.compare_playlist_func)
self.emit("playlist-created", item)
+ callback(new_playlist)
def cursor_callback(cursor, res, data):
try:
@@ -473,6 +479,11 @@ class Playlists(GObject.GObject):
@log
def add_to_playlist(self, playlist, items):
+ """Adds songs to a playlist.
+
+ :param Playlist playlist:
+ :param list items: list of Grl.Media
+ """
def get_callback(source, param, item, count, data, error):
if item:
self.emit('song-added-to-playlist', playlist, item)
@@ -483,7 +494,7 @@ class Playlists(GObject.GObject):
return
entry_id = cursor.get_integer(0)
grilo.get_playlist_song_with_id(
- playlist_id, entry_id, get_callback)
+ playlist.props.pl_id, entry_id, get_callback)
def update_callback(conn, res, data):
entry_urn = conn.update_blank_finish(res)[0][0]['entry']
@@ -491,13 +502,12 @@ class Playlists(GObject.GObject):
Query.get_playlist_song_with_urn(entry_urn), None,
query_callback, None)
- playlist_id = playlist.get_id()
for item in items:
uri = item.get_url()
if not uri:
continue
self._tracker.update_blank_async(
- Query.add_song_to_playlist(playlist_id, uri),
+ Query.add_song_to_playlist(playlist.props.pl_id, uri),
GLib.PRIORITY_LOW, None, update_callback, None)
@log
@@ -542,7 +552,7 @@ class Playlists(GObject.GObject):
@log
def get_user_playlists(self):
def user_playlists_filter(playlist):
- return (playlist.props.id not in self._pls_todelete.keys()
+ return (playlist.props.pl_id not in self._pls_todelete.keys()
and not playlist.props.is_smart)
model_filter = Dazzle.ListModelFilter.new(self._playlists_model)
@@ -613,8 +623,3 @@ class Playlists(GObject.GObject):
self._playlists_model.insert(index, playlist)
return index
-
- @log
- def get_playlists_to_delete(self):
- """Gets playlists ids ready for deletion"""
- return self._pls_todelete.keys()
diff --git a/gnomemusic/views/playlistsview.py b/gnomemusic/views/playlistsview.py
index 2e0f30bc..b8641cfa 100644
--- a/gnomemusic/views/playlistsview.py
+++ b/gnomemusic/views/playlistsview.py
@@ -739,7 +739,8 @@ class PlaylistsView(BaseView):
@log
def _on_song_added_to_playlist(self, playlists, playlist, item):
- if self._is_current_playlist(playlist):
+ if (self._current_playlist
+ and playlist.props.pl_id != self._current_playlist.get_id()):
iter_ = self._add_song_to_model(item, self.model)
playlist_id = self._current_playlist.get_id()
if self.player.playing_playlist(
diff --git a/gnomemusic/widgets/playlistdialog.py b/gnomemusic/widgets/playlistdialog.py
index 0635635e..e328f422 100644
--- a/gnomemusic/widgets/playlistdialog.py
+++ b/gnomemusic/widgets/playlistdialog.py
@@ -25,7 +25,6 @@
from gi.repository import Gtk
from gnomemusic import log
-from gnomemusic.grilo import grilo
from gnomemusic.playlists import Playlists
from gnomemusic.widgets.playlistdialogrow import PlaylistDialogRow
@@ -62,11 +61,11 @@ class PlaylistDialog(Gtk.Dialog):
self.set_titlebar(self._title_bar)
self._user_playlists_available = False
- self._playlist = Playlists.get_default()
- self._playlists_todelete_ids = self._playlist.get_playlists_to_delete()
- self._playlist.connect('playlist-created', self._on_playlist_created)
-
- self._populate()
+ self._playlists = Playlists.get_default()
+ playlists_model = self._playlists.get_user_playlists()
+ self._listbox.bind_model(
+ playlists_model, self._create_playlist_row)
+ self._set_view()
@log
def get_selected(self):
@@ -92,27 +91,12 @@ class PlaylistDialog(Gtk.Dialog):
self._add_playlist_entry = self._first_playlist_entry
@log
- def _populate(self):
- grilo.populate_user_playlists(0, self._add_item)
-
- @log
- def _add_item(self, source, param, item, remaining=0, data=None):
- if item:
- self._add_playlist_to_listbox(item)
- if remaining == 0:
- self._set_view()
-
- @log
- def _add_playlist_to_listbox(self, item):
+ def _create_playlist_row(self, playlist):
"""Adds (non-smart only) playlists to the model"""
-
- # Hide playlists that are going to be deleted
- if item.get_id() in self._playlists_todelete_ids:
- return None
-
self._user_playlists_available = True
- row = PlaylistDialogRow(item)
- self._listbox.insert(row, -1)
+ self._set_view()
+
+ row = PlaylistDialogRow(playlist)
return row
@@ -140,17 +124,16 @@ class PlaylistDialog(Gtk.Dialog):
@Gtk.Template.Callback()
@log
def _on_editing_done(self, sender, data=None):
+ def select_and_close_dialog(playlist):
+ for row in self._listbox:
+ if row.props.playlist == playlist:
+ self._listbox.select_row(row)
+ break
+ self.response(Gtk.ResponseType.ACCEPT)
+
text = self._add_playlist_entry.props.text
if text:
- self._playlist.create_playlist(text)
-
- @log
- def _on_playlist_created(self, playlists, item):
- row = self._add_playlist_to_listbox(item)
- if not row:
- return
- self._listbox.select_row(row)
- self.response(Gtk.ResponseType.ACCEPT)
+ self._playlists.create_playlist(text, select_and_close_dialog)
@Gtk.Template.Callback()
@log
diff --git a/gnomemusic/widgets/playlistdialogrow.py b/gnomemusic/widgets/playlistdialogrow.py
index 4de4d94d..1e27b2bc 100644
--- a/gnomemusic/widgets/playlistdialogrow.py
+++ b/gnomemusic/widgets/playlistdialogrow.py
@@ -22,9 +22,9 @@
# code, but you are not obligated to do so. If you do not wish to do so,
# delete this exception statement from your version.
-from gi.repository import GObject, Grl, Gtk
+from gi.repository import GObject, Gtk
-import gnomemusic.utils as utils
+from gnomemusic.playlists import Playlist
@Gtk.Template(resource_path="/org/gnome/Music/ui/PlaylistDialogRow.ui")
@@ -32,7 +32,7 @@ class PlaylistDialogRow(Gtk.ListBoxRow):
__gtype_name__ = "PlaylistDialogRow"
- playlist = GObject.Property(type=Grl.Media, default=None)
+ playlist = GObject.Property(type=Playlist, default=None)
selected = GObject.Property(type=bool, default=False)
_label = Gtk.Template.Child()
@@ -44,12 +44,12 @@ class PlaylistDialogRow(Gtk.ListBoxRow):
def __init__(self, playlist):
"""Create a row of the PlaylistDialog
- :param Grl.Media playlist: the associated playlist
+ :param Playlist playlist: the associated playlist
"""
super().__init__()
self.props.playlist = playlist
- self._label.props.label = utils.get_media_title(playlist)
+ self._label.props.label = playlist.props.title
self.bind_property(
"selected", self._selection_icon, "visible",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]