Favor explicit refference cloning, as suggested by clippy.
This commit is contained in:
parent
048d4800da
commit
5fb783c0c0
@ -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 {
|
||||
|
||||
@ -3,6 +3,8 @@
|
||||
use diesel::prelude::*;
|
||||
use models::{Episode, Podcast, Source};
|
||||
|
||||
// TODO: Needs cleanup.
|
||||
|
||||
pub fn get_sources(con: &SqliteConnection) -> QueryResult<Vec<Source>> {
|
||||
use schema::source::dsl::*;
|
||||
|
||||
|
||||
@ -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<Mutex<SqliteConnection>>, stack: gtk::Stack) -> gtk::HeaderBar {
|
||||
pub fn get_headerbar(db: &Arc<Mutex<SqliteConnection>>, 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<Mutex<SqliteConnection>>, 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<Mutex<SqliteConnection>>, 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
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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<Mutex<SqliteConnection>>, stack: gtk::Stack) {
|
||||
pub fn refresh_db(db: &Arc<Mutex<SqliteConnection>>, 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<Mutex<SqliteConnection>>, 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<Mutex<SqliteConnection>>, stack: gtk::Stack, source: &mut Source) {
|
||||
pub fn refresh_feed(db: &Arc<Mutex<SqliteConnection>>, 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<Mutex<SqliteConnection>>, 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.
|
||||
|
||||
@ -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<Mutex<SqliteConnection>>,
|
||||
stack: gtk::Stack,
|
||||
flowbox: gtk::FlowBox,
|
||||
db: &Arc<Mutex<SqliteConnection>>,
|
||||
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<Mutex<SqliteConnection>>, stack: gtk::Stack) {
|
||||
let pd_widget = podcast_widget(db.clone(), None, None, None);
|
||||
fn setup_podcast_widget(db: &Arc<Mutex<SqliteConnection>>, 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<Mutex<SqliteConnection>>, stack: gtk::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();
|
||||
@ -94,14 +96,14 @@ fn setup_podcasts_grid(db: Arc<Mutex<SqliteConnection>>, 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<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.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<Mutex<SqliteConnection>>) -> gtk::Stack {
|
||||
stack
|
||||
}
|
||||
|
||||
pub fn update_podcasts_view(db: Arc<Mutex<SqliteConnection>>, stack: gtk::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();
|
||||
|
||||
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);
|
||||
|
||||
@ -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<Mutex<SqliteConnection>>,
|
||||
connection: &Arc<Mutex<SqliteConnection>>,
|
||||
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<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();
|
||||
@ -96,7 +99,7 @@ pub fn episodes_listbox(connection: Arc<Mutex<SqliteConnection>>, 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)
|
||||
});
|
||||
|
||||
|
||||
@ -10,7 +10,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>,
|
||||
@ -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<Pixbuf>) -> 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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user