Initial implementation of the new ShowWidget.
This commit is contained in:
@@ -70,6 +70,11 @@ pub fn get_pixbuf_from_path(pd: &Podcast) -> Option<Pixbuf> {
|
||||
Pixbuf::new_from_file_at_scale(&img_path, 256, 256, true).ok()
|
||||
}
|
||||
|
||||
pub fn get_pixbuf_from_path_128(pd: &Podcast) -> Option<Pixbuf> {
|
||||
let img_path = downloader::cache_image(pd)?;
|
||||
Pixbuf::new_from_file_at_scale(&img_path, 128, 128, true).ok()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use hammond_data::Source;
|
||||
|
||||
@@ -9,7 +9,7 @@ use hammond_data::Podcast;
|
||||
use hammond_downloader::downloader;
|
||||
|
||||
use widgets::episode::episodes_listbox;
|
||||
use utils::get_pixbuf_from_path;
|
||||
use utils::get_pixbuf_from_path_128;
|
||||
use content::ShowStack;
|
||||
use headerbar::Header;
|
||||
|
||||
@@ -19,34 +19,38 @@ use std::rc::Rc;
|
||||
pub struct ShowWidget {
|
||||
pub container: gtk::Box,
|
||||
cover: gtk::Image,
|
||||
title: gtk::Label,
|
||||
description: gtk::TextView,
|
||||
view: gtk::Viewport,
|
||||
description: gtk::Label,
|
||||
link: gtk::Button,
|
||||
settings: gtk::Button,
|
||||
unsub: gtk::Button,
|
||||
played: gtk::Button,
|
||||
episodes: gtk::Box,
|
||||
}
|
||||
|
||||
impl ShowWidget {
|
||||
pub fn new() -> ShowWidget {
|
||||
// Adapted from gnome-music AlbumWidget
|
||||
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/show_widget.ui");
|
||||
let container: gtk::Box = builder.get_object("podcast_widget").unwrap();
|
||||
let container: gtk::Box = builder.get_object("container").unwrap();
|
||||
let episodes: gtk::Box = builder.get_object("episodes").unwrap();
|
||||
|
||||
let cover: gtk::Image = builder.get_object("cover").unwrap();
|
||||
let title: gtk::Label = builder.get_object("title_label").unwrap();
|
||||
let description: gtk::TextView = builder.get_object("desc_text_view").unwrap();
|
||||
let view: gtk::Viewport = builder.get_object("view").unwrap();
|
||||
let description: gtk::Label = builder.get_object("description").unwrap();
|
||||
let unsub: gtk::Button = builder.get_object("unsub_button").unwrap();
|
||||
let played: gtk::Button = builder.get_object("mark_all_played_button").unwrap();
|
||||
let link: gtk::Button = builder.get_object("link_button").unwrap();
|
||||
let settings: gtk::Button = builder.get_object("settings_button").unwrap();
|
||||
|
||||
unsub
|
||||
.get_style_context()
|
||||
.map(|c| c.add_class("destructive-action"));
|
||||
|
||||
ShowWidget {
|
||||
container,
|
||||
cover,
|
||||
title,
|
||||
description,
|
||||
view,
|
||||
unsub,
|
||||
played,
|
||||
link,
|
||||
settings,
|
||||
episodes,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,38 +69,34 @@ impl ShowWidget {
|
||||
header.switch_to_normal();
|
||||
}));
|
||||
|
||||
self.title.set_text(pd.title());
|
||||
let listbox = episodes_listbox(pd);
|
||||
if let Ok(l) = listbox {
|
||||
self.view.add(&l);
|
||||
self.episodes.add(&l);
|
||||
}
|
||||
|
||||
{
|
||||
let buff = self.description.get_buffer().unwrap();
|
||||
buff.set_text(pd.description());
|
||||
}
|
||||
self.description.set_text(pd.description());
|
||||
|
||||
let img = get_pixbuf_from_path(pd);
|
||||
let img = get_pixbuf_from_path_128(pd);
|
||||
if let Some(i) = img {
|
||||
self.cover.set_from_pixbuf(&i);
|
||||
}
|
||||
|
||||
self.played.connect_clicked(clone!(shows, pd => move |_| {
|
||||
on_played_button_clicked(shows.clone(), &pd);
|
||||
}));
|
||||
// self.played.connect_clicked(clone!(shows, pd => move |_| {
|
||||
// on_played_button_clicked(shows.clone(), &pd);
|
||||
// }));
|
||||
|
||||
self.show_played_button(pd);
|
||||
// self.show_played_button(pd);
|
||||
}
|
||||
|
||||
fn show_played_button(&self, pd: &Podcast) {
|
||||
let new_episodes = dbqueries::get_pd_unplayed_episodes(pd);
|
||||
// fn show_played_button(&self, pd: &Podcast) {
|
||||
// let new_episodes = dbqueries::get_pd_unplayed_episodes(pd);
|
||||
|
||||
if let Ok(n) = new_episodes {
|
||||
if !n.is_empty() {
|
||||
self.played.show()
|
||||
}
|
||||
}
|
||||
}
|
||||
// if let Ok(n) = new_episodes {
|
||||
// if !n.is_empty() {
|
||||
// self.played.show()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
fn on_unsub_button_clicked(shows: Rc<ShowStack>, pd: &Podcast, unsub_button: >k::Button) {
|
||||
|
||||
Reference in New Issue
Block a user