From dae2882e0dee9a5340f4fa8cbcfe00725f85a969 Mon Sep 17 00:00:00 2001 From: Erica Z Date: Tue, 5 Nov 2024 21:44:20 +0100 Subject: [PATCH] playbinsong -> model::song --- resources/play_queue_song.blp | 10 +++++----- src/main.rs | 3 +-- src/model.rs | 2 ++ src/{playbin_song.rs => model/song.rs} | 2 +- src/ui/play_queue/song.rs | 8 ++++---- src/ui/playbar.rs | 16 ++++++++-------- src/ui/window.rs | 14 +++++++------- 7 files changed, 28 insertions(+), 27 deletions(-) create mode 100644 src/model.rs rename src/{playbin_song.rs => model/song.rs} (97%) diff --git a/resources/play_queue_song.blp b/resources/play_queue_song.blp index 182563c..b70cd3c 100644 --- a/resources/play_queue_song.blp +++ b/resources/play_queue_song.blp @@ -39,7 +39,7 @@ template $AudreyUiPlayQueueSong: Box { margin-top: 1; margin-bottom: 1; pixel-size: 50; - // paintable: bind template.song as <$AudreyPlaybinSong>.thumbnail; + // paintable: bind template.song as <$AudreyModelSong>.thumbnail; } Box title_box { @@ -70,7 +70,7 @@ template $AudreyUiPlayQueueSong: Box { ellipsize: end; max-width-chars: 90; justify: fill; - label: bind template.song as <$AudreyPlaybinSong>.title; + label: bind template.song as <$AudreyModelSong>.title; } Label { @@ -85,7 +85,7 @@ template $AudreyUiPlayQueueSong: Box { ellipsize: end; max-width-chars: 90; justify: fill; - label: bind template.song as <$AudreyPlaybinSong>.artist; + label: bind template.song as <$AudreyModelSong>.artist; } } } @@ -101,12 +101,12 @@ template $AudreyUiPlayQueueSong: Box { "dim-label" ] - label: bind $format_duration(template.song as <$AudreyPlaybinSong>.duration) as ; + label: bind $format_duration(template.song as <$AudreyModelSong>.duration) as ; } Button { focusable: true; - // TODO icon-name: bind $star_button_icon_name (template.song as <$AudreyPlaybinSong>.starred) as ; + // TODO icon-name: bind $star_button_icon_name (template.song as <$AudreyModelSong>.starred) as ; icon-name: bind $star_button_icon_name() as ; styles [ diff --git a/src/main.rs b/src/main.rs index 5f43ccb..42ca808 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,8 +11,7 @@ pub mod ui; pub mod mpris; pub use mpris::Mpris; -pub mod playbin_song; -pub use playbin_song::Song as PlaybinSong; +pub mod model; pub mod subsonic; diff --git a/src/model.rs b/src/model.rs new file mode 100644 index 0000000..e3ebdf1 --- /dev/null +++ b/src/model.rs @@ -0,0 +1,2 @@ +mod song; +pub use song::Song; diff --git a/src/playbin_song.rs b/src/model/song.rs similarity index 97% rename from src/playbin_song.rs rename to src/model/song.rs index 63b9318..18fe3ad 100644 --- a/src/playbin_song.rs +++ b/src/model/song.rs @@ -35,7 +35,7 @@ mod imp { #[glib::object_subclass] impl ObjectSubclass for Song { - const NAME: &'static str = "AudreyPlaybinSong"; + const NAME: &'static str = "AudreyModelSong"; type Type = super::Song; } diff --git a/src/ui/play_queue/song.rs b/src/ui/play_queue/song.rs index aea6c46..d350fb2 100644 --- a/src/ui/play_queue/song.rs +++ b/src/ui/play_queue/song.rs @@ -1,5 +1,5 @@ mod imp { - use crate::PlaybinSong; + use crate::model::Song as ModelSong; use glib::subclass::InitializingObject; use gtk::{gdk, gio, glib, prelude::*, subclass::prelude::*}; use std::cell::{Cell, RefCell}; @@ -28,7 +28,7 @@ mod imp { #[property(set, get)] displayed_position: Cell, #[property(get, set)] - song: RefCell>, + song: RefCell>, drag_pos: Cell<(i32, i32)>, drag_widget: Cell>, @@ -174,7 +174,7 @@ mod imp { } } -use crate::PlaybinSong; +use crate::model::Song as ModelSong; use adw::prelude::*; use gtk::glib; @@ -190,7 +190,7 @@ impl Song { } pub fn bind(&self, position: u32, window: &crate::ui::Window) { - let song: PlaybinSong = window + let song: ModelSong = window .playlist_model() .item(position) .unwrap() diff --git a/src/ui/playbar.rs b/src/ui/playbar.rs index 767bf8a..95ed5ea 100644 --- a/src/ui/playbar.rs +++ b/src/ui/playbar.rs @@ -1,5 +1,5 @@ mod imp { - use crate::PlaybinSong; + use crate::model::Song; use adw::prelude::*; use adw::subclass::prelude::*; use glib::subclass::InitializingObject; @@ -16,7 +16,7 @@ mod imp { pulse_bar: TemplateChild, #[property(get, set, nullable)] - song: RefCell>, + song: RefCell>, #[property(get, set)] playing_cover_art: RefCell>, #[property(get, set, default = true)] @@ -168,18 +168,18 @@ mod imp { // these are nedeed because with regular bindings, if song becomes None, the labes are not // updated #[template_callback] - fn song_title(&self, song: Option<&PlaybinSong>) -> String { - song.map(PlaybinSong::title).unwrap_or("".to_string()) + fn song_title(&self, song: Option<&Song>) -> String { + song.map(Song::title).unwrap_or("".to_string()) } #[template_callback] - fn song_artist(&self, song: Option<&PlaybinSong>) -> String { - song.map(PlaybinSong::artist).unwrap_or("".to_string()) + fn song_artist(&self, song: Option<&Song>) -> String { + song.map(Song::artist).unwrap_or("".to_string()) } #[template_callback] - fn song_album(&self, song: Option<&PlaybinSong>) -> String { - song.map(PlaybinSong::album).unwrap_or("".to_string()) + fn song_album(&self, song: Option<&Song>) -> String { + song.map(Song::album).unwrap_or("".to_string()) } } diff --git a/src/ui/window.rs b/src/ui/window.rs index 5dad9b0..6d747b5 100644 --- a/src/ui/window.rs +++ b/src/ui/window.rs @@ -1,6 +1,6 @@ mod imp { + use crate::model::Song; use crate::mpv; - use crate::PlaybinSong; use adw::prelude::*; use adw::subclass::prelude::*; use glib::subclass::InitializingObject; @@ -26,7 +26,7 @@ mod imp { #[property(get, set, nullable)] playing_cover_art: RefCell>, - #[property(type = Option, get = Self::song, nullable)] + #[property(type = Option, get = Self::song, nullable)] _song: (), pub(super) setup: crate::ui::Setup, @@ -95,7 +95,7 @@ mod imp { setup: Default::default(), api: Default::default(), mpv, - playlist_model: gio::ListStore::new::(), + playlist_model: gio::ListStore::new::(), _volume: (), _mute: (), @@ -398,7 +398,7 @@ mod imp { Rc::clone(api.as_ref().unwrap()) }; for song in api.get_random_songs(10).await.unwrap().into_iter() { - let song = PlaybinSong::from_child(&api, &song); + let song = Song::from_child(&api, &song); self.mpv .command(["loadfile", &song.stream_url(), "append-play"]) .unwrap(); @@ -474,7 +474,7 @@ mod imp { { let left = duration.map(|f| f as i64); - let right = self.song().as_ref().map(crate::PlaybinSong::duration); + let right = self.song().as_ref().map(crate::model::Song::duration); if left != right { event!( Level::WARN, @@ -498,11 +498,11 @@ mod imp { .unwrap() } - fn song(&self) -> Option { + fn song(&self) -> Option { if self.obj().playlist_pos() < 0 { None } else { - let song: PlaybinSong = self + let song: Song = self .obj() .playlist_model() .item(self.obj().playlist_pos() as u32)