Implement download cancel action. #24
This commit is contained in:
@@ -16,6 +16,17 @@ use std::thread;
|
||||
pub struct Progress {
|
||||
total_bytes: u64,
|
||||
downloaded_bytes: u64,
|
||||
cancel: bool,
|
||||
}
|
||||
|
||||
impl Default for Progress {
|
||||
fn default() -> Self {
|
||||
Progress {
|
||||
total_bytes: 0,
|
||||
downloaded_bytes: 0,
|
||||
cancel: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Progress {
|
||||
@@ -37,14 +48,9 @@ impl Progress {
|
||||
pub fn get_downloaded(&self) -> u64 {
|
||||
self.downloaded_bytes
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Progress {
|
||||
fn default() -> Self {
|
||||
Progress {
|
||||
total_bytes: 0,
|
||||
downloaded_bytes: 0,
|
||||
}
|
||||
pub fn cancel(&mut self) {
|
||||
self.cancel = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,6 +62,10 @@ impl DownloadProgress for Progress {
|
||||
fn set_size(&mut self, bytes: u64) {
|
||||
self.total_bytes = bytes;
|
||||
}
|
||||
|
||||
fn should_cancel(&self) -> bool {
|
||||
self.cancel
|
||||
}
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
|
||||
@@ -240,6 +240,13 @@ impl EpisodeWidget {
|
||||
// with the http ContentLength header number rather than
|
||||
// relying to the RSS feed.
|
||||
update_total_size_callback(prog.clone(), total_size);
|
||||
|
||||
self.cancel.connect_clicked(clone!(prog => move |cancel| {
|
||||
if let Ok(mut m) = prog.lock() {
|
||||
m.cancel();
|
||||
cancel.set_sensitive(false);
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user