From 0080399db2fb6e30465ed0aa59947b4b20a99d89 Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Fri, 15 Jun 2018 18:05:19 +0300 Subject: [PATCH] PlayerWidget: Move on_duration_change and on_postion_updated methods. Previously they depended on the player/pipeline to get the ClockTime values, and only `PlayerWidget` had access to the `gst_player::Player` object. Now that it uses the gst_player methods instead of the raw pipeline methods to get the ClockTime values it no longer needs access to the whole PlayerWidget object. --- hammond-gtk/src/app.rs | 4 +-- hammond-gtk/src/widgets/player.rs | 56 ++++++++++++++----------------- 2 files changed, 28 insertions(+), 32 deletions(-) diff --git a/hammond-gtk/src/app.rs b/hammond-gtk/src/app.rs index e112e68..a47382a 100644 --- a/hammond-gtk/src/app.rs +++ b/hammond-gtk/src/app.rs @@ -212,8 +212,8 @@ impl App { notif.show(&overlay); }, Ok(Action::InitEpisode(rowid)) => player.initialize_episode(rowid).unwrap(), - Ok(Action::PlayerDurationChanged(clock)) => player.on_duration_changed(clock), - Ok(Action::PlayerPositionUpdated(clock)) => player.on_position_updated(clock), + Ok(Action::PlayerDurationChanged(clock)) => player.timer.on_duration_changed(clock), + Ok(Action::PlayerPositionUpdated(clock)) => player.timer.on_position_updated(clock), Err(_) => (), } diff --git a/hammond-gtk/src/widgets/player.rs b/hammond-gtk/src/widgets/player.rs index d3e8402..6b938be 100644 --- a/hammond-gtk/src/widgets/player.rs +++ b/hammond-gtk/src/widgets/player.rs @@ -82,6 +82,31 @@ pub struct PlayerTimes { slider_update: Arc, } +impl PlayerTimes { + /// Update the duration `gtk::Label` and the max range of the `gtk::SclaeBar`. + // FIXME: Refactor the labels to use some kind of Human™ time/values. + pub fn on_duration_changed(&self, duration: ClockTime) { + let seconds = duration.seconds().map(|v| v as f64).unwrap_or(0.0); + + self.slider.block_signal(&self.slider_update); + self.slider.set_range(0.0, seconds); + self.slider.unblock_signal(&self.slider_update); + + self.duration.set_text(&format!("{:.2}", seconds / 60.0)); + } + + /// Update the `gtk::SclaeBar` when the pipeline position is changed. + pub fn on_position_updated(&self, position: ClockTime) { + let seconds = position.seconds().map(|v| v as f64).unwrap_or(0.0); + + self.slider.block_signal(&self.slider_update); + self.slider.set_value(seconds); + self.slider.unblock_signal(&self.slider_update); + + self.progressed.set_text(&format!("{:.2}", seconds / 60.0)); + } +} + #[derive(Debug, Clone)] struct PlayerControls { container: gtk::Box, @@ -96,7 +121,7 @@ pub struct PlayerWidget { pub action_bar: gtk::ActionBar, player: gst_player::Player, controls: PlayerControls, - timer: PlayerTimes, + pub timer: PlayerTimes, info: PlayerInfo, } @@ -248,35 +273,6 @@ impl PlayerWidget { player.seek(ClockTime::from_seconds(value as u64)); })) } - - /// Update the duration `gtk::Label` and the max range of the `gtk::SclaeBar`. - // FIXME: Refactor the labels to use some kind of Human™ time/values. - pub fn on_duration_changed(&self, duration: ClockTime) { - let slider = &self.timer.slider; - let seconds = duration.seconds().map(|v| v as f64).unwrap_or(0.0); - - slider.block_signal(&self.timer.slider_update); - slider.set_range(0.0, seconds); - slider.unblock_signal(&self.timer.slider_update); - - self.timer - .duration - .set_text(&format!("{:.2}", seconds / 60.0)); - } - - /// Update the `gtk::SclaeBar` when the pipeline position is changed. - pub fn on_position_updated(&self, position: ClockTime) { - let slider = &self.timer.slider; - let seconds = position.seconds().map(|v| v as f64).unwrap_or(0.0); - - slider.block_signal(&self.timer.slider_update); - slider.set_value(seconds); - slider.unblock_signal(&self.timer.slider_update); - - self.timer - .progressed - .set_text(&format!("{:.2}", seconds / 60.0)); - } } impl PlayerExt for PlayerWidget {