diff --git a/hammond-downloader/src/downloader.rs b/hammond-downloader/src/downloader.rs index ff2cffb..fa79a70 100644 --- a/hammond-downloader/src/downloader.rs +++ b/hammond-downloader/src/downloader.rs @@ -120,14 +120,21 @@ fn get_episode(connection: &SqliteConnection, ep: &mut Episode, dl_folder: &str) Ok(()) } -pub fn cache_image(pd: &Podcast) -> Option { - if let Some(url) = pd.image_uri() { +// pub fn cache_image(pd: &Podcast) -> Option { +pub fn cache_image(title: &str, image_uri: Option<&str>) -> Option { + info!("{:?}", image_uri); + if let Some(url) = image_uri { + if url == "" { + return None; + } + let ext = url.split('.').last().unwrap(); - let dl_fold = format!("{}/{}", HAMMOND_CACHE.to_str().unwrap(), pd.title()); + let dl_fold = format!("{}/{}", HAMMOND_CACHE.to_str().unwrap(), title); + info!("Img Dl path: {}", dl_fold); DirBuilder::new().recursive(true).create(&dl_fold).unwrap(); - let dlpath = format!("{}/{}.{}", dl_fold, pd.title(), ext); + let dlpath = format!("{}/{}.{}", dl_fold, title, ext); info!("Cached img path: {}", dlpath); if Path::new(&dlpath).exists() { diff --git a/hammond-gtk/gtk/foo.ui b/hammond-gtk/gtk/foo.ui index d60d972..8a4a060 100644 --- a/hammond-gtk/gtk/foo.ui +++ b/hammond-gtk/gtk/foo.ui @@ -26,8 +26,8 @@ False - 800 - 400 + 1000 + 600 True @@ -59,8 +59,6 @@ 200 True False - center - center True 5 5 diff --git a/hammond-gtk/src/main.rs b/hammond-gtk/src/main.rs index 29662e9..18ef348 100644 --- a/hammond-gtk/src/main.rs +++ b/hammond-gtk/src/main.rs @@ -20,9 +20,9 @@ use hammond_data::dbqueries; use hammond_data::models::Podcast; // TODO: setup a img downloader, caching system, and then display them. -fn create_child(pd: &Podcast) -> gtk::Box { +fn create_child(title: &str, image_uri: Option<&str>) -> gtk::Box { let box_ = gtk::Box::new(Orientation::Vertical, 5); - let imgpath = hammond_downloader::downloader::cache_image(pd); + let imgpath = hammond_downloader::downloader::cache_image(title, image_uri); info!("{:?}", imgpath); let img = if let Some(i) = imgpath { let pixbuf = Pixbuf::new_from_file_at_scale(&i, 200, 200, true); @@ -37,11 +37,9 @@ fn create_child(pd: &Podcast) -> gtk::Box { gtk::Image::new_from_icon_name("gtk-missing-image", IconSize::Menu.into()) }; - img.set_size_request(200, 200); - - let label = gtk::Label::new(pd.title()); + let label = gtk::Label::new(title); box_.set_size_request(200, 200); - box_.pack_start(&img, false, false, 0); + box_.pack_start(&img, true, true, 0); box_.pack_start(&label, false, false, 0); box_ } @@ -142,6 +140,12 @@ fn main() { let header: gtk::HeaderBar = header_build.get_object("headerbar1").unwrap(); window.set_titlebar(&header); + // Debuging TreeStore + // let box2: gtk::Box = builder.get_object("box2").unwrap(); + // let treeview = create_and_setup_view(); + // treeview.set_model(Some(&pd_model)); + // box2.add(&treeview); + let refresh_button: gtk::Button = header_build.get_object("refbutton").unwrap(); // TODO: Have a small dropdown menu let _add_button: gtk::Button = header_build.get_object("addbutton").unwrap(); @@ -163,19 +167,23 @@ fn main() { let flowbox: gtk::FlowBox = builder.get_object("flowbox1").unwrap(); let db = hammond_data::establish_connection(); let pd_model = create_tree_store(&db, &builder); - let podcasts = dbqueries::get_podcasts(&db).unwrap(); - for pd in &podcasts { - let f = create_child(pd); + let iter = pd_model.get_iter_first().unwrap(); + // this will iterate over the episodes. + // let iter = pd_model.iter_children(&iter).unwrap(); + loop { + let title = pd_model.get_value(&iter, 1).get::().unwrap(); + let image_uri = pd_model.get_value(&iter, 5).get::(); + info!("{:?}", title); + let f = create_child(&title, image_uri.as_ref().map(|s| s.as_str())); + flowbox.add(&f); + + if !pd_model.iter_next(&iter) { + break; + } } - // let box2: gtk::Box = builder.get_object("box2").unwrap(); - - // let treeview = create_and_setup_view(); - // treeview.set_model(Some(&pd_model)); - // box2.add(&treeview); - window.show_all(); gtk::main(); }