My code is horrible, don't look at it.

This commit is contained in:
Jordan Petridis 2017-12-07 09:43:47 +02:00
parent 2b2f44b10e
commit 973212254c
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
2 changed files with 47 additions and 0 deletions

View File

@ -2,6 +2,7 @@ use gtk;
use gtk::prelude::*;
use hammond_data::Podcast;
use hammond_data::dbqueries;
use widgets::podcast::PodcastWidget;
use views::podcasts::PopulatedView;
@ -36,6 +37,10 @@ impl Content {
}
}
trait UpdateView {
fn update(&mut self);
}
#[derive(Debug)]
struct Empty {
content: Content
@ -67,6 +72,10 @@ impl Empty {
}
}
impl UpdateView for Empty {
fn update(&mut self) {}
}
impl PodcastsView {
fn into_empty(self) -> Result<Empty, PodcastsView> {
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 {
fn into_podcasts(self) -> PodcastsView {
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)]
pub enum ContentState {
empty(Empty),
@ -135,6 +171,14 @@ impl ContentState {
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: &gtk::Stack, pdw: &PodcastWidget) {

View File

@ -1,5 +1,6 @@
use gtk::prelude::*;
use gtk;
use diesel::Identifiable;
use std::fs;
@ -53,6 +54,8 @@ impl PodcastWidget {
}
pub fn init(&self, stack: &gtk::Stack, pd: &Podcast) {
WidgetExt::set_name(&self.container, &pd.id().to_string());
// TODO: should spawn a thread to avoid locking the UI probably.
self.unsub.connect_clicked(clone!(stack, pd => move |bttn| {
on_unsub_button_clicked(&stack, &pd, bttn);