[gnome-music/wip/jfelder/playlistdialog-user-playlist-3-34] playlistdialog: Use a model which only contains user playlists



commit 2e109d4bbfff48553983e5eee9785132f6d94582
Author: Jean Felder <jfelder src gnome org>
Date:   Tue Sep 3 14:40:44 2019 +0200

    playlistdialog: Use a model which only contains user playlists
    
    PlaylistDialog only displays the user playlists because the smart
    playlists are automatically generated. However, PlaylistDialog uses
    model which contains user and smart playlists. Thus, the function
    which creates the ListBox rows discards the smart playlists and
    returns None. This results in GTK errors, because a GTK widget is
    supposed to be returned.
    
    Fix the issue by adding a new model which only contains the user
    playlists.

 gnomemusic/coremodel.py                         | 19 +++++++++++++++++++
 gnomemusic/grilowrappers/grltrackerplaylists.py |  9 +++++++++
 gnomemusic/widgets/playlistdialog.py            |  7 ++-----
 3 files changed, 30 insertions(+), 5 deletions(-)
---
diff --git a/gnomemusic/coremodel.py b/gnomemusic/coremodel.py
index d068257d..d00e7886 100644
--- a/gnomemusic/coremodel.py
+++ b/gnomemusic/coremodel.py
@@ -126,6 +126,13 @@ class CoreModel(GObject.GObject):
         self._playlists_model_sort.set_sort_func(
             self._wrap_list_store_sort_func(self._playlists_sort))
 
+        self._user_playlists_model_filter = Gfm.FilterListModel.new(
+            self._playlists_model)
+        self._user_playlists_model_sort = Gfm.SortListModel.new(
+            self._user_playlists_model_filter)
+        self._user_playlists_model_sort.set_sort_func(
+            self._wrap_list_store_sort_func(self._playlists_sort))
+
         self.props.grilo = CoreGrilo(self, self._coreselection)
         # FIXME: Not all instances of internal _grilo use have been
         # fixed.
@@ -481,3 +488,15 @@ class CoreModel(GObject.GObject):
         flags=GObject.ParamFlags.READABLE)
     def playlists_filter(self):
         return self._playlists_model_filter
+
+    @GObject.Property(
+        type=Gfm.SortListModel, default=None,
+        flags=GObject.ParamFlags.READABLE)
+    def user_playlists_sort(self):
+        return self._user_playlists_model_sort
+
+    @GObject.Property(
+        type=Gfm.SortListModel, default=None,
+        flags=GObject.ParamFlags.READABLE)
+    def user_playlists_filter(self):
+        return self._user_playlists_model_filter
diff --git a/gnomemusic/grilowrappers/grltrackerplaylists.py b/gnomemusic/grilowrappers/grltrackerplaylists.py
index 0e024ec7..0e2a0a4f 100644
--- a/gnomemusic/grilowrappers/grltrackerplaylists.py
+++ b/gnomemusic/grilowrappers/grltrackerplaylists.py
@@ -78,9 +78,12 @@ class GrlTrackerPlaylists(GObject.GObject):
         self._source = source
         self._model = self._coremodel.props.playlists
         self._model_filter = self._coremodel.props.playlists_filter
+        self._user_model_filter = self._coremodel.props.user_playlists_filter
         self._pls_todelete = []
         self._tracker = tracker_wrapper.props.tracker
 
+        self._user_model_filter.set_filter_func(self._user_playlists_filter)
+
         self._fast_options = Grl.OperationOptions()
         self._fast_options.set_resolution_flags(
             Grl.ResolutionFlags.FAST_ONLY | Grl.ResolutionFlags.IDLE_RELAY)
@@ -154,6 +157,10 @@ class GrlTrackerPlaylists(GObject.GObject):
     def _playlists_filter(self, playlist):
         return playlist not in self._pls_todelete
 
+    def _user_playlists_filter(self, playlist):
+        return (playlist not in self._pls_todelete
+                and playlist.props.is_smart is False)
+
     def stage_playlist_deletion(self, playlist):
         """Adds playlist to the list of playlists to delete
 
@@ -171,6 +178,8 @@ class GrlTrackerPlaylists(GObject.GObject):
         self._pls_todelete.remove(playlist)
         if deleted is False:
             self._model_filter.set_filter_func(self._playlists_filter)
+            self._user_model_filter.set_filter_func(
+                self._user_playlists_filter)
             return
 
         def _delete_cb(conn, res, data):
diff --git a/gnomemusic/widgets/playlistdialog.py b/gnomemusic/widgets/playlistdialog.py
index bd042f41..055a9d6c 100644
--- a/gnomemusic/widgets/playlistdialog.py
+++ b/gnomemusic/widgets/playlistdialog.py
@@ -62,11 +62,11 @@ 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._coremodel = parent._app.props.coremodel
         self._listbox.bind_model(
-            self._coremodel.props.playlists_sort, self._create_playlist_row)
+            self._coremodel.props.user_playlists_sort,
+            self._create_playlist_row)
 
         self._set_view()
 
@@ -86,9 +86,6 @@ 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()
 


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