EpisodeWidget: Update the local_size label.
This commit is contained in:
parent
c54f29e82a
commit
68d7c621d3
@ -32,6 +32,10 @@ impl Progress {
|
|||||||
pub fn get_total_size(&self) -> u64 {
|
pub fn get_total_size(&self) -> u64 {
|
||||||
self.total_bytes
|
self.total_bytes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_downloaded(&self) -> u64 {
|
||||||
|
self.downloaded_bytes
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Progress {
|
impl Default for Progress {
|
||||||
|
|||||||
@ -206,23 +206,28 @@ impl EpisodeWidget {
|
|||||||
.parse::<i32>()
|
.parse::<i32>()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let m = manager::ACTIVE_DOWNLOADS.read().unwrap();
|
let prog_struct = {
|
||||||
if !m.contains_key(&id) {
|
let m = manager::ACTIVE_DOWNLOADS.read().unwrap();
|
||||||
return;
|
if !m.contains_key(&id) {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
m.get(&id).cloned()
|
||||||
};
|
};
|
||||||
|
|
||||||
let progress_bar = self.progress.clone();
|
let progress_bar = self.progress.clone();
|
||||||
let total_size = self.total_size.clone();
|
let total_size = self.total_size.clone();
|
||||||
if let Some(prog) = m.get(&id) {
|
let local_size = self.local_size.clone();
|
||||||
|
if let Some(prog) = prog_struct {
|
||||||
self.download.hide();
|
self.download.hide();
|
||||||
self.progress.show();
|
self.progress.show();
|
||||||
self.local_size.show();
|
self.local_size.show();
|
||||||
self.total_size.show();
|
self.total_size.show();
|
||||||
|
self.separator2.show();
|
||||||
self.prog_separator.show();
|
self.prog_separator.show();
|
||||||
self.cancel.show();
|
self.cancel.show();
|
||||||
|
|
||||||
// Setup a callback that will update the progress bar.
|
// Setup a callback that will update the progress bar.
|
||||||
update_progressbar_callback(prog.clone(), id, progress_bar);
|
update_progressbar_callback(prog.clone(), id, progress_bar, local_size);
|
||||||
|
|
||||||
// Setup a callback that will update the total_size label
|
// Setup a callback that will update the total_size label
|
||||||
// with the http ContentLength header number rather than
|
// with the http ContentLength header number rather than
|
||||||
@ -269,15 +274,19 @@ fn update_progressbar_callback(
|
|||||||
prog: Arc<Mutex<manager::Progress>>,
|
prog: Arc<Mutex<manager::Progress>>,
|
||||||
episode_rowid: i32,
|
episode_rowid: i32,
|
||||||
progress_bar: gtk::ProgressBar,
|
progress_bar: gtk::ProgressBar,
|
||||||
|
local_size: gtk::Label,
|
||||||
) {
|
) {
|
||||||
timeout_add(
|
timeout_add(
|
||||||
400,
|
400,
|
||||||
clone!(prog, progress_bar=> move || {
|
clone!(prog, progress_bar => move || {
|
||||||
let fraction = {
|
let (fraction, downloaded) = {
|
||||||
let m = prog.lock().unwrap();
|
let m = prog.lock().unwrap();
|
||||||
m.get_fraction()
|
(m.get_fraction(), m.get_downloaded())
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Update local_size label
|
||||||
|
downloaded.file_size(SIZE_OPTS.clone()).map(|x| local_size.set_text(&x));
|
||||||
|
|
||||||
// I hate floating points.
|
// I hate floating points.
|
||||||
if (fraction >= 0.0) && (fraction <= 1.0) && (!fraction.is_nan()) {
|
if (fraction >= 0.0) && (fraction <= 1.0) && (!fraction.is_nan()) {
|
||||||
progress_bar.set_fraction(fraction);
|
progress_bar.set_fraction(fraction);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user