property limits etc

This commit is contained in:
Erica Z 2024-11-07 10:05:26 +01:00
parent 2b9b6ee6c7
commit 0cbf091b91
3 changed files with 16 additions and 18 deletions

View file

@ -8,7 +8,7 @@ mod imp {
#[template(resource = "/eu/callcc/audrey/play_queue_song.ui")] #[template(resource = "/eu/callcc/audrey/play_queue_song.ui")]
#[properties(wrapper_type = super::Song)] #[properties(wrapper_type = super::Song)]
pub struct Song { pub struct Song {
#[property(type = i32, set = Self::set_playlist_pos)] #[property(type = i64, set = Self::set_playlist_pos)]
_playlist_pos: (), _playlist_pos: (),
#[property(set, get)] #[property(set, get)]
@ -167,9 +167,9 @@ mod imp {
true true
} }
fn set_playlist_pos(&self, playlist_pos: i32) { fn set_playlist_pos(&self, playlist_pos: i64) {
self.obj() self.obj()
.set_current(playlist_pos == self.position.get() as i32); .set_current(playlist_pos == self.position.get() as i64);
} }
} }
} }

View file

@ -95,7 +95,7 @@ mod imp {
#[template_callback] #[template_callback]
fn on_skip_forward_clicked(&self) { fn on_skip_forward_clicked(&self) {
if self.window().playlist_pos() + 1 < self.window().playlist_count() as i32 { if self.window().playlist_pos() + 1 < self.window().playlist_count() {
self.window().playlist_next(); self.window().playlist_next();
} else { } else {
self.window().playlist_play_index(None); self.window().playlist_play_index(None);

View file

@ -38,13 +38,13 @@ mod imp {
#[property(get)] #[property(get)]
playlist_model: gio::ListStore, playlist_model: gio::ListStore,
#[property(type = u32, get = Self::volume, set = Self::set_volume)] #[property(type = i64, get = Self::volume, set = Self::set_volume, minimum = 0, maximum = 100)]
_volume: (), _volume: (),
#[property(type = bool, get = Self::mute, set = Self::set_mute)] #[property(type = bool, get = Self::mute, set = Self::set_mute)]
_mute: (), _mute: (),
#[property(type = bool, get = Self::pause, set = Self::set_pause)] #[property(type = bool, get = Self::pause, set = Self::set_pause)]
_pause: (), _pause: (),
#[property(type = i32, get = Self::playlist_pos)] #[property(type = i64, get = Self::playlist_pos)]
_playlist_pos: (), _playlist_pos: (),
#[property(type = f64, get = Self::time_pos)] #[property(type = f64, get = Self::time_pos)]
_time_pos: (), _time_pos: (),
@ -52,7 +52,7 @@ mod imp {
_duration: (), // as reported by mpv, compare with song.duration _duration: (), // as reported by mpv, compare with song.duration
#[property(type = bool, get = Self::idle_active)] #[property(type = bool, get = Self::idle_active)]
_idle_active: (), _idle_active: (),
#[property(type = u32, get = Self::playlist_count)] #[property(type = i64, get = Self::playlist_count)]
_playlist_count: (), _playlist_count: (),
pub(super) queued_seek: Cell<Option<f64>>, pub(super) queued_seek: Cell<Option<f64>>,
@ -290,7 +290,7 @@ mod imp {
self.setup.present(Some(self.obj().as_ref())); self.setup.present(Some(self.obj().as_ref()));
} }
fn volume(&self) -> u32 { fn volume(&self) -> i64 {
self.mpv self.mpv
.get_property::<i64>("volume") .get_property::<i64>("volume")
.unwrap() .unwrap()
@ -298,7 +298,7 @@ mod imp {
.unwrap() .unwrap()
} }
fn set_volume(&self, volume: u32) { fn set_volume(&self, volume: i64) {
self.mpv.set_property("volume", volume as i64).unwrap(); self.mpv.set_property("volume", volume as i64).unwrap();
} }
@ -318,11 +318,9 @@ mod imp {
self.mpv.set_property("pause", pause).unwrap(); self.mpv.set_property("pause", pause).unwrap();
} }
fn playlist_pos(&self) -> i32 { fn playlist_pos(&self) -> i64 {
self.mpv self.mpv
.get_property::<i64>("playlist-pos") .get_property("playlist-pos")
.unwrap()
.try_into()
.unwrap() .unwrap()
} }
@ -368,7 +366,7 @@ mod imp {
self.mpv.get_property("idle-active").unwrap() self.mpv.get_property("idle-active").unwrap()
} }
fn playlist_count(&self) -> u32 { fn playlist_count(&self) -> i64 {
self.mpv self.mpv
.get_property::<i64>("playlist-count") .get_property::<i64>("playlist-count")
.unwrap() .unwrap()
@ -377,16 +375,16 @@ mod imp {
} }
fn song(&self) -> Option<Song> { fn song(&self) -> Option<Song> {
match self.obj().playlist_pos() { match self.obj().playlist_pos().try_into() {
playlist_pos if playlist_pos < 0 => None, Ok(playlist_pos) => Some(
playlist_pos => Some(
self.obj() self.obj()
.playlist_model() .playlist_model()
.item(playlist_pos as u32) .item(playlist_pos)
.unwrap() .unwrap()
.dynamic_cast() .dynamic_cast()
.unwrap(), .unwrap(),
), ),
Err(_) => None,
} }
} }