diff --git a/Cargo.lock b/Cargo.lock index ac55762..679aa25 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,7 +2,6 @@ name = "hammond-gtk" version = "0.1.0" dependencies = [ - "diesel 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)", "dissolve 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "gdk 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "gdk-pixbuf 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/hammond-gtk/Cargo.toml b/hammond-gtk/Cargo.toml index 1d3ed4a..a6cc857 100644 --- a/hammond-gtk/Cargo.toml +++ b/hammond-gtk/Cargo.toml @@ -11,7 +11,6 @@ glib = "0.3" gio = "0.2" gdk-pixbuf = "0.2" -diesel = { version = "0.16", features = ["sqlite"] } loggerv = "0.3" log = "0.3" open = "1.2" diff --git a/hammond-gtk/src/main.rs b/hammond-gtk/src/main.rs index 0fa3ff1..a089203 100644 --- a/hammond-gtk/src/main.rs +++ b/hammond-gtk/src/main.rs @@ -4,7 +4,7 @@ extern crate gio; extern crate glib; extern crate gtk; -extern crate diesel; +// extern crate diesel; extern crate dissolve; extern crate hammond_data; extern crate hammond_downloader; diff --git a/hammond-gtk/src/views/podcasts_view.rs b/hammond-gtk/src/views/podcasts_view.rs index 4ce5a70..6c9afa3 100644 --- a/hammond-gtk/src/views/podcasts_view.rs +++ b/hammond-gtk/src/views/podcasts_view.rs @@ -24,65 +24,6 @@ macro_rules! clone { ); } -// NOT IN USE. -// TRYING OUT STORELESS ATM. -pub fn populate_podcasts_flowbox(db: &Database, stack: >k::Stack, flowbox: >k::FlowBox) { - let tempdb = db.lock().unwrap(); - let pd_model = podcast_liststore(&tempdb); - drop(tempdb); - - // Get a ListStore iterator at the first element. - let iter = if let Some(it) = pd_model.get_iter_first() { - it - } else { - // stolen from gnome-news. - let builder = include_str!("../../gtk/empty_view.ui"); - let builder = gtk::Builder::new_from_string(builder); - let view: gtk::Box = builder.get_object("empty_view").unwrap(); - stack.add_named(&view, "empty"); - stack.set_visible_child_name("empty"); - - info!("Empty view."); - return; - }; - - loop { - let title = pd_model - .get_value(&iter, 1) - .get::() - .unwrap_or_default(); - let description = pd_model.get_value(&iter, 2).get::(); - let image_uri = pd_model.get_value(&iter, 4).get::(); - - let pixbuf = get_pixbuf_from_path(image_uri.as_ref().map(|s| s.as_str()), &title); - let f = create_flowbox_child(&title, pixbuf.clone()); - - f.connect_activate(clone!(stack, db => move |_| { - let old = stack.get_child_by_name("pdw").unwrap(); - let pdw = podcast_widget( - &db, - Some(title.as_str()), - description.as_ref().map(|x| x.as_str()), - pixbuf.clone(), - ); - - stack.remove(&old); - stack.add_named(&pdw, "pdw"); - stack.set_visible_child(&pdw); - // aggresive memory cleanup - // probably not needed - old.destroy(); - println!("Hello World!, child activated"); - })); - flowbox.add(&f); - - if !pd_model.iter_next(&iter) { - break; - } - } - flowbox.show_all(); -} - fn show_empty_view(stack: >k::Stack) { let builder = include_str!("../../gtk/empty_view.ui"); let builder = gtk::Builder::new_from_string(builder); @@ -93,7 +34,7 @@ fn show_empty_view(stack: >k::Stack) { info!("Empty view."); } -pub fn populate_flowbox_no_store(db: &Database, stack: >k::Stack, flowbox: >k::FlowBox) { +fn populate_flowbox(db: &Database, stack: >k::Stack, flowbox: >k::FlowBox) { let podcasts = { let db = db.lock().unwrap(); dbqueries::get_podcasts(&db) @@ -114,6 +55,7 @@ pub fn populate_flowbox_no_store(db: &Database, stack: >k::Stack, flowbox: > } else { show_empty_view(stack); } + flowbox.show_all(); } fn setup_podcast_widget(db: &Database, stack: >k::Stack) { @@ -133,7 +75,7 @@ fn setup_podcasts_grid(db: &Database, stack: >k::Stack) { let flowbox: gtk::FlowBox = builder.get_object("flowbox").unwrap(); // Populate the flowbox with the Podcasts. // populate_podcasts_flowbox(db, stack, &flowbox); - populate_flowbox_no_store(db, stack, &flowbox); + populate_flowbox(db, stack, &flowbox); } pub fn setup_stack(db: &Database) -> gtk::Stack { @@ -150,7 +92,7 @@ pub fn update_podcasts_view(db: &Database, stack: >k::Stack) { let flowbox: gtk::FlowBox = builder.get_object("flowbox").unwrap(); // Populate the flowbox with the Podcasts. - populate_podcasts_flowbox(db, stack, &flowbox); + populate_flowbox(db, stack, &flowbox); let old = stack.get_child_by_name("pd_grid").unwrap(); let vis = stack.get_visible_child_name().unwrap(); diff --git a/hammond-gtk/src/widgets/episode.rs b/hammond-gtk/src/widgets/episode.rs index 1c1c123..5954b4f 100644 --- a/hammond-gtk/src/widgets/episode.rs +++ b/hammond-gtk/src/widgets/episode.rs @@ -42,7 +42,6 @@ thread_local!( gtk::Button, Receiver))>> = RefCell::new(None)); -// TODO: REFACTOR AND MODULATE ME. fn epidose_widget(db: &Database, episode: &mut Episode, pd_title: &str) -> gtk::Box { // This is just a prototype and will be reworked probably. let builder = include_str!("../../gtk/episode_widget.ui"); diff --git a/hammond-gtk/src/widgets/podcast.rs b/hammond-gtk/src/widgets/podcast.rs index dbd0681..14f1145 100644 --- a/hammond-gtk/src/widgets/podcast.rs +++ b/hammond-gtk/src/widgets/podcast.rs @@ -2,8 +2,6 @@ use gtk::prelude::*; use gtk; use gdk_pixbuf::Pixbuf; -use diesel::prelude::SqliteConnection; -use hammond_data::dbqueries; use hammond_data::models::Podcast; use hammond_downloader::downloader; use hammond_data::index_feed::Database; @@ -90,31 +88,13 @@ pub fn on_flowbox_child_activate( println!("Hello World!, child activated"); } -// NOT IN USE. -// TRYING OUT STORELESS ATM. -pub fn podcast_liststore(connection: &SqliteConnection) -> gtk::ListStore { - let builder = include_str!("../../gtk/podcast_widget.ui"); - let builder = gtk::Builder::new_from_string(builder); - let podcast_model: gtk::ListStore = builder.get_object("pd_store").unwrap(); - - // TODO: handle unwrap. - let podcasts = dbqueries::get_podcasts(connection).unwrap(); - - for pd in &podcasts { - podcast_model.insert_with_values( - None, - &[0, 1, 2, 3, 4], - &[ - &pd.id(), - &pd.title(), - &pd.description(), - &pd.link(), - &pd.image_uri().unwrap_or_default(), - ], - ); +pub fn get_pixbuf_from_path(img_path: Option<&str>, pd_title: &str) -> Option { + let img_path = downloader::cache_image(pd_title, img_path); + if let Some(i) = img_path { + Pixbuf::new_from_file_at_scale(&i, 200, 200, true).ok() + } else { + None } - - podcast_model } // pub fn update_podcast_widget(db: &&Database, stack: >k::Stack, pd: @@ -132,12 +112,3 @@ pub fn podcast_liststore(connection: &SqliteConnection) -> gtk::ListStore { // let img = get_pixbuf_from_path(pd.image_uri(), pd.title()); // podcast_widget(db, Some(pd.title()), Some(pd.description()), img) // } - -pub fn get_pixbuf_from_path(img_path: Option<&str>, pd_title: &str) -> Option { - let img_path = downloader::cache_image(pd_title, img_path); - if let Some(i) = img_path { - Pixbuf::new_from_file_at_scale(&i, 200, 200, true).ok() - } else { - None - } -}