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

View File

@ -21,6 +21,7 @@ use hammond_data::{EpisodeWidgetQuery, PodcastCoverQuery};
use app::Action;
use utils::set_image_from_path;
use std::ops::Deref;
use std::path::Path;
use std::rc::Rc;
use std::sync::Arc;
@ -82,10 +83,30 @@ pub struct PlayerTimes {
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 {
/// 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) {
pub fn on_duration_changed(&self, duration: Duration) {
let seconds = duration.seconds().map(|v| v as f64).unwrap_or(0.0);
self.slider.block_signal(&self.slider_update);
@ -96,7 +117,7 @@ impl PlayerTimes {
}
/// 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);
self.slider.block_signal(&self.slider_update);
@ -212,14 +233,14 @@ impl PlayerWidget {
}));
s.player.connect_duration_changed(clone!(sender => move |_, duration| {
sender.send(Action::PlayerDurationChanged(duration))
s.player.connect_duration_changed(clone!(sender => move |_, clock| {
sender.send(Action::PlayerDurationChanged(Duration(clock)))
.map_err(|err| error!("Error: {}", err))
.ok();
}));
s.player.connect_position_updated(clone!(sender => move |_, position| {
sender.send(Action::PlayerPositionUpdated(position))
s.player.connect_position_updated(clone!(sender => move |_, clock| {
sender.send(Action::PlayerPositionUpdated(Position(clock)))
.map_err(|err| error!("Error: {}", err))
.ok();
}));