EpisodeWidget: Wire the total_size label again.
The size might be provided by the rss feed but not alwasy. Additionally it might be missleading so when a download starts we replace the label with the HTTP ContentLength header.
This commit is contained in:
parent
9466c5ea10
commit
c303c697a9
@ -324,7 +324,12 @@ impl EpisodeWidget {
|
||||
}));
|
||||
}));
|
||||
|
||||
// FIXME: Wire Total Size label
|
||||
// Setup a callback that will update the total_size label
|
||||
// with the http ContentLength header number rather than
|
||||
// relying to the RSS feed.
|
||||
update_total_size_callback(&widget, &prog);
|
||||
|
||||
// FIXME: Wire the progress_bar
|
||||
|
||||
// Change the widget layout/state
|
||||
widget.state_prog();
|
||||
@ -425,11 +430,6 @@ fn determine_media_state(
|
||||
|
||||
// Setup a callback that will update the progress bar.
|
||||
update_progressbar_callback(&prog, &media_machine, id);
|
||||
|
||||
// Setup a callback that will update the total_size label
|
||||
// with the http ContentLength header number rather than
|
||||
// relying to the RSS feed.
|
||||
update_total_size_callback(&prog, &media_machine);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@ -541,19 +541,16 @@ fn progress_bar_helper(
|
||||
// with the http ContentLength header number rather than
|
||||
// relying to the RSS feed.
|
||||
#[inline]
|
||||
fn update_total_size_callback(
|
||||
prog: &Arc<Mutex<manager::Progress>>,
|
||||
media: &Rc<RefCell<MediaMachine>>,
|
||||
) {
|
||||
let callback = clone!(prog, media => move || {
|
||||
total_size_helper(&prog, &media).unwrap_or(glib::Continue(true))
|
||||
fn update_total_size_callback(widget: &Rc<EpisodeWidget>, prog: &Arc<Mutex<manager::Progress>>) {
|
||||
let callback = clone!(prog, widget => move || {
|
||||
total_size_helper(&widget, &prog).unwrap_or(glib::Continue(true))
|
||||
});
|
||||
timeout_add(500, callback);
|
||||
}
|
||||
|
||||
fn total_size_helper(
|
||||
widget: &Rc<EpisodeWidget>,
|
||||
prog: &Arc<Mutex<manager::Progress>>,
|
||||
media: &Rc<RefCell<MediaMachine>>,
|
||||
) -> Result<glib::Continue, Error> {
|
||||
// Get the total_bytes.
|
||||
let total_bytes = {
|
||||
@ -566,11 +563,7 @@ fn total_size_helper(
|
||||
debug!("Total Size: {}", total_bytes);
|
||||
if total_bytes != 0 {
|
||||
// Update the total_size label
|
||||
if let Ok(mut m) = media.try_borrow_mut() {
|
||||
take_mut::take(m.deref_mut(), |machine| {
|
||||
machine.set_size(Some(total_bytes as i32))
|
||||
});
|
||||
}
|
||||
widget.info.set_size(Some(total_bytes as i32));
|
||||
|
||||
// Do not call again the callback
|
||||
Ok(glib::Continue(false))
|
||||
|
||||
@ -203,14 +203,6 @@ type Playable<Y> = Media<Play, Y, Hidden>;
|
||||
type InProgress = Media<Hidden, Shown, Shown>;
|
||||
|
||||
impl<X, Y, Z> Media<X, Y, Z> {
|
||||
fn set_size(self, s: &str) -> Media<X, Shown, Z> {
|
||||
Media {
|
||||
dl: self.dl,
|
||||
size: self.size.set_size(s),
|
||||
progress: self.progress,
|
||||
}
|
||||
}
|
||||
|
||||
fn hide_size(self) -> Media<X, Hidden, Z> {
|
||||
Media {
|
||||
dl: self.dl,
|
||||
@ -334,21 +326,6 @@ impl ButtonsState {
|
||||
PlayableWithoutSize(m) => m.into_progress(),
|
||||
}
|
||||
}
|
||||
|
||||
fn set_size(self, size: Option<String>) -> Self {
|
||||
use self::ButtonsState::*;
|
||||
|
||||
match (self, size) {
|
||||
(New(m), Some(s)) => New(m.set_size(&s)),
|
||||
(New(m), None) => NewWithoutSize(m.hide_size()),
|
||||
(Playable(m), Some(s)) => Playable(m.set_size(&s)),
|
||||
(Playable(m), None) => PlayableWithoutSize(m.hide_size()),
|
||||
(bttn @ NewWithoutSize(_), None) => bttn,
|
||||
(bttn @ PlayableWithoutSize(_), None) => bttn,
|
||||
(NewWithoutSize(m), Some(s)) => New(m.into_new(&s)),
|
||||
(PlayableWithoutSize(m), Some(s)) => Playable(m.into_playable(&s)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@ -382,17 +359,6 @@ impl MediaMachine {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_size(self, bytes: Option<i32>) -> Self {
|
||||
use self::MediaMachine::*;
|
||||
let size = size_helper(bytes);
|
||||
|
||||
match (self, size) {
|
||||
(Initialized(bttn), s) => Initialized(bttn.set_size(s)),
|
||||
(InProgress(val), Some(s)) => InProgress(val.set_size(&s)),
|
||||
(n @ InProgress(_), None) => n,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update_progress(&mut self, local_size: &str, fraction: f64) {
|
||||
use self::MediaMachine::*;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user