From a8084e1bdf88192002cf42911663e671e695e6f2 Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Sun, 15 Oct 2017 00:56:31 +0300 Subject: [PATCH] Switched back to a ListStore for now. The dream would be to use One TStroe for all/many views, but that seem to be expensive and not pleasant to work with. Might also completly drop all stores, or at least some, since I could construct the views using just Diesel models. --- hammond-gtk/gtk/foo.ui | 16 ++++++++++++++++ hammond-gtk/src/main.rs | 30 ++++++++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/hammond-gtk/gtk/foo.ui b/hammond-gtk/gtk/foo.ui index e059a4f..7cf9500 100644 --- a/hammond-gtk/gtk/foo.ui +++ b/hammond-gtk/gtk/foo.ui @@ -24,6 +24,22 @@ + + + + + + + + + + + + + + + + False 1000 diff --git a/hammond-gtk/src/main.rs b/hammond-gtk/src/main.rs index d96cb88..2f64c0f 100644 --- a/hammond-gtk/src/main.rs +++ b/hammond-gtk/src/main.rs @@ -89,6 +89,31 @@ fn create_and_fill_tree_store(connection: &SqliteConnection, builder: >k::Buil podcast_model } +fn create_and_fill_list_store( + connection: &SqliteConnection, + builder: >k::Builder, +) -> gtk::ListStore { + let podcast_model: gtk::ListStore = builder.get_object("PdListStore").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(), + ], + ); + } + + podcast_model +} + fn main() { loggerv::init_with_level(LogLevel::Info).unwrap(); @@ -138,14 +163,15 @@ fn main() { let flowbox: gtk::FlowBox = builder.get_object("flowbox1").unwrap(); let db = hammond_data::establish_connection(); - let pd_model = create_and_fill_tree_store(&db, &builder); + // let pd_model = create_and_fill_tree_store(&db, &builder); + let pd_model = create_and_fill_list_store(&db, &builder); 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::(); + let image_uri = pd_model.get_value(&iter, 4).get::(); let f = create_flowbox_child(&title, image_uri.as_ref().map(|s| s.as_str())); let stack_clone = stack.clone();