EpisodesView: Custom Diesel model not really necessary.
This commit is contained in:
parent
895591f628
commit
914cad72f5
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::*;
|
||||||
use diesel;
|
use diesel;
|
||||||
use models::queryables::{Episode, EpisodeViewWidgetQuery, EpisodeWidgetQuery, Podcast, Source};
|
use models::queryables::{Episode, EpisodeWidgetQuery, Podcast, Source};
|
||||||
use chrono::prelude::*;
|
use chrono::prelude::*;
|
||||||
use errors::*;
|
use errors::*;
|
||||||
|
|
||||||
@ -84,17 +84,13 @@ pub fn get_episodes_with_limit(limit: u32) -> Result<Vec<Episode>> {
|
|||||||
.load::<Episode>(&*con)?)
|
.load::<Episode>(&*con)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_episodes_view_widgets_with_limit(limit: u32) -> Result<Vec<EpisodeViewWidgetQuery>> {
|
pub fn get_episodes_widgets_with_limit(limit: u32) -> Result<Vec<EpisodeWidgetQuery>> {
|
||||||
use schema::{episode, podcast};
|
use schema::episode;
|
||||||
|
|
||||||
joinable!(episode -> podcast (podcast_id));
|
|
||||||
allow_tables_to_appear_in_same_query!(episode, podcast);
|
|
||||||
|
|
||||||
let db = connection();
|
let db = connection();
|
||||||
let con = db.get()?;
|
let con = db.get()?;
|
||||||
|
|
||||||
Ok(episode::table
|
Ok(episode::table
|
||||||
.left_join(podcast::table)
|
|
||||||
.select((
|
.select((
|
||||||
episode::rowid,
|
episode::rowid,
|
||||||
episode::title,
|
episode::title,
|
||||||
@ -104,11 +100,10 @@ pub fn get_episodes_view_widgets_with_limit(limit: u32) -> Result<Vec<EpisodeVie
|
|||||||
episode::length,
|
episode::length,
|
||||||
episode::played,
|
episode::played,
|
||||||
episode::podcast_id,
|
episode::podcast_id,
|
||||||
(podcast::image_uri).nullable(),
|
|
||||||
))
|
))
|
||||||
.order(episode::epoch.desc())
|
.order(episode::epoch.desc())
|
||||||
.limit(i64::from(limit))
|
.limit(i64::from(limit))
|
||||||
.load::<EpisodeViewWidgetQuery>(&*con)?)
|
.load::<EpisodeWidgetQuery>(&*con)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_podcast_from_id(pid: i32) -> Result<Podcast> {
|
pub fn get_podcast_from_id(pid: i32) -> Result<Podcast> {
|
||||||
|
|||||||
@ -61,7 +61,7 @@ pub(crate) mod models;
|
|||||||
mod parser;
|
mod parser;
|
||||||
mod schema;
|
mod schema;
|
||||||
|
|
||||||
pub use models::queryables::{Episode, EpisodeViewWidgetQuery, EpisodeWidgetQuery, Podcast, Source};
|
pub use models::queryables::{Episode, EpisodeWidgetQuery, Podcast, Source};
|
||||||
|
|
||||||
/// [XDG Base Direcotory](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html) Paths.
|
/// [XDG Base Direcotory](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html) Paths.
|
||||||
#[allow(missing_debug_implementations)]
|
#[allow(missing_debug_implementations)]
|
||||||
|
|||||||
@ -320,53 +320,6 @@ impl EpisodeWidgetQuery {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<EpisodeViewWidgetQuery> for EpisodeWidgetQuery {
|
|
||||||
fn from(view: EpisodeViewWidgetQuery) -> EpisodeWidgetQuery {
|
|
||||||
EpisodeWidgetQuery {
|
|
||||||
rowid: view.rowid,
|
|
||||||
title: view.title,
|
|
||||||
uri: view.uri,
|
|
||||||
local_uri: view.local_uri,
|
|
||||||
epoch: view.epoch,
|
|
||||||
length: view.length,
|
|
||||||
played: view.played,
|
|
||||||
// favorite: view.favorite,
|
|
||||||
// archive: view.archive,
|
|
||||||
podcast_id: view.podcast_id,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Queryable, Debug, Clone)]
|
|
||||||
/// Diesel Model to be used for constructing `EpisodeWidgets`.
|
|
||||||
pub struct EpisodeViewWidgetQuery {
|
|
||||||
rowid: i32,
|
|
||||||
title: String,
|
|
||||||
uri: Option<String>,
|
|
||||||
local_uri: Option<String>,
|
|
||||||
epoch: i32,
|
|
||||||
length: Option<i32>,
|
|
||||||
played: Option<i32>,
|
|
||||||
// favorite: bool,
|
|
||||||
// archive: bool,
|
|
||||||
podcast_id: i32,
|
|
||||||
image_uri: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl EpisodeViewWidgetQuery {
|
|
||||||
/// Get the `image_uri`.
|
|
||||||
///
|
|
||||||
/// Represents the uri(url usually) that the Feed cover image is located at.
|
|
||||||
pub fn image_uri(&self) -> Option<&str> {
|
|
||||||
self.image_uri.as_ref().map(|s| s.as_str())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// `Podcast` table foreign key.
|
|
||||||
pub fn podcast_id(&self) -> i32 {
|
|
||||||
self.podcast_id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Queryable, Identifiable, AsChangeset, Associations, PartialEq)]
|
#[derive(Queryable, Identifiable, AsChangeset, Associations, PartialEq)]
|
||||||
#[belongs_to(Source, foreign_key = "source_id")]
|
#[belongs_to(Source, foreign_key = "source_id")]
|
||||||
#[changeset_options(treat_none_as_null = "true")]
|
#[changeset_options(treat_none_as_null = "true")]
|
||||||
|
|||||||
@ -60,6 +60,7 @@ fn refresh_podcasts_view() -> glib::Continue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: use something that would just scale?
|
// FIXME: use something that would just scale?
|
||||||
|
// TODO: make a diesel model with only title, local_uri
|
||||||
|
|
||||||
pub fn get_pixbuf_from_path(pd: &Podcast) -> Option<Pixbuf> {
|
pub fn get_pixbuf_from_path(pd: &Podcast) -> Option<Pixbuf> {
|
||||||
let img_path = downloader::cache_image(pd)?;
|
let img_path = downloader::cache_image(pd)?;
|
||||||
|
|||||||
@ -2,7 +2,7 @@ use gtk;
|
|||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
|
|
||||||
use hammond_data::dbqueries;
|
use hammond_data::dbqueries;
|
||||||
use hammond_data::EpisodeViewWidgetQuery;
|
use hammond_data::EpisodeWidgetQuery;
|
||||||
|
|
||||||
use widgets::episode::EpisodeWidget;
|
use widgets::episode::EpisodeWidget;
|
||||||
use utils::get_pixbuf_from_path_64;
|
use utils::get_pixbuf_from_path_64;
|
||||||
@ -32,7 +32,7 @@ impl EpisodesView {
|
|||||||
pub fn new() -> Rc<EpisodesView> {
|
pub fn new() -> Rc<EpisodesView> {
|
||||||
let view = EpisodesView::default();
|
let view = EpisodesView::default();
|
||||||
|
|
||||||
let episodes = dbqueries::get_episodes_view_widgets_with_limit(100).unwrap();
|
let episodes = dbqueries::get_episodes_widgets_with_limit(100).unwrap();
|
||||||
let frame = gtk::Frame::new(None);
|
let frame = gtk::Frame::new(None);
|
||||||
let list = gtk::ListBox::new();
|
let list = gtk::ListBox::new();
|
||||||
|
|
||||||
@ -45,8 +45,8 @@ impl EpisodesView {
|
|||||||
list.set_visible(true);
|
list.set_visible(true);
|
||||||
list.set_selection_mode(gtk::SelectionMode::None);
|
list.set_selection_mode(gtk::SelectionMode::None);
|
||||||
|
|
||||||
episodes.into_iter().for_each(|ep| {
|
episodes.into_iter().for_each(|mut ep| {
|
||||||
let viewep = EpisodesViewWidget::new(ep);
|
let viewep = EpisodesViewWidget::new(&mut ep);
|
||||||
list.add(&viewep.container);
|
list.add(&viewep.container);
|
||||||
|
|
||||||
let sep = gtk::Separator::new(gtk::Orientation::Vertical);
|
let sep = gtk::Separator::new(gtk::Orientation::Vertical);
|
||||||
@ -86,20 +86,21 @@ impl Default for EpisodesViewWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl EpisodesViewWidget {
|
impl EpisodesViewWidget {
|
||||||
fn new(episode: EpisodeViewWidgetQuery) -> EpisodesViewWidget {
|
fn new(episode: &mut EpisodeWidgetQuery) -> EpisodesViewWidget {
|
||||||
let builder =
|
let builder =
|
||||||
gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/episodes_view_widget.ui");
|
gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/episodes_view_widget.ui");
|
||||||
let container: gtk::Box = builder.get_object("container").unwrap();
|
let container: gtk::Box = builder.get_object("container").unwrap();
|
||||||
let image: gtk::Image = builder.get_object("cover").unwrap();
|
let image: gtk::Image = builder.get_object("cover").unwrap();
|
||||||
|
|
||||||
// FIXME:
|
// FIXME:
|
||||||
let pd = dbqueries::get_podcast_from_id(episode.podcast_id()).unwrap();
|
if let Ok(pd) = dbqueries::get_podcast_from_id(episode.podcast_id()) {
|
||||||
let img = get_pixbuf_from_path_64(&pd);
|
let img = get_pixbuf_from_path_64(&pd);
|
||||||
if let Some(i) = img {
|
if let Some(i) = img {
|
||||||
image.set_from_pixbuf(&i);
|
image.set_from_pixbuf(&i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let ep = EpisodeWidget::new(&mut episode.into());
|
let ep = EpisodeWidget::new(episode);
|
||||||
container.pack_start(&ep.container, true, true, 5);
|
container.pack_start(&ep.container, true, true, 5);
|
||||||
|
|
||||||
EpisodesViewWidget {
|
EpisodesViewWidget {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user