audrey/src/ui/play_queue.rs

96 lines
2.7 KiB
Rust
Raw Normal View History

2024-10-31 10:24:58 +00:00
pub mod song;
2024-10-29 14:46:33 +00:00
pub use song::Song;
2024-10-31 10:24:58 +00:00
2024-10-31 11:02:00 +00:00
mod imp {
use adw::{glib, prelude::*, subclass::prelude::*};
use glib::{subclass::InitializingObject, WeakRef};
2024-10-31 10:24:58 +00:00
2024-10-31 11:02:00 +00:00
#[derive(gtk::CompositeTemplate, glib::Properties, Default)]
#[template(resource = "/eu/callcc/audrey/play_queue.ui")]
#[properties(wrapper_type = super::PlayQueue)]
pub struct PlayQueue {
#[property(get, set)]
playbin: WeakRef<crate::Playbin>,
2024-10-31 10:24:58 +00:00
}
2024-10-31 11:02:00 +00:00
#[glib::object_subclass]
impl ObjectSubclass for PlayQueue {
const NAME: &'static str = "AudreyUiPlayQueue";
type Type = super::PlayQueue;
type ParentType = adw::Bin;
fn class_init(klass: &mut Self::Class) {
klass.bind_template();
klass.bind_template_callbacks();
}
fn instance_init(obj: &InitializingObject<Self>) {
obj.init_template();
}
2024-10-31 10:24:58 +00:00
}
2024-10-31 11:02:00 +00:00
#[glib::derived_properties]
impl ObjectImpl for PlayQueue {}
impl WidgetImpl for PlayQueue {}
impl BinImpl for PlayQueue {}
#[gtk::template_callbacks]
impl PlayQueue {
#[template_callback]
fn visible_child_name(&self, n_items: u32) -> &'static str {
if n_items > 0 {
"not-empty"
} else {
"empty"
}
}
#[template_callback]
fn on_song_list_setup(&self, item: &gtk::ListItem, _factory: &gtk::SignalListItemFactory) {
let child = super::Song::new(&self.playbin.upgrade().unwrap());
child.set_draggable(true);
child.set_show_position(true);
child.set_show_artist(true);
child.set_show_cover(true);
item.set_child(Some(&child));
}
#[template_callback]
fn on_song_list_bind(&self, item: &gtk::ListItem, _factory: &gtk::SignalListItemFactory) {
let child = item.child().and_downcast::<super::Song>().unwrap();
child.bind(
item.position(),
2024-10-31 12:16:42 +00:00
item.item()
.unwrap()
.downcast_ref::<crate::playbin::Song>()
.unwrap(),
2024-10-31 11:02:00 +00:00
);
}
#[template_callback]
fn on_song_list_unbind(&self, item: &gtk::ListItem, _factory: &gtk::SignalListItemFactory) {
let child = item.child().and_downcast::<super::Song>().unwrap();
child.unbind();
}
#[template_callback]
fn on_row_activated(&self, position: u32) {
self.obj().playbin().unwrap().select_track(position);
}
2024-10-31 10:24:58 +00:00
}
}
use gtk::glib;
glib::wrapper! {
2024-10-31 11:02:00 +00:00
pub struct PlayQueue(ObjectSubclass<imp::PlayQueue>)
2024-10-31 10:24:58 +00:00
@extends adw::Bin, gtk::Widget,
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
}