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