From 9f2a2d2039a14326b97ece45b46b8623053226de Mon Sep 17 00:00:00 2001 From: me Date: Fri, 11 Oct 2024 07:53:30 +0000 Subject: [PATCH] more changes --- src/api.vala | 5 ++++ src/application.vala | 70 ++++++++++++++++++++++---------------------- src/play_queue.vala | 11 +++---- src/window.blp | 28 ++++++++++++++++-- src/window.vala | 2 ++ 5 files changed, 73 insertions(+), 43 deletions(-) diff --git a/src/api.vala b/src/api.vala index b0cddce..493c112 100644 --- a/src/api.vala +++ b/src/api.vala @@ -85,6 +85,7 @@ public class Wavelet.Song : Object { public string album { get; private set; } public string artist { get; private set; } public int64 track { get; private set; } + public int64 year { get; private set; } public Song (Json.Reader reader) { reader.read_member ("id"); @@ -106,6 +107,10 @@ public class Wavelet.Song : Object { reader.read_member ("track"); this.track = reader.get_int_value (); reader.end_member (); + + reader.read_member ("year"); + this.year = reader.get_int_value (); + reader.end_member (); } } diff --git a/src/application.vala b/src/application.vala index 84e6340..e2b0914 100644 --- a/src/application.vala +++ b/src/application.vala @@ -63,38 +63,6 @@ public class Wavelet.Application : Adw.Application { win.artist_list.set_loading (); win.song_list.set_loading (); - win.setup.connected.connect ((api) => { - win.artist_list.model = api.artist_list; - win.song_list.model = api.song_list; - - api.done_reloading.connect (() => { - win.artist_list.set_ready (); - win.song_list.set_ready (); - }); - //api.reload.begin (); - - win.shuffle_all_tracks.sensitive = true; - win.shuffle_all_tracks.activated.connect (() => { - win.shuffle_all_tracks.sensitive = false; - win.play_queue.clear (); - api.get_random_songs.begin (null, (song) => { - win.play_queue.queue (song); - }, (obj, res) => { - api.get_random_songs.end (res); - win.shuffle_all_tracks.sensitive = true; - }); - }); - - win.play_queue.play_now.connect ((song) => { - win.play_position.sensitive = false; - - playbin.set_state (Gst.State.READY); - playbin.set ("uri", api.stream_uri (song.id)); - playbin.set_state (Gst.State.PLAYING); - }); - }); - win.setup.load (config_db); - playbin = Gst.ElementFactory.make ("playbin3", null); assert (playbin != null); @@ -143,9 +111,41 @@ public class Wavelet.Application : Adw.Application { return true; }); - Signal.connect (playbin, "about-to-finish", () => { - print("about to finish\n"); - }, null); + var next_queue = new AsyncQueue (); + + win.setup.connected.connect ((api) => { + win.artist_list.model = api.artist_list; + win.song_list.model = api.song_list; + + api.done_reloading.connect (() => { + win.artist_list.set_ready (); + win.song_list.set_ready (); + }); + //api.reload.begin (); + + win.shuffle_all_tracks.sensitive = true; + win.shuffle_all_tracks.activated.connect (() => { + win.shuffle_all_tracks.sensitive = false; + win.play_queue.clear (); + api.get_random_songs.begin (null, (song) => { + win.play_queue.queue (song); + }, (obj, res) => { + api.get_random_songs.end (res); + win.shuffle_all_tracks.sensitive = true; + }); + }); + + win.play_queue.play_now.connect ((song) => { + win.play_position.sensitive = false; + + playbin.set_state (Gst.State.READY); + playbin.set ("uri", api.stream_uri (song.id)); + playbin.set_state (Gst.State.PLAYING); + + win.song = song; + }); + }); + win.setup.load (config_db); } private void on_about_action () { diff --git a/src/play_queue.vala b/src/play_queue.vala index b15b0be..03de8c9 100644 --- a/src/play_queue.vala +++ b/src/play_queue.vala @@ -48,12 +48,13 @@ public class Wavelet.PlayQueue : Adw.NavigationPage { this.songs.append (song); } - public Song? next () { - if (this.current >= this.songs.get_n_items ()) { - return null; - } else { + public void next () { + if (this.current < this.songs.get_n_items ()) { this.current += 1; - return (Song) this.songs.get_item (this.current); } } + + public Song? peek () { + return (Song?) this.songs.get_item (this.current+1); + } } diff --git a/src/window.blp b/src/window.blp index c6d2e25..ec978da 100644 --- a/src/window.blp +++ b/src/window.blp @@ -113,13 +113,33 @@ template $WaveletWindow: Adw.ApplicationWindow { valign: center; Label { + styles [ "caption-heading" ] halign: start; - label: "Title"; + label: bind template.song as <$WaveletSong>.title; } - Label { + Box { halign: start; - label: "Artist - Album - Year"; + Label { + styles [ "caption" ] + label: bind template.song as <$WaveletSong>.artist; + } + Label { + styles [ "caption" ] + label: " - "; + } + Label { + styles [ "caption" ] + label: bind template.song as <$WaveletSong>.album; + } + Label { + styles [ "caption" ] + label: " - "; + } + Label { + styles [ "caption" ] + label: bind template.song as <$WaveletSong>.year; + } } Box { @@ -128,6 +148,7 @@ template $WaveletWindow: Adw.ApplicationWindow { Label play_position_label { styles [ + "caption", "numeric", ] @@ -148,6 +169,7 @@ template $WaveletWindow: Adw.ApplicationWindow { Label play_duration { styles [ + "caption", "numeric", ] diff --git a/src/window.vala b/src/window.vala index ed79e1a..6b92b7a 100644 --- a/src/window.vala +++ b/src/window.vala @@ -41,6 +41,8 @@ public class Wavelet.Window : Adw.ApplicationWindow { public double volume { get; set; default = 1.0; } + public Song? song { get; set; default = null; } + public Window (Gtk.Application app) { Object (application: app); }