Added Browse tab and implemented logic to change stack state

This commit is contained in:
Sumner Evans
2020-01-01 12:14:49 -07:00
parent 6a24fbada5
commit ba35cae6e1
5 changed files with 107 additions and 36 deletions

View File

@@ -154,12 +154,13 @@ def show_song_popover(
# Determine if we should enable the download button.
download_sensitive, remove_download_sensitive = False, False
albums, artists = set(), set()
albums, artists, parents = set(), set(), set()
for song_id in song_ids:
details = CacheManager.get_song_details(song_id).result()
status = CacheManager.get_cached_status(details)
albums.add(details.albumId)
artists.add(details.artistId)
parents.add(details.parent)
if download_sensitive or status == SongCacheStatus.NOT_CACHED:
download_sensitive = True
@@ -181,6 +182,14 @@ def show_song_popover(
artist_value = GLib.Variant('s', list(artists)[0])
go_to_artist_button.set_action_target_value(artist_value)
browse_to_song = Gtk.ModelButton(
text=f"Browse to {pluralize('song', song_count)}",
action_name='app.browse-to-song',
)
if len(parents) == 1 and list(parents)[0] is not None:
parent_value = GLib.Variant('s', list(parents)[0])
browse_to_song.set_action_target_value(parent_value)
menu_items = [
Gtk.ModelButton(
text='Play next',
@@ -193,31 +202,38 @@ def show_song_popover(
action_target=GLib.Variant('as', song_ids),
),
Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL),
go_to_album_button,
go_to_artist_button,
Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL),
(
Gtk.ModelButton(
text=f"Download {pluralize('song', song_count)}",
sensitive=download_sensitive,
),
on_download_songs_click,
),
(
Gtk.ModelButton(
text=f"Remove {pluralize('download', song_count)}",
sensitive=remove_download_sensitive,
),
on_remove_downloads_click,
),
Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL),
Gtk.ModelButton(
text=f"Add {pluralize('song', song_count)} to playlist",
menu_name='add-to-playlist',
),
*extra_menu_items,
]
if CacheManager.browse_by_tags():
menu_items.extend([go_to_album_button, go_to_artist_button])
else:
menu_items.extend([browse_to_song])
menu_items.extend(
[
Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL),
(
Gtk.ModelButton(
text=f"Download {pluralize('song', song_count)}",
sensitive=download_sensitive,
),
on_download_songs_click,
),
(
Gtk.ModelButton(
text=f"Remove {pluralize('download', song_count)}",
sensitive=remove_download_sensitive,
),
on_remove_downloads_click,
),
Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL),
Gtk.ModelButton(
text=f"Add {pluralize('song', song_count)} to playlist",
menu_name='add-to-playlist',
),
*extra_menu_items,
])
for item in menu_items:
if type(item) == tuple:
el, fn = item