My code is horrible, don't look at it.
This commit is contained in:
parent
2b2f44b10e
commit
973212254c
@ -2,6 +2,7 @@ use gtk;
|
|||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
|
|
||||||
use hammond_data::Podcast;
|
use hammond_data::Podcast;
|
||||||
|
use hammond_data::dbqueries;
|
||||||
|
|
||||||
use widgets::podcast::PodcastWidget;
|
use widgets::podcast::PodcastWidget;
|
||||||
use views::podcasts::PopulatedView;
|
use views::podcasts::PopulatedView;
|
||||||
@ -36,6 +37,10 @@ impl Content {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trait UpdateView {
|
||||||
|
fn update(&mut self);
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct Empty {
|
struct Empty {
|
||||||
content: Content
|
content: Content
|
||||||
@ -67,6 +72,10 @@ impl Empty {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl UpdateView for Empty {
|
||||||
|
fn update(&mut self) {}
|
||||||
|
}
|
||||||
|
|
||||||
impl PodcastsView {
|
impl PodcastsView {
|
||||||
fn into_empty(self) -> Result<Empty, PodcastsView> {
|
fn into_empty(self) -> Result<Empty, PodcastsView> {
|
||||||
if !self.content.podcasts.flowbox.get_children().is_empty() {
|
if !self.content.podcasts.flowbox.get_children().is_empty() {
|
||||||
@ -91,6 +100,19 @@ impl PodcastsView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl UpdateView for PodcastsView {
|
||||||
|
fn update(&mut self) {
|
||||||
|
let old = self.content.stack.get_child_by_name("podcasts").unwrap();
|
||||||
|
|
||||||
|
self.content.podcasts = PopulatedView::new_initialized(&self.content.stack);
|
||||||
|
|
||||||
|
self.content.stack.remove(&old);
|
||||||
|
self.content.stack.add_named(&self.content.podcasts.container, "podcasts");
|
||||||
|
|
||||||
|
old.destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl WidgetsView {
|
impl WidgetsView {
|
||||||
fn into_podcasts(self) -> PodcastsView {
|
fn into_podcasts(self) -> PodcastsView {
|
||||||
self.content.stack.set_visible_child_name("podcasts");
|
self.content.stack.set_visible_child_name("podcasts");
|
||||||
@ -107,6 +129,20 @@ impl WidgetsView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl UpdateView for WidgetsView {
|
||||||
|
fn update(&mut self) {
|
||||||
|
let old = self.content.stack.get_child_by_name("widget").unwrap();
|
||||||
|
let id = WidgetExt::get_name(&old).unwrap();
|
||||||
|
let pd = dbqueries::get_podcast_from_id(id.parse::<i32>().unwrap()).unwrap();
|
||||||
|
|
||||||
|
self.content.widget = PodcastWidget::new_initialized(&self.content.stack, &pd);;
|
||||||
|
self.content.stack.remove(&old);
|
||||||
|
self.content.stack.add_named(&self.content.widget.container, "widget");
|
||||||
|
|
||||||
|
old.destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum ContentState {
|
pub enum ContentState {
|
||||||
empty(Empty),
|
empty(Empty),
|
||||||
@ -135,6 +171,14 @@ impl ContentState {
|
|||||||
ContentState::pd(ref e) => e.content.stack.clone(),
|
ContentState::pd(ref e) => e.content.stack.clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn update(&mut self) {
|
||||||
|
match *self {
|
||||||
|
ContentState::empty(ref mut e) => e.update(),
|
||||||
|
ContentState::pop(ref mut e) => e.update(),
|
||||||
|
ContentState::pd(ref mut e) => e.update(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn replace_widget(stack: >k::Stack, pdw: &PodcastWidget) {
|
fn replace_widget(stack: >k::Stack, pdw: &PodcastWidget) {
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use gtk;
|
use gtk;
|
||||||
|
use diesel::Identifiable;
|
||||||
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
@ -53,6 +54,8 @@ impl PodcastWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn init(&self, stack: >k::Stack, pd: &Podcast) {
|
pub fn init(&self, stack: >k::Stack, pd: &Podcast) {
|
||||||
|
WidgetExt::set_name(&self.container, &pd.id().to_string());
|
||||||
|
|
||||||
// TODO: should spawn a thread to avoid locking the UI probably.
|
// TODO: should spawn a thread to avoid locking the UI probably.
|
||||||
self.unsub.connect_clicked(clone!(stack, pd => move |bttn| {
|
self.unsub.connect_clicked(clone!(stack, pd => move |bttn| {
|
||||||
on_unsub_button_clicked(&stack, &pd, bttn);
|
on_unsub_button_clicked(&stack, &pd, bttn);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user