diff --git a/src/main.rs b/src/main.rs index d0df490..bb49235 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,11 +11,10 @@ pub mod ui; pub mod mpris; pub use mpris::Mpris; -pub mod playbin_vala; -pub use playbin_vala::Song as PlaybinSong; +pub mod playbin_song; +pub use playbin_song::Song as PlaybinSong; pub mod subsonic; -pub mod subsonic_vala; pub mod playbin2; pub type Playbin = playbin2::Playbin; diff --git a/src/playbin_vala/song.rs b/src/playbin_song.rs similarity index 100% rename from src/playbin_vala/song.rs rename to src/playbin_song.rs diff --git a/src/playbin_vala.rs b/src/playbin_vala.rs deleted file mode 100644 index 1d76a24..0000000 --- a/src/playbin_vala.rs +++ /dev/null @@ -1,190 +0,0 @@ -pub mod song; -pub use song::Song; - -mod state; -pub use state::State; - -pub mod ffi { - use gtk::{gio, glib}; - - #[repr(C)] - pub struct AudreyPlaybin { - parent_instance: glib::gobject_ffi::GObject, - } - - #[repr(C)] - pub struct AudreyPlaybinClass { - parent_class: glib::gobject_ffi::GObjectClass, - } - - extern "C" { - pub fn audrey_playbin_get_type() -> glib::ffi::GType; - pub fn audrey_playbin_new() -> *mut AudreyPlaybin; - 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_stop(self_: *mut AudreyPlaybin); - pub fn audrey_playbin_clear(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); - pub fn audrey_playbin_set_api( - self_: *mut AudreyPlaybin, - api: *mut crate::subsonic_vala::client::ffi::AudreySubsonicClient, - ); - pub fn audrey_playbin_seek(self_: *mut AudreyPlaybin, position: f64); - pub fn audrey_playbin_go_to_next_track(self_: *mut AudreyPlaybin); - pub fn audrey_playbin_go_to_prev_track(self_: *mut AudreyPlaybin); - pub fn audrey_playbin_get_position(self_: *mut AudreyPlaybin) -> f64; - pub fn audrey_playbin_get_duration(self_: *mut AudreyPlaybin) -> f64; - pub fn audrey_playbin_get_mute(self_: *mut AudreyPlaybin) -> glib::ffi::gboolean; - pub fn audrey_playbin_set_mute(self_: *mut AudreyPlaybin, mute: glib::ffi::gboolean); - pub fn audrey_playbin_get_play_queue_position( - self_: *mut AudreyPlaybin, - ) -> std::ffi::c_uint; - pub fn audrey_playbin_get_play_queue_length(self_: *mut AudreyPlaybin) -> std::ffi::c_uint; - pub fn audrey_playbin_move_track( - self_: *mut AudreyPlaybin, - from: std::ffi::c_uint, - to: std::ffi::c_uint, - ); - pub fn audrey_playbin_remove_track(self_: *mut AudreyPlaybin, position: std::ffi::c_uint); - pub fn audrey_playbin_select_track(self_: *mut AudreyPlaybin, position: std::ffi::c_uint); - pub fn audrey_playbin_get_play_queue( - self_: *mut AudreyPlaybin, - ) -> *mut gio::ffi::GListModel; - } -} - -use adw::prelude::*; -use glib::translate::{from_glib, from_glib_none, IntoGlib, ToGlibPtr}; -use gtk::{gio, glib}; - -glib::wrapper! { - pub struct Playbin(Object); - - match fn { - type_ => || ffi::audrey_playbin_get_type(), - } -} - -impl Default for Playbin { - fn default() -> Self { - unsafe { from_glib_none(ffi::audrey_playbin_new()) } - } -} - -impl Playbin { - pub fn state(&self) -> State { - unsafe { glib::translate::from_glib(ffi::audrey_playbin_get_state(self.to_glib_none().0)) } - } - - pub fn pause(&self) { - unsafe { ffi::audrey_playbin_pause(self.to_glib_none().0) } - } - - pub fn play(&self) { - unsafe { ffi::audrey_playbin_play(self.to_glib_none().0) } - } - - pub fn volume(&self) -> i32 { - unsafe { ffi::audrey_playbin_get_volume(self.to_glib_none().0) } - } - - pub fn set_volume(&self, value: i32) { - unsafe { ffi::audrey_playbin_set_volume(self.to_glib_none().0, value) } - } - - pub fn seek(&self, position: f64) { - unsafe { ffi::audrey_playbin_seek(self.to_glib_none().0, position) } - } - - pub fn go_to_next_track(&self) { - unsafe { ffi::audrey_playbin_go_to_next_track(self.to_glib_none().0) } - } - - pub fn go_to_prev_track(&self) { - unsafe { ffi::audrey_playbin_go_to_prev_track(self.to_glib_none().0) } - } - - pub fn position(&self) -> f64 { - unsafe { ffi::audrey_playbin_get_position(self.to_glib_none().0) } - } - - pub fn duration(&self) -> f64 { - unsafe { ffi::audrey_playbin_get_duration(self.to_glib_none().0) } - } - - pub fn mute(&self) -> bool { - unsafe { from_glib(ffi::audrey_playbin_get_mute(self.to_glib_none().0)) } - } - - pub fn set_mute(&self, mute: bool) { - unsafe { ffi::audrey_playbin_set_mute(self.to_glib_none().0, mute.into_glib()) } - } - - pub fn play_queue_position(&self) -> u32 { - unsafe { ffi::audrey_playbin_get_play_queue_position(self.to_glib_none().0) } - } - - pub fn play_queue_length(&self) -> u32 { - unsafe { ffi::audrey_playbin_get_play_queue_length(self.to_glib_none().0) } - } - - pub fn move_track(&self, from: u32, to: u32) { - unsafe { ffi::audrey_playbin_move_track(self.to_glib_none().0, from, to) } - } - - pub fn remove_track(&self, position: u32) { - unsafe { ffi::audrey_playbin_remove_track(self.to_glib_none().0, position) } - } - - pub fn select_track(&self, position: u32) { - unsafe { ffi::audrey_playbin_select_track(self.to_glib_none().0, position) } - } - - pub fn stop(&self) { - unsafe { ffi::audrey_playbin_stop(self.to_glib_none().0) } - } - - pub fn clear(&self) { - unsafe { ffi::audrey_playbin_clear(self.to_glib_none().0) } - } - - pub fn play_queue(&self) -> gio::ListModel { - unsafe { from_glib_none(ffi::audrey_playbin_get_play_queue(self.to_glib_none().0)) } - } - - pub fn connect_new_track(&self, f: F) -> glib::SignalHandlerId { - self.connect_closure( - "new-track", - false, - glib::closure_local!(|playbin, song| f(playbin, song)), - ) - } - - pub fn connect_seeked(&self, f: F) -> glib::SignalHandlerId { - self.connect_closure( - "seeked", - false, - glib::closure_local!(|playbin, position| f(playbin, position)), - ) - } - - // FIXME: this would be useful in other places, probably - pub fn connect_notify_future_local< - F: Fn(&Self, &glib::ParamSpec) -> U + 'static, - U: std::future::Future + 'static, - >( - &self, - name: &str, - f: F, - ) { - self.connect_notify_local(Some(name), move |self_, param_spec| { - glib::spawn_future_local(f(self_, param_spec)); - }); - } - - pub fn set_api(&self, api: &crate::subsonic_vala::Client) { - unsafe { ffi::audrey_playbin_set_api(self.to_glib_none().0, api.to_glib_none().0) } - } -} diff --git a/src/playbin_vala/state.rs b/src/playbin_vala/state.rs deleted file mode 100644 index 7379bc4..0000000 --- a/src/playbin_vala/state.rs +++ /dev/null @@ -1,46 +0,0 @@ -pub mod ffi { - use gtk::glib; - - pub type State = std::ffi::c_int; - - extern "C" { - pub fn audrey_playbin_state_get_type() -> glib::ffi::GType; - } -} - -use glib::prelude::*; -use gtk::glib; - -#[derive(Copy, Clone, PartialEq, Eq)] -pub enum State { - Stopped, - Paused, - Playing, -} - -impl glib::translate::FromGlib for State { - unsafe fn from_glib(value: ffi::State) -> Self { - match value { - 0 => Self::Stopped, - 1 => Self::Paused, - 2 => Self::Playing, - _ => unreachable!(), - } - } -} - -unsafe impl<'a> glib::value::FromValue<'a> for State { - type Checker = glib::value::GenericValueTypeChecker; - - 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 { - fn static_type() -> glib::Type { - unsafe { glib::translate::from_glib(ffi::audrey_playbin_state_get_type()) } - } -} diff --git a/src/subsonic_vala.rs b/src/subsonic_vala.rs deleted file mode 100644 index a8a3367..0000000 --- a/src/subsonic_vala.rs +++ /dev/null @@ -1,5 +0,0 @@ -pub mod client; -pub use client::Client; - -mod song; -pub use song::Song; diff --git a/src/subsonic_vala/client.rs b/src/subsonic_vala/client.rs deleted file mode 100644 index c4647b2..0000000 --- a/src/subsonic_vala/client.rs +++ /dev/null @@ -1,48 +0,0 @@ -pub mod ffi { - use gtk::glib; - use std::ffi::c_char; - - #[repr(C)] - pub struct AudreySubsonicClient { - parent_instance: glib::gobject_ffi::GObject, - } - - #[repr(C)] - pub struct AudreySubsonicClientClass { - parent_class: glib::gobject_ffi::GObjectClass, - } - - extern "C" { - pub fn audrey_subsonic_client_get_type() -> glib::ffi::GType; - pub fn audrey_subsonic_client_new_with_token( - server_url: *mut c_char, - username: *mut c_char, - token: *mut c_char, - salt: *mut c_char, - ) -> *mut AudreySubsonicClient; - } -} - -use glib::translate::{from_glib_none, ToGlibPtr}; -use gtk::glib; - -glib::wrapper! { - pub struct Client(Object); - - match fn { - type_ => || ffi::audrey_subsonic_client_get_type(), - } -} - -impl Client { - pub fn with_token(server_url: &str, username: &str, token: &str, salt: &str) -> Self { - unsafe { - from_glib_none(ffi::audrey_subsonic_client_new_with_token( - server_url.to_glib_none().0, - username.to_glib_none().0, - token.to_glib_none().0, - salt.to_glib_none().0, - )) - } - } -} diff --git a/src/subsonic_vala/song.rs b/src/subsonic_vala/song.rs deleted file mode 100644 index 6b315bf..0000000 --- a/src/subsonic_vala/song.rs +++ /dev/null @@ -1,39 +0,0 @@ -mod ffi { - use gtk::glib; - use std::ffi::*; - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct AudreySubsonicSong { - pub id: *mut c_char, - pub title: *mut c_char, - pub album: *mut c_char, - pub artist: *mut c_char, - pub track: i64, - pub year: i64, - pub starred: *mut glib::ffi::GDateTime, - pub duration: i64, - pub play_count: i64, - pub genre: *mut c_char, - pub cover_art: *mut c_char, - } - - extern "C" { - pub fn audrey_subsonic_song_copy(ptr: *const AudreySubsonicSong) - -> *mut AudreySubsonicSong; - pub fn audrey_subsonic_song_free(ptr: *mut AudreySubsonicSong); - pub fn audrey_subsonic_song_get_type() -> glib::ffi::GType; - } -} - -use gtk::glib; - -glib::wrapper! { - pub struct Song(BoxedInline); - - match fn { - copy => |ptr| ffi::audrey_subsonic_song_copy(ptr), - free => |ptr| ffi::audrey_subsonic_song_free(ptr), - type_ => || ffi::audrey_subsonic_song_get_type(), - } -} diff --git a/src/ui/setup.rs b/src/ui/setup.rs index ee207ec..be640c2 100644 --- a/src/ui/setup.rs +++ b/src/ui/setup.rs @@ -45,16 +45,7 @@ mod imp { } #[glib::derived_properties] - impl ObjectImpl for Setup { - fn signals() -> &'static [Signal] { - static SIGNALS: OnceLock> = OnceLock::new(); - SIGNALS.get_or_init(|| { - vec![Signal::builder("connected") - .param_types([crate::subsonic_vala::Client::static_type()]) - .build()] - }) - } - } + impl ObjectImpl for Setup {} impl WidgetImpl for Setup {} @@ -121,34 +112,6 @@ mod imp { .await .unwrap(); - // please REMOVEME once we've killed vala - fn get_random_salt(length: usize) -> String { - use rand::Rng; - let mut rng = rand::thread_rng(); - std::iter::repeat(()) - // 0.9: s/distributions/distr - .map(|()| rng.sample(rand::distributions::Alphanumeric)) - .map(char::from) - .take(length) - .collect::() - } - let new_salt = get_random_salt(8); - use md5::Digest; - let mut hasher = md5::Md5::new(); - hasher.update(self.obj().password().as_bytes()); - hasher.update(new_salt.as_bytes()); - let new_token_bytes = hasher.finalize(); - let new_token = base16ct::lower::encode_string(&new_token_bytes); - - let vala_api = crate::subsonic_vala::Client::with_token( - &self.obj().server_url(), - &self.obj().username(), - &new_token, - &new_salt, - ); - self.obj().set_authn_can_edit(true); - - self.obj().emit_by_name::<()>("connected", &[&vala_api]); self.connected.emit(self.obj().as_ref(), Rc::new(api)); } }