WIP
This commit is contained in:
@@ -23,55 +23,43 @@ class AlbumWithSongs(Gtk.Box):
|
||||
),
|
||||
}
|
||||
|
||||
album = None
|
||||
offline_mode = True
|
||||
|
||||
cover_art_result = None
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
album: API.Album,
|
||||
cover_art_size: int = 200,
|
||||
show_artist_name: bool = True,
|
||||
):
|
||||
Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL)
|
||||
self.album = album
|
||||
|
||||
self.show_artist_name = show_artist_name
|
||||
|
||||
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
|
||||
artist_artwork = SpinnerImage(
|
||||
self.artist_artwork = SpinnerImage(
|
||||
loading=False,
|
||||
image_name="artist-album-list-artwork",
|
||||
spinner_name="artist-artwork-spinner",
|
||||
image_size=cover_art_size,
|
||||
)
|
||||
# Account for 10px margin on all sides with "+ 20".
|
||||
# artist_artwork.set_size_request(cover_art_size + 20, cover_art_size + 20)
|
||||
box.pack_start(artist_artwork, False, False, 0)
|
||||
self.artist_artwork.set_size_request(cover_art_size + 20, cover_art_size + 20)
|
||||
box.pack_start(self.artist_artwork, False, False, 0)
|
||||
box.pack_start(Gtk.Box(), True, True, 0)
|
||||
self.pack_start(box, False, False, 0)
|
||||
|
||||
def cover_art_future_done(f: Result):
|
||||
artist_artwork.set_from_file(f.result())
|
||||
artist_artwork.set_loading(False)
|
||||
|
||||
cover_art_filename_future = AdapterManager.get_cover_art_uri(
|
||||
album.cover_art,
|
||||
"file",
|
||||
before_download=lambda: artist_artwork.set_loading(True),
|
||||
)
|
||||
cover_art_filename_future.add_done_callback(
|
||||
lambda f: GLib.idle_add(cover_art_future_done, f)
|
||||
)
|
||||
|
||||
album_details = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
|
||||
album_title_and_buttons = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
|
||||
|
||||
# TODO (#43): deal with super long-ass titles
|
||||
album_title_and_buttons.add(
|
||||
Gtk.Label(
|
||||
label=album.name,
|
||||
name="artist-album-list-album-name",
|
||||
halign=Gtk.Align.START,
|
||||
ellipsize=Pango.EllipsizeMode.END,
|
||||
)
|
||||
self.title = Gtk.Label(
|
||||
name="artist-album-list-album-name",
|
||||
halign=Gtk.Align.START,
|
||||
ellipsize=Pango.EllipsizeMode.END,
|
||||
)
|
||||
album_title_and_buttons.add(self.title)
|
||||
|
||||
self.play_btn = IconButton(
|
||||
"media-playback-start-symbolic",
|
||||
@@ -113,20 +101,11 @@ class AlbumWithSongs(Gtk.Box):
|
||||
|
||||
album_details.add(album_title_and_buttons)
|
||||
|
||||
stats: List[Any] = [
|
||||
album.artist.name if show_artist_name and album.artist else None,
|
||||
album.year,
|
||||
album.genre.name if album.genre else None,
|
||||
util.format_sequence_duration(album.duration) if album.duration else None,
|
||||
]
|
||||
|
||||
album_details.add(
|
||||
Gtk.Label(
|
||||
label=util.dot_join(*stats),
|
||||
halign=Gtk.Align.START,
|
||||
margin_left=10,
|
||||
)
|
||||
self.stats = Gtk.Label(
|
||||
halign=Gtk.Align.START,
|
||||
margin_left=10,
|
||||
)
|
||||
album_details.add(self.stats)
|
||||
|
||||
self.loading_indicator_container = Gtk.Box()
|
||||
album_details.add(self.loading_indicator_container)
|
||||
@@ -169,7 +148,7 @@ class AlbumWithSongs(Gtk.Box):
|
||||
|
||||
self.pack_end(album_details, True, True, 0)
|
||||
|
||||
self.update_album_songs(album.id)
|
||||
# self.update_album_songs(album.id)
|
||||
|
||||
# Event Handlers
|
||||
# =========================================================================
|
||||
@@ -257,7 +236,9 @@ class AlbumWithSongs(Gtk.Box):
|
||||
def deselect_all(self):
|
||||
self.album_songs.get_selection().unselect_all()
|
||||
|
||||
def update(self, app_config: AppConfiguration = None, force: bool = False):
|
||||
def update(self, album: API.Album, app_config: AppConfiguration, force: bool = False):
|
||||
update_songs = False
|
||||
|
||||
if app_config:
|
||||
# Deselect everything and reset the error container if switching between
|
||||
# online and offline.
|
||||
@@ -266,9 +247,43 @@ class AlbumWithSongs(Gtk.Box):
|
||||
for c in self.error_container.get_children():
|
||||
self.error_container.remove(c)
|
||||
|
||||
update_songs = True
|
||||
|
||||
self.offline_mode = app_config.offline_mode
|
||||
|
||||
self.update_album_songs(self.album.id, app_config=app_config, force=force)
|
||||
if album != self.album:
|
||||
self.album = album
|
||||
|
||||
self.title.set_label(album.name)
|
||||
|
||||
self.stats.set_label(util.dot_join(
|
||||
album.artist.name if self.show_artist_name and album.artist else None,
|
||||
album.year,
|
||||
album.genre.name if album.genre else None,
|
||||
util.format_sequence_duration(album.duration) if album.duration else None,
|
||||
))
|
||||
|
||||
if self.cover_art_result is not None:
|
||||
self.cover_art_result.cancel()
|
||||
|
||||
def cover_art_future_done(f: Result):
|
||||
self.artist_artwork.set_from_file(f.result())
|
||||
self.artist_artwork.set_loading(False)
|
||||
self.cover_art_result = None
|
||||
|
||||
self.cover_art_result = AdapterManager.get_cover_art_uri(
|
||||
album.cover_art,
|
||||
"file",
|
||||
before_download=lambda: self.artist_artwork.set_loading(True),
|
||||
)
|
||||
self.cover_art_result.add_done_callback(
|
||||
lambda f: GLib.idle_add(cover_art_future_done, f)
|
||||
)
|
||||
|
||||
update_songs = True
|
||||
|
||||
if update_songs:
|
||||
self.update_album_songs(self.album.id, app_config=app_config, force=force)
|
||||
|
||||
def set_loading(self, loading: bool):
|
||||
if loading:
|
||||
|
Reference in New Issue
Block a user