From e7e7341c89b6556e25c119645ee316c333cb833c Mon Sep 17 00:00:00 2001 From: Erica Z Date: Sun, 3 Nov 2024 19:36:52 +0100 Subject: [PATCH] (sickos) yes... yes!! --- resources/window.blp | 1 - src/main.rs | 5 +-- src/mpris/player.rs | 6 ++-- src/{playbin.rs => playbin_vala.rs} | 0 src/{playbin => playbin_vala}/song.rs | 0 src/{playbin => playbin_vala}/state.rs | 0 src/ui/play_queue.rs | 13 ++------ src/ui/play_queue/song.rs | 10 ++---- src/ui/playbar.rs | 46 ++++++++++---------------- src/ui/window.rs | 28 ++++------------ 10 files changed, 35 insertions(+), 74 deletions(-) rename src/{playbin.rs => playbin_vala.rs} (100%) rename src/{playbin => playbin_vala}/song.rs (100%) rename src/{playbin => playbin_vala}/state.rs (100%) diff --git a/resources/window.blp b/resources/window.blp index 67e7a4f..641ec3b 100644 --- a/resources/window.blp +++ b/resources/window.blp @@ -128,7 +128,6 @@ template $AudreyUiWindow: Adw.ApplicationWindow { [bottom] $AudreyUiPlaybar playbar { song: bind template.song; - playbin: bind template.playbin; playing_cover_art: bind template.playing_cover_art; show_cover_art: bind $show_playbar_cover_art (stack.visible-child-name) as ; } diff --git a/src/main.rs b/src/main.rs index bff1568..d0df490 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,13 +11,14 @@ pub mod ui; pub mod mpris; pub use mpris::Mpris; -pub mod playbin; -pub use playbin::Playbin; +pub mod playbin_vala; +pub use playbin_vala::Song as PlaybinSong; pub mod subsonic; pub mod subsonic_vala; pub mod playbin2; +pub type Playbin = playbin2::Playbin; mod signal; pub use signal::{Signal, SignalEmitter, SignalHandler}; diff --git a/src/mpris/player.rs b/src/mpris/player.rs index 9849080..743aa1c 100644 --- a/src/mpris/player.rs +++ b/src/mpris/player.rs @@ -1,11 +1,9 @@ +use crate::{Playbin, PlaybinSong}; use gtk::glib::spawn_future_local; use std::collections::HashMap; use std::rc::{Rc, Weak}; use zbus::zvariant::{ObjectPath, OwnedObjectPath, OwnedValue, Value}; -use crate::playbin::Song as PlaybinSong; -type Playbin = crate::playbin2::Playbin; - const MICROSECONDS: f64 = 1e6; // in a second #[derive(Default)] @@ -37,7 +35,7 @@ struct MetadataMap { } impl MetadataMap { - fn from_playbin_song(song: Option<&crate::playbin::Song>) -> Self { + fn from_playbin_song(song: Option<&PlaybinSong>) -> Self { song.map(|song| MetadataMap { // use a unique growing counter to identify tracks track_id: Some({ diff --git a/src/playbin.rs b/src/playbin_vala.rs similarity index 100% rename from src/playbin.rs rename to src/playbin_vala.rs diff --git a/src/playbin/song.rs b/src/playbin_vala/song.rs similarity index 100% rename from src/playbin/song.rs rename to src/playbin_vala/song.rs diff --git a/src/playbin/state.rs b/src/playbin_vala/state.rs similarity index 100% rename from src/playbin/state.rs rename to src/playbin_vala/state.rs diff --git a/src/ui/play_queue.rs b/src/ui/play_queue.rs index 0a7cc7f..76ea7f8 100644 --- a/src/ui/play_queue.rs +++ b/src/ui/play_queue.rs @@ -2,14 +2,12 @@ pub mod song; pub use song::Song; mod imp { - use crate::playbin::Song as PlaybinSong; + use crate::{Playbin, PlaybinSong}; use adw::{gio, glib, prelude::*, subclass::prelude::*}; use glib::{subclass::InitializingObject, WeakRef}; use std::cell::{Cell, RefCell}; use std::rc::Rc; - type Playbin = crate::playbin2::Playbin; - #[derive(gtk::CompositeTemplate, glib::Properties, Default)] #[template(resource = "/eu/callcc/audrey/play_queue.ui")] #[properties(wrapper_type = super::PlayQueue)] @@ -78,10 +76,7 @@ mod imp { child.bind( item.position(), - item.item() - .unwrap() - .downcast_ref::() - .unwrap(), + item.item().unwrap().downcast_ref::().unwrap(), ); } @@ -109,13 +104,11 @@ mod imp { } } -use crate::playbin::Song as PlaybinSong; +use crate::Playbin; use adw::subclass::prelude::*; use gtk::glib; use std::rc::Rc; -type Playbin = crate::playbin2::Playbin; - glib::wrapper! { pub struct PlayQueue(ObjectSubclass) @extends adw::Bin, gtk::Widget, diff --git a/src/ui/play_queue/song.rs b/src/ui/play_queue/song.rs index 4eb5676..7e0ceb7 100644 --- a/src/ui/play_queue/song.rs +++ b/src/ui/play_queue/song.rs @@ -1,13 +1,11 @@ mod imp { - use crate::playbin::Song as PlaybinSong; use crate::signal::SignalHandler; + use crate::{Playbin, PlaybinSong}; use glib::{subclass::InitializingObject, WeakRef}; use gtk::{gdk, gio, glib, prelude::*, subclass::prelude::*}; use std::cell::{Cell, RefCell}; use std::rc::Rc; - type Playbin = crate::playbin2::Playbin; - #[derive(gtk::CompositeTemplate, glib::Properties, Default)] #[template(resource = "/eu/callcc/audrey/play_queue_song.ui")] #[properties(wrapper_type = super::Song)] @@ -167,15 +165,13 @@ mod imp { } } -use crate::playbin::Song as PlaybinSong; +use crate::{Playbin, PlaybinSong}; use adw::prelude::*; use adw::subclass::prelude::*; use glib::Object; use gtk::glib; use std::rc::Rc; -type Playbin = crate::playbin2::Playbin; - glib::wrapper! { pub struct Song(ObjectSubclass) @extends gtk::Box, gtk::Widget, @@ -199,7 +195,7 @@ impl Song { Rc::clone(self.imp().playbin.borrow().as_ref().unwrap()) } - pub fn bind(&self, position: u32, song: &crate::playbin::Song) { + pub fn bind(&self, position: u32, song: &PlaybinSong) { self.set_displayed_position(position + 1); self.set_song(song); self.set_current(self.playbin().current_entry() == Some(position as usize)); diff --git a/src/ui/playbar.rs b/src/ui/playbar.rs index c994f05..4c88c8e 100644 --- a/src/ui/playbar.rs +++ b/src/ui/playbar.rs @@ -1,4 +1,5 @@ mod imp { + use crate::PlaybinSong; use adw::prelude::*; use adw::subclass::prelude::*; use glib::subclass::InitializingObject; @@ -11,7 +12,7 @@ mod imp { #[template(resource = "/eu/callcc/audrey/playbar.ui")] pub struct Playbar { #[property(get, set)] - song: RefCell>, + song: RefCell>, #[property(get, set)] playing_cover_art: RefCell>, #[property(get, set, default = true)] @@ -53,17 +54,17 @@ mod imp { #[gtk::template_callbacks] impl Playbar { #[template_callback] - fn song_title(&self, song: Option<&crate::playbin::Song>) -> Option { + fn song_title(&self, song: Option<&PlaybinSong>) -> Option { song.map(|song| song.title()) } #[template_callback] - fn song_artist(&self, song: Option<&crate::playbin::Song>) -> Option { + fn song_artist(&self, song: Option<&PlaybinSong>) -> Option { song.map(|song| song.artist()) } #[template_callback] - fn song_album(&self, song: Option<&crate::playbin::Song>) -> Option { + fn song_album(&self, song: Option<&PlaybinSong>) -> Option { song.map(|song| song.album()) } @@ -72,25 +73,6 @@ mod imp { gformat!("{:02}:{:02}", (s as i64) / 64, (s as i64) % 60) } - #[template_callback] - fn playbin_active(&self, state: crate::playbin::State) -> bool { - true // TODO - } - - #[template_callback] - fn can_press_play(&self, state: crate::playbin::State, n_items: u32) -> bool { - true // TODO - } - - #[template_callback] - fn play_pause_icon_name(&self, state: crate::playbin::State) -> &'static str { - /* - match state { - crate::playbin::State::Playing => "media-playback-pause", - _ => "media-playback-start", - }*/todo!() - } - #[template_callback] fn mute_button_icon_name(&self, mute: bool) -> &'static str { if mute { @@ -112,21 +94,24 @@ mod imp { if range.adjustment().lower() < range.adjustment().upper() { playbin.seek(value); } - false*/todo!() + false*/ + todo!() } #[template_callback] fn on_skip_forward_clicked(&self) { /* let playbin = self.playbin.upgrade().unwrap(); - playbin.go_to_next_track();*/todo!() + playbin.go_to_next_track();*/ + todo!() } #[template_callback] fn on_skip_backward_clicked(&self) { /* let playbin = self.playbin.upgrade().unwrap(); - playbin.go_to_prev_track();*/todo!() + playbin.go_to_prev_track();*/ + todo!() } #[template_callback] @@ -138,7 +123,8 @@ mod imp { if new_position < 0.0 { new_position = 0.0; } - playbin.seek(new_position);*/todo!() + playbin.seek(new_position);*/ + todo!() } #[template_callback] @@ -150,7 +136,8 @@ mod imp { if new_position > playbin.duration() { new_position = playbin.duration(); } - playbin.seek(new_position);*/todo!() + playbin.seek(new_position);*/ + todo!() } #[template_callback] @@ -162,7 +149,8 @@ mod imp { playbin.pause(); } else { playbin.play(); - }*/todo!() + }*/ + todo!() } #[template_callback] diff --git a/src/ui/window.rs b/src/ui/window.rs index a262a26..5ed2d8c 100644 --- a/src/ui/window.rs +++ b/src/ui/window.rs @@ -1,4 +1,5 @@ mod imp { + use crate::{Playbin, PlaybinSong}; use adw::prelude::*; use adw::subclass::prelude::*; use glib::subclass::InitializingObject; @@ -6,7 +7,7 @@ mod imp { use std::cell::{Cell, RefCell}; use std::rc::Rc; - impl crate::playbin2::PlaybinEntry for crate::playbin::Song { + impl crate::playbin2::PlaybinEntry for PlaybinSong { fn url(&self) -> url::Url { self.stream_url() } @@ -22,9 +23,6 @@ mod imp { #[template_child] pub(super) play_queue: TemplateChild, - #[property(get, set)] - playbin: RefCell, - #[property(get, set, default = false)] can_click_shuffle_all: Cell, @@ -32,11 +30,11 @@ mod imp { playing_cover_art: RefCell>, #[property(get, set, nullable)] - song: RefCell>, + song: RefCell>, pub(super) setup: crate::ui::Setup, - pub(super) playbin2: Rc>, + pub(super) playbin2: Rc, pub(super) api2: RefCell>>, } @@ -138,7 +136,7 @@ mod imp { let api = api.as_ref().unwrap(); for song in api.get_random_songs(10).await.unwrap().into_iter() { self.playbin2 - .push_entry(crate::playbin::Song::from_child(api, &song)); + .push_entry(PlaybinSong::from_child(api, &song)); } self.obj().set_can_click_shuffle_all(true); } @@ -148,7 +146,7 @@ mod imp { self.setup.present(Some(self.obj().as_ref())); } - pub(super) fn now_playing(&self, _song: &crate::playbin::Song) { + pub(super) fn now_playing(&self, _song: PlaybinSong) { /* this.song = song; // api.scrobble.begin (this.song.id); TODO @@ -185,6 +183,7 @@ mod imp { } } +use crate::PlaybinSong; use adw::prelude::*; use adw::subclass::prelude::*; use gtk::{gdk, gio, glib}; @@ -286,19 +285,6 @@ impl Window { true }); - window.playbin().connect_closure( - "stopped", - false, - glib::closure_local!( - #[weak] - window, - move |_playbin: crate::Playbin| { - window.set_playing_cover_art(None::); - window.set_song(None::); - } - ), - ); - window } }