[gnome-music/wip/jfelder/fix-playlist-renaming: 13/13] grltrackerplaylists: Use title setter to rename a playlist



commit 43a7fb6e484b94436adc708b31567e9da19374f2
Author: Jean Felder <jfelder src gnome org>
Date:   Tue Jan 7 20:14:33 2020 +0100

    grltrackerplaylists: Use title setter to rename a playlist

 gnomemusic/grilowrappers/grltrackerplaylists.py | 33 +++++++++++++++++--------
 gnomemusic/widgets/playlistcontrols.py          |  2 +-
 2 files changed, 24 insertions(+), 11 deletions(-)
---
diff --git a/gnomemusic/grilowrappers/grltrackerplaylists.py b/gnomemusic/grilowrappers/grltrackerplaylists.py
index 427096c6..25acde5e 100644
--- a/gnomemusic/grilowrappers/grltrackerplaylists.py
+++ b/gnomemusic/grilowrappers/grltrackerplaylists.py
@@ -295,7 +295,6 @@ class Playlist(GObject.GObject):
     pl_id = GObject.Property(type=str, default=None)
     query = GObject.Property(type=str, default=None)
     tag_text = GObject.Property(type=str, default=None)
-    title = GObject.Property(type=str, default=None)
 
     def __repr__(self):
         return "<Playlist>"
@@ -319,9 +318,11 @@ class Playlist(GObject.GObject):
         """
         if media:
             self.props.pl_id = media.get_id()
-            self.props.title = utils.get_media_title(media)
+            self._title = utils.get_media_title(media)
             self.props.count = media.get_childcount()
             self.props.creation_date = media.get_creation_date()
+        else:
+            self._title = None
 
         self.props.query = query
         self.props.tag_text = tag_text
@@ -413,7 +414,17 @@ class Playlist(GObject.GObject):
         self._source.query(
             query, self.METADATA_KEYS, options, _add_to_playlist_cb, None)
 
-    def rename(self, new_name):
+    @GObject.Property(type=str, default=None)
+    def title(self):
+        """Playlist title
+
+        :returns: playlist title
+        :rtype: str
+        """
+        return self._title
+
+    @title.setter
+    def title(self, new_name):
         """Rename a playlist
 
         :param str new_name: new playlist name
@@ -426,11 +437,12 @@ class Playlist(GObject.GObject):
             except GLib.Error as e:
                 logger.warning(
                     "Unable to rename playlist from {} to {}: {}".format(
-                        self.props.title, new_name, e.message))
+                        self._title, new_name, e.message))
             else:
-                self.props.title = new_name
+                self._title = new_name
             finally:
                 self._window.notifications_popup.pop_loading()
+                self.thaw_notify()
 
         query = """
         INSERT OR REPLACE {
@@ -451,6 +463,7 @@ class Playlist(GObject.GObject):
             'playlist_id': self.props.pl_id
         }
 
+        self.freeze_notify()
         self._tracker.update_async(
             query, GLib.PRIORITY_LOW, None, update_cb, None)
 
@@ -732,7 +745,7 @@ class MostPlayed(SmartPlaylist):
 
         self.props.tag_text = "MOST_PLAYED"
         # TRANSLATORS: this is a playlist name
-        self.props.title = _("Most Played")
+        self._title = _("Most Played")
         self.props.query = """
         SELECT
             rdf:type(?song)
@@ -769,7 +782,7 @@ class NeverPlayed(SmartPlaylist):
 
         self.props.tag_text = "NEVER_PLAYED"
         # TRANSLATORS: this is a playlist name
-        self.props.title = _("Never Played")
+        self._title = _("Never Played")
         self.props.query = """
         SELECT
             rdf:type(?song)
@@ -805,7 +818,7 @@ class RecentlyPlayed(SmartPlaylist):
 
         self.props.tag_text = "RECENTLY_PLAYED"
         # TRANSLATORS: this is a playlist name
-        self.props.title = _("Recently Played")
+        self._title = _("Recently Played")
 
         sparql_midnight_dateTime_format = "%Y-%m-%dT00:00:00Z"
         days_difference = 7
@@ -851,7 +864,7 @@ class RecentlyAdded(SmartPlaylist):
 
         self.props.tag_text = "RECENTLY_ADDED"
         # TRANSLATORS: this is a playlist name
-        self.props.title = _("Recently Added")
+        self._title = _("Recently Added")
 
         sparql_midnight_dateTime_format = "%Y-%m-%dT00:00:00Z"
         days_difference = 7
@@ -896,7 +909,7 @@ class Favorites(SmartPlaylist):
 
         self.props.tag_text = "FAVORITES"
         # TRANSLATORS: this is a playlist name
-        self.props.title = _("Favorite Songs")
+        self._title = _("Favorite Songs")
         self.props.query = """
             SELECT
                 rdf:type(?song)
diff --git a/gnomemusic/widgets/playlistcontrols.py b/gnomemusic/widgets/playlistcontrols.py
index 4c03474c..888de539 100644
--- a/gnomemusic/widgets/playlistcontrols.py
+++ b/gnomemusic/widgets/playlistcontrols.py
@@ -103,7 +103,7 @@ class PlaylistControls(Gtk.Grid):
         if not new_name:
             return
 
-        self.props.playlist.rename(new_name)
+        self.props.playlist.props.title = new_name
         self._disable_rename_playlist()
 
     @log


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]