Commit 6fa8949f authored by Jean Felder's avatar Jean Felder Committed by Marinus Schraal

playlistsdialog: Port to the new model

parent 88ae0c93
......@@ -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"""
......
......@@ -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:
......
......@@ -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")
......
......@@ -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()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment