Wired add button, Fixed db refresh and changed the index API.
This commit is contained in:
parent
eb0ee994fe
commit
0e8ea41ca7
@ -16,8 +16,8 @@ use hammond_data::errors::*;
|
||||
use hammond_data::index_feed;
|
||||
use hammond_downloader::downloader;
|
||||
|
||||
// Should probably had made an Enum instead.
|
||||
// TODO: Refactor to enum, add --force for update
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
#[derive(StructOpt, Debug)]
|
||||
#[structopt(name = "example", about = "An example of StructOpt usage.")]
|
||||
struct Opt {
|
||||
@ -50,7 +50,8 @@ fn run() -> Result<()> {
|
||||
|
||||
if args.up {
|
||||
let db = hammond_data::establish_connection();
|
||||
index_feed::index_loop(db, false)?;
|
||||
let db = Arc::new(Mutex::new(db));
|
||||
index_feed::index_loop(db.clone(), false)?;
|
||||
}
|
||||
|
||||
if args.dl >= 0 {
|
||||
|
||||
@ -78,13 +78,11 @@ fn insert_return_episode(con: &SqliteConnection, ep: &NewEpisode) -> Result<Epis
|
||||
Ok(dbqueries::load_episode(con, ep.uri.unwrap())?)
|
||||
}
|
||||
|
||||
pub fn index_loop(db: SqliteConnection, force: bool) -> Result<()> {
|
||||
let m = Arc::new(Mutex::new(db));
|
||||
|
||||
let mut f = fetch_feeds(m.clone(), force)?;
|
||||
pub fn index_loop(db: Arc<Mutex<SqliteConnection>>, force: bool) -> Result<()> {
|
||||
let mut f = fetch_feeds(db.clone(), force)?;
|
||||
|
||||
f.par_iter_mut().for_each(|&mut (ref mut req, ref source)| {
|
||||
complete_index_from_source(req, source, m.clone()).unwrap();
|
||||
complete_index_from_source(req, source, db.clone()).unwrap();
|
||||
});
|
||||
|
||||
Ok(())
|
||||
@ -249,7 +247,8 @@ mod tests {
|
||||
#[test]
|
||||
/// Insert feeds and update/index them.
|
||||
fn test_index_loop() {
|
||||
let TempDB(_tmp_dir, db_path, db) = get_temp_db();
|
||||
let TempDB(_tmp_dir, _db_path, db) = get_temp_db();
|
||||
let db = Arc::new(Mutex::new(db));
|
||||
|
||||
let inpt = vec![
|
||||
"https://request-for-explanation.github.io/podcast/rss.xml",
|
||||
@ -259,16 +258,14 @@ mod tests {
|
||||
];
|
||||
|
||||
inpt.iter().for_each(|feed| {
|
||||
index_source(&db, &NewSource::new_with_uri(feed)).unwrap()
|
||||
let tempdb = db.lock().unwrap();
|
||||
index_source(&tempdb, &NewSource::new_with_uri(feed)).unwrap()
|
||||
});
|
||||
|
||||
index_loop(db, true).unwrap();
|
||||
|
||||
// index_loop takes oweneship of the dbconnection in order to create mutexes.
|
||||
let db = SqliteConnection::establish(db_path.to_str().unwrap()).unwrap();
|
||||
index_loop(db.clone(), true).unwrap();
|
||||
|
||||
// Run again to cover Unique constrains erros.
|
||||
index_loop(db, true).unwrap();
|
||||
index_loop(db.clone(), true).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@ -44,7 +44,7 @@
|
||||
<property name="lines">3</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
@ -78,6 +78,7 @@
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="padding">5</property>
|
||||
<property name="pack_type">end</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
@ -100,6 +101,7 @@
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="padding">5</property>
|
||||
<property name="pack_type">end</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
@ -52,13 +52,12 @@
|
||||
<child>
|
||||
<object class="GtkStack" id="add-button-stack">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="interpolate_size">True</property>
|
||||
<child>
|
||||
<object class="GtkButton" id="add-button">
|
||||
<property name="label" translatable="yes">Add</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="sensitive">False</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<style>
|
||||
|
||||
@ -74,7 +74,6 @@
|
||||
<property name="use_markup">True</property>
|
||||
<property name="wrap">True</property>
|
||||
<property name="wrap_mode">word-char</property>
|
||||
<property name="selectable">True</property>
|
||||
<property name="ellipsize">end</property>
|
||||
<property name="max_width_chars">30</property>
|
||||
<property name="lines">5</property>
|
||||
|
||||
@ -16,6 +16,7 @@ extern crate open;
|
||||
use log::LogLevel;
|
||||
use diesel::prelude::*;
|
||||
use hammond_data::dbqueries;
|
||||
use hammond_data::index_feed;
|
||||
use hammond_data::models::Episode;
|
||||
use hammond_downloader::downloader;
|
||||
|
||||
@ -231,14 +232,26 @@ fn build_ui() {
|
||||
let add_popover: gtk::Popover = header_build.get_object("add-popover").unwrap();
|
||||
let new_url: gtk::Entry = header_build.get_object("new-url").unwrap();
|
||||
let add_button: gtk::Button = header_build.get_object("add-button").unwrap();
|
||||
// TODO: check if url exists in the db and lock the button
|
||||
new_url.connect_changed(move |url| {
|
||||
println!("{:?}", url.get_text());
|
||||
});
|
||||
// FIXME: Button is not clickable for some reason
|
||||
add_button.connect_clicked(move |f| {
|
||||
println!("{:?} feed added", f);
|
||||
let add_popover_clone = add_popover.clone();
|
||||
let db_clone = db.clone();
|
||||
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);
|
||||
drop(tempdb);
|
||||
println!("{:?} feed added", url);
|
||||
|
||||
// update the db
|
||||
// TODO: refactor the update and spin a thread.
|
||||
index_feed::index_loop(db_clone.clone(), false).unwrap();
|
||||
|
||||
// TODO: lock the button instead of hiding and add notification of feed added.
|
||||
add_popover_clone.hide();
|
||||
});
|
||||
// add_button.clicked();
|
||||
add_popover.hide();
|
||||
add_toggle_button.set_popover(&add_popover);
|
||||
|
||||
@ -255,10 +268,10 @@ fn build_ui() {
|
||||
// FIXME: There appears to be a memmory leak here.
|
||||
let db_clone = db.clone();
|
||||
refresh_button.connect_clicked(move |_| {
|
||||
let _db_clone = db_clone.clone();
|
||||
// fsdaa, The things I do for the borrow checker.
|
||||
let db_clone = db_clone.clone();
|
||||
thread::spawn(move || {
|
||||
// let tempdb = db_clone.lock().unwrap();
|
||||
// hammond_data::index_feed::index_loop(*tempdb, false).unwrap();
|
||||
hammond_data::index_feed::index_loop(db_clone.clone(), false).unwrap();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user