[gnome-music/wip/jfelder/playlistview-protected] playlistview: Simplify protected playlists check



commit 120104c12cddee685677bffaf962ee58f5a6748a
Author: Jean Felder <jfelder src gnome org>
Date:   Tue May 14 08:45:32 2019 +0200

    playlistview: Simplify protected playlists check
    
    A playlist is protected if and only if it is a static one. Therefore,
    the "is_static_playlist" method from Playlists can be used to check if
    a playlist is protected.
    
    This allows to remove the "_current_playlist_is_protected" method from
    PlaylistView.

 gnomemusic/views/playlistview.py | 25 ++++++++-----------------
 1 file changed, 8 insertions(+), 17 deletions(-)
---
diff --git a/gnomemusic/views/playlistview.py b/gnomemusic/views/playlistview.py
index 1e05a549..5bb90ba4 100644
--- a/gnomemusic/views/playlistview.py
+++ b/gnomemusic/views/playlistview.py
@@ -519,8 +519,9 @@ class PlaylistView(BaseView):
     @log
     def remove_playlist(self):
         """Removes the current selected playlist"""
-        if not self._current_playlist_is_protected():
-            self._stage_playlist_for_deletion(None)
+        if playlists.is_static_playlist(self._current_playlist):
+            return
+        self._stage_playlist_for_deletion(None)
 
     @log
     def _on_playlist_activated(self, sidebar, row, data=None):
@@ -545,16 +546,11 @@ class PlaylistView(BaseView):
         self._pl_ctrls.props.display_songs_count = False
         grilo.populate_playlist_songs(playlist, self._add_song)
 
-        if self._current_playlist_is_protected():
-            self._playlist_delete_action.set_enabled(False)
-            self._playlist_rename_action.set_enabled(False)
-            self._remove_song_action.set_enabled(False)
-            self._view.set_reorderable(False)
-        else:
-            self._playlist_delete_action.set_enabled(True)
-            self._playlist_rename_action.set_enabled(True)
-            self._remove_song_action.set_enabled(True)
-            self._view.set_reorderable(True)
+        protected_pl = playlists.is_static_playlist(self._current_playlist)
+        self._playlist_delete_action.set_enabled(not protected_pl)
+        self._playlist_rename_action.set_enabled(not protected_pl)
+        self._remove_song_action.set_enabled(not protected_pl)
+        self._view.set_reorderable(not protected_pl)
 
     @log
     def _add_song(self, source, param, song, remaining=0, data=None):
@@ -603,11 +599,6 @@ class PlaylistView(BaseView):
     def _on_play_activate(self, menuitem, data=None):
         self._view.emit('row-activated', None, None)
 
-    @log
-    def _current_playlist_is_protected(self):
-        current_playlist_id = self._current_playlist.get_id()
-        return current_playlist_id in StaticPlaylists().get_ids()
-
     @log
     def _is_current_playlist(self, playlist):
         """Check if playlist is currently displayed"""


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