Added the ability to mark episodes of a Podcast as watched/played.
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
<property name="name">delete_button</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="halign">center</property>
|
||||
<property name="halign">end</property>
|
||||
<property name="valign">center</property>
|
||||
<child>
|
||||
<object class="GtkImage">
|
||||
@@ -37,6 +37,7 @@
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="halign">end</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="margin_top">5</property>
|
||||
<property name="margin_bottom">5</property>
|
||||
@@ -55,13 +56,14 @@
|
||||
<property name="fill">False</property>
|
||||
<property name="padding">5</property>
|
||||
<property name="pack_type">end</property>
|
||||
<property name="position">1</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="play_button">
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="halign">end</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="margin_top">5</property>
|
||||
<property name="margin_bottom">5</property>
|
||||
@@ -79,6 +81,51 @@
|
||||
<property name="fill">False</property>
|
||||
<property name="padding">5</property>
|
||||
<property name="pack_type">end</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="mark_unplayed_button">
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="tooltip_text" translatable="yes">Mark episode as Unplayed.</property>
|
||||
<property name="halign">end</property>
|
||||
<property name="valign">center</property>
|
||||
<child>
|
||||
<object class="GtkImage">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="stock">gtk-undo</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="pack_type">end</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="mark_played_button">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="tooltip_text" translatable="yes">Mark episode as played.</property>
|
||||
<property name="halign">end</property>
|
||||
<property name="valign">center</property>
|
||||
<child>
|
||||
<object class="GtkImage">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="stock">gtk-apply</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="pack_type">end</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
@@ -151,7 +198,6 @@
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="padding">5</property>
|
||||
<property name="position">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
@@ -19,14 +19,12 @@
|
||||
<property name="margin_bottom">32</property>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="width_request">50</property>
|
||||
<property name="height_request">50</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">center</property>
|
||||
<property name="valign">start</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="spacing">18</property>
|
||||
<property name="spacing">15</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="cover">
|
||||
<property name="visible">True</property>
|
||||
@@ -86,9 +84,10 @@
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
<property name="padding">5</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
@@ -114,9 +113,29 @@ Warn: This will delete downloaded content associated with this Podcast.</propert
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="mark_all_played_button">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="tooltip_text" translatable="yes">Mark all episodes as Played.</property>
|
||||
<child>
|
||||
<object class="GtkImage">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="stock">gtk-apply</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
@@ -141,21 +160,21 @@ Warn: This will delete downloaded content associated with this Podcast.</propert
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
@@ -52,6 +52,8 @@ fn epidose_widget(db: &Database, episode: &mut Episode, pd_title: &str) -> gtk::
|
||||
let download_button: gtk::Button = builder.get_object("download_button").unwrap();
|
||||
let play_button: gtk::Button = builder.get_object("play_button").unwrap();
|
||||
let delete_button: gtk::Button = builder.get_object("delete_button").unwrap();
|
||||
let played_button: gtk::Button = builder.get_object("mark_played_button").unwrap();
|
||||
let unplayed_button: gtk::Button = builder.get_object("mark_unplayed_button").unwrap();
|
||||
|
||||
let title_label: gtk::Label = builder.get_object("title_label").unwrap();
|
||||
let desc_label: gtk::Label = builder.get_object("desc_label").unwrap();
|
||||
@@ -73,6 +75,11 @@ fn epidose_widget(db: &Database, episode: &mut Episode, pd_title: &str) -> gtk::
|
||||
});
|
||||
}
|
||||
|
||||
if episode.watched().is_some() {
|
||||
unplayed_button.show();
|
||||
played_button.hide();
|
||||
}
|
||||
|
||||
// Show or hide the play/delete/download buttons upon widget initialization.
|
||||
let local_uri = episode.local_uri();
|
||||
if local_uri.is_some() && Path::new(local_uri.unwrap()).exists() {
|
||||
@@ -83,7 +90,7 @@ fn epidose_widget(db: &Database, episode: &mut Episode, pd_title: &str) -> gtk::
|
||||
|
||||
play_button.connect_clicked(clone!(db, episode => move |_| {
|
||||
on_play_bttn_clicked(&db, episode.id());
|
||||
let _ = set_watched(&db, &mut episode.clone());
|
||||
let _ = set_watched_now(&db, &mut episode.clone());
|
||||
}));
|
||||
|
||||
delete_button.connect_clicked(
|
||||
@@ -95,6 +102,20 @@ fn epidose_widget(db: &Database, episode: &mut Episode, pd_title: &str) -> gtk::
|
||||
}),
|
||||
);
|
||||
|
||||
played_button.connect_clicked(clone!(db, episode, unplayed_button => move |watched| {
|
||||
let _ = set_watched_now(&db, &mut episode.clone());
|
||||
watched.hide();
|
||||
unplayed_button.show();
|
||||
}));
|
||||
|
||||
unplayed_button.connect_clicked(clone!(db, episode, played_button => move |un| {
|
||||
let mut episode = episode.clone();
|
||||
episode.set_watched(None);
|
||||
let _ = episode.save(&db);
|
||||
un.hide();
|
||||
played_button.show();
|
||||
}));
|
||||
|
||||
let pd_title = pd_title.to_owned();
|
||||
download_button.connect_clicked(
|
||||
clone!(db, play_button, delete_button, episode => move |dl| {
|
||||
|
||||
@@ -7,7 +7,7 @@ use std::fs;
|
||||
use hammond_data::models::Podcast;
|
||||
use hammond_downloader::downloader;
|
||||
use hammond_data::index_feed::Database;
|
||||
use hammond_data::dbqueries::{load_podcast_from_title, remove_feed};
|
||||
use hammond_data::dbqueries;
|
||||
|
||||
use widgets::episode::episodes_listbox;
|
||||
use podcasts_view::update_podcasts_view;
|
||||
@@ -30,6 +30,7 @@ macro_rules! clone {
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: Refacto to take a Podcast Stuct as argument instead.
|
||||
pub fn podcast_widget(
|
||||
db: &Database,
|
||||
stack: >k::Stack,
|
||||
@@ -47,6 +48,9 @@ pub fn podcast_widget(
|
||||
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 unsub_button: gtk::Button = pd_widget_buidler.get_object("unsub_button").unwrap();
|
||||
let played_button: gtk::Button = pd_widget_buidler
|
||||
.get_object("mark_all_played_button")
|
||||
.unwrap();
|
||||
|
||||
// TODO: refactor, splitoff, spawn a thread probably.
|
||||
if title.is_some() {
|
||||
@@ -54,10 +58,10 @@ pub fn podcast_widget(
|
||||
unsub_button.connect_clicked(clone!(db, stack, t => move |bttn| {
|
||||
let pd = {
|
||||
let tempdb = db.lock().unwrap();
|
||||
load_podcast_from_title(&tempdb, &t)};
|
||||
dbqueries::load_podcast_from_title(&tempdb, &t)};
|
||||
if let Ok(pd) = pd {
|
||||
|
||||
let res = remove_feed(&db, &pd);
|
||||
let res = dbqueries::remove_feed(&db, &pd);
|
||||
if res.is_ok(){
|
||||
info!("{} was removed succesfully.", &t);
|
||||
// hack to get away without properly checking for none.
|
||||
@@ -93,6 +97,29 @@ pub fn podcast_widget(
|
||||
cover.set_from_pixbuf(&i);
|
||||
}
|
||||
|
||||
// TODO: refactor
|
||||
if let Some(t) = title {
|
||||
let t = t.to_owned();
|
||||
played_button.connect_clicked(clone!(db, stack, t => move |_| {
|
||||
let tempdb = db.lock().unwrap();
|
||||
let parent = dbqueries::load_podcast_from_title(&tempdb, &t).unwrap();
|
||||
let _ = dbqueries::update_none_to_played_now(&tempdb, &parent);
|
||||
drop(tempdb);
|
||||
update_podcast_widget(&db, &stack, &parent);
|
||||
}));
|
||||
}
|
||||
|
||||
if let Some(t) = title {
|
||||
let tempdb = db.lock().unwrap();
|
||||
let parent = dbqueries::load_podcast_from_title(&tempdb, &t).unwrap();
|
||||
let f = dbqueries::get_pd_unplayed_episodes(&tempdb, &parent);
|
||||
if let Ok(l) = f {
|
||||
if l.len() > 0 {
|
||||
played_button.show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pd_widget
|
||||
}
|
||||
|
||||
@@ -158,18 +185,17 @@ pub fn get_pixbuf_from_path(img_path: Option<&str>, pd_title: &str) -> Option<Pi
|
||||
}
|
||||
}
|
||||
|
||||
// pub fn update_podcast_widget(db: &&Database, stack: >k::Stack, pd:
|
||||
// &Podcast){
|
||||
// let old = stack.get_child_by_name("pdw").unwrap();
|
||||
// let pdw = pd_widget_from_diesel_model(&db.clone(), pd, &stack.clone());
|
||||
// let vis = stack.get_visible_child_name().unwrap();
|
||||
pub fn update_podcast_widget(db: &Database, stack: >k::Stack, pd: &Podcast) {
|
||||
let old = stack.get_child_by_name("pdw").unwrap();
|
||||
let pdw = pd_widget_from_diesel_model(db, pd, stack);
|
||||
let vis = stack.get_visible_child_name().unwrap();
|
||||
|
||||
// stack.remove(&old);
|
||||
// stack.add_named(&pdw, "pdw");
|
||||
// stack.set_visible_child_name(&vis);
|
||||
// }
|
||||
stack.remove(&old);
|
||||
stack.add_named(&pdw, "pdw");
|
||||
stack.set_visible_child_name(&vis);
|
||||
}
|
||||
|
||||
// pub fn pd_widget_from_diesel_model(db: &Database, 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)
|
||||
// }
|
||||
fn pd_widget_from_diesel_model(db: &Database, pd: &Podcast, stack: >k::Stack) -> gtk::Box {
|
||||
let img = get_pixbuf_from_path(pd.image_uri(), pd.title());
|
||||
podcast_widget(db, stack, Some(pd.title()), Some(pd.description()), img)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user