From 590e99b7e827df940f4af5b3f873466b46e19d4f Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Thu, 19 Oct 2017 17:22:17 +0300 Subject: [PATCH] Small refinements, handling of unwraps, addin of TODOs and other Notes. --- .../2017-09-15-001128_init_schema/up.sql | 5 +++++ hammond-gtk/gtk/episode_widget.ui | 2 +- hammond-gtk/gtk/foo.ui | 22 ------------------- hammond-gtk/src/headerbar.rs | 9 ++++++-- hammond-gtk/src/main.rs | 4 +--- hammond-gtk/src/utils.rs | 7 ++++-- hammond-gtk/src/views/podcasts_view.rs | 2 +- hammond-gtk/src/widgets/episode.rs | 1 + hammond-gtk/src/widgets/podcast.rs | 2 +- 9 files changed, 22 insertions(+), 32 deletions(-) delete mode 100644 hammond-gtk/gtk/foo.ui diff --git a/hammond-data/migrations/2017-09-15-001128_init_schema/up.sql b/hammond-data/migrations/2017-09-15-001128_init_schema/up.sql index 4c20f39..1ba35d9 100644 --- a/hammond-data/migrations/2017-09-15-001128_init_schema/up.sql +++ b/hammond-data/migrations/2017-09-15-001128_init_schema/up.sql @@ -1,3 +1,8 @@ +-- Till version 0.2 is released the plan is to edited directly and dont expect +-- any kind of non-braking changes. +-- After there is a stable prototype, Only diesel migrations will be used +-- in order to change the db schema. + CREATE TABLE `source` ( `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, `uri` TEXT NOT NULL UNIQUE, diff --git a/hammond-gtk/gtk/episode_widget.ui b/hammond-gtk/gtk/episode_widget.ui index 647d513..6221f55 100644 --- a/hammond-gtk/gtk/episode_widget.ui +++ b/hammond-gtk/gtk/episode_widget.ui @@ -44,7 +44,7 @@ 3 - True + False False 1 diff --git a/hammond-gtk/gtk/foo.ui b/hammond-gtk/gtk/foo.ui deleted file mode 100644 index d2a0dbe..0000000 --- a/hammond-gtk/gtk/foo.ui +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - False - 1000 - 600 - - - True - False - - - - - - - - - - diff --git a/hammond-gtk/src/headerbar.rs b/hammond-gtk/src/headerbar.rs index 460a24e..66eab90 100644 --- a/hammond-gtk/src/headerbar.rs +++ b/hammond-gtk/src/headerbar.rs @@ -30,10 +30,15 @@ pub fn get_headerbar(db: Arc>, stack: gtk::Stack) -> gtk add_button.connect_clicked(move |_| { let tempdb = db_clone.lock().unwrap(); - let url = new_url.get_text().unwrap(); - let _ = index_feed::insert_return_source(&tempdb, &url); + let url = new_url.get_text().unwrap_or_default(); + // TODO: check if the feed is already present. + let f = index_feed::insert_return_source(&tempdb, &url); drop(tempdb); info!("{:?} feed added", url); + if f.is_err() { + error!("Expected Error, feed probably already exists."); + error!("Error: {:?}", f.unwrap_err()); + } // update the db utils::refresh_db(db_clone.clone()); diff --git a/hammond-gtk/src/main.rs b/hammond-gtk/src/main.rs index 1b162ff..03f83e4 100644 --- a/hammond-gtk/src/main.rs +++ b/hammond-gtk/src/main.rs @@ -30,7 +30,6 @@ use views::podcasts_view; /* THIS IS STILL A PROTOTYPE. -THE CODE IS TERIBLE AND USES UNWRAPS EVERYWHERE. */ fn build_ui(app: >k::Application) { @@ -42,7 +41,6 @@ fn build_ui(app: >k::Application) { app.add_window(&window); // Setup the Stack that will magane the switche between podcasts_view and podcast_widget. let stack = podcasts_view::setup_stack(db.clone()); - // Populate the flowbox with the Podcasts. window.add(&stack); // FIXME: @@ -66,7 +64,7 @@ fn build_ui(app: >k::Application) { // ddcb30d01631c0083710cf486caf04c831d38cb7/src/process_viewer.rs#L367 fn main() { loggerv::init_with_level(LogLevel::Info).unwrap(); - hammond_data::init().unwrap(); + hammond_data::init().expect("Hammond Initialazation failed."); // Not sure if needed. if gtk::init().is_err() { diff --git a/hammond-gtk/src/utils.rs b/hammond-gtk/src/utils.rs index b89d312..de4bc9b 100644 --- a/hammond-gtk/src/utils.rs +++ b/hammond-gtk/src/utils.rs @@ -7,7 +7,10 @@ use std::sync::{Arc, Mutex}; pub fn refresh_db(db: Arc>) { let db_clone = db.clone(); thread::spawn(move || { - // FIXME: Handle unwrap - hammond_data::index_feed::index_loop(db_clone.clone(), false).unwrap(); + let t = hammond_data::index_feed::index_loop(db_clone.clone(), false); + if t.is_err() { + error!("Error While trying to update the database."); + error!("Error msg: {}", t.unwrap_err()); + }; }); } diff --git a/hammond-gtk/src/views/podcasts_view.rs b/hammond-gtk/src/views/podcasts_view.rs index 54eee07..d147d63 100644 --- a/hammond-gtk/src/views/podcasts_view.rs +++ b/hammond-gtk/src/views/podcasts_view.rs @@ -30,7 +30,6 @@ pub fn populate_podcasts_flowbox( let image_uri = pd_model.get_value(&iter, 4).get::(); let imgpath = downloader::cache_image(&title, image_uri.as_ref().map(|s| s.as_str())); - let pixbuf = if let Some(i) = imgpath { Pixbuf::new_from_file_at_scale(&i, 200, 200, true).ok() } else { @@ -80,6 +79,7 @@ fn setup_podcasts_grid(db: Arc>, stack: gtk::Stack) { // Adapted copy of the way gnome-music does albumview // FIXME: flowbox childs activate with space/enter but not with clicks. let flowbox: gtk::FlowBox = builder.get_object("flowbox").unwrap(); + // Populate the flowbox with the Podcasts. populate_podcasts_flowbox(db.clone(), stack.clone(), flowbox.clone()); } diff --git a/hammond-gtk/src/widgets/episode.rs b/hammond-gtk/src/widgets/episode.rs index 23ea5ca..f6bb38d 100644 --- a/hammond-gtk/src/widgets/episode.rs +++ b/hammond-gtk/src/widgets/episode.rs @@ -73,6 +73,7 @@ fn epidose_widget( } pub fn episodes_listbox(connection: Arc>, pd_title: &str) -> gtk::ListBox { + // TODO: handle unwraps. let m = connection.lock().unwrap(); let pd = dbqueries::load_podcast(&m, pd_title).unwrap(); let mut episodes = dbqueries::get_pd_episodes(&m, &pd).unwrap(); diff --git a/hammond-gtk/src/widgets/podcast.rs b/hammond-gtk/src/widgets/podcast.rs index b76a1ae..f1ef67b 100644 --- a/hammond-gtk/src/widgets/podcast.rs +++ b/hammond-gtk/src/widgets/podcast.rs @@ -66,7 +66,7 @@ pub fn create_flowbox_child(title: &str, cover: Option) -> gtk::FlowBoxC let fbc = gtk::FlowBoxChild::new(); fbc.add(&box_); - info!("flowbox child created"); + // info!("flowbox child created"); fbc }