Cleaned up a bit the downloader moduel and added some unit tests.
This commit is contained in:
@@ -6,6 +6,8 @@ pub fn init() -> Result<(), Error> {
|
||||
let res_bytes = include_bytes!("../resources/resources.gresource");
|
||||
|
||||
// Create Resource it will live as long the value lives.
|
||||
// TODO: change it into Bytes::From_static once the fix lands
|
||||
// https://bugzilla.gnome.org/show_bug.cgi?id=790030
|
||||
let gbytes = Bytes::from(&res_bytes.as_ref());
|
||||
let resource = Resource::new_from_data(&gbytes)?;
|
||||
// let resource = Resource::new_from_data(&res_bytes.as_ref().into())?;
|
||||
|
||||
@@ -46,7 +46,7 @@ fn create_flowbox_child(db: &Database, pd: &Podcast) -> gtk::FlowBoxChild {
|
||||
|
||||
pd_title.set_text(pd.title());
|
||||
|
||||
let cover = get_pixbuf_from_path(pd.image_uri(), pd.title());
|
||||
let cover = get_pixbuf_from_path(pd.title(), pd.image_uri());
|
||||
if let Some(img) = cover {
|
||||
pd_cover.set_from_pixbuf(&img);
|
||||
};
|
||||
|
||||
@@ -40,7 +40,7 @@ pub fn podcast_widget(db: &Database, stack: >k::Stack, pd: &Podcast) -> gtk::B
|
||||
buff.set_text(pd.description());
|
||||
}
|
||||
|
||||
let img = get_pixbuf_from_path(pd.image_uri(), pd.title());
|
||||
let img = get_pixbuf_from_path(pd.title(), pd.image_uri());
|
||||
if let Some(i) = img {
|
||||
cover.set_from_pixbuf(&i);
|
||||
}
|
||||
@@ -101,7 +101,7 @@ fn show_played_button(db: &Database, pd: &Podcast, played_button: >k::Button)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_pixbuf_from_path(img_path: Option<&str>, pd_title: &str) -> Option<Pixbuf> {
|
||||
pub fn get_pixbuf_from_path(pd_title: &str, img_path: Option<&str>) -> Option<Pixbuf> {
|
||||
let img_path = downloader::cache_image(pd_title, img_path);
|
||||
if let Some(i) = img_path {
|
||||
Pixbuf::new_from_file_at_scale(&i, 256, 256, true).ok()
|
||||
@@ -127,3 +127,15 @@ pub fn update_podcast_widget(db: &Database, stack: >k::Stack, pd: &Podcast) {
|
||||
stack.set_visible_child_name(&vis);
|
||||
old.destroy();
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_get_pixbuf_from_path() {
|
||||
let pxbuf =
|
||||
get_pixbuf_from_path("New Rustacean", Some("http://newrustacean.com/podcast.png"));
|
||||
assert!(pxbuf.is_some());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user