From 90c637ed531c8865a13e2b053bfe2044de701d86 Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Sat, 21 Oct 2017 09:08:03 +0300 Subject: [PATCH] Cleaned up unnecessary clone() calls. --- hammond-downloader/src/downloader.rs | 5 +++-- hammond-gtk/src/headerbar.rs | 4 ++-- hammond-gtk/src/main.rs | 6 +++--- hammond-gtk/src/utils.rs | 16 ++++++---------- hammond-gtk/src/views/podcasts_view.rs | 14 +++++++------- hammond-gtk/src/widgets/episode.rs | 4 ++-- hammond-gtk/src/widgets/podcast.rs | 2 +- 7 files changed, 24 insertions(+), 27 deletions(-) diff --git a/hammond-downloader/src/downloader.rs b/hammond-downloader/src/downloader.rs index 0bf127a..57b41d0 100644 --- a/hammond-downloader/src/downloader.rs +++ b/hammond-downloader/src/downloader.rs @@ -124,8 +124,9 @@ pub fn get_episode(connection: &SqliteConnection, ep: &mut Episode, dl_folder: & let uri = ep.uri().to_owned(); - // This would not be needed in general but I want to be able to block the - // a higher order thread in src/widgets/episode.rs epsode. + // This would not be needed in general but I want to be able to call + // this function from the gtk client. + // should get removed probably once custom callbacks are implemented. thread::spawn(move || { let res = download_to(&dlpath, uri.as_str()); if let Err(err) = res { diff --git a/hammond-gtk/src/headerbar.rs b/hammond-gtk/src/headerbar.rs index 781a09c..80182df 100644 --- a/hammond-gtk/src/headerbar.rs +++ b/hammond-gtk/src/headerbar.rs @@ -40,7 +40,7 @@ pub fn get_headerbar(db: &Arc>, stack: >k::Stack) -> g 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, &stack_clone, &mut source); } else { error!("Expected Error, feed probably already exists."); error!("Error: {:?}", f.unwrap_err()); @@ -66,7 +66,7 @@ pub fn get_headerbar(db: &Arc>, stack: >k::Stack) -> g // 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.clone(), &stack_clone.clone()); + utils::refresh_db(&db_clone, &stack_clone); }); header diff --git a/hammond-gtk/src/main.rs b/hammond-gtk/src/main.rs index dcd5dc0..60da407 100644 --- a/hammond-gtk/src/main.rs +++ b/hammond-gtk/src/main.rs @@ -43,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); window.add(&stack); // FIXME: @@ -55,9 +55,9 @@ fn build_ui(app: >k::Application) { }); // Get the headerbar - let header = headerbar::get_headerbar(&db.clone(), &stack.clone()); + let header = headerbar::get_headerbar(&db, &stack); // Uncomment this when etag implementation is fixed and refesh_db thread is non blocking. - // utils::refresh_db(db.clone(), stack.clone()); + // utils::refresh_db(&db, &stack); window.set_titlebar(&header); window.show_all(); diff --git a/hammond-gtk/src/utils.rs b/hammond-gtk/src/utils.rs index e013bd7..de4c724 100644 --- a/hammond-gtk/src/utils.rs +++ b/hammond-gtk/src/utils.rs @@ -17,7 +17,7 @@ use views::podcasts_view; 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, false); if t.is_err() { error!("Error While trying to update the database."); error!("Error msg: {}", t.unwrap_err()); @@ -28,24 +28,20 @@ pub fn refresh_db(db: &Arc>, stack: >k::Stack) { // TODO: emit a signal in order to update the podcast widget. let _ = handle.join(); - podcasts_view::update_podcasts_view(&db.clone(), &stack.clone()); + podcasts_view::update_podcasts_view(&db, &stack); } pub fn refresh_feed(db: &Arc>, stack: >k::Stack, source: &mut Source) { let db_clone = db.clone(); - let source_ = source.clone(); + let mut 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_, false); drop(db_); if let Ok((mut req, s)) = foo_ { - let s = hammond_data::index_feed::complete_index_from_source( - &mut req, - &s, - &db_clone.clone(), - ); + let s = hammond_data::index_feed::complete_index_from_source(&mut req, &s, &db_clone); if s.is_err() { error!("Error While trying to update the database."); error!("Error msg: {}", s.unwrap_err()); @@ -57,7 +53,7 @@ pub fn refresh_feed(db: &Arc>, stack: >k::Stack, sourc // TODO: emit a signal in order to update the podcast widget. let _ = handle.join(); - podcasts_view::update_podcasts_view(&db.clone(), &stack.clone()); + podcasts_view::update_podcasts_view(&db, &stack); } // https://github. diff --git a/hammond-gtk/src/views/podcasts_view.rs b/hammond-gtk/src/views/podcasts_view.rs index 94b5a0d..d6c3a99 100644 --- a/hammond-gtk/src/views/podcasts_view.rs +++ b/hammond-gtk/src/views/podcasts_view.rs @@ -51,7 +51,7 @@ pub fn populate_podcasts_flowbox( f.connect_activate(move |_| { let old = stack_clone.get_child_by_name("pdw").unwrap(); let pdw = podcast_widget( - &db_clone.clone(), + &db_clone, Some(title.as_str()), description.as_ref().map(|x| x.as_str()), pixbuf.clone(), @@ -72,7 +72,7 @@ pub fn populate_podcasts_flowbox( } fn setup_podcast_widget(db: &Arc>, stack: >k::Stack) { - let pd_widget = podcast_widget(&db.clone(), None, None, None); + let pd_widget = podcast_widget(&db, None, None, None); stack.add_named(&pd_widget, "pdw"); } @@ -87,14 +87,14 @@ fn setup_podcasts_grid(db: &Arc>, stack: >k::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, &stack, &flowbox); } 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()); + // let _st_clone = stack.clone(); + setup_podcast_widget(&db, &stack); + setup_podcasts_grid(&db, &stack); // stack.connect("foo", true, move |_| { // update_podcasts_view(db.clone(), st_clone.clone()); // None @@ -109,7 +109,7 @@ pub fn update_podcasts_view(db: &Arc>, stack: >k::Stac 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, &stack, &flowbox); 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 b4cc355..73486b7 100644 --- a/hammond-gtk/src/widgets/episode.rs +++ b/hammond-gtk/src/widgets/episode.rs @@ -84,7 +84,7 @@ fn epidose_widget( // TODO: emit a signal and show notification when dl is finished and block play_bttn till // then. thread::spawn(move || { - let dl_fold = downloader::get_dl_folder(&pd_title.clone()).unwrap(); + let dl_fold = downloader::get_dl_folder(&pd_title).unwrap(); let tempdb = db_clone.lock().unwrap(); let e = downloader::get_episode(&tempdb, &mut ep_clone, dl_fold.as_str()); drop(tempdb); @@ -109,7 +109,7 @@ pub fn episodes_listbox(connection: &Arc>, pd_title: &st 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, ep, pd_title); list.add(&w) }); diff --git a/hammond-gtk/src/widgets/podcast.rs b/hammond-gtk/src/widgets/podcast.rs index 8f09a97..d285b02 100644 --- a/hammond-gtk/src/widgets/podcast.rs +++ b/hammond-gtk/src/widgets/podcast.rs @@ -110,7 +110,7 @@ pub fn podcast_liststore(connection: &SqliteConnection) -> gtk::ListStore { pub fn pd_widget_from_diesel_model(db: &Arc>, pd: &Podcast) -> gtk::Box { let img = get_pixbuf_from_path(pd.image_uri(), pd.title()); - podcast_widget(&db.clone(), Some(pd.title()), Some(pd.description()), img) + podcast_widget(&db, Some(pd.title()), Some(pd.description()), img) } pub fn get_pixbuf_from_path(img_path: Option<&str>, pd_title: &str) -> Option {