EpidoseWidget: Only refresh background views when download is clicked.

This commit is contained in:
Jordan Petridis 2018-04-11 23:59:08 +03:00
parent 0720222423
commit 8d4fdb8ece
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6

View File

@ -99,7 +99,7 @@ impl EpisodeWidget {
self.set_duration(episode.duration()); self.set_duration(episode.duration());
// Determine what the state of the media widgets should be. // Determine what the state of the media widgets should be.
if let Err(err) = self.determine_media_state(&episode) { if let Err(err) = determine_media_state(self.media.clone(), &episode, &self.container) {
error!("Something went wrong determining the Media State."); error!("Something went wrong determining the Media State.");
error!("Error: {}", err); error!("Error: {}", err);
} }
@ -119,7 +119,9 @@ impl EpisodeWidget {
} }
})); }));
media.download_connect_clicked(clone!(episode, sender => move |dl| { let media_machine = self.media.clone();
let parent = self.container.clone();
media.download_connect_clicked(clone!(media_machine, episode, sender => move |dl| {
dl.set_sensitive(false); dl.set_sensitive(false);
if let Ok(ep) = episode.lock() { if let Ok(ep) = episode.lock() {
if let Err(err) = on_download_clicked(&ep, sender.clone()) { if let Err(err) = on_download_clicked(&ep, sender.clone()) {
@ -127,6 +129,11 @@ impl EpisodeWidget {
error!("Error: {}", err); error!("Error: {}", err);
} else { } else {
info!("Donwload started succesfully."); info!("Donwload started succesfully.");
let line_limit = determine_media_state(media_machine.clone(), &ep, &parent);
if let Err(err) = line_limit {
error!("Something went wrong determining the Media State.");
error!("Error: {}", err);
}
} }
} }
})); }));
@ -153,9 +160,14 @@ impl EpisodeWidget {
let machine = &mut self.duration; let machine = &mut self.duration;
take_mut::take(machine, |duration| duration.determine_state(seconds)); take_mut::take(machine, |duration| duration.determine_state(seconds));
} }
}
fn determine_media_state(&self, episode: &EpisodeWidgetQuery) -> Result<(), Error> { fn determine_media_state(
let id = WidgetExt::get_name(&self.container) media_machine: Arc<Mutex<MediaMachine>>,
episode: &EpisodeWidgetQuery,
parent: &gtk::Box,
) -> Result<(), Error> {
let id = WidgetExt::get_name(parent)
.ok_or_else(|| format_err!("Failed to get widget Name"))? .ok_or_else(|| format_err!("Failed to get widget Name"))?
.parse::<i32>()?; .parse::<i32>()?;
@ -167,7 +179,7 @@ impl EpisodeWidget {
Ok(m.get(&id).cloned()) Ok(m.get(&id).cloned())
}()?; }()?;
let mut lock = self.media.lock().map_err(|err| format_err!("{}", err))?; let mut lock = media_machine.lock().map_err(|err| format_err!("{}", err))?;
take_mut::take(lock.deref_mut(), |media| { take_mut::take(lock.deref_mut(), |media| {
media.determine_state( media.determine_state(
episode.length(), episode.length(),
@ -182,16 +194,15 @@ impl EpisodeWidget {
drop(lock); drop(lock);
// Setup a callback that will update the progress bar. // Setup a callback that will update the progress bar.
update_progressbar_callback(prog.clone(), self.media.clone(), id); update_progressbar_callback(prog.clone(), media_machine.clone(), id);
// 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
// relying to the RSS feed. // relying to the RSS feed.
update_total_size_callback(prog.clone(), self.media.clone()); update_total_size_callback(prog.clone(), media_machine.clone());
} }
Ok(()) Ok(())
}
} }
#[inline] #[inline]
@ -203,8 +214,7 @@ fn on_download_clicked(ep: &EpisodeWidgetQuery, sender: Sender<Action>) -> Resul
manager::add(ep.rowid(), download_fold, sender.clone())?; manager::add(ep.rowid(), download_fold, sender.clone())?;
// Update Views // Update Views
sender.send(Action::RefreshEpisodesView)?; sender.send(Action::RefreshEpisodesViewBGR)?;
sender.send(Action::RefreshWidgetIfVis)?;
Ok(()) Ok(())
} }