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



commit 35ec8ee59594bde604e4ae87700c5e8cba387dd9
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 | 27 +++++++++------------------
 1 file changed, 9 insertions(+), 18 deletions(-)
---
diff --git a/gnomemusic/views/playlistview.py b/gnomemusic/views/playlistview.py
index 1e05a549..6d0184a5 100644
--- a/gnomemusic/views/playlistview.py
+++ b/gnomemusic/views/playlistview.py
@@ -29,7 +29,7 @@ from gi.repository import Gdk, Gio, GLib, GObject, Gtk, Pango
 from gnomemusic import log
 from gnomemusic.grilo import grilo
 from gnomemusic.player import ValidationStatus, PlayerPlaylist
-from gnomemusic.playlists import Playlists, StaticPlaylists
+from gnomemusic.playlists import Playlists
 from gnomemusic.views.baseview import BaseView
 from gnomemusic.widgets.notificationspopup import PlaylistNotification
 from gnomemusic.widgets.playlistcontextmenu import PlaylistContextMenu
@@ -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]