This commit is contained in:
Erica Z 2024-10-31 11:44:46 +01:00
parent 96067675d4
commit 118b2d6f7e
2 changed files with 8 additions and 9 deletions

View file

@ -1,3 +1,4 @@
/*
[GtkTemplate (ui = "/eu/callcc/audrey/play_queue.ui")] [GtkTemplate (ui = "/eu/callcc/audrey/play_queue.ui")]
public class Audrey.Ui.PlayQueue : Adw.Bin { public class Audrey.Ui.PlayQueue : Adw.Bin {
private weak Playbin _playbin; private weak Playbin _playbin;

View file

@ -1,13 +1,13 @@
mod imp { mod imp {
use glib::{subclass::InitializingObject, WeakRef}; use glib::{subclass::InitializingObject, WeakRef};
use gtk::{gdk, gio, glib, prelude::*, subclass::prelude::*}; use gtk::{gdk, gio, glib, prelude::*, subclass::prelude::*};
use std::cell::{Cell, RefCell}; use std::cell::{RefCell, Cell};
#[derive(gtk::CompositeTemplate, glib::Properties, Default)] #[derive(gtk::CompositeTemplate, glib::Properties, Default)]
#[template(resource = "/eu/callcc/audrey/play_queue_song.ui")] #[template(resource = "/eu/callcc/audrey/play_queue_song.ui")]
#[properties(wrapper_type = super::Song)] #[properties(wrapper_type = super::Song)]
pub struct Song { pub struct Song {
pub(super) playbin: RefCell<Option<WeakRef<crate::Playbin>>>, pub(super) playbin: WeakRef<crate::Playbin>,
#[property(set, get)] #[property(set, get)]
draggable: Cell<bool>, draggable: Cell<bool>,
@ -121,7 +121,7 @@ mod imp {
fn on_drag_begin(&self, drag: &gdk::Drag) { fn on_drag_begin(&self, drag: &gdk::Drag) {
let drag_widget = gtk::ListBox::new(); 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_draggable(false);
drag_row.set_show_position(self.obj().show_position()); drag_row.set_show_position(self.obj().show_position());
drag_row.set_show_artist(self.obj().show_artist()); drag_row.set_show_artist(self.obj().show_artist());
@ -175,16 +175,14 @@ glib::wrapper! {
} }
impl Song { impl Song {
pub fn new(playbin: crate::Playbin) -> Self { pub fn new(playbin: &crate::Playbin) -> Self {
let song: Self = Object::new(); let song: Self = Object::new();
song.imp().playbin.replace(Some(playbin.downgrade())); song.imp().playbin.set(Some(playbin));
song song
} }
fn playbin(&self) -> crate::Playbin { fn playbin(&self) -> crate::Playbin {
let playbin = self.imp().playbin.borrow(); self.imp().playbin.upgrade().unwrap()
let playbin = playbin.as_ref().unwrap(); // weak
playbin.upgrade().unwrap().clone() // strong
} }
pub fn bind(&self, position: u32, song: &crate::playbin::Song) { 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( extern "C" fn audrey_ui_play_queue_song_new(
playbin: *mut crate::playbin::ffi::AudreyPlaybin, playbin: *mut crate::playbin::ffi::AudreyPlaybin,
) -> *mut AudreyUiPlayQueueSong { ) -> *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] #[no_mangle]