diff --git a/hammond-gtk/src/widgets/episode.rs b/hammond-gtk/src/widgets/episode.rs index 8ec2133..b700daa 100644 --- a/hammond-gtk/src/widgets/episode.rs +++ b/hammond-gtk/src/widgets/episode.rs @@ -189,12 +189,11 @@ impl EpisodeWidget { fn set_total_size(&self, bytes: Option) { if let Some(size) = bytes { if size != 0 { - let s = size.file_size(SIZE_OPTS.clone()); - if let Ok(s) = s { + size.file_size(SIZE_OPTS.clone()).ok().map(|s| { self.total_size.set_text(&s); self.total_size.show(); self.separator2.show(); - } + }); } }; } @@ -250,16 +249,17 @@ fn on_download_clicked(ep: &EpisodeWidgetQuery, sender: Sender) { } fn on_play_bttn_clicked(episode_id: i32) { - let local_uri = dbqueries::get_episode_local_uri_from_id(episode_id).unwrap(); + let local_uri = dbqueries::get_episode_local_uri_from_id(episode_id) + .ok() + .and_then(|x| x); if let Some(uri) = local_uri { if Path::new(&uri).exists() { info!("Opening {}", uri); - let e = open::that(&uri); - if let Err(err) = e { + open::that(&uri).err().map(|err| { error!("Error while trying to open file: {}", uri); error!("Error: {}", err); - }; + }); } } else { error!( @@ -285,14 +285,18 @@ fn update_progressbar_callback( }; // Update local_size label - downloaded.file_size(SIZE_OPTS.clone()).map(|x| local_size.set_text(&x)); + downloaded.file_size(SIZE_OPTS.clone()).ok().map(|x| local_size.set_text(&x)); // I hate floating points. + // Update the progress_bar. if (fraction >= 0.0) && (fraction <= 1.0) && (!fraction.is_nan()) { progress_bar.set_fraction(fraction); } + // info!("Fraction: {}", progress_bar.get_fraction()); // info!("Fraction: {}", fraction); + + // Check if the download is still active let active = { let m = manager::ACTIVE_DOWNLOADS.read().unwrap(); m.contains_key(&episode_rowid) @@ -323,10 +327,8 @@ fn update_total_size_callback(prog: Arc>, total_size: g debug!("Total Size: {}", total_bytes); if total_bytes != 0 { - let size = total_bytes.file_size(SIZE_OPTS.clone()); - if let Ok(s) = size { - total_size.set_text(&s); - } + // Update the total_size label + total_bytes.file_size(SIZE_OPTS.clone()).ok().map(|x| total_size.set_text(&x)); glib::Continue(false) } else { glib::Continue(true) diff --git a/hammond-gtk/src/widgets/show.rs b/hammond-gtk/src/widgets/show.rs index 6470596..eb7fc24 100644 --- a/hammond-gtk/src/widgets/show.rs +++ b/hammond-gtk/src/widgets/show.rs @@ -82,24 +82,22 @@ impl ShowWidget { self.link.set_tooltip_text(Some(link.as_str())); self.link.connect_clicked(move |_| { info!("Opening link: {}", &link); - let _ = open::that(&link); + open::that(&link) + .err() + .map(|err| error!("Something went wrong: {}", err)); }); } /// Populate the listbox with the shows episodes. fn setup_listbox(&self, pd: &Podcast, sender: Sender) { let listbox = episodes_listbox(pd, sender.clone()); - if let Ok(l) = listbox { - self.episodes.add(&l); - } + listbox.ok().map(|l| self.episodes.add(&l)); } /// Set the show cover. fn set_cover(&self, pd: &Podcast) { let img = get_pixbuf_from_path(&pd.clone().into(), 128); - if let Some(i) = img { - self.cover.set_from_pixbuf(&i); - } + img.map(|i| self.cover.set_from_pixbuf(&i)); } /// Set the descripton text. @@ -126,19 +124,17 @@ fn on_unsub_button_clicked( unsub_button.hide(); // Spawn a thread so it won't block the ui. thread::spawn(clone!(pd => move || { - let res = dbqueries::remove_feed(&pd); - if res.is_ok() { + dbqueries::remove_feed(&pd).ok().map(|_| { info!("{} was removed succesfully.", pd.title()); - let dl_fold = downloader::get_download_folder(pd.title()); - if let Ok(fold) = dl_fold { + downloader::get_download_folder(pd.title()).ok().map(|fold| { let res3 = fs::remove_dir_all(&fold); // TODO: Show errors? if res3.is_ok() { info!("All the content at, {} was removed succesfully", &fold); } - }; - } + }); + }); })); shows.switch_podcasts_animated(); // Queue a refresh after the switch to avoid blocking the db.