From 6483f3dd1718cfbe27ec033d465a9d276266eb66 Mon Sep 17 00:00:00 2001 From: Erica Z Date: Sun, 3 Nov 2024 20:18:12 +0100 Subject: [PATCH] de-warn --- src/mpris/player.rs | 60 +++++++++++++++++++++++++++++++-------- src/playbin.rs | 6 ++-- src/signal.rs | 1 - src/ui/play_queue.rs | 8 +++--- src/ui/play_queue/song.rs | 3 +- src/ui/playbar.rs | 5 ++-- src/ui/setup.rs | 3 +- src/ui/window.rs | 11 +++---- 8 files changed, 65 insertions(+), 32 deletions(-) diff --git a/src/mpris/player.rs b/src/mpris/player.rs index 743aa1c..987e76d 100644 --- a/src/mpris/player.rs +++ b/src/mpris/player.rs @@ -45,11 +45,11 @@ impl MetadataMap { }), length: Some(song.duration() * MICROSECONDS as i64), //art_url: Some(song.cover_art_url()), // FIXME: this would leak credentials - album: Some(song.album().into()), - artist: Some(vec![song.artist().into()]), + album: Some(song.album()), + artist: Some(vec![song.artist()]), //content_created: song.year().map(|year| chrono::NaiveDate::from_yo_opt(year, 1).unwrap()), // FIXME: replace this unwrap with Some(Err) -> None //genre: Some(song.genre.iter().collect()), - title: Some(song.title().into()), + title: Some(song.title()), //track_number: song.track().map(|u| u as i32), //user_rating: Some(if song.starred().is_none() { 0.0 } else { 1.0 }), ..Default::default() @@ -273,6 +273,46 @@ impl Player { .await } + async fn previous(&self) -> zbus::fdo::Result<()> { + self.with_local(move |local| async move { local.previous() }) + .await + } + + async fn pause(&self) -> zbus::fdo::Result<()> { + self.with_local(move |local| async move { local.pause() }) + .await + } + + async fn play_pause(&self) -> zbus::fdo::Result<()> { + self.with_local(move |local| async move { local.play_pause() }) + .await + } + + async fn stop(&self) -> zbus::fdo::Result<()> { + self.with_local(move |local| async move { local.stop() }) + .await + } + + async fn play(&self) -> zbus::fdo::Result<()> { + self.with_local(move |local| async move { local.play() }) + .await + } + + async fn seek(&self, offset: i64) -> zbus::fdo::Result<()> { + self.with_local(move |local| async move { local.seek(offset) }) + .await + } + + async fn set_position(&self, track_id: ObjectPath<'_>, position: i64) -> zbus::fdo::Result<()> { + let track_id = track_id.to_owned(); + self.with_local(move |local| async move { local.set_position(track_id, position) }) + .await + } + + async fn open_uri(&self, _s: String) -> zbus::fdo::Result<()> { + Err(zbus::fdo::Error::NotSupported("OpenUri".into())) + } + #[zbus(property)] async fn playback_status(&self) -> zbus::fdo::Result { self.with_local(|local| async move { local.playback_status() }) @@ -473,14 +513,14 @@ impl LocalPlayer { todo!() } - fn set_position(&self, _track_id: ObjectPath<'_>, _position: i64) -> zbus::fdo::Result<()> { + fn set_position( + &self, + _track_id: ObjectPath<'static>, + _position: i64, + ) -> zbus::fdo::Result<()> { todo!() } - fn open_uri(&self, _s: &str) -> zbus::fdo::Result<()> { - Err(zbus::fdo::Error::NotSupported("OpenUri".into())) - } - fn playback_status(&self) -> zbus::fdo::Result { match self.playbin()?.paused() { //crate::playbin::State::Stopped => Ok("Stopped".into()), @@ -532,10 +572,6 @@ impl LocalPlayer { // we don't play anything that can't be seeked true } - - fn can_control(&self) -> bool { - true - } } impl Drop for Player { diff --git a/src/playbin.rs b/src/playbin.rs index 8fc996a..c9588c7 100644 --- a/src/playbin.rs +++ b/src/playbin.rs @@ -137,7 +137,7 @@ where entries.push(entry); drop(entries); - self.entry_inserted.emit(self, index as usize); + self.entry_inserted.emit(self, index); } pub fn insert_entry(&self, index: usize, entry: E) { @@ -145,7 +145,7 @@ where self.mpv .command(["loadfile", entry.url().as_str(), "insert-at-play"]) .unwrap(); - entries.insert(index as usize, entry); + entries.insert(index, entry); drop(entries); self.entry_inserted.emit(self, index); @@ -166,7 +166,7 @@ where self.mpv .command(["playlist-remove", &index.to_string()]) .unwrap(); - entries.remove(index as usize); + entries.remove(index); drop(entries); self.entry_removed.emit(self, index); diff --git a/src/signal.rs b/src/signal.rs index c1be112..1602a2c 100644 --- a/src/signal.rs +++ b/src/signal.rs @@ -102,7 +102,6 @@ impl SignalEmitter { handlers.append(self.just_connected.borrow_mut().as_mut()); let mut i = 0; - let mut skip = 0; // FIXME: does not preserve ordering while i < handlers.len() { if handlers[i](emitter, f()) { diff --git a/src/ui/play_queue.rs b/src/ui/play_queue.rs index 76ea7f8..5ba6846 100644 --- a/src/ui/play_queue.rs +++ b/src/ui/play_queue.rs @@ -4,8 +4,8 @@ pub use song::Song; mod imp { use crate::{Playbin, PlaybinSong}; use adw::{gio, glib, prelude::*, subclass::prelude::*}; - use glib::{subclass::InitializingObject, WeakRef}; - use std::cell::{Cell, RefCell}; + use glib::subclass::InitializingObject; + use std::cell::RefCell; use std::rc::Rc; #[derive(gtk::CompositeTemplate, glib::Properties, Default)] @@ -134,13 +134,13 @@ impl PlayQueue { }); playbin .stopped() - .connect_object(self, |playbin, play_queue, ()| { + .connect_object(self, |_playbin, play_queue, ()| { play_queue.model().unwrap().remove_all(); true }); playbin .entry_removed() - .connect_object(self, |playbin, play_queue, index| { + .connect_object(self, |_playbin, play_queue, index| { play_queue.model().unwrap().remove(index as u32); true }); diff --git a/src/ui/play_queue/song.rs b/src/ui/play_queue/song.rs index 7e0ceb7..3950a39 100644 --- a/src/ui/play_queue/song.rs +++ b/src/ui/play_queue/song.rs @@ -1,7 +1,7 @@ mod imp { use crate::signal::SignalHandler; use crate::{Playbin, PlaybinSong}; - use glib::{subclass::InitializingObject, WeakRef}; + use glib::subclass::InitializingObject; use gtk::{gdk, gio, glib, prelude::*, subclass::prelude::*}; use std::cell::{Cell, RefCell}; use std::rc::Rc; @@ -166,7 +166,6 @@ mod imp { } use crate::{Playbin, PlaybinSong}; -use adw::prelude::*; use adw::subclass::prelude::*; use glib::Object; use gtk::glib; diff --git a/src/ui/playbar.rs b/src/ui/playbar.rs index 8a75b49..abaf795 100644 --- a/src/ui/playbar.rs +++ b/src/ui/playbar.rs @@ -3,7 +3,6 @@ mod imp { use adw::prelude::*; use adw::subclass::prelude::*; use glib::subclass::InitializingObject; - use glib::{gformat, GString, WeakRef}; use gtk::{gdk, glib}; use std::cell::{Cell, RefCell}; @@ -86,8 +85,8 @@ mod imp { fn on_play_position_seek( &self, _scroll_type: gtk::ScrollType, - value: f64, - range: >k::Range, + _value: f64, + _range: >k::Range, ) -> bool { /* let playbin = self.playbin.upgrade().unwrap(); diff --git a/src/ui/setup.rs b/src/ui/setup.rs index 46ea2fb..e503f6c 100644 --- a/src/ui/setup.rs +++ b/src/ui/setup.rs @@ -1,10 +1,9 @@ mod imp { use crate::signal::SignalEmitter; use adw::{glib, prelude::*, subclass::prelude::*}; - use glib::subclass::{InitializingObject, Signal}; + use glib::subclass::InitializingObject; use std::cell::{Cell, RefCell}; use std::rc::Rc; - use std::sync::OnceLock; #[derive(gtk::CompositeTemplate, glib::Properties, Default)] #[template(resource = "/eu/callcc/audrey/setup.ui")] diff --git a/src/ui/window.rs b/src/ui/window.rs index f37a102..8057c3d 100644 --- a/src/ui/window.rs +++ b/src/ui/window.rs @@ -140,7 +140,7 @@ mod imp { self.setup.present(Some(self.obj().as_ref())); } - pub(super) fn now_playing(&self, _song: PlaybinSong) { + pub(super) fn now_playing(&self, _song: &PlaybinSong) { /* this.song = song; // api.scrobble.begin (this.song.id); TODO @@ -177,10 +177,9 @@ mod imp { } } -use crate::PlaybinSong; use adw::prelude::*; use adw::subclass::prelude::*; -use gtk::{gdk, gio, glib}; +use gtk::{gio, glib}; use std::rc::Rc; glib::wrapper! { @@ -274,8 +273,10 @@ impl Window { .imp() .playbin2 .file_started() - .connect_object(&window, |_playbin, _window, ()| { - // TODO window.imp().now_playing(song); + .connect_object(&window, |playbin, window, ()| { + window + .imp() + .now_playing(&playbin.entries()[playbin.current_entry().unwrap()]); true });