weaken that one playbin reference
This commit is contained in:
parent
8dc40ac3fb
commit
472770013e
1 changed files with 12 additions and 20 deletions
|
@ -2,7 +2,7 @@ mod imp {
|
|||
use adw::prelude::*;
|
||||
use adw::subclass::prelude::*;
|
||||
use glib::subclass::InitializingObject;
|
||||
use glib::{gformat, GString};
|
||||
use glib::{gformat, GString, WeakRef};
|
||||
use gtk::{gdk, glib};
|
||||
use std::cell::{Cell, RefCell};
|
||||
|
||||
|
@ -15,7 +15,7 @@ mod imp {
|
|||
#[property(get, set)]
|
||||
playing_cover_art: RefCell<Option<gdk::Paintable>>,
|
||||
#[property(get, set)]
|
||||
playbin: RefCell<Option<crate::Playbin>>, // TODO: weak
|
||||
playbin: WeakRef<crate::Playbin>,
|
||||
#[property(get, set, default = true)]
|
||||
show_cover_art: Cell<bool>,
|
||||
|
||||
|
@ -102,8 +102,7 @@ mod imp {
|
|||
value: f64,
|
||||
range: >k::Range,
|
||||
) -> bool {
|
||||
let playbin = self.playbin.borrow();
|
||||
let playbin = playbin.as_ref().unwrap();
|
||||
let playbin = self.playbin.upgrade().unwrap();
|
||||
if range.adjustment().lower() < range.adjustment().upper() {
|
||||
playbin.seek(value);
|
||||
}
|
||||
|
@ -112,22 +111,19 @@ mod imp {
|
|||
|
||||
#[template_callback]
|
||||
fn on_skip_forward_clicked(&self) {
|
||||
let playbin = self.playbin.borrow();
|
||||
let playbin = playbin.as_ref().unwrap();
|
||||
let playbin = self.playbin.upgrade().unwrap();
|
||||
playbin.go_to_next_track();
|
||||
}
|
||||
|
||||
#[template_callback]
|
||||
fn on_skip_backward_clicked(&self) {
|
||||
let playbin = self.playbin.borrow();
|
||||
let playbin = playbin.as_ref().unwrap();
|
||||
let playbin = self.playbin.upgrade().unwrap();
|
||||
playbin.go_to_prev_track();
|
||||
}
|
||||
|
||||
#[template_callback]
|
||||
fn seek_backward(&self) {
|
||||
let playbin = self.playbin.borrow();
|
||||
let playbin = playbin.as_ref().unwrap();
|
||||
let playbin = self.playbin.upgrade().unwrap();
|
||||
// 10 seconds
|
||||
let mut new_position = playbin.position() - 10.0;
|
||||
if new_position < 0.0 {
|
||||
|
@ -138,8 +134,7 @@ mod imp {
|
|||
|
||||
#[template_callback]
|
||||
fn seek_forward(&self) {
|
||||
let playbin = self.playbin.borrow();
|
||||
let playbin = playbin.as_ref().unwrap();
|
||||
let playbin = self.playbin.upgrade().unwrap();
|
||||
// 10 seconds
|
||||
let mut new_position = playbin.position() + 10.0;
|
||||
if new_position > playbin.duration() {
|
||||
|
@ -150,8 +145,7 @@ mod imp {
|
|||
|
||||
#[template_callback]
|
||||
fn on_play_pause_clicked(&self, _button: >k::Button) {
|
||||
let playbin = self.playbin.borrow();
|
||||
let playbin = playbin.as_ref().unwrap();
|
||||
let playbin = self.playbin.upgrade().unwrap();
|
||||
|
||||
if playbin.state() == crate::playbin::State::Playing {
|
||||
playbin.pause();
|
||||
|
@ -162,23 +156,21 @@ mod imp {
|
|||
|
||||
#[template_callback]
|
||||
fn on_mute_toggle(&self) {
|
||||
let playbin = self.playbin.borrow();
|
||||
let playbin = playbin.as_ref().unwrap();
|
||||
let playbin = self.playbin.upgrade().unwrap();
|
||||
playbin.set_mute(!playbin.mute());
|
||||
}
|
||||
|
||||
fn volume(&self) -> i32 {
|
||||
let playbin = self.playbin.borrow();
|
||||
let playbin = self.playbin.upgrade();
|
||||
|
||||
match playbin.as_ref() {
|
||||
match playbin {
|
||||
None => 100,
|
||||
Some(playbin) => playbin.volume(),
|
||||
}
|
||||
}
|
||||
|
||||
fn set_volume(&self, value: i32) {
|
||||
let playbin = self.playbin.borrow();
|
||||
let playbin = playbin.as_ref().unwrap();
|
||||
let playbin = self.playbin.upgrade().unwrap();
|
||||
playbin.set_volume(value);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue