PlayerTimes: create wrapper struct of gst::ClockTime.

Now on_duration_changed requires a `Duration` type and
on_position_updated requires a `Position` type as oppose to
both accepting `ClockTime` as their argument.
This commit is contained in:
Jordan Petridis 2018-06-16 12:35:51 +03:00
parent a6a34d8246
commit b58d28c723
2 changed files with 33 additions and 13 deletions

View File

@ -5,7 +5,6 @@ use gio::{
SimpleAction, SimpleActionExt, SimpleAction, SimpleActionExt,
}; };
use glib; use glib;
use gst::ClockTime;
use gtk; use gtk;
use gtk::prelude::*; use gtk::prelude::*;
use gtk::SettingsExt as GtkSettingsExt; use gtk::SettingsExt as GtkSettingsExt;
@ -18,7 +17,7 @@ use settings::{self, WindowGeometry};
use stacks::{Content, PopulatedState}; use stacks::{Content, PopulatedState};
use utils; use utils;
use widgets::appnotif::{InAppNotification, UndoState}; use widgets::appnotif::{InAppNotification, UndoState};
use widgets::player::*; use widgets::player;
use widgets::{about_dialog, mark_all_notif, remove_show_notif}; use widgets::{about_dialog, mark_all_notif, remove_show_notif};
use std::rc::Rc; use std::rc::Rc;
@ -56,8 +55,8 @@ pub enum Action {
RemoveShow(Arc<Podcast>), RemoveShow(Arc<Podcast>),
ErrorNotification(String), ErrorNotification(String),
InitEpisode(i32), InitEpisode(i32),
PlayerDurationChanged(ClockTime), PlayerDurationChanged(player::Duration),
PlayerPositionUpdated(ClockTime), PlayerPositionUpdated(player::Position),
} }
#[derive(Debug)] #[derive(Debug)]
@ -123,7 +122,7 @@ impl App {
// Add the overlay to the main Box // Add the overlay to the main Box
wrap.add(&overlay); wrap.add(&overlay);
let player = PlayerWidget::new(&sender); let player = player::PlayerWidget::new(&sender);
// Add the player to the main Box // Add the player to the main Box
wrap.add(&player.action_bar); wrap.add(&player.action_bar);
// player.reveal(); // player.reveal();
@ -212,8 +211,8 @@ impl App {
notif.show(&overlay); notif.show(&overlay);
}, },
Ok(Action::InitEpisode(rowid)) => player.initialize_episode(rowid).unwrap(), Ok(Action::InitEpisode(rowid)) => player.initialize_episode(rowid).unwrap(),
Ok(Action::PlayerDurationChanged(clock)) => player.timer.on_duration_changed(clock), Ok(Action::PlayerDurationChanged(dur)) => player.timer.on_duration_changed(dur),
Ok(Action::PlayerPositionUpdated(clock)) => player.timer.on_position_updated(clock), Ok(Action::PlayerPositionUpdated(pos)) => player.timer.on_position_updated(pos),
Err(_) => (), Err(_) => (),
} }

View File

@ -21,6 +21,7 @@ use hammond_data::{EpisodeWidgetQuery, PodcastCoverQuery};
use app::Action; use app::Action;
use utils::set_image_from_path; use utils::set_image_from_path;
use std::ops::Deref;
use std::path::Path; use std::path::Path;
use std::rc::Rc; use std::rc::Rc;
use std::sync::Arc; use std::sync::Arc;
@ -82,10 +83,30 @@ pub struct PlayerTimes {
slider_update: Arc<SignalHandlerId>, slider_update: Arc<SignalHandlerId>,
} }
#[derive(Debug, Clone, Copy)]
pub struct Duration(ClockTime);
impl Deref for Duration {
type Target = ClockTime;
fn deref(&self) -> &Self::Target {
&self.0
}
}
#[derive(Debug, Clone, Copy)]
pub struct Position(ClockTime);
impl Deref for Position {
type Target = ClockTime;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl PlayerTimes { impl PlayerTimes {
/// Update the duration `gtk::Label` and the max range of the `gtk::SclaeBar`. /// 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. // FIXME: Refactor the labels to use some kind of Human™ time/values.
pub fn on_duration_changed(&self, duration: ClockTime) { pub fn on_duration_changed(&self, duration: Duration) {
let seconds = duration.seconds().map(|v| v as f64).unwrap_or(0.0); let seconds = duration.seconds().map(|v| v as f64).unwrap_or(0.0);
self.slider.block_signal(&self.slider_update); self.slider.block_signal(&self.slider_update);
@ -96,7 +117,7 @@ impl PlayerTimes {
} }
/// Update the `gtk::SclaeBar` when the pipeline position is changed. /// Update the `gtk::SclaeBar` when the pipeline position is changed.
pub fn on_position_updated(&self, position: ClockTime) { pub fn on_position_updated(&self, position: Position) {
let seconds = position.seconds().map(|v| v as f64).unwrap_or(0.0); let seconds = position.seconds().map(|v| v as f64).unwrap_or(0.0);
self.slider.block_signal(&self.slider_update); self.slider.block_signal(&self.slider_update);
@ -212,14 +233,14 @@ impl PlayerWidget {
})); }));
s.player.connect_duration_changed(clone!(sender => move |_, duration| { s.player.connect_duration_changed(clone!(sender => move |_, clock| {
sender.send(Action::PlayerDurationChanged(duration)) sender.send(Action::PlayerDurationChanged(Duration(clock)))
.map_err(|err| error!("Error: {}", err)) .map_err(|err| error!("Error: {}", err))
.ok(); .ok();
})); }));
s.player.connect_position_updated(clone!(sender => move |_, position| { s.player.connect_position_updated(clone!(sender => move |_, clock| {
sender.send(Action::PlayerPositionUpdated(position)) sender.send(Action::PlayerPositionUpdated(Position(clock)))
.map_err(|err| error!("Error: {}", err)) .map_err(|err| error!("Error: {}", err))
.ok(); .ok();
})); }));