Temporary exposed download cleaner into the gui.

This commit is contained in:
Jordan Petridis 2017-10-28 08:51:59 +03:00
parent eb8fdb2edb
commit 1cdae2b8b0
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
5 changed files with 55 additions and 19 deletions

View File

@ -35,10 +35,11 @@
**DB changes:** **DB changes:**
- [ ] episodes: add watched field - [x] episodes: add watched field
- [ ] Mark episodes/podcast for archival
- [x] Podcast deletion - [x] Podcast deletion
- [ ] Download cleaner - [x] Download cleaner
- [ ] Discuss and decide when to schedule the download cleaner.
- [ ] Mark episodes/podcast for archival
- [ ] Mark stuff as Favorite. Maybe auto-archive favorites? - [ ] Mark stuff as Favorite. Maybe auto-archive favorites?
- [ ] New episode notifier on podcast_flowbox_child, like the one vocal has - [ ] New episode notifier on podcast_flowbox_child, like the one vocal has

View File

@ -10,22 +10,20 @@ use std::path::Path;
use std::fs; use std::fs;
// TODO: Write unit test. // TODO: Write unit test.
pub fn download_checker(db: Database) -> Result<()> { fn download_checker(db: &Database) -> Result<()> {
let mut episodes = { let mut episodes = {
let tempdb = db.lock().unwrap(); let tempdb = db.lock().unwrap();
dbqueries::get_downloaded_episodes(&tempdb)? dbqueries::get_downloaded_episodes(&tempdb)?
}; };
episodes.par_iter_mut().for_each(|ep| { episodes.par_iter_mut().for_each(|ep| {
if ep.local_uri().is_some() { if !Path::new(ep.local_uri().unwrap()).exists() {
if !Path::new(ep.local_uri().unwrap()).exists() { ep.set_local_uri(None);
ep.set_local_uri(None); let res = ep.save(&db.clone());
let res = ep.save(&db.clone()); if let Err(err) = res {
if let Err(err) = res { error!("Error while trying to update episode: {:#?}", ep);
error!("Error while trying to update episode: {:#?}", ep); error!("Error: {}", err);
error!("Error: {}", err); };
};
}
} }
}); });
@ -33,7 +31,7 @@ pub fn download_checker(db: Database) -> Result<()> {
} }
// TODO: Write unit test. // TODO: Write unit test.
pub fn watched_cleaner(db: &Database) -> Result<()> { fn watched_cleaner(db: &Database) -> Result<()> {
let mut episodes = { let mut episodes = {
let tempdb = db.lock().unwrap(); let tempdb = db.lock().unwrap();
dbqueries::get_watched_episodes(&tempdb)? dbqueries::get_watched_episodes(&tempdb)?
@ -46,7 +44,7 @@ pub fn watched_cleaner(db: &Database) -> Result<()> {
// TODO: expose a config and a user set option. // TODO: expose a config and a user set option.
let limit = watched + 172_800; // add 2days in seconds let limit = watched + 172_800; // add 2days in seconds
if now_utc > limit { if now_utc > limit {
let e = delete_local_content(db, &mut ep); let e = delete_local_content(&db.clone(), &mut ep);
if let Err(err) = e { if let Err(err) = e {
error!("Error while trying to delete file: {:?}", ep.local_uri()); error!("Error while trying to delete file: {:?}", ep.local_uri());
error!("Error: {}", err); error!("Error: {}", err);
@ -79,3 +77,16 @@ pub fn delete_local_content(db: &Database, ep: &mut Episode) -> Result<()> {
} }
Ok(()) Ok(())
} }
pub fn set_watched(db: &Database, ep: &mut Episode) -> Result<()> {
let epoch = Utc::now().timestamp() as i32;
ep.set_watched(Some(epoch));
ep.save(db)?;
Ok(())
}
pub fn run(db: &Database) -> Result<()> {
download_checker(db)?;
watched_cleaner(db)?;
Ok(())
}

View File

@ -8,6 +8,7 @@ use errors::*;
#[derive(Queryable, Identifiable, AsChangeset, Associations)] #[derive(Queryable, Identifiable, AsChangeset, Associations)]
#[table_name = "episode"] #[table_name = "episode"]
#[changeset_options(treat_none_as_null = "true")]
#[belongs_to(Podcast, foreign_key = "podcast_id")] #[belongs_to(Podcast, foreign_key = "podcast_id")]
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Episode { pub struct Episode {
@ -113,6 +114,7 @@ impl Episode {
#[derive(Queryable, Identifiable, AsChangeset, Associations)] #[derive(Queryable, Identifiable, AsChangeset, Associations)]
#[belongs_to(Source, foreign_key = "source_id")] #[belongs_to(Source, foreign_key = "source_id")]
#[changeset_options(treat_none_as_null = "true")]
#[table_name = "podcast"] #[table_name = "podcast"]
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Podcast { pub struct Podcast {
@ -170,6 +172,7 @@ impl Podcast {
#[derive(Queryable, Identifiable, AsChangeset)] #[derive(Queryable, Identifiable, AsChangeset)]
#[table_name = "source"] #[table_name = "source"]
#[changeset_options(treat_none_as_null = "true")]
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Source { pub struct Source {
id: i32, id: i32,

View File

@ -15,11 +15,12 @@ extern crate open;
use log::LogLevel; use log::LogLevel;
use hammond_data::index_feed; use hammond_data::index_feed;
use hammond_data::dbcheckup;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use gtk::prelude::*; use gtk::prelude::*;
use gio::ApplicationExt; use gio::{ActionMapExt, ApplicationExt, MenuExt, SimpleActionExt};
mod views; mod views;
mod widgets; mod widgets;
@ -36,6 +37,11 @@ THIS IS STILL A PROTOTYPE.
fn build_ui(app: &gtk::Application) { fn build_ui(app: &gtk::Application) {
let db = Arc::new(Mutex::new(hammond_data::establish_connection())); let db = Arc::new(Mutex::new(hammond_data::establish_connection()));
let menu = gio::Menu::new();
menu.append("Quit", "app.quit");
menu.append("Checkup", "app.check");
app.set_app_menu(&menu);
// Get the main window // Get the main window
let window = gtk::ApplicationWindow::new(app); let window = gtk::ApplicationWindow::new(app);
window.set_default_size(1050, 600); window.set_default_size(1050, 600);
@ -48,10 +54,24 @@ fn build_ui(app: &gtk::Application) {
Inhibit(false) Inhibit(false)
}); });
let quit = gio::SimpleAction::new("quit", None);
let window2 = window.clone();
quit.connect_activate(move |_, _| {
window2.destroy();
});
app.add_action(&quit);
let db2 = db.clone();
let check = gio::SimpleAction::new("check", None);
check.connect_activate(move |_, _| {
let _ = dbcheckup::run(&db2);
});
app.add_action(&check);
// Get the headerbar // Get the headerbar
let header = headerbar::get_headerbar(&db, &stack); let header = headerbar::get_headerbar(&db, &stack);
// TODO: add delay, cause else theres lock contention for the db obj. // TODO: add delay, cause else there's lock contention for the db obj.
// utils::refresh_db(db.clone(), stack.clone()); // utils::refresh_db(db.clone(), stack.clone());
window.set_titlebar(&header); window.set_titlebar(&header);

View File

@ -4,7 +4,7 @@ use hammond_data::dbqueries;
use hammond_data::models::Episode; use hammond_data::models::Episode;
use hammond_downloader::downloader; use hammond_downloader::downloader;
use hammond_data::index_feed::Database; use hammond_data::index_feed::Database;
use hammond_data::dbcheckup::delete_local_content; use hammond_data::dbcheckup::*;
use dissolve::strip_html_tags; use dissolve::strip_html_tags;
@ -81,8 +81,9 @@ fn epidose_widget(db: &Database, episode: &mut Episode, pd_title: &str) -> gtk::
delete_button.show(); delete_button.show();
} }
play_button.connect_clicked(clone!(episode, db => move |_| { play_button.connect_clicked(clone!(db, episode => move |_| {
on_play_bttn_clicked(&db, episode.id()); on_play_bttn_clicked(&db, episode.id());
let _ = set_watched(&db, &mut episode.clone());
})); }));
delete_button.connect_clicked( delete_button.connect_clicked(