[gnome-music/wip/mschraal/core] playlistsdialog: Port to the new model
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/mschraal/core] playlistsdialog: Port to the new model
- Date: Sat, 13 Jul 2019 22:40:30 +0000 (UTC)
commit 6fa8949f43f9849be739ed17c98505d5a97aa9f2
Author: Jean Felder <jfelder src gnome org>
Date: Tue Jul 9 00:28:15 2019 +0200
playlistsdialog: Port to the new model
gnomemusic/grilowrappers/grltrackerplaylists.py | 73 +++++++++++++++++++++++++
gnomemusic/widgets/playlistdialog.py | 28 +++++-----
gnomemusic/widgets/playlistdialogrow.py | 2 +-
gnomemusic/window.py | 6 +-
4 files changed, 90 insertions(+), 19 deletions(-)
---
diff --git a/gnomemusic/grilowrappers/grltrackerplaylists.py b/gnomemusic/grilowrappers/grltrackerplaylists.py
index b8d74888..98cc16f0 100644
--- a/gnomemusic/grilowrappers/grltrackerplaylists.py
+++ b/gnomemusic/grilowrappers/grltrackerplaylists.py
@@ -360,6 +360,79 @@ class Playlist(GObject.GObject):
self._tracker.update_async(
query, GLib.PRIORITY_LOW, None, update_cb, None)
+ def add_songs(self, coresongs):
+ """Adds songs to the playlist
+
+ :param Playlist playlist:
+ :param list coresongs: list of Coresong
+ """
+ def _add_to_model(source, op_id, media, remaining, error):
+ coresong = CoreSong(media, self._coreselection, self._grilo)
+ if coresong not in self._songs_todelete:
+ self._model.append(coresong)
+
+ def update_callback(conn, res, coresong):
+ query = """
+ SELECT DISTINCT
+ rdf:type(?song)
+ ?song AS ?tracker_urn
+ nie:title(?song) AS ?title
+ tracker:id(?song) AS ?id
+ ?song
+ nie:url(?song) AS ?url
+ nie:title(?song) AS ?title
+ nmm:artistName(nmm:performer(?song)) AS ?artist
+ nie:title(nmm:musicAlbum(?song)) AS ?album
+ nfo:duration(?song) AS ?duration
+ nie:usageCounter(?song) AS ?play_count
+ nmm:trackNumber(?song) AS ?track_number
+ nmm:setNumber(nmm:musicAlbumDisc(?song)) AS ?album_disc_number
+ ?tag AS ?favourite
+ WHERE {
+ ?song a nmm:MusicPiece .
+ OPTIONAL {
+ ?song nao:hasTag ?tag .
+ FILTER (?tag = nao:predefined-tag-favorite)
+ }
+ FILTER ( tracker:id(?song) = %(grilo_id)s )
+ }
+ """.replace("\n", " ").strip() % {
+ "grilo_id": coresong.props.media.get_id()}
+
+ # FIXME: seems bad!
+ if self._model is not None:
+ options = self._fast_options.copy()
+ self._source.query(
+ query, self.METADATA_KEYS, options, _add_to_model)
+
+ for coresong in coresongs:
+ query = """
+ INSERT OR REPLACE {
+ _:entry a nfo:MediaFileListEntry ;
+ nfo:entryUrl "%(song_uri)s" ;
+ nfo:listPosition ?position .
+ ?playlist nfo:entryCounter ?position ;
+ nfo:hasMediaFileListEntry _:entry .
+ }
+ WHERE {
+ SELECT ?playlist
+ (?counter + 1) AS ?position
+ WHERE {
+ ?playlist a nmm:Playlist ;
+ a nfo:MediaList ;
+ nfo:entryCounter ?counter .
+ FILTER (
+ tracker:id(?playlist) = %(playlist_id)s
+ )
+ }
+ }
+ """.replace("\n", " ").strip() % {
+ "playlist_id": self.props.pl_id,
+ "song_uri": coresong.props.media.get_url()}
+
+ self._tracker.update_blank_async(
+ query, GLib.PRIORITY_LOW, None, update_callback, coresong)
+
class SmartPlaylist(Playlist):
"""Base class for smart playlists"""
diff --git a/gnomemusic/widgets/playlistdialog.py b/gnomemusic/widgets/playlistdialog.py
index e328f422..26014d52 100644
--- a/gnomemusic/widgets/playlistdialog.py
+++ b/gnomemusic/widgets/playlistdialog.py
@@ -22,10 +22,10 @@
# 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 Gtk
+from gi.repository import GObject, Gtk
from gnomemusic import log
-from gnomemusic.playlists import Playlists
+from gnomemusic.grilowrappers.grltrackerplaylists import Playlist
from gnomemusic.widgets.playlistdialogrow import PlaylistDialogRow
@@ -35,6 +35,8 @@ class PlaylistDialog(Gtk.Dialog):
__gtype_name__ = 'PlaylistDialog'
+ selected_playlist = GObject.Property(type=Playlist, default=None)
+
_add_playlist_stack = Gtk.Template.Child()
_normal_box = Gtk.Template.Child()
_empty_box = Gtk.Template.Child()
@@ -60,22 +62,13 @@ class PlaylistDialog(Gtk.Dialog):
self.props.transient_for = parent
self.set_titlebar(self._title_bar)
+ # FIXME: should we use a special model without the smart playlists?
self._user_playlists_available = False
- self._playlists = Playlists.get_default()
- playlists_model = self._playlists.get_user_playlists()
+ self._coremodel = parent._app.props.coremodel
self._listbox.bind_model(
- playlists_model, self._create_playlist_row)
- self._set_view()
-
- @log
- def get_selected(self):
- """Get the selected playlist"""
- selected_row = self._listbox.get_selected_row()
+ self._coremodel.props.playlists_sort, self._create_playlist_row)
- if not selected_row:
- return None
-
- return selected_row.props.playlist
+ self._set_view()
@log
def _set_view(self):
@@ -93,6 +86,9 @@ class PlaylistDialog(Gtk.Dialog):
@log
def _create_playlist_row(self, playlist):
"""Adds (non-smart only) playlists to the model"""
+ if playlist.props.is_smart:
+ return None
+
self._user_playlists_available = True
self._set_view()
@@ -116,6 +112,8 @@ class PlaylistDialog(Gtk.Dialog):
self._add_playlist_entry.props.text = ""
self._add_playlist_button.props.sensitive = False
selected_row = self._listbox.get_selected_row()
+ if selected_row is not None:
+ self.props.selected_playlist = selected_row.props.playlist
self._select_button.props.sensitive = selected_row is not None
for row in self._listbox:
diff --git a/gnomemusic/widgets/playlistdialogrow.py b/gnomemusic/widgets/playlistdialogrow.py
index 1e27b2bc..030c17ff 100644
--- a/gnomemusic/widgets/playlistdialogrow.py
+++ b/gnomemusic/widgets/playlistdialogrow.py
@@ -24,7 +24,7 @@
from gi.repository import GObject, Gtk
-from gnomemusic.playlists import Playlist
+from gnomemusic.grilowrappers.grltrackerplaylists import Playlist
@Gtk.Template(resource_path="/org/gnome/Music/ui/PlaylistDialogRow.ui")
diff --git a/gnomemusic/window.py b/gnomemusic/window.py
index ec701b11..b95dbb2d 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -495,9 +495,9 @@ class Window(Gtk.ApplicationWindow):
return
playlist_dialog = PlaylistDialog(self)
- # if playlist_dialog.run() == Gtk.ResponseType.ACCEPT:
- # playlists.add_to_playlist(
- # playlist_dialog.get_selected(), selected_songs)
+ if playlist_dialog.run() == Gtk.ResponseType.ACCEPT:
+ playlist = playlist_dialog.props.selected_playlist
+ playlist.add_songs(selected_songs)
self.props.selection_mode = False
playlist_dialog.destroy()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]