Trying to figure out stuff for delete playlist

This commit is contained in:
Sumner Evans
2019-09-07 13:32:28 -06:00
parent a959f378ff
commit 596932ddee
4 changed files with 56 additions and 42 deletions

View File

@@ -95,6 +95,10 @@ class LibremsonicApp(Gtk.Application):
self.on_go_to_playlist, self.on_go_to_playlist,
parameter_type='s') parameter_type='s')
add_action('delete-playlist',
self.on_delete_playlist,
parameter_type='s')
add_action('mute-toggle', self.on_mute_toggle) add_action('mute-toggle', self.on_mute_toggle)
add_action( add_action(
'update-play-queue-from-server', 'update-play-queue-from-server',
@@ -317,6 +321,12 @@ class LibremsonicApp(Gtk.Application):
self.state.selected_playlist_id = playlist_id.get_string() self.state.selected_playlist_id = playlist_id.get_string()
self.update_window() self.update_window()
def on_delete_playlist(self, action, playlist_id):
# Update state.
self.state.current_tab = 'playlists'
self.state.selected_playlist_id = None
self.update_window()
def on_server_list_changed(self, action, servers): def on_server_list_changed(self, action, servers):
self.state.config.servers = servers self.state.config.servers = servers
self.state.save() self.state.save()

View File

@@ -250,12 +250,12 @@ class CacheManager(metaclass=Singleton):
return str(abs_path) return str(abs_path)
def delete_cached(self, relative_path: Union[Path, str]): def delete_cached_cover_art(self, id: int):
""" tag = 'tag_' if self.browse_by_tags else ''
:param relative_path: The path to the cached element to delete. relative_path = f'cover_art/{tag}{id}_*'
Note that this can be a globed path.
"""
abs_path = self.calculate_abs_path(relative_path) abs_path = self.calculate_abs_path(relative_path)
for path in glob.glob(str(abs_path)): for path in glob.glob(str(abs_path)):
Path(path).unlink() Path(path).unlink()
@@ -275,6 +275,14 @@ class CacheManager(metaclass=Singleton):
return CacheManager.executor.submit(do_get_playlists) return CacheManager.executor.submit(do_get_playlists)
def invalidate_playlists_cache(self):
if not self.cache.get('playlists'):
return
with self.cache_lock:
self.cache['playlists'] = []
self.save_cache_info()
def get_playlist( def get_playlist(
self, self,
playlist_id: int, playlist_id: int,
@@ -301,8 +309,7 @@ class CacheManager(metaclass=Singleton):
# Invalidate the cached photo if we are forcing a retrieval # Invalidate the cached photo if we are forcing a retrieval
# from the server. # from the server.
if force: if force:
self.delete_cached( self.delete_cached_cover_art(playlist.id)
f'cover_art/{playlist_details.coverArt}_*')
return playlist_details return playlist_details

View File

@@ -38,13 +38,6 @@ class EditFormDialog(Gtk.Dialog):
transient_for=parent, transient_for=parent,
flags=0, flags=0,
) )
self.add_buttons(
Gtk.STOCK_CANCEL,
Gtk.ResponseType.CANCEL,
Gtk.STOCK_EDIT if editing else Gtk.STOCK_ADD,
Gtk.ResponseType.OK,
)
if not existing_object: if not existing_object:
existing_object = self.get_default_object() existing_object = self.get_default_object()
@@ -111,10 +104,15 @@ class EditFormDialog(Gtk.Dialog):
content_area.pack_start(content_grid, True, True, 10) content_area.pack_start(content_grid, True, True, 10)
# Create a box for buttons. # Create a box for buttons.
if len(self.extra_buttons) > 0: for button, response_id in self.extra_buttons:
button_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) self.add_action_widget(button, response_id)
for button in self.extra_buttons:
button_box.pack_start(button, False, True, 5) self.add_buttons(
content_area.pack_start(button_box, True, True, 10) Gtk.STOCK_CANCEL,
Gtk.ResponseType.CANCEL,
Gtk.STOCK_EDIT if editing else Gtk.STOCK_ADD,
Gtk.ResponseType.OK,
)
self.show_all() self.show_all()

View File

@@ -16,24 +16,29 @@ from libremsonic.ui.common import EditFormDialog, IconButton, SpinnerImage
class EditPlaylistDialog(EditFormDialog): class EditPlaylistDialog(EditFormDialog):
__gsignals__ = {
'delete-playlist':
(GObject.SignalFlags.RUN_FIRST, GObject.TYPE_NONE, ()),
}
entity_name: str = 'Playlist' entity_name: str = 'Playlist'
initial_size = (350, 120) initial_size = (350, 120)
text_fields = [('Name', 'name', False), ('Comment', 'comment', False)] text_fields = [('Name', 'name', False), ('Comment', 'comment', False)]
boolean_fields = [('Public', 'public')] boolean_fields = [('Public', 'public')]
def __init__(self, *args, **kwargs): def __init__(self, *args, playlist_id=None, **kwargs):
delete_playlist = Gtk.Button(label='Delete Playlist') delete_playlist = Gtk.Button(
delete_playlist.connect('clicked', self.on_delete_playlist_click) label='Delete Playlist',
self.extra_buttons = [delete_playlist] action_name='app.delete-playlist',
super().__init__(*args, **kwargs) action_target=GLib.Variant('s', playlist_id),
)
def on_delete_playlist_click(self, event): def on_delete_playlist(e):
self.emit('delete-playlist') # Delete the playlists and invalidate caches.
CacheManager.delete_playlist(playlist_id)
CacheManager.delete_cached_cover_art(playlist_id)
CacheManager.invalidate_playlists_cache()
self.close()
delete_playlist.connect('clicked', on_delete_playlist)
self.extra_buttons = [(delete_playlist, Gtk.ResponseType.DELETE_EVENT)]
super().__init__(*args, **kwargs)
class PlaylistsPanel(Gtk.Paned): class PlaylistsPanel(Gtk.Paned):
@@ -503,14 +508,9 @@ class PlaylistDetailPanel(Gtk.Overlay):
def on_playlist_edit_button_click(self, button): def on_playlist_edit_button_click(self, button):
dialog = EditPlaylistDialog( dialog = EditPlaylistDialog(
self.get_toplevel(), self.get_toplevel(),
CacheManager.get_playlist(self.playlist_id).result()) CacheManager.get_playlist(self.playlist_id).result(),
playlist_id=self.playlist_id,
def on_delete_playlist(e): )
CacheManager.delete_playlist(self.playlist_id)
dialog.destroy()
self.update_playlist_view(force=True)
dialog.connect('delete-playlist', on_delete_playlist)
result = dialog.run() result = dialog.run()
if result == Gtk.ResponseType.OK: if result == Gtk.ResponseType.OK:
@@ -521,9 +521,8 @@ class PlaylistDetailPanel(Gtk.Overlay):
public=dialog.data['public'].get_active(), public=dialog.data['public'].get_active(),
) )
# TODO # Invalidate the cover art cache.
# cover_art_filename = f'cover_art/{playlist.coverArt}_*' CacheManager.delete_cached_cover_art(playlist.id)
# CacheManager.delete_cached(cover_art_filename)
self.update_playlist_view(self.playlist_id, force=True) self.update_playlist_view(self.playlist_id, force=True)
dialog.destroy() dialog.destroy()