2024-10-13 09:41:01 +00:00
|
|
|
[GtkTemplate (ui = "/eu/callcc/audrey/ui/window.ui")]
|
|
|
|
class Ui.Window : Adw.ApplicationWindow {
|
2024-10-10 09:53:52 +00:00
|
|
|
[GtkChild] private unowned Gtk.ListBox sidebar;
|
|
|
|
[GtkChild] private unowned Gtk.ListBoxRow sidebar_play_queue;
|
|
|
|
[GtkChild] private unowned Gtk.Stack stack;
|
|
|
|
|
2024-10-13 09:41:01 +00:00
|
|
|
[GtkChild] public unowned Ui.PlayQueue play_queue;
|
2024-10-19 15:04:56 +00:00
|
|
|
[GtkChild] public unowned Ui.Playbar playbar;
|
2024-10-10 10:51:12 +00:00
|
|
|
[GtkChild] public unowned Adw.ButtonRow shuffle_all_tracks;
|
2024-10-06 11:21:53 +00:00
|
|
|
|
2024-10-12 20:52:29 +00:00
|
|
|
private Setup setup;
|
2024-10-16 11:02:32 +00:00
|
|
|
|
|
|
|
private Subsonic.Client api;
|
2024-10-11 06:57:01 +00:00
|
|
|
|
2024-10-17 10:05:20 +00:00
|
|
|
public int volume {
|
2024-10-12 16:35:42 +00:00
|
|
|
get { return this.playbin.volume; }
|
|
|
|
set { this.playbin.volume = value; }
|
|
|
|
}
|
|
|
|
public bool mute {
|
|
|
|
get { return this.playbin.mute; }
|
|
|
|
set { this.playbin.mute = value; }
|
|
|
|
}
|
2024-10-11 06:57:01 +00:00
|
|
|
|
2024-10-18 20:55:38 +00:00
|
|
|
public Subsonic.Song? song { get; private set; }
|
2024-10-20 10:02:06 +00:00
|
|
|
public Gdk.Paintable? playing_cover_art { get; set; default = null; }
|
2024-10-18 20:55:38 +00:00
|
|
|
|
2024-10-11 09:09:47 +00:00
|
|
|
private Cancellable cancel_loading_art;
|
|
|
|
public bool cover_art_loading { get; set; default = false; }
|
|
|
|
|
2024-10-15 20:33:39 +00:00
|
|
|
public Playbin playbin { get; private set; default = new Playbin (); }
|
2024-10-12 12:28:05 +00:00
|
|
|
|
2024-10-06 11:21:53 +00:00
|
|
|
public Window (Gtk.Application app) {
|
|
|
|
Object (application: app);
|
|
|
|
}
|
2024-10-10 09:53:52 +00:00
|
|
|
|
2024-10-20 11:17:40 +00:00
|
|
|
private void now_playing (Subsonic.Song song) {
|
|
|
|
this.song = song;
|
|
|
|
// api.scrobble.begin (this.song.id); TODO
|
|
|
|
|
|
|
|
if (this.cancel_loading_art != null) {
|
|
|
|
this.cancel_loading_art.cancel ();
|
|
|
|
}
|
|
|
|
this.cancel_loading_art = new GLib.Cancellable ();
|
|
|
|
|
|
|
|
this.playing_cover_art = null; // TODO: preload next art somehow
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-10-10 09:53:52 +00:00
|
|
|
construct {
|
2024-10-18 00:48:42 +00:00
|
|
|
// TODO: mpris
|
|
|
|
// Bus.own_name (
|
|
|
|
// BusType.SESSION,
|
|
|
|
// "org.mpris.MediaPlayer2.audrey",
|
|
|
|
// BusNameOwnerFlags.NONE,
|
|
|
|
// (conn) => {
|
|
|
|
// try {
|
|
|
|
// } catch (IOError e) {
|
|
|
|
// error ("could not register dbus service: %s", e.message);
|
|
|
|
// }
|
|
|
|
// },
|
|
|
|
// () => {},
|
|
|
|
// () => { error ("could not acquire dbus name"); });
|
2024-10-12 16:35:42 +00:00
|
|
|
|
2024-10-15 20:29:14 +00:00
|
|
|
this.setup = new Setup ();
|
2024-10-15 11:27:47 +00:00
|
|
|
|
2024-10-12 12:28:05 +00:00
|
|
|
this.setup.connected.connect ((api) => {
|
2024-10-16 11:02:32 +00:00
|
|
|
this.api = api;
|
2024-10-15 11:27:47 +00:00
|
|
|
this.playbin.api = api;
|
2024-10-20 10:02:06 +00:00
|
|
|
});
|
|
|
|
this.setup.load ();
|
2024-10-15 11:27:47 +00:00
|
|
|
|
2024-10-20 10:02:06 +00:00
|
|
|
this.sidebar.select_row (this.sidebar.get_row_at_index (0));
|
2024-10-17 20:36:29 +00:00
|
|
|
|
2024-10-20 11:17:40 +00:00
|
|
|
this.playbin.new_track.connect (() => {
|
|
|
|
this.now_playing (this.playbin.play_queue.get_item (this.playbin.play_queue_position) as Subsonic.Song);
|
2024-10-12 12:28:05 +00:00
|
|
|
});
|
|
|
|
|
2024-10-20 10:02:06 +00:00
|
|
|
this.playbin.stopped.connect (() => {
|
2024-10-20 10:05:48 +00:00
|
|
|
this.playing_cover_art = null;
|
2024-10-20 10:02:06 +00:00
|
|
|
this.song = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
this.shuffle_all_tracks.sensitive = true;
|
|
|
|
this.shuffle_all_tracks.activated.connect (() => {
|
|
|
|
this.shuffle_all_tracks.sensitive = false;
|
2024-10-20 11:17:40 +00:00
|
|
|
this.playbin.clear ();
|
2024-10-20 10:02:06 +00:00
|
|
|
api.get_random_songs.begin (null, (song) => {
|
2024-10-20 11:17:40 +00:00
|
|
|
this.playbin.append_track (song);
|
2024-10-20 10:02:06 +00:00
|
|
|
}, (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);
|
|
|
|
});
|
|
|
|
});
|
2024-10-10 09:53:52 +00:00
|
|
|
}
|
2024-10-11 06:57:01 +00:00
|
|
|
|
2024-10-11 08:22:05 +00:00
|
|
|
[GtkCallback] private void on_sidebar_row_activated (Gtk.ListBoxRow row) {
|
2024-10-12 19:06:15 +00:00
|
|
|
if (row == this.sidebar_play_queue) {
|
2024-10-11 08:22:05 +00:00
|
|
|
this.stack.set_visible_child_name("play_queue");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-12 19:06:15 +00:00
|
|
|
[GtkCallback] private void show_setup_dialog () {
|
|
|
|
this.setup.present (this);
|
|
|
|
}
|
2024-10-06 11:21:53 +00:00
|
|
|
}
|