diff --git a/hammond-cli/src/main.rs b/hammond-cli/src/main.rs index deebc72..d032967 100644 --- a/hammond-cli/src/main.rs +++ b/hammond-cli/src/main.rs @@ -51,7 +51,7 @@ fn run() -> Result<()> { if args.up { let db = hammond_data::establish_connection(); let db = Arc::new(Mutex::new(db)); - index_feed::index_loop(db.clone(), false)?; + index_feed::index_loop(&db.clone(), false)?; } if args.dl >= 0 { diff --git a/hammond-data/src/dbqueries.rs b/hammond-data/src/dbqueries.rs index f2079e9..7f0ff31 100644 --- a/hammond-data/src/dbqueries.rs +++ b/hammond-data/src/dbqueries.rs @@ -3,6 +3,8 @@ use diesel::prelude::*; use models::{Episode, Podcast, Source}; +// TODO: Needs cleanup. + pub fn get_sources(con: &SqliteConnection) -> QueryResult> { use schema::source::dsl::*; diff --git a/hammond-gtk/src/headerbar.rs b/hammond-gtk/src/headerbar.rs index c367d22..781a09c 100644 --- a/hammond-gtk/src/headerbar.rs +++ b/hammond-gtk/src/headerbar.rs @@ -1,3 +1,5 @@ +#![cfg_attr(feature = "cargo-clippy", allow(clone_on_ref_ptr))] + use gtk; use gtk::prelude::*; @@ -7,7 +9,7 @@ use utils; use std::sync::{Arc, Mutex}; -pub fn get_headerbar(db: Arc>, stack: gtk::Stack) -> gtk::HeaderBar { +pub fn get_headerbar(db: &Arc>, stack: >k::Stack) -> gtk::HeaderBar { let builder = include_str!("../gtk/headerbar.ui"); let builder = gtk::Builder::new_from_string(builder); @@ -38,7 +40,7 @@ pub fn get_headerbar(db: Arc>, stack: gtk::Stack) -> gtk info!("{:?} feed added", url); if let Ok(mut source) = f { // update the db - utils::refresh_feed(db_clone.clone(), stack_clone.clone(), &mut source); + utils::refresh_feed(&db_clone.clone(), &stack_clone.clone(), &mut source); } else { error!("Expected Error, feed probably already exists."); error!("Error: {:?}", f.unwrap_err()); @@ -60,10 +62,11 @@ pub fn get_headerbar(db: Arc>, stack: gtk::Stack) -> gtk }); let stack_clone = stack.clone(); + let db_clone = db.clone(); // FIXME: There appears to be a memmory leak here. refresh_button.connect_clicked(move |_| { // fsdaa, The things I do for the borrow checker. - utils::refresh_db(db.clone(), stack_clone.clone()); + utils::refresh_db(&db_clone.clone(), &stack_clone.clone()); }); header diff --git a/hammond-gtk/src/main.rs b/hammond-gtk/src/main.rs index f8ab2c2..dcd5dc0 100644 --- a/hammond-gtk/src/main.rs +++ b/hammond-gtk/src/main.rs @@ -1,3 +1,5 @@ +#![cfg_attr(feature = "cargo-clippy", allow(clone_on_ref_ptr))] + // extern crate glib; extern crate gdk; @@ -41,7 +43,7 @@ fn build_ui(app: >k::Application) { window.set_default_size(1050, 600); 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()); + let stack = podcasts_view::setup_stack(&db.clone()); window.add(&stack); // FIXME: @@ -53,7 +55,7 @@ fn build_ui(app: >k::Application) { }); // Get the headerbar - let header = headerbar::get_headerbar(db.clone(), stack.clone()); + let header = headerbar::get_headerbar(&db.clone(), &stack.clone()); // Uncomment this when etag implementation is fixed and refesh_db thread is non blocking. // utils::refresh_db(db.clone(), stack.clone()); window.set_titlebar(&header); diff --git a/hammond-gtk/src/utils.rs b/hammond-gtk/src/utils.rs index 55a4b62..e013bd7 100644 --- a/hammond-gtk/src/utils.rs +++ b/hammond-gtk/src/utils.rs @@ -1,3 +1,5 @@ +#![cfg_attr(feature = "cargo-clippy", allow(clone_on_ref_ptr))] + // use glib; use gtk; @@ -12,10 +14,10 @@ use std::sync::{Arc, Mutex}; use views::podcasts_view; -pub fn refresh_db(db: Arc>, stack: gtk::Stack) { +pub fn refresh_db(db: &Arc>, stack: >k::Stack) { let db_clone = db.clone(); let handle = thread::spawn(move || { - let t = hammond_data::index_feed::index_loop(db_clone.clone(), false); + 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()); @@ -24,25 +26,25 @@ pub fn refresh_db(db: Arc>, stack: gtk::Stack) { // FIXME: atm freezing the ui till update is done. // Make it instead emmit a signal on update completion. // TODO: emit a signal in order to update the podcast widget. - handle.join(); + let _ = handle.join(); - podcasts_view::update_podcasts_view(db.clone(), stack.clone()); + podcasts_view::update_podcasts_view(&db.clone(), &stack.clone()); } -pub fn refresh_feed(db: Arc>, stack: gtk::Stack, source: &mut Source) { +pub fn refresh_feed(db: &Arc>, stack: >k::Stack, source: &mut Source) { let db_clone = db.clone(); let source_ = source.clone(); // TODO: add timeout option and error reporting. let handle = thread::spawn(move || { let db_ = db_clone.lock().unwrap(); - let foo = hammond_data::index_feed::refresh_source(&db_, &mut source_.clone(), false); + let foo_ = hammond_data::index_feed::refresh_source(&db_, &mut source_.clone(), false); drop(db_); - if let Ok((mut req, s)) = foo { + if let Ok((mut req, s)) = foo_ { let s = hammond_data::index_feed::complete_index_from_source( &mut req, &s, - db_clone.clone(), + &db_clone.clone(), ); if s.is_err() { error!("Error While trying to update the database."); @@ -53,9 +55,9 @@ pub fn refresh_feed(db: Arc>, stack: gtk::Stack, source: // FIXME: atm freezing the ui till update is done. // Make it instead emmit a signal on update completion. // TODO: emit a signal in order to update the podcast widget. - handle.join(); + let _ = handle.join(); - podcasts_view::update_podcasts_view(db.clone(), stack.clone()); + podcasts_view::update_podcasts_view(&db.clone(), &stack.clone()); } // https://github. diff --git a/hammond-gtk/src/views/podcasts_view.rs b/hammond-gtk/src/views/podcasts_view.rs index 41ab13a..7690ed9 100644 --- a/hammond-gtk/src/views/podcasts_view.rs +++ b/hammond-gtk/src/views/podcasts_view.rs @@ -1,3 +1,5 @@ +#![cfg_attr(feature = "cargo-clippy", allow(clone_on_ref_ptr))] + use gtk; use gtk::prelude::*; use gtk::StackTransitionType; @@ -11,9 +13,9 @@ use std::sync::{Arc, Mutex}; use widgets::podcast::*; pub fn populate_podcasts_flowbox( - db: Arc>, - stack: gtk::Stack, - flowbox: gtk::FlowBox, + db: &Arc>, + stack: >k::Stack, + flowbox: >k::FlowBox, ) { let tempdb = db.lock().unwrap(); let pd_model = podcast_liststore(&tempdb); @@ -59,7 +61,7 @@ pub fn populate_podcasts_flowbox( stack_clone.remove(&pdw); let pdw = podcast_widget( - db_clone.clone(), + &db_clone.clone(), Some(title.as_str()), description.as_ref().map(|x| x.as_str()), pixbuf.clone(), @@ -78,12 +80,12 @@ pub fn populate_podcasts_flowbox( flowbox.show_all(); } -fn setup_podcast_widget(db: Arc>, stack: gtk::Stack) { - let pd_widget = podcast_widget(db.clone(), None, None, None); +fn setup_podcast_widget(db: &Arc>, stack: >k::Stack) { + let pd_widget = podcast_widget(&db.clone(), None, None, None); stack.add_named(&pd_widget, "pdw"); } -fn setup_podcasts_grid(db: Arc>, stack: gtk::Stack) { +fn setup_podcasts_grid(db: &Arc>, stack: >k::Stack) { let builder = include_str!("../../gtk/podcasts_view.ui"); let builder = gtk::Builder::new_from_string(builder); let grid: gtk::Grid = builder.get_object("grid").unwrap(); @@ -94,14 +96,14 @@ fn setup_podcasts_grid(db: Arc>, stack: gtk::Stack) { // 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()); + populate_podcasts_flowbox(&db.clone(), &stack.clone(), &flowbox.clone()); } -pub fn setup_stack(db: Arc>) -> gtk::Stack { +pub fn setup_stack(db: &Arc>) -> gtk::Stack { let stack = gtk::Stack::new(); let _st_clone = stack.clone(); - setup_podcast_widget(db.clone(), stack.clone()); - setup_podcasts_grid(db.clone(), stack.clone()); + setup_podcast_widget(&db.clone(), &stack.clone()); + setup_podcasts_grid(&db.clone(), &stack.clone()); // stack.connect("foo", true, move |_| { // update_podcasts_view(db.clone(), st_clone.clone()); // None @@ -109,14 +111,14 @@ pub fn setup_stack(db: Arc>) -> gtk::Stack { stack } -pub fn update_podcasts_view(db: Arc>, stack: gtk::Stack) { +pub fn update_podcasts_view(db: &Arc>, stack: >k::Stack) { let builder = include_str!("../../gtk/podcasts_view.ui"); let builder = gtk::Builder::new_from_string(builder); let grid: gtk::Grid = builder.get_object("grid").unwrap(); let flowbox: gtk::FlowBox = builder.get_object("flowbox").unwrap(); // Populate the flowbox with the Podcasts. - populate_podcasts_flowbox(db.clone(), stack.clone(), flowbox.clone()); + populate_podcasts_flowbox(&db.clone(), &stack.clone(), &flowbox.clone()); let old = stack.get_child_by_name("pd_grid").unwrap(); stack.remove(&old); diff --git a/hammond-gtk/src/widgets/episode.rs b/hammond-gtk/src/widgets/episode.rs index 9676867..599cdad 100644 --- a/hammond-gtk/src/widgets/episode.rs +++ b/hammond-gtk/src/widgets/episode.rs @@ -1,3 +1,6 @@ + +#![cfg_attr(feature = "cargo-clippy", allow(clone_on_ref_ptr))] + use open; use diesel::prelude::SqliteConnection; use hammond_data::dbqueries; @@ -17,7 +20,7 @@ use gtk::prelude::*; // use utils; fn epidose_widget( - connection: Arc>, + connection: &Arc>, episode: &mut Episode, pd_title: &str, ) -> gtk::Box { @@ -47,7 +50,7 @@ fn epidose_widget( expander.connect_activate(move |_| { let plain_text = strip_html_tags(&d).join(" "); - desc_label.set_text(&plain_text.trim()) + desc_label.set_text(plain_text.trim()) }); } @@ -63,7 +66,7 @@ fn epidose_widget( }); } - let pd_title_cloned = pd_title.clone().to_owned(); + let pd_title_cloned = pd_title.to_owned(); let db = connection.clone(); let ep_clone = episode.clone(); dl_button.connect_clicked(move |_| { @@ -87,7 +90,7 @@ fn epidose_widget( ep } -pub fn episodes_listbox(connection: Arc>, pd_title: &str) -> gtk::ListBox { +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(); @@ -96,7 +99,7 @@ pub fn episodes_listbox(connection: Arc>, pd_title: &str let list = gtk::ListBox::new(); episodes.iter_mut().for_each(|ep| { - let w = epidose_widget(connection.clone(), ep, pd_title); + let w = epidose_widget(&connection.clone(), ep, pd_title); list.add(&w) }); diff --git a/hammond-gtk/src/widgets/podcast.rs b/hammond-gtk/src/widgets/podcast.rs index f1ef67b..037617b 100644 --- a/hammond-gtk/src/widgets/podcast.rs +++ b/hammond-gtk/src/widgets/podcast.rs @@ -10,7 +10,7 @@ use std::sync::{Arc, Mutex}; use widgets::episode::episodes_listbox; pub fn podcast_widget( - connection: Arc>, + connection: &Arc>, title: Option<&str>, description: Option<&str>, image: Option, @@ -27,7 +27,7 @@ pub fn podcast_widget( if let Some(t) = title { title_label.set_text(t); - let listbox = episodes_listbox(connection.clone(), t); + let listbox = episodes_listbox(&connection.clone(), t); view.add(&listbox); } @@ -56,9 +56,9 @@ pub fn create_flowbox_child(title: &str, cover: Option) -> gtk::FlowBoxC // GDK.TOUCH_MASK // https://developer.gnome.org/gdk3/stable/gdk3-Events.html#GDK-TOUCH-MASK:CAPS // http://gtk-rs.org/docs/gdk/constant.TOUCH_MASK.html - events.add_events(4194304); + events.add_events(4_194_304); - pd_title.set_text(&title); + pd_title.set_text(title); if let Some(img) = cover { pd_cover.set_from_pixbuf(&img);