Cleanup of downloader module.
This commit is contained in:
+18
-13
@@ -1,22 +1,27 @@
|
||||
[package]
|
||||
authors = ["Jordan Petridis <jordanpetridis@protonmail.com>"]
|
||||
build = "build.rs"
|
||||
name = "hammond-gtk"
|
||||
version = "0.1.0"
|
||||
authors = ["Jordan Petridis <jordanpetridis@protonmail.com>"]
|
||||
workspace = "../"
|
||||
build = "build.rs"
|
||||
|
||||
[dependencies]
|
||||
gtk = { version = "0.2", features = ["v3_22"]}
|
||||
gdk = "0.6"
|
||||
glib = "0.3"
|
||||
gio = "0.2"
|
||||
gdk-pixbuf = "0.2"
|
||||
|
||||
loggerv = "0.4"
|
||||
log = "0.3"
|
||||
open = "1.2"
|
||||
dissolve = "0.2"
|
||||
gdk = "0.6"
|
||||
gdk-pixbuf = "0.2"
|
||||
gio = "0.2"
|
||||
glib = "0.3"
|
||||
log = "0.3"
|
||||
loggerv = "0.4"
|
||||
open = "1.2"
|
||||
rayon = "0.8"
|
||||
|
||||
hammond-data = {path = "../hammond-data"}
|
||||
hammond-downloader = {path = "../hammond-downloader"}
|
||||
[dependencies.gtk]
|
||||
features = ["v3_22"]
|
||||
version = "0.2"
|
||||
|
||||
[dependencies.hammond-data]
|
||||
path = "../hammond-data"
|
||||
|
||||
[dependencies.hammond-downloader]
|
||||
path = "../hammond-downloader"
|
||||
|
||||
@@ -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.title(), pd.image_uri());
|
||||
let cover = get_pixbuf_from_path(pd);
|
||||
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.title(), pd.image_uri());
|
||||
let img = get_pixbuf_from_path(pd);
|
||||
if let Some(i) = img {
|
||||
cover.set_from_pixbuf(&i);
|
||||
}
|
||||
@@ -101,8 +101,8 @@ fn show_played_button(db: &Database, pd: &Podcast, played_button: >k::Button)
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
pub fn get_pixbuf_from_path(pd: &Podcast) -> Option<Pixbuf> {
|
||||
let img_path = downloader::cache_image(pd);
|
||||
if let Some(i) = img_path {
|
||||
Pixbuf::new_from_file_at_scale(&i, 256, 256, true).ok()
|
||||
} else {
|
||||
@@ -130,12 +130,21 @@ pub fn update_podcast_widget(db: &Database, stack: >k::Stack, pd: &Podcast) {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use hammond_data::models::NewPodcast;
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_get_pixbuf_from_path() {
|
||||
let pxbuf =
|
||||
get_pixbuf_from_path("New Rustacean", Some("http://newrustacean.com/podcast.png"));
|
||||
let pd = NewPodcast {
|
||||
title: "New Rustacean".to_string(),
|
||||
description: "".to_string(),
|
||||
link: "".to_string(),
|
||||
image_uri: Some("http://newrustacean.com/podcast.png".to_string()),
|
||||
source_id: 0,
|
||||
};
|
||||
let pd = pd.into_podcast();
|
||||
|
||||
let pxbuf = get_pixbuf_from_path(&pd);
|
||||
assert!(pxbuf.is_some());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user