Implemented Partial feed deletion.
Cleans up the db but it leaves behind the downloaded content atm.
This commit is contained in:
parent
674b233805
commit
0137e1e49b
@ -1,7 +1,10 @@
|
|||||||
#![cfg_attr(feature = "cargo-clippy", allow(let_and_return))]
|
#![cfg_attr(feature = "cargo-clippy", allow(let_and_return))]
|
||||||
|
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::*;
|
||||||
|
use diesel;
|
||||||
use models::{Episode, Podcast, Source};
|
use models::{Episode, Podcast, Source};
|
||||||
|
use index_feed::Database;
|
||||||
|
use errors::*;
|
||||||
|
|
||||||
// TODO: Needs cleanup.
|
// TODO: Needs cleanup.
|
||||||
|
|
||||||
@ -110,3 +113,38 @@ pub fn load_episode_from_uri(con: &SqliteConnection, uri_: &str) -> QueryResult<
|
|||||||
let ep = episode.filter(uri.eq(uri_)).get_result::<Episode>(con);
|
let ep = episode.filter(uri.eq(uri_)).get_result::<Episode>(con);
|
||||||
ep
|
ep
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn remove_feed(db: &Database, pd: &Podcast) -> Result<()> {
|
||||||
|
let s_id = pd.source_id();
|
||||||
|
let pd_id = pd.id();
|
||||||
|
let tempdb = db.lock().unwrap();
|
||||||
|
|
||||||
|
tempdb.transaction(|| -> Result<()> {
|
||||||
|
delete_source(&tempdb, s_id)?;
|
||||||
|
delete_podcast(&tempdb, pd_id)?;
|
||||||
|
delete_podcast_episodes(&tempdb, pd_id)?;
|
||||||
|
Ok(())
|
||||||
|
})?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn delete_source(connection: &SqliteConnection, source_id: i32) -> Result<()> {
|
||||||
|
use schema::source::dsl::*;
|
||||||
|
|
||||||
|
diesel::delete(source.filter(id.eq(source_id))).execute(connection)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn delete_podcast(connection: &SqliteConnection, podcast_id: i32) -> Result<()> {
|
||||||
|
use schema::podcast::dsl::*;
|
||||||
|
|
||||||
|
diesel::delete(podcast.filter(id.eq(podcast_id))).execute(connection)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn delete_podcast_episodes(connection: &SqliteConnection, parent_id: i32) -> Result<()> {
|
||||||
|
use schema::episode::dsl::*;
|
||||||
|
|
||||||
|
diesel::delete(episode.filter(podcast_id.eq(parent_id))).execute(connection)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|||||||
@ -118,6 +118,10 @@ impl Podcast {
|
|||||||
self.id
|
self.id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn source_id(&self) -> i32 {
|
||||||
|
self.source_id
|
||||||
|
}
|
||||||
|
|
||||||
pub fn title(&self) -> &str {
|
pub fn title(&self) -> &str {
|
||||||
&self.title
|
&self.title
|
||||||
}
|
}
|
||||||
|
|||||||
@ -86,12 +86,11 @@ fn epidose_widget(db: &Database, episode: &mut Episode, pd_title: &str) -> gtk::
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
delete_button.connect_clicked(
|
delete_button.connect_clicked(
|
||||||
clone!(episode, db, play_button, download_button => move |del|{
|
clone!(episode, db, play_button, download_button => move |del| {
|
||||||
on_delete_bttn_clicked(&db, episode.id());
|
on_delete_bttn_clicked(&db, episode.id());
|
||||||
del.hide();
|
del.hide();
|
||||||
play_button.hide();
|
play_button.hide();
|
||||||
download_button.show();
|
download_button.show();
|
||||||
// TODO: reload the widget
|
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -5,9 +5,28 @@ use gdk_pixbuf::Pixbuf;
|
|||||||
use hammond_data::models::Podcast;
|
use hammond_data::models::Podcast;
|
||||||
use hammond_downloader::downloader;
|
use hammond_downloader::downloader;
|
||||||
use hammond_data::index_feed::Database;
|
use hammond_data::index_feed::Database;
|
||||||
|
use hammond_data::dbqueries::{load_podcast_from_title, remove_feed};
|
||||||
|
|
||||||
use widgets::episode::episodes_listbox;
|
use widgets::episode::episodes_listbox;
|
||||||
|
|
||||||
|
// http://gtk-rs.org/tuto/closures
|
||||||
|
macro_rules! clone {
|
||||||
|
(@param _) => ( _ );
|
||||||
|
(@param $x:ident) => ( $x );
|
||||||
|
($($n:ident),+ => move || $body:expr) => (
|
||||||
|
{
|
||||||
|
$( let $n = $n.clone(); )+
|
||||||
|
move || $body
|
||||||
|
}
|
||||||
|
);
|
||||||
|
($($n:ident),+ => move |$($p:tt),+| $body:expr) => (
|
||||||
|
{
|
||||||
|
$( let $n = $n.clone(); )+
|
||||||
|
move |$(clone!(@param $p),)+| $body
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn podcast_widget(
|
pub fn podcast_widget(
|
||||||
db: &Database,
|
db: &Database,
|
||||||
title: Option<&str>,
|
title: Option<&str>,
|
||||||
@ -23,6 +42,26 @@ pub fn podcast_widget(
|
|||||||
let title_label: gtk::Label = pd_widget_buidler.get_object("title_label").unwrap();
|
let title_label: gtk::Label = pd_widget_buidler.get_object("title_label").unwrap();
|
||||||
let desc_label: gtk::Label = pd_widget_buidler.get_object("description_label").unwrap();
|
let desc_label: gtk::Label = pd_widget_buidler.get_object("description_label").unwrap();
|
||||||
let view: gtk::Viewport = pd_widget_buidler.get_object("view").unwrap();
|
let view: gtk::Viewport = pd_widget_buidler.get_object("view").unwrap();
|
||||||
|
let unsub_button: gtk::Button = pd_widget_buidler.get_object("unsub_button").unwrap();
|
||||||
|
|
||||||
|
// TODO: handle unwraps properly.
|
||||||
|
// TODO: also remove the downloaded content.
|
||||||
|
if title.is_some() {
|
||||||
|
let t = title.unwrap().to_owned();
|
||||||
|
// TODO: update the stack views after.
|
||||||
|
unsub_button.connect_clicked(clone!(db, t => move |bttn| {
|
||||||
|
let pd = {
|
||||||
|
let tempdb = db.lock().unwrap();
|
||||||
|
load_podcast_from_title(&tempdb, &t).unwrap()};
|
||||||
|
let res = remove_feed(&db, &pd);
|
||||||
|
if res.is_ok(){
|
||||||
|
info!("{} was removed succesfully.", t);
|
||||||
|
// hack to get away without properly checking for none.
|
||||||
|
// if pressed twice would panic.
|
||||||
|
bttn.hide();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(t) = title {
|
if let Some(t) = title {
|
||||||
title_label.set_text(t);
|
title_label.set_text(t);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user