Changed arguments Arc<T> to bepassed by value, clone on arc just copies the refference anyway.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#![cfg_attr(feature = "cargo-clippy", allow(clone_on_ref_ptr))]
|
||||
#![cfg_attr(feature = "cargo-clippy", allow(needless_pass_by_value))]
|
||||
|
||||
use gtk;
|
||||
use gtk::prelude::*;
|
||||
@@ -40,7 +41,7 @@ pub fn get_headerbar(db: Arc<Mutex<SqliteConnection>>, stack: gtk::Stack) -> gtk
|
||||
info!("{:?} feed added", url);
|
||||
if let Ok(mut source) = f {
|
||||
// update the db
|
||||
utils::refresh_feed(&db_clone, &stack_clone, &mut source);
|
||||
utils::refresh_feed(db_clone.clone(), &stack_clone, &mut source);
|
||||
} else {
|
||||
error!("Expected Error, feed probably already exists.");
|
||||
error!("Error: {:?}", f.unwrap_err());
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#![cfg_attr(feature = "cargo-clippy", allow(clone_on_ref_ptr))]
|
||||
#![cfg_attr(feature = "cargo-clippy", allow(needless_pass_by_value))]
|
||||
|
||||
extern crate gdk;
|
||||
extern crate gdk_pixbuf;
|
||||
@@ -42,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);
|
||||
let stack = podcasts_view::setup_stack(db.clone());
|
||||
window.add(&stack);
|
||||
|
||||
// FIXME:
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#![cfg_attr(feature = "cargo-clippy", allow(clone_on_ref_ptr))]
|
||||
#![cfg_attr(feature = "cargo-clippy", allow(needless_pass_by_value))]
|
||||
|
||||
use glib;
|
||||
|
||||
@@ -33,7 +34,7 @@ pub fn refresh_db(db: Arc<Mutex<SqliteConnection>>, stack: gtk::Stack) {
|
||||
// The implementation of how this is done is probably terrible but it works!.
|
||||
let db_clone = db.clone();
|
||||
thread::spawn(move || {
|
||||
let t = hammond_data::index_feed::index_loop(&db_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());
|
||||
@@ -44,18 +45,19 @@ pub fn refresh_db(db: Arc<Mutex<SqliteConnection>>, stack: gtk::Stack) {
|
||||
});
|
||||
}
|
||||
|
||||
pub fn refresh_feed(db: &Arc<Mutex<SqliteConnection>>, stack: >k::Stack, source: &mut Source) {
|
||||
pub fn refresh_feed(db: Arc<Mutex<SqliteConnection>>, stack: >k::Stack, source: &mut Source) {
|
||||
let db_clone = db.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 db_ = db_clone.clone();
|
||||
let db_ = db_.lock().unwrap();
|
||||
let foo_ = hammond_data::index_feed::refresh_source(&db_, &mut source_, false);
|
||||
drop(db_);
|
||||
|
||||
if let Ok(x) = foo_ {
|
||||
let Feed(mut req, s) = x;
|
||||
let s = hammond_data::index_feed::complete_index_from_source(&mut req, &s, &db_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());
|
||||
@@ -93,7 +95,7 @@ fn receive() -> glib::Continue {
|
||||
GLOBAL.with(|global| {
|
||||
if let Some((ref db, ref stack, ref reciever)) = *global.borrow() {
|
||||
if let Ok(_) = reciever.try_recv() {
|
||||
podcasts_view::update_podcasts_view(db, stack);
|
||||
podcasts_view::update_podcasts_view(db.clone(), stack);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -11,7 +11,7 @@ use std::sync::{Arc, Mutex};
|
||||
use widgets::podcast::*;
|
||||
|
||||
pub fn populate_podcasts_flowbox(
|
||||
db: &Arc<Mutex<SqliteConnection>>,
|
||||
db: Arc<Mutex<SqliteConnection>>,
|
||||
stack: >k::Stack,
|
||||
flowbox: >k::FlowBox,
|
||||
) {
|
||||
@@ -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,
|
||||
db_clone.clone(),
|
||||
Some(title.as_str()),
|
||||
description.as_ref().map(|x| x.as_str()),
|
||||
pixbuf.clone(),
|
||||
@@ -71,12 +71,12 @@ pub fn populate_podcasts_flowbox(
|
||||
flowbox.show_all();
|
||||
}
|
||||
|
||||
fn setup_podcast_widget(db: &Arc<Mutex<SqliteConnection>>, stack: >k::Stack) {
|
||||
fn setup_podcast_widget(db: Arc<Mutex<SqliteConnection>>, stack: >k::Stack) {
|
||||
let pd_widget = podcast_widget(db, None, None, None);
|
||||
stack.add_named(&pd_widget, "pdw");
|
||||
}
|
||||
|
||||
fn setup_podcasts_grid(db: &Arc<Mutex<SqliteConnection>>, stack: >k::Stack) {
|
||||
fn setup_podcasts_grid(db: Arc<Mutex<SqliteConnection>>, 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();
|
||||
@@ -90,19 +90,14 @@ fn setup_podcasts_grid(db: &Arc<Mutex<SqliteConnection>>, stack: >k::Stack) {
|
||||
populate_podcasts_flowbox(db, stack, &flowbox);
|
||||
}
|
||||
|
||||
pub fn setup_stack(db: &Arc<Mutex<SqliteConnection>>) -> gtk::Stack {
|
||||
pub fn setup_stack(db: Arc<Mutex<SqliteConnection>>) -> gtk::Stack {
|
||||
let stack = gtk::Stack::new();
|
||||
// let _st_clone = stack.clone();
|
||||
setup_podcast_widget(db, &stack);
|
||||
setup_podcast_widget(db.clone(), &stack);
|
||||
setup_podcasts_grid(db, &stack);
|
||||
// stack.connect("update_grid", true, move |_| {
|
||||
// update_podcasts_view(&db_clone, &st_clone);
|
||||
// None
|
||||
// });
|
||||
stack
|
||||
}
|
||||
|
||||
pub fn update_podcasts_view(db: &Arc<Mutex<SqliteConnection>>, stack: >k::Stack) {
|
||||
pub fn update_podcasts_view(db: Arc<Mutex<SqliteConnection>>, 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();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
|
||||
#![cfg_attr(feature = "cargo-clippy", allow(clone_on_ref_ptr))]
|
||||
#![cfg_attr(feature = "cargo-clippy", allow(needless_pass_by_value))]
|
||||
|
||||
use open;
|
||||
use diesel::prelude::SqliteConnection;
|
||||
@@ -22,7 +23,7 @@ use gtk::ContainerExt;
|
||||
// use utils;
|
||||
|
||||
fn epidose_widget(
|
||||
connection: &Arc<Mutex<SqliteConnection>>,
|
||||
connection: Arc<Mutex<SqliteConnection>>,
|
||||
episode: &mut Episode,
|
||||
pd_title: &str,
|
||||
) -> gtk::Box {
|
||||
@@ -101,7 +102,7 @@ fn epidose_widget(
|
||||
}
|
||||
|
||||
|
||||
pub fn episodes_listbox(connection: &Arc<Mutex<SqliteConnection>>, pd_title: &str) -> gtk::ListBox {
|
||||
pub fn episodes_listbox(connection: Arc<Mutex<SqliteConnection>>, pd_title: &str) -> gtk::ListBox {
|
||||
// TODO: handle unwraps.
|
||||
let m = connection.lock().unwrap();
|
||||
let pd = dbqueries::load_podcast(&m, pd_title).unwrap();
|
||||
@@ -110,7 +111,7 @@ pub fn episodes_listbox(connection: &Arc<Mutex<SqliteConnection>>, pd_title: &st
|
||||
|
||||
let list = gtk::ListBox::new();
|
||||
episodes.iter_mut().for_each(|ep| {
|
||||
let w = epidose_widget(connection, ep, pd_title);
|
||||
let w = epidose_widget(connection.clone(), ep, pd_title);
|
||||
list.add(&w)
|
||||
});
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ use std::sync::{Arc, Mutex};
|
||||
use widgets::episode::episodes_listbox;
|
||||
|
||||
pub fn podcast_widget(
|
||||
connection: &Arc<Mutex<SqliteConnection>>,
|
||||
connection: Arc<Mutex<SqliteConnection>>,
|
||||
title: Option<&str>,
|
||||
description: Option<&str>,
|
||||
image: Option<Pixbuf>,
|
||||
@@ -29,7 +29,7 @@ pub fn podcast_widget(
|
||||
|
||||
if let Some(t) = title {
|
||||
title_label.set_text(t);
|
||||
let listbox = episodes_listbox(&connection, t);
|
||||
let listbox = episodes_listbox(connection, t);
|
||||
view.add(&listbox);
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ pub fn podcast_liststore(connection: &SqliteConnection) -> gtk::ListStore {
|
||||
// stack.set_visible_child_full("pdw", StackTransitionType::None);
|
||||
// }
|
||||
|
||||
pub fn pd_widget_from_diesel_model(db: &Arc<Mutex<SqliteConnection>>, pd: &Podcast) -> gtk::Box {
|
||||
pub fn pd_widget_from_diesel_model(db: Arc<Mutex<SqliteConnection>>, pd: &Podcast) -> gtk::Box {
|
||||
let img = get_pixbuf_from_path(pd.image_uri(), pd.title());
|
||||
podcast_widget(db, Some(pd.title()), Some(pd.description()), img)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user