From 118b2d6f7e5c17f143dc3595ffedad30785d5c45 Mon Sep 17 00:00:00 2001 From: Erica Z Date: Thu, 31 Oct 2024 11:44:46 +0100 Subject: [PATCH] smal fix --- src/ui/play_queue.vala | 1 + src/ui/play_queue/song.rs | 16 +++++++--------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/ui/play_queue.vala b/src/ui/play_queue.vala index 15638e1..5f1ec92 100644 --- a/src/ui/play_queue.vala +++ b/src/ui/play_queue.vala @@ -1,3 +1,4 @@ +/* [GtkTemplate (ui = "/eu/callcc/audrey/play_queue.ui")] public class Audrey.Ui.PlayQueue : Adw.Bin { private weak Playbin _playbin; diff --git a/src/ui/play_queue/song.rs b/src/ui/play_queue/song.rs index c7146bf..c5d1a0b 100644 --- a/src/ui/play_queue/song.rs +++ b/src/ui/play_queue/song.rs @@ -1,13 +1,13 @@ mod imp { use glib::{subclass::InitializingObject, WeakRef}; use gtk::{gdk, gio, glib, prelude::*, subclass::prelude::*}; - use std::cell::{Cell, RefCell}; + use std::cell::{RefCell, Cell}; #[derive(gtk::CompositeTemplate, glib::Properties, Default)] #[template(resource = "/eu/callcc/audrey/play_queue_song.ui")] #[properties(wrapper_type = super::Song)] pub struct Song { - pub(super) playbin: RefCell>>, + pub(super) playbin: WeakRef, #[property(set, get)] draggable: Cell, @@ -121,7 +121,7 @@ mod imp { fn on_drag_begin(&self, drag: &gdk::Drag) { let drag_widget = gtk::ListBox::new(); - let drag_row = super::Song::new(self.obj().playbin()); + let drag_row = super::Song::new(&self.obj().playbin()); drag_row.set_draggable(false); drag_row.set_show_position(self.obj().show_position()); drag_row.set_show_artist(self.obj().show_artist()); @@ -175,16 +175,14 @@ glib::wrapper! { } impl Song { - pub fn new(playbin: crate::Playbin) -> Self { + pub fn new(playbin: &crate::Playbin) -> Self { let song: Self = Object::new(); - song.imp().playbin.replace(Some(playbin.downgrade())); + song.imp().playbin.set(Some(playbin)); song } fn playbin(&self) -> crate::Playbin { - let playbin = self.imp().playbin.borrow(); - let playbin = playbin.as_ref().unwrap(); // weak - playbin.upgrade().unwrap().clone() // strong + self.imp().playbin.upgrade().unwrap() } pub fn bind(&self, position: u32, song: &crate::playbin::Song) { @@ -230,7 +228,7 @@ pub mod ffi { extern "C" fn audrey_ui_play_queue_song_new( playbin: *mut crate::playbin::ffi::AudreyPlaybin, ) -> *mut AudreyUiPlayQueueSong { - unsafe { super::Song::new(from_glib_none(playbin)).into_glib_ptr() } + unsafe { super::Song::new(&from_glib_none(playbin)).into_glib_ptr() } } #[no_mangle]