[gnome-music] window: Move away some playlist notification logic
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music] window: Move away some playlist notification logic
- Date: Mon, 5 Feb 2018 12:10:34 +0000 (UTC)
commit a89da7b50a431bbb2dc1ec91a1abc66f0b9d604f
Author: Jean Felder <jean felder gmail com>
Date: Tue Jan 30 00:34:19 2018 +0100
window: Move away some playlist notification logic
gnomemusic/views/playlistview.py | 35 ++++++++++++++++++++++++++---------
gnomemusic/window.py | 14 +++++---------
2 files changed, 31 insertions(+), 18 deletions(-)
---
diff --git a/gnomemusic/views/playlistview.py b/gnomemusic/views/playlistview.py
index f607fb8..6cdd839 100644
--- a/gnomemusic/views/playlistview.py
+++ b/gnomemusic/views/playlistview.py
@@ -130,7 +130,7 @@ class PlaylistView(BaseView):
self._iter_to_clean = None
self._iter_to_clean_model = None
- self.current_playlist = None
+ self._current_playlist = None
self._current_playlist_index = None
self.pl_todelete = {}
self._songs_count = 0
@@ -354,7 +354,7 @@ class PlaylistView(BaseView):
_iter = self.model.get_iter(path)
if self.model[_iter][8] != self._error_icon_name:
self.player.set_playlist(
- 'Playlist', self.current_playlist.get_id(), self.model,
+ 'Playlist', self._current_playlist.get_id(), self.model,
_iter, 5, 11)
self.player.set_playing(True)
@@ -422,7 +422,7 @@ class PlaylistView(BaseView):
new_iter = self.model.get_iter_from_string(str(pos))
self._iter_to_clean = new_iter
self.player.set_playlist(
- 'Playlist', self.current_playlist.get_id(), self.model,
+ 'Playlist', self._current_playlist.get_id(), self.model,
new_iter, 5, 11)
first_pos = min(new_pos, prev_pos)
@@ -435,7 +435,7 @@ class PlaylistView(BaseView):
songs.append(model[_iter][5])
positions.append(pos + 1)
- playlists.reorder_playlist(self.current_playlist, songs, positions)
+ playlists.reorder_playlist(self._current_playlist, songs, positions)
@log
def _play_song(self, menuitem, data=None):
@@ -459,7 +459,7 @@ class PlaylistView(BaseView):
def _remove_song(self, menuitem, data=None):
model, _iter = self._view.get_selection().get_selected()
song = model[_iter][5]
- playlists.remove_from_playlist(self.current_playlist, [song])
+ playlists.remove_from_playlist(self._current_playlist, [song])
@log
def _on_playlist_update(self, playlists, playlist_id):
@@ -535,7 +535,7 @@ class PlaylistView(BaseView):
if self.rename_active:
self.disable_rename_playlist()
- self.current_playlist = playlist
+ self._current_playlist = playlist
self._name_label.set_text(playlist_name)
self._current_playlist_index = row.get_index()
@@ -615,7 +615,7 @@ class PlaylistView(BaseView):
@log
def _current_playlist_is_protected(self):
- current_playlist_id = self.current_playlist.get_id()
+ current_playlist_id = self._current_playlist.get_id()
if current_playlist_id in StaticPlaylists().get_ids():
return True
else:
@@ -624,11 +624,22 @@ class PlaylistView(BaseView):
@log
def _is_current_playlist(self, playlist):
"""Check if playlist is currently displayed"""
- if (self.current_playlist
- and playlist.get_id() == self.current_playlist.get_id()):
+ if (self._current_playlist
+ and playlist.get_id() == self._current_playlist.get_id()):
return True
return False
+ @log
+ def _get_removal_notification_message(self):
+ playlist_title = utils.get_media_title(self.pl_todelete['playlist'])
+ msg = _("Playlist {} removed".format(playlist_title))
+ return msg
+
+ @log
+ def _create_playlist_notification(self):
+ msg = self._get_removal_notification_message()
+ self._window.show_playlist_notification(msg)
+
@log
def _stage_playlist_for_deletion(self, menutime, data=None):
self._window.show_playlist_notification()
@@ -647,12 +658,18 @@ class PlaylistView(BaseView):
self._sidebar.select_row(row_next)
self._sidebar.emit('row-activated', row_next)
+ self._create_playlist_notification()
+
@log
def undo_playlist_deletion(self):
"""Revert the last playlist removal"""
self._add_playlist_to_sidebar(
self.pl_todelete['playlist'], self.pl_todelete['index'])
+ @log
+ def finish_playlist_deletion(self):
+ playlists.delete_playlist(self.pl_todelete['playlist'])
+
@log
@property
def rename_active(self):
diff --git a/gnomemusic/window.py b/gnomemusic/window.py
index a7e7dc2..09bf634 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -361,7 +361,7 @@ class Window(Gtk.ApplicationWindow):
view.select_none()
@log
- def show_playlist_notification(self):
+ def show_playlist_notification(self, message):
"""Show a notification on playlist removal and provide an
option to undo for 5 seconds.
"""
@@ -369,8 +369,7 @@ class Window(Gtk.ApplicationWindow):
# Callback to remove playlists
def remove_playlist_timeout_cb(self):
# Remove the playlist
- playlist.delete_playlist(
- self.views[View.PLAYLIST].pl_todelete['playlist'])
+ self.views[View.PLAYLIST].finish_playlist_deletion()
# Hide the notification
self._playlist_notification.set_reveal_child(False)
@@ -385,14 +384,11 @@ class Window(Gtk.ApplicationWindow):
GLib.source_remove(self._playlist_notification_timeout_id)
remove_playlist_timeout_cb(self)
- playlist_title = self.views[View.PLAYLIST].current_playlist.get_title()
- label = _("Playlist {} removed".format(playlist_title))
-
- self._playlist_notification.label.set_label(label)
+ self._playlist_notification.label.set_label(message)
self._playlist_notification.set_reveal_child(True)
- timeout_id = GLib.timeout_add_seconds(5, remove_playlist_timeout_cb,
- self)
+ timeout_id = GLib.timeout_add_seconds(
+ 5, remove_playlist_timeout_cb, self)
self._playlist_notification_timeout_id = timeout_id
@log
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]