Compare commits

..

No commits in common. "bf8b02de127342f228dbea88418cebdfe4c06c13" and "6f3b3537ad501fa0fcf07d08deb630da58b951bc" have entirely different histories.

4 changed files with 22 additions and 93 deletions

View file

@ -121,7 +121,7 @@ template $AudreyUiPlaybar: Adw.Bin {
valign: center; valign: center;
sensitive: bind $can_press_play (template.playbin as <$AudreyPlaybin>.state as <$AudreyPlaybinState>, template.playbin as <$AudreyPlaybin>.play-queue-length) as <bool>; sensitive: bind $can_press_play (template.playbin as <$AudreyPlaybin>.state as <$AudreyPlaybinState>, template.playbin as <$AudreyPlaybin>.play-queue-length) as <bool>;
clicked => $on_play_pause_clicked (template); clicked => $on_play_pause_clicked ();
} }
Button { Button {

View file

@ -19,11 +19,6 @@ mod ffi {
extern "C" { extern "C" {
pub fn audrey_playbin_get_type() -> glib::ffi::GType; pub fn audrey_playbin_get_type() -> glib::ffi::GType;
pub fn audrey_playbin_get_state(self_: *mut AudreyPlaybin) -> super::state::ffi::State;
pub fn audrey_playbin_pause(self_: *mut AudreyPlaybin);
pub fn audrey_playbin_play(self_: *mut AudreyPlaybin);
pub fn audrey_playbin_get_volume(self_: *mut AudreyPlaybin) -> std::ffi::c_int;
pub fn audrey_playbin_set_volume(self_: *mut AudreyPlaybin, volume: std::ffi::c_int);
} }
} }
@ -36,35 +31,3 @@ glib::wrapper! {
type_ => || ffi::audrey_playbin_get_type(), type_ => || ffi::audrey_playbin_get_type(),
} }
} }
impl Playbin {
pub fn get_state(&self) -> State {
use glib::translate::ToGlibPtr;
unsafe { glib::translate::from_glib(ffi::audrey_playbin_get_state(self.to_glib_none().0)) }
}
pub fn pause(&self) {
use glib::translate::ToGlibPtr;
unsafe { ffi::audrey_playbin_pause(self.to_glib_none().0) }
}
pub fn play(&self) {
use glib::translate::ToGlibPtr;
unsafe { ffi::audrey_playbin_play(self.to_glib_none().0) }
}
pub fn get_volume(&self) -> i32 {
use glib::translate::ToGlibPtr;
unsafe { ffi::audrey_playbin_get_volume(self.to_glib_none().0) }
}
pub fn set_volume(&self, value: i32) {
use glib::translate::ToGlibPtr;
unsafe { ffi::audrey_playbin_set_volume(self.to_glib_none().0, value) }
}
}

View file

@ -1,15 +1,13 @@
pub mod ffi { mod ffi {
use gtk::glib; use gtk::glib;
pub type State = std::ffi::c_int;
extern "C" { extern "C" {
pub fn audrey_playbin_state_get_type() -> glib::ffi::GType; pub fn audrey_playbin_state_get_type() -> glib::ffi::GType;
} }
} }
use glib::prelude::*;
use gtk::glib; use gtk::glib;
use glib::prelude::*;
#[derive(Copy, Clone, PartialEq, Eq)] #[derive(Copy, Clone, PartialEq, Eq)]
pub enum State { pub enum State {
@ -18,9 +16,13 @@ pub enum State {
Playing, Playing,
} }
impl glib::translate::FromGlib<ffi::State> for State { unsafe impl<'a> glib::value::FromValue<'a> for State {
unsafe fn from_glib(value: ffi::State) -> Self { type Checker = glib::value::GenericValueTypeChecker<Self>;
match value {
unsafe fn from_value(value: &'a glib::Value) -> Self {
use glib::translate::ToGlibPtr;
match glib::gobject_ffi::g_value_get_enum(value.to_glib_none().0) {
0 => Self::Stopped, 0 => Self::Stopped,
1 => Self::Paused, 1 => Self::Paused,
2 => Self::Playing, 2 => Self::Playing,
@ -29,16 +31,6 @@ impl glib::translate::FromGlib<ffi::State> for State {
} }
} }
unsafe impl<'a> glib::value::FromValue<'a> for State {
type Checker = glib::value::GenericValueTypeChecker<Self>;
unsafe fn from_value(value: &'a glib::Value) -> Self {
use glib::translate::ToGlibPtr;
glib::translate::from_glib(glib::gobject_ffi::g_value_get_enum(value.to_glib_none().0))
}
}
impl StaticType for State { impl StaticType for State {
fn static_type() -> glib::Type { fn static_type() -> glib::Type {
unsafe { glib::translate::from_glib(ffi::audrey_playbin_state_get_type()) } unsafe { glib::translate::from_glib(ffi::audrey_playbin_state_get_type()) }

View file

@ -18,8 +18,8 @@ mod imp {
#[property(get, set, default = true)] #[property(get, set, default = true)]
show_cover_art: Cell<bool>, show_cover_art: Cell<bool>,
#[property(get = Self::get_volume, set = Self::set_volume)] #[property(get, set)]
volume: i32, volume: Cell<i32>,
} }
#[glib::object_subclass] #[glib::object_subclass]
@ -96,20 +96,11 @@ mod imp {
#[template_callback] #[template_callback]
fn mute_button_icon_name(&self, mute: bool) -> &'static str { fn mute_button_icon_name(&self, mute: bool) -> &'static str {
if mute { if mute { "audio-volume-muted" } else { "audio-volume-high" }
"audio-volume-muted"
} else {
"audio-volume-high"
}
} }
#[template_callback] #[template_callback]
fn on_play_position_seek( fn on_play_position_seek(&self, _range: &gtk::Range, _scroll_type: gtk::ScrollType, _value: f64) -> bool {
&self,
_range: &gtk::Range,
_scroll_type: gtk::ScrollType,
_value: f64,
) -> bool {
/* /*
if (range.adjustment.lower < range.adjustment.upper) { if (range.adjustment.lower < range.adjustment.upper) {
this.playbin.seek ((int64) value); this.playbin.seek ((int64) value);
@ -150,15 +141,13 @@ mod imp {
} }
#[template_callback] #[template_callback]
fn on_play_pause_clicked(&self, _button: &gtk::Button) { fn on_play_pause_clicked(&self) {
let playbin = self.playbin.borrow(); // if (this.playbin.state == PlaybinState.PLAYING) {
let playbin = playbin.as_ref().unwrap(); // this.playbin.pause();
// } else {
if playbin.get_state() == crate::playbin::State::Playing { // this.playbin.play();
playbin.pause(); // }
} else { todo!()
playbin.play();
}
} }
#[template_callback] #[template_callback]
@ -166,21 +155,6 @@ mod imp {
//this.playbin.mute = !this.playbin.mute; //this.playbin.mute = !this.playbin.mute;
todo!() todo!()
} }
fn get_volume(&self) -> i32 {
let playbin = self.playbin.borrow();
match playbin.as_ref() {
None => 100,
Some(playbin) => playbin.get_volume(),
}
}
fn set_volume(&self, value: i32) {
let playbin = self.playbin.borrow();
let playbin = playbin.as_ref().unwrap();
playbin.set_volume(value);
}
} }
} }