From b24dc30afd3ed5fbceca10f72a1351c1ffe25e7c Mon Sep 17 00:00:00 2001 From: "Jakob L. Kreuze" Date: Sun, 7 Aug 2022 09:57:03 -0400 Subject: Initial queueing from query UI --- src/main.rs | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 9c92cf7..cc1959b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -142,8 +142,9 @@ impl QueryInfo { let container = gtk::Box::new(gtk::Orientation::Vertical, 2); let query_input = gtk::Entry::builder().visible(true).build(); + let sender1 = sender.clone(); query_input.connect_key_press_event(move |widget, _| { - let mut sender = sender.clone(); // Interesting ownership puzzle :D + let mut sender = sender1.clone(); // Interesting ownership puzzle :D sender .try_send(StateUpdateKind::QueryUpdateEvent(widget.text().into())) .expect("Couldn't notify thread"); @@ -153,6 +154,8 @@ impl QueryInfo { let model = gio::ListStore::new(SongObject::static_type()); let listbox = gtk::ListBox::new(); listbox.bind_model(Some(&model), move |item| { + let sender = sender.clone(); + let box_ = gtk::ListBoxRow::new(); let item = item .downcast_ref::() @@ -160,6 +163,19 @@ impl QueryInfo { let hbox = gtk::Box::new(gtk::Orientation::Horizontal, 32); + let add_individual_song = + gtk::Button::from_icon_name(Some("list-add-symbolic"), gtk::IconSize::SmallToolbar); + add_individual_song.set_visible(true); + let filename = item.property::("filename"); + add_individual_song.connect_clicked(move |_| { + let filename = filename.clone(); + let mut sender = sender.clone(); + sender + .try_send(StateUpdateKind::QueueAddRequest(filename)) + .expect("Couldn't notify thread"); + }); + hbox.pack_start(&add_individual_song, false, false, 0); + let title_label = gtk::Label::new(None); item.bind_property("title", &title_label, "label") .flags(glib::BindingFlags::DEFAULT | glib::BindingFlags::SYNC_CREATE) @@ -216,6 +232,7 @@ glib::wrapper! { impl SongObject { pub fn new(song: &mpd::song::Song) -> Self { glib::Object::new(&[ + ("filename", &song.file.clone()), ( "title", &song @@ -257,6 +274,7 @@ mod imp { // Object holding the state #[derive(Default)] pub struct SongObject { + filename: RefCell, title: RefCell, artist: RefCell, album: RefCell, @@ -274,6 +292,7 @@ mod imp { fn properties() -> &'static [ParamSpec] { static PROPERTIES: Lazy> = Lazy::new(|| { vec![ + ParamSpecString::builder("filename").build(), ParamSpecString::builder("title").build(), ParamSpecString::builder("artist").build(), ParamSpecString::builder("album").build(), @@ -284,6 +303,12 @@ mod imp { fn set_property(&self, _obj: &Self::Type, _id: usize, value: &Value, pspec: &ParamSpec) { match pspec.name() { + "filename" => { + let input = value + .get() + .expect("The value needs to be of type `String`."); + self.filename.replace(input); + } "title" => { let input = value .get() @@ -308,6 +333,7 @@ mod imp { fn property(&self, _obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> Value { match pspec.name() { + "filename" => self.filename.borrow().to_value(), "title" => self.title.borrow().to_value(), "artist" => self.artist.borrow().to_value(), "album" => self.album.borrow().to_value(), @@ -321,6 +347,7 @@ mod imp { enum StateUpdateKind { MpdEvent, QueryUpdateEvent(String), + QueueAddRequest(String), } fn main() { @@ -441,6 +468,9 @@ fn main() { query_info.model.insert(0, &SongObject::new(&song)); } } + StateUpdateKind::QueueAddRequest(filename) => { + conn.push_str(filename).expect("Couldn't queue song"); + } } } }); -- cgit v1.3