pub mod song; pub use song::Song; mod imp { use adw::{glib, prelude::*, subclass::prelude::*}; use glib::{subclass::InitializingObject, WeakRef}; #[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, } #[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) { obj.init_template(); } } #[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: >k::ListItem, _factory: >k::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: >k::ListItem, _factory: >k::SignalListItemFactory) { let child = item.child().and_downcast::().unwrap(); child.bind( item.position(), item.item().unwrap().downcast_ref::().unwrap(), ); } #[template_callback] fn on_song_list_unbind(&self, item: >k::ListItem, _factory: >k::SignalListItemFactory) { let child = item.child().and_downcast::().unwrap(); child.unbind(); } #[template_callback] fn on_row_activated(&self, position: u32) { self.obj().playbin().unwrap().select_track(position); } } } use gtk::glib; glib::wrapper! { pub struct PlayQueue(ObjectSubclass) @extends adw::Bin, gtk::Widget, @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget; }