EpisodeWidget: Wire the progressbar again.
This commit is contained in:
parent
c303c697a9
commit
a090c11f4a
@ -271,6 +271,11 @@ impl EpisodeWidget {
|
|||||||
// self.info.set_size(size);
|
// self.info.set_size(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn update_progress(&self, local_size: &str, fraction: f64) {
|
||||||
|
self.info.local_size.set_text(local_size);
|
||||||
|
self.progressbar.set_fraction(fraction);
|
||||||
|
}
|
||||||
|
|
||||||
fn determine_buttons_state(
|
fn determine_buttons_state(
|
||||||
widget: &Rc<Self>,
|
widget: &Rc<Self>,
|
||||||
episode: &EpisodeWidgetQuery,
|
episode: &EpisodeWidgetQuery,
|
||||||
@ -329,7 +334,8 @@ impl EpisodeWidget {
|
|||||||
// relying to the RSS feed.
|
// relying to the RSS feed.
|
||||||
update_total_size_callback(&widget, &prog);
|
update_total_size_callback(&widget, &prog);
|
||||||
|
|
||||||
// FIXME: Wire the progress_bar
|
// Setup a callback that will update the progress bar.
|
||||||
|
update_progressbar_callback(&widget, &prog, id);
|
||||||
|
|
||||||
// Change the widget layout/state
|
// Change the widget layout/state
|
||||||
widget.state_prog();
|
widget.state_prog();
|
||||||
@ -427,9 +433,6 @@ fn determine_media_state(
|
|||||||
glib::Continue(true)
|
glib::Continue(true)
|
||||||
});
|
});
|
||||||
gtk::timeout_add(250, callback);
|
gtk::timeout_add(250, callback);
|
||||||
|
|
||||||
// Setup a callback that will update the progress bar.
|
|
||||||
update_progressbar_callback(&prog, &media_machine, id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -480,21 +483,21 @@ fn open_uri(rowid: i32) -> Result<(), Error> {
|
|||||||
#[inline]
|
#[inline]
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(if_same_then_else))]
|
#[cfg_attr(feature = "cargo-clippy", allow(if_same_then_else))]
|
||||||
fn update_progressbar_callback(
|
fn update_progressbar_callback(
|
||||||
|
widget: &Rc<EpisodeWidget>,
|
||||||
prog: &Arc<Mutex<manager::Progress>>,
|
prog: &Arc<Mutex<manager::Progress>>,
|
||||||
media: &Rc<RefCell<MediaMachine>>,
|
|
||||||
episode_rowid: i32,
|
episode_rowid: i32,
|
||||||
) {
|
) {
|
||||||
let callback = clone!(prog, media => move || {
|
let callback = clone!(widget, prog => move || {
|
||||||
progress_bar_helper(&prog, &media, episode_rowid)
|
progress_bar_helper(&widget, &prog, episode_rowid)
|
||||||
.unwrap_or(glib::Continue(false))
|
.unwrap_or(glib::Continue(false))
|
||||||
});
|
});
|
||||||
timeout_add(300, callback);
|
timeout_add(150, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(if_same_then_else)]
|
#[allow(if_same_then_else)]
|
||||||
fn progress_bar_helper(
|
fn progress_bar_helper(
|
||||||
|
widget: &Rc<EpisodeWidget>,
|
||||||
prog: &Arc<Mutex<manager::Progress>>,
|
prog: &Arc<Mutex<manager::Progress>>,
|
||||||
media: &Rc<RefCell<MediaMachine>>,
|
|
||||||
episode_rowid: i32,
|
episode_rowid: i32,
|
||||||
) -> Result<glib::Continue, Error> {
|
) -> Result<glib::Continue, Error> {
|
||||||
let (fraction, downloaded) = {
|
let (fraction, downloaded) = {
|
||||||
@ -512,9 +515,7 @@ fn progress_bar_helper(
|
|||||||
.file_size(SIZE_OPTS.clone())
|
.file_size(SIZE_OPTS.clone())
|
||||||
.map_err(|err| format_err!("{}", err))?;
|
.map_err(|err| format_err!("{}", err))?;
|
||||||
|
|
||||||
if let Ok(mut m) = media.try_borrow_mut() {
|
widget.update_progress(&size, fraction);
|
||||||
m.update_progress(&size, fraction);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// info!("Fraction: {}", progress_bar.get_fraction());
|
// info!("Fraction: {}", progress_bar.get_fraction());
|
||||||
|
|||||||
@ -181,14 +181,6 @@ impl<S> Progress<S> {
|
|||||||
state: Hidden {},
|
state: Hidden {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused_must_use)]
|
|
||||||
// This does not need to be &mut since gtk-rs does not model ownership
|
|
||||||
// But I think it wouldn't hurt if we treat it as a Rust api.
|
|
||||||
fn update_progress(&mut self, local_size: &str, fraction: f64) {
|
|
||||||
self.local_size.set_text(local_size);
|
|
||||||
self.bar.set_fraction(fraction);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@ -264,15 +256,6 @@ impl<X, Z> Media<X, Hidden, Z> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InProgress {
|
|
||||||
#[allow(unused_must_use)]
|
|
||||||
// This does not need to be &mut since gtk-rs does not model ownership
|
|
||||||
// But I think it wouldn't hurt if we treat it as a Rust api.
|
|
||||||
fn update_progress(&mut self, local_size: &str, fraction: f64) {
|
|
||||||
self.progress.update_progress(local_size, fraction)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum ButtonsState {
|
pub enum ButtonsState {
|
||||||
New(Media<Download, Shown, Hidden>),
|
New(Media<Download, Shown, Hidden>),
|
||||||
@ -358,15 +341,6 @@ impl MediaMachine {
|
|||||||
(i @ InProgress(_), _, _, _) => i,
|
(i @ InProgress(_), _, _, _) => i,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_progress(&mut self, local_size: &str, fraction: f64) {
|
|
||||||
use self::MediaMachine::*;
|
|
||||||
|
|
||||||
match *self {
|
|
||||||
Initialized(_) => (),
|
|
||||||
InProgress(ref mut val) => val.update_progress(local_size, fraction),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn size_helper(bytes: Option<i32>) -> Option<String> {
|
fn size_helper(bytes: Option<i32>) -> Option<String> {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user