Commit 79588c4f authored by Jean Felder's avatar Jean Felder Committed by Marinus Schraal

playlistsview: Restore add song to playlist from the context menu

parent 6fa8949f
......@@ -367,43 +367,58 @@ class Playlist(GObject.GObject):
:param list coresongs: list of Coresong
"""
def _add_to_model(source, op_id, media, remaining, error):
if not media:
self.props.count = self._model.get_n_items()
return
coresong = CoreSong(media, self._coreselection, self._grilo)
if coresong not in self._songs_todelete:
self._model.append(coresong)
def update_callback(conn, res, coresong):
def _requery_media(conn, res, coresong):
if self._model is None:
return
media_id = coresong.props.media.get_id()
query = """
SELECT DISTINCT
SELECT
rdf:type(?song)
?song AS ?tracker_urn
nie:title(?song) AS ?title
tracker:id(?song) AS ?id
?song
tracker:id(?entry) AS ?id
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
nie:contentAccessed(?song) AS ?last_played_time
nie:usageCounter(?song) AS ?play_count
WHERE {
?song a nmm:MusicPiece .
?playlist a nmm:Playlist ;
a nfo:MediaList ;
nfo:hasMediaFileListEntry ?entry .
?entry a nfo:MediaFileListEntry ;
nfo:entryUrl ?url .
?song a nmm:MusicPiece ;
a nfo:FileDataObject ;
nie:url ?url .
OPTIONAL {
?song nao:hasTag ?tag .
FILTER (?tag = nao:predefined-tag-favorite)
FILTER( ?tag = nao:predefined-tag-favorite )
}
FILTER ( tracker:id(?song) = %(grilo_id)s )
FILTER (
%(filter_clause)s
)
FILTER (
NOT EXISTS { ?song a nmm:Video }
&& NOT EXISTS { ?song a nmm:Playlist }
)
}
""".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)
"filter_clause": "tracker:id(?entry) = " + media_id}
options = self._fast_options.copy()
self._source.query(
query, self.METADATA_KEYS, options, _add_to_model)
for coresong in coresongs:
query = """
......@@ -431,7 +446,7 @@ class Playlist(GObject.GObject):
"song_uri": coresong.props.media.get_url()}
self._tracker.update_blank_async(
query, GLib.PRIORITY_LOW, None, update_callback, coresong)
query, GLib.PRIORITY_LOW, None, _requery_media, coresong)
class SmartPlaylist(Playlist):
......
......@@ -32,6 +32,7 @@ from gnomemusic.views.baseview import BaseView
from gnomemusic.widgets.notificationspopup import PlaylistNotification
from gnomemusic.widgets.playlistcontextmenu import PlaylistContextMenu
from gnomemusic.widgets.playlistcontrols import PlaylistControls
from gnomemusic.widgets.playlistdialog import PlaylistDialog
from gnomemusic.widgets.sidebarrow import SidebarRow
from gnomemusic.widgets.songwidget import SongWidget
......@@ -74,10 +75,10 @@ class PlaylistsView(BaseView):
play_song.connect('activate', self._play_song)
self._window.add_action(play_song)
# add_song_to_playlist = Gio.SimpleAction.new(
# 'add_song_to_playlist', None)
# add_song_to_playlist.connect('activate', self._add_song_to_playlist)
# self._window.add_action(add_song_to_playlist)
add_song_to_playlist = Gio.SimpleAction.new(
'add_song_to_playlist', None)
add_song_to_playlist.connect('activate', self._add_song_to_playlist)
self._window.add_action(add_song_to_playlist)
self._remove_song_action = Gio.SimpleAction.new('remove_song', None)
self._remove_song_action.connect(
......@@ -182,6 +183,20 @@ class PlaylistsView(BaseView):
self._view.unselect_all()
self._song_activated(song_widget)
def _add_song_to_playlist(self, menuitem, data=None):
selected_row = self._view.get_selected_row()
song_widget = selected_row.get_child()
coresong = song_widget.props.coresong
print(coresong.props.media.get_source())
playlist_dialog = PlaylistDialog(self._window)
if playlist_dialog.run() == Gtk.ResponseType.ACCEPT:
playlist = playlist_dialog.props.selected_playlist
playlist.add_songs([coresong])
self._view.unselect_all()
playlist_dialog.destroy()
@log
def _stage_song_for_deletion(self, menuitem, data=None):
selected_row = self._view.get_selected_row()
......
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