EpisodeWidget: Remove Podcast depndancy from new() method.
This commit is contained in:
parent
32cd24fc7b
commit
61bd7893c7
@ -84,6 +84,28 @@ pub fn get_episodes_with_limit(limit: u32) -> Result<Vec<Episode>> {
|
||||
.load::<Episode>(&*con)?)
|
||||
}
|
||||
|
||||
pub fn get_episodeswidgets_with_limit(limit: u32) -> Result<Vec<EpisodeWidgetQuery>> {
|
||||
use schema::episode::dsl::*;
|
||||
|
||||
let db = connection();
|
||||
let con = db.get()?;
|
||||
|
||||
Ok(episode
|
||||
.select((
|
||||
rowid,
|
||||
title,
|
||||
uri,
|
||||
local_uri,
|
||||
epoch,
|
||||
length,
|
||||
played,
|
||||
podcast_id,
|
||||
))
|
||||
.order(epoch.desc())
|
||||
.limit(i64::from(limit))
|
||||
.load::<EpisodeWidgetQuery>(&*con)?)
|
||||
}
|
||||
|
||||
pub fn get_podcast_from_id(pid: i32) -> Result<Podcast> {
|
||||
use schema::podcast::dsl::*;
|
||||
|
||||
|
||||
@ -177,6 +177,7 @@
|
||||
<property name="label" translatable="yes">Cancel</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="no_show_all">True</property>
|
||||
<property name="valign">center</property>
|
||||
</object>
|
||||
<packing>
|
||||
@ -191,6 +192,7 @@
|
||||
<property name="name">delete_button</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="no_show_all">True</property>
|
||||
<property name="halign">end</property>
|
||||
<property name="valign">center</property>
|
||||
<child>
|
||||
@ -213,6 +215,7 @@
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="no_show_all">True</property>
|
||||
<property name="halign">end</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="always_show_image">True</property>
|
||||
@ -235,6 +238,7 @@
|
||||
<object class="GtkButton" id="play_button">
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="no_show_all">True</property>
|
||||
<property name="valign">center</property>
|
||||
<child>
|
||||
<object class="GtkImage">
|
||||
@ -271,6 +275,7 @@
|
||||
<child>
|
||||
<object class="GtkProgressBar" id="progress_bar">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="no_show_all">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
||||
@ -156,7 +156,7 @@ struct EpisodeStack {
|
||||
|
||||
impl EpisodeStack {
|
||||
fn new() -> Rc<EpisodeStack> {
|
||||
let episodes = EpisodesView::default();
|
||||
let episodes = EpisodesView::new();
|
||||
let empty = EmptyView::new();
|
||||
let stack = gtk::Stack::new();
|
||||
|
||||
|
||||
@ -1,8 +1,12 @@
|
||||
use gtk;
|
||||
use gtk::prelude::*;
|
||||
|
||||
use hammond_data::dbqueries;
|
||||
|
||||
use widgets::episode::EpisodeWidget;
|
||||
|
||||
use std::rc::Rc;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct EpisodesView {
|
||||
pub container: gtk::Box,
|
||||
@ -22,6 +26,38 @@ impl Default for EpisodesView {
|
||||
}
|
||||
}
|
||||
|
||||
impl EpisodesView {
|
||||
pub fn new() -> Rc<EpisodesView> {
|
||||
let view = EpisodesView::default();
|
||||
|
||||
let episodes = dbqueries::get_episodeswidgets_with_limit(100).unwrap();
|
||||
let frame = gtk::Frame::new("Recent Episodes");
|
||||
let list = gtk::ListBox::new();
|
||||
|
||||
view.frame_parent.add(&frame);
|
||||
frame.add(&list);
|
||||
|
||||
list.set_vexpand(false);
|
||||
list.set_hexpand(false);
|
||||
list.set_visible(true);
|
||||
list.set_selection_mode(gtk::SelectionMode::None);
|
||||
|
||||
episodes.into_iter().for_each(|mut ep| {
|
||||
let widget = EpisodeWidget::new(&mut ep);
|
||||
list.add(&widget.container);
|
||||
|
||||
let sep = gtk::Separator::new(gtk::Orientation::Vertical);
|
||||
sep.set_sensitive(false);
|
||||
sep.set_can_focus(false);
|
||||
|
||||
list.add(&sep);
|
||||
sep.show()
|
||||
});
|
||||
|
||||
Rc::new(view)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct EpisodesViewWidget {
|
||||
container: gtk::Box,
|
||||
|
||||
@ -82,16 +82,16 @@ impl Default for EpisodeWidget {
|
||||
}
|
||||
|
||||
impl EpisodeWidget {
|
||||
pub fn new(episode: &mut EpisodeWidgetQuery, pd: &Podcast) -> EpisodeWidget {
|
||||
pub fn new(episode: &mut EpisodeWidgetQuery) -> EpisodeWidget {
|
||||
let widget = EpisodeWidget::default();
|
||||
widget.init(episode, pd);
|
||||
widget.init(episode);
|
||||
widget
|
||||
}
|
||||
|
||||
// TODO: calculate lenght.
|
||||
// TODO: wire the progress_bar to the downloader.
|
||||
// TODO: wire the cancel button.
|
||||
fn init(&self, episode: &mut EpisodeWidgetQuery, pd: &Podcast) {
|
||||
fn init(&self, episode: &mut EpisodeWidgetQuery) {
|
||||
self.title.set_xalign(0.0);
|
||||
self.title.set_text(episode.title());
|
||||
|
||||
@ -147,7 +147,6 @@ impl EpisodeWidget {
|
||||
download.show();
|
||||
}));
|
||||
|
||||
let pd_title = pd.title().to_owned();
|
||||
let play = &self.play;
|
||||
let delete = &self.delete;
|
||||
let cancel = &self.cancel;
|
||||
@ -155,7 +154,6 @@ impl EpisodeWidget {
|
||||
self.download.connect_clicked(
|
||||
clone!(play, delete, episode, cancel, progress => move |dl| {
|
||||
on_download_clicked(
|
||||
&pd_title,
|
||||
&mut episode.clone(),
|
||||
dl,
|
||||
&play,
|
||||
@ -170,7 +168,6 @@ impl EpisodeWidget {
|
||||
|
||||
// TODO: show notification when dl is finished.
|
||||
fn on_download_clicked(
|
||||
pd_title: &str,
|
||||
ep: &mut EpisodeWidgetQuery,
|
||||
download_bttn: >k::Button,
|
||||
play_bttn: >k::Button,
|
||||
@ -194,7 +191,8 @@ fn on_download_clicked(
|
||||
}),
|
||||
);
|
||||
|
||||
let pd_title = pd_title.to_owned();
|
||||
let pd = dbqueries::get_podcast_from_id(ep.podcast_id()).unwrap();
|
||||
let pd_title = pd.title().to_owned();
|
||||
let mut ep = ep.clone();
|
||||
cancel_bttn.show();
|
||||
progress_bar.show();
|
||||
@ -270,7 +268,7 @@ pub fn episodes_listbox(pd: &Podcast) -> Result<gtk::ListBox> {
|
||||
let list = gtk::ListBox::new();
|
||||
|
||||
episodes.into_iter().for_each(|mut ep| {
|
||||
let widget = EpisodeWidget::new(&mut ep, pd);
|
||||
let widget = EpisodeWidget::new(&mut ep);
|
||||
list.add(&widget.container);
|
||||
|
||||
let sep = gtk::Separator::new(gtk::Orientation::Vertical);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user