diff --git a/src/ui/window.vala b/src/ui/window.vala index 87c75cf..d8cdc67 100644 --- a/src/ui/window.vala +++ b/src/ui/window.vala @@ -22,10 +22,10 @@ class Ui.Window : Adw.ApplicationWindow { } public Subsonic.Song? song { get; private set; } + public Gdk.Paintable? playing_cover_art { get; set; default = null; } private Cancellable cancel_loading_art; public bool cover_art_loading { get; set; default = false; } - public Gdk.Paintable playing_cover_art { get; set; } public Playbin playbin { get; private set; default = new Playbin (); } @@ -53,61 +53,60 @@ class Ui.Window : Adw.ApplicationWindow { this.setup.connected.connect ((api) => { this.api = api; this.playbin.api = api; - - this.playbin.now_playing.connect ((playbin, now, next) => { - this.song = now; - api.scrobble.begin (this.song.id); - - if (this.cancel_loading_art != null) { - this.cancel_loading_art.cancel (); - } - this.cancel_loading_art = new GLib.Cancellable (); - - this.playing_cover_art = Gdk.Paintable.empty (1, 1); - if (this.song != null) { - this.cover_art_loading = true; - - string song_id = this.song.id; - this.api.cover_art.begin (song_id, this.cancel_loading_art, (obj, res) => { - try { - this.playing_cover_art = Gdk.Texture.for_pixbuf (this.api.cover_art.end (res)); - this.cover_art_loading = false; - } catch (Error e) { - if (!(e is IOError.CANCELLED)) { - warning ("could not load cover for %s: %s", song_id, e.message); - this.cover_art_loading = false; - } - } - }); - } - }); - - this.playbin.stopped.connect (() => { - this.playing_cover_art = Gdk.Paintable.empty (1, 1); - this.song = null; - }); - - this.shuffle_all_tracks.sensitive = true; - this.shuffle_all_tracks.activated.connect (() => { - this.shuffle_all_tracks.sensitive = false; - this.playbin.play_queue.remove_all (); - api.get_random_songs.begin (null, (song) => { - this.playbin.play_queue.append (song); - }, (obj, res) => { - try { - api.get_random_songs.end (res); - } catch (Error e) { - error ("could not get random songs: %s", e.message); - } - this.shuffle_all_tracks.sensitive = true; - - this.playbin.select_track (0); - }); - }); }); this.setup.load (); this.sidebar.select_row (this.sidebar.get_row_at_index (0)); + + this.playbin.now_playing.connect ((playbin, now, next) => { + this.song = now; + api.scrobble.begin (this.song.id); + + if (this.cancel_loading_art != null) { + this.cancel_loading_art.cancel (); + } + this.cancel_loading_art = new GLib.Cancellable (); + + if (this.song != null) { + this.cover_art_loading = true; + + string song_id = this.song.id; + this.api.cover_art.begin (song_id, this.cancel_loading_art, (obj, res) => { + try { + this.playing_cover_art = Gdk.Texture.for_pixbuf (this.api.cover_art.end (res)); + this.cover_art_loading = false; + } catch (Error e) { + if (!(e is IOError.CANCELLED)) { + warning ("could not load cover for %s: %s", song_id, e.message); + this.cover_art_loading = false; + } + } + }); + } + }); + + this.playbin.stopped.connect (() => { + this.playing_cover_art = Gdk.Paintable.empty (1, 1); + this.song = null; + }); + + this.shuffle_all_tracks.sensitive = true; + this.shuffle_all_tracks.activated.connect (() => { + this.shuffle_all_tracks.sensitive = false; + this.playbin.play_queue.remove_all (); + api.get_random_songs.begin (null, (song) => { + this.playbin.play_queue.append (song); + }, (obj, res) => { + try { + api.get_random_songs.end (res); + } catch (Error e) { + error ("could not get random songs: %s", e.message); + } + this.shuffle_all_tracks.sensitive = true; + + this.playbin.select_track (0); + }); + }); } [GtkCallback] private void on_sidebar_row_activated (Gtk.ListBoxRow row) {