Commit ac84b9b8 authored by Marinus Schraal's avatar Marinus Schraal

playlistview: Add back playlist renaming

parent eebdd874
Pipeline #93714 passed with stages
in 30 minutes and 12 seconds
......@@ -3,10 +3,11 @@ import time
from gettext import gettext as _
import gi
gi.require_versions({"Grl": "0.3", 'Tracker': "2.0"})
gi.require_versions({"Grl": "0.3"})
from gi.repository import Gio, Grl, GLib, GObject
from gnomemusic.coresong import CoreSong
from gnomemusic.trackerwrapper import TrackerWrapper
import gnomemusic.utils as utils
......@@ -153,6 +154,7 @@ class Playlist(GObject.GObject):
self._coremodel = coremodel
self._coreselection = coreselection
self._grilo = grilo
self._tracker = TrackerWrapper().props.tracker
self._fast_options = Grl.OperationOptions()
self._fast_options.set_resolution_flags(
......@@ -227,6 +229,39 @@ class Playlist(GObject.GObject):
self._source.query(
query, self.METADATA_KEYS, options, _add_to_playlist_cb, None)
def rename(self, new_name):
"""Rename a playlist
:param str new_name: new playlist name
"""
def update_cb(conn, res, data):
# FIXME: Check for failure.
conn.update_finish(res)
# FIXME: Requery instead?
self.props.title = new_name
query = """
INSERT OR REPLACE {
?playlist nie:title "%(title)s"
}
WHERE {
?playlist a nmm:Playlist ;
a nfo:MediaList .
OPTIONAL {
?playlist nfo:hasMediaFileListEntry ?entry .
}
FILTER (
tracker:id(?playlist) = %(playlist_id)s
)
}
""".replace("\n", " ").strip() % {
'title': new_name,
'playlist_id': self.props.pl_id
}
self._tracker.update_async(
query, GLib.PRIORITY_LOW, None, update_cb, None)
class SmartPlaylist(Playlist):
"""Base class for smart playlists"""
......
......@@ -24,7 +24,7 @@
from gettext import gettext as _
from gi.repository import GObject, Gtk
from gi.repository import GObject, Gio, Gtk
from gnomemusic import log
from gnomemusic.player import PlayerPlaylist
......@@ -92,11 +92,11 @@ class PlaylistsView(BaseView):
# self._playlist_delete_action.connect(
# 'activate', self._stage_playlist_for_deletion)
# self._window.add_action(self._playlist_delete_action)
# self._playlist_rename_action = Gio.SimpleAction.new(
# 'playlist_rename', None)
# self._playlist_rename_action.connect(
# 'activate', self._stage_playlist_for_renaming)
# self._window.add_action(self._playlist_rename_action)
self._playlist_rename_action = Gio.SimpleAction.new(
'playlist_rename', None)
self._playlist_rename_action.connect(
'activate', self._stage_playlist_for_renaming)
self._window.add_action(self._playlist_rename_action)
self._grid.insert_row(0)
self._grid.attach(self._pl_ctrls, 1, 0, 1, 1)
......@@ -175,6 +175,8 @@ class PlaylistsView(BaseView):
self._update_songs_count(playlist.props.count)
playlist.connect("notify::count", self._on_song_count_changed)
self._playlist_rename_action.set_enabled(not playlist.props.is_smart)
def _on_song_count_changed(self, playlist, value):
self._update_songs_count(playlist.props.count)
......@@ -218,8 +220,7 @@ class PlaylistsView(BaseView):
selection.props.text = new_name
pl_torename = selection.playlist
pl_torename.props.title = new_name
self._playlists.rename(pl_torename, new_name)
pl_torename.rename(new_name)
@log
def _populate(self, data=None):
......
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