Commit 94e78dbe authored by Jean Felder's avatar Jean Felder Committed by Marinus Schraal

coremodel: Add user playlist creation logic

parent 57113d6f
......@@ -172,3 +172,14 @@ class CoreGrilo(GObject.GObject):
if wrapper.source.props.source_id == "grl-tracker-source":
wrapper.finish_playlist_deletion(playlist, deleted)
break
def create_playlist(self, playlist_title, callback):
"""Creates a new user playlist.
:param str playlist_title: playlist title
:param callback: function to perform once, the playlist is created
"""
for wrapper in self._wrappers:
if wrapper.source.props.source_id == "grl-tracker-source":
wrapper.create_playlist(playlist_title, callback)
break
......@@ -108,6 +108,9 @@ class GrlTrackerPlaylists(GObject.GObject):
coreselection=self._coreselection, grilo=self._grilo)
self._model.append(playlist)
callback = data
if callback is not None:
callback(playlist)
def _playlists_filter(self, playlist):
return playlist not in self._pls_todelete
......@@ -163,6 +166,45 @@ class GrlTrackerPlaylists(GObject.GObject):
self._tracker.update_async(
query, GLib.PRIORITY_LOW, None, _delete_cb, None)
def create_playlist(self, playlist_title, callback):
"""Creates a new user playlist.
:param str playlist_title: playlist title
:param callback: function to perform once, the playlist is created
"""
def _create_cb(conn, res, data):
result = conn.update_blank_finish(res)
playlist_urn = result[0][0]['playlist']
query = """
SELECT
rdf:type(?playlist)
tracker:id(?playlist) AS ?id
nie:title(?playlist) AS ?title
tracker:added(?playlist) AS ?creation_date
nfo:entryCounter(?playlist) AS ?childcount
WHERE
{
?playlist a nmm:Playlist .
FILTER ( <%(playlist_urn)s> = ?playlist )
}
""".replace("\n", " ").strip() % {"playlist_urn": playlist_urn}
options = self._fast_options.copy()
self._source.query(
query, self.METADATA_KEYS, options, self._add_user_playlist,
callback)
query = """
INSERT {
_:playlist a nmm:Playlist ;
a nfo:MediaList ;
nie:title "%(title)s" ;
nfo:entryCounter 0 .
}
""".replace("\n", " ").strip() % {"title": playlist_title}
self._tracker.update_blank_async(
query, GLib.PRIORITY_LOW, None, _create_cb, None)
class Playlist(GObject.GObject):
""" Base class of all playlists """
......
......@@ -131,7 +131,7 @@ class PlaylistDialog(Gtk.Dialog):
text = self._add_playlist_entry.props.text
if text:
self._playlists.create_playlist(text, select_and_close_dialog)
self._coremodel.create_playlist(text, select_and_close_dialog)
@Gtk.Template.Callback()
@log
......
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