podcasts_view further refactoring.

This commit is contained in:
Jordan Petridis 2017-10-18 22:24:05 +03:00
parent 0ed6fee39f
commit 70d1f44147
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
9 changed files with 112 additions and 90 deletions

View File

@ -11,58 +11,7 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkGrid" id="grid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="row_homogeneous">True</property>
<property name="column_homogeneous">True</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkViewport">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkFlowBox" id="flowbox1">
<property name="name">FlowBox1</property>
<property name="width_request">600</property>
<property name="height_request">600</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="homogeneous">True</property>
<property name="column_spacing">5</property>
<property name="row_spacing">5</property>
<property name="max_children_per_line">25</property>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
</object>
<packing>
<property name="name">page0</property>
<property name="title" translatable="yes">page0</property>
</packing>
<placeholder/>
</child>
</object>
</child>

View File

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.1 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkGrid" id="grid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="row_homogeneous">True</property>
<property name="column_homogeneous">True</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkViewport">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkFlowBox" id="flowbox">
<property name="name">FlowBox1</property>
<property name="width_request">600</property>
<property name="height_request">600</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="homogeneous">True</property>
<property name="column_spacing">5</property>
<property name="row_spacing">5</property>
<property name="max_children_per_line">25</property>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
</object>
</interface>

View File

@ -1,17 +1,13 @@
use gtk;
use gtk::prelude::*;
use diesel::prelude::*;
use diesel::prelude::SqliteConnection;
use index_feed;
use utils;
use std::sync::{Arc, Mutex};
pub fn get_headerbar(
db: Arc<Mutex<SqliteConnection>>,
stack: gtk::Stack,
grid: gtk::Grid,
) -> gtk::HeaderBar {
pub fn get_headerbar(db: Arc<Mutex<SqliteConnection>>, stack: gtk::Stack) -> gtk::HeaderBar {
let builder = include_str!("../gtk/headerbar.ui");
let builder = gtk::Builder::new_from_string(builder);
@ -43,6 +39,7 @@ pub fn get_headerbar(
utils::refresh_db(db_clone.clone());
// TODO: lock the button instead of hiding and add notification of feed added.
// TODO: map the spinner
add_popover_clone.hide();
});
add_popover.hide();
@ -50,6 +47,7 @@ pub fn get_headerbar(
// TODO: make it a back arrow button, that will hide when appropriate,
// and add a StackSwitcher when more views are added.
let grid = stack.get_child_by_name("pd_grid").unwrap();
home_button.connect_clicked(move |_| stack.set_visible_child(&grid));
// FIXME: There appears to be a memmory leak here.

View File

@ -26,26 +26,24 @@ pub mod widgets;
pub mod headerbar;
pub mod utils;
use widgets::podcast::*;
use views::podcasts_view::populate_podcasts_flowbox;
use views::podcasts_view;
/*
THIS IS STILL A PROTOTYPE.
THE CODE IS TERIBLE AND USES UNWRAPS EVERYWHERE.
*/
fn build_ui() {
let glade_src = include_str!("../gtk/foo.ui");
let builder = gtk::Builder::new_from_string(glade_src);
fn build_ui(app: &gtk::Application) {
let db = Arc::new(Mutex::new(hammond_data::establish_connection()));
// Get the main window
let window: gtk::Window = builder.get_object("window1").unwrap();
// Get the Stack
let stack: gtk::Stack = builder.get_object("stack1").unwrap();
let db = Arc::new(Mutex::new(hammond_data::establish_connection()));
let pd_widget = podcast_widget(db.clone(), None, None, None);
stack.add_named(&pd_widget, "pdw");
let window = gtk::ApplicationWindow::new(app);
window.set_default_size(1000, 600);
app.add_window(&window);
// Setup the Stack that will magane the switche between podcasts_view and podcast_widget.
let stack = podcasts_view::setup_stack(db.clone());
// Populate the flowbox with the Podcasts.
window.add(&stack);
// FIXME:
// GLib-GIO-WARNING **: Your application does not implement g_application_activate()
@ -55,17 +53,10 @@ fn build_ui() {
Inhibit(false)
});
// Adapted copy of the way gnome-music does albumview
// FIXME: flowbox childs activate with space/enter but not with clicks.
let flowbox: gtk::FlowBox = builder.get_object("flowbox1").unwrap();
let grid: gtk::Grid = builder.get_object("grid").unwrap();
// Get the headerbar
let header = headerbar::get_headerbar(db.clone(), stack.clone(), grid.clone());
let header = headerbar::get_headerbar(db.clone(), stack.clone());
window.set_titlebar(&header);
populate_podcasts_flowbox(db.clone(), stack.clone(), flowbox.clone());
window.show_all();
gtk::main();
}
@ -88,8 +79,8 @@ fn main() {
gio::ApplicationFlags::empty(),
).expect("Initialization failed...");
application.connect_startup(move |_| {
build_ui();
application.connect_startup(move |app| {
build_ui(app);
});
// Not sure if this will be kept.

View File

@ -1,5 +1,5 @@
use hammond_data;
use diesel::prelude::*;
use diesel::prelude::SqliteConnection;
use std::thread;
use std::sync::{Arc, Mutex};

View File

@ -3,7 +3,7 @@ use gtk::prelude::*;
use gdk_pixbuf::Pixbuf;
use hammond_downloader::downloader;
use diesel::prelude::*;
use diesel::prelude::SqliteConnection;
use std::sync::{Arc, Mutex};
@ -22,8 +22,11 @@ pub fn populate_podcasts_flowbox(
let iter = pd_model.get_iter_first().unwrap();
loop {
let title = pd_model.get_value(&iter, 1).get::<String>().unwrap();
let description = pd_model.get_value(&iter, 2).get::<String>().unwrap();
let title = pd_model
.get_value(&iter, 1)
.get::<String>()
.unwrap_or_default();
let description = pd_model.get_value(&iter, 2).get::<String>();
let image_uri = pd_model.get_value(&iter, 4).get::<String>();
let imgpath = downloader::cache_image(&title, image_uri.as_ref().map(|s| s.as_str()));
@ -42,12 +45,14 @@ pub fn populate_podcasts_flowbox(
f.connect_activate(move |_| {
let pdw = stack_clone.get_child_by_name("pdw").unwrap();
stack_clone.remove(&pdw);
let pdw = podcast_widget(
db_clone.clone(),
Some(title.as_str()),
Some(description.as_str()),
description.as_ref().map(|x| x.as_str()),
pixbuf.clone(),
);
stack_clone.add_named(&pdw, "pdw");
stack_clone.set_visible_child(&pdw);
println!("Hello World!, child activated");
@ -59,3 +64,28 @@ pub fn populate_podcasts_flowbox(
}
}
}
fn setup_podcast_widget(db: Arc<Mutex<SqliteConnection>>, stack: gtk::Stack) {
let pd_widget = podcast_widget(db.clone(), None, None, None);
stack.add_named(&pd_widget, "pdw");
}
fn setup_podcasts_grid(db: Arc<Mutex<SqliteConnection>>, stack: gtk::Stack) {
let builder = include_str!("../../gtk/podcasts_grid.ui");
let builder = gtk::Builder::new_from_string(builder);
let grid: gtk::Grid = builder.get_object("grid").unwrap();
stack.add_named(&grid, "pd_grid");
stack.set_visible_child(&grid);
// Adapted copy of the way gnome-music does albumview
// FIXME: flowbox childs activate with space/enter but not with clicks.
let flowbox: gtk::FlowBox = builder.get_object("flowbox").unwrap();
populate_podcasts_flowbox(db.clone(), stack.clone(), flowbox.clone());
}
pub fn setup_stack(db: Arc<Mutex<SqliteConnection>>) -> gtk::Stack {
let stack = gtk::Stack::new();
setup_podcast_widget(db.clone(), stack.clone());
setup_podcasts_grid(db.clone(), stack.clone());
stack
}

View File

@ -1,5 +1,5 @@
use open;
use diesel::prelude::*;
use diesel::prelude::SqliteConnection;
use hammond_data::dbqueries;
use hammond_data::models::Episode;
use hammond_downloader::downloader;
@ -37,7 +37,7 @@ fn epidose_widget(
desc_label.set_text(d);
}
if let Some(_) = episode.local_uri() {
if episode.local_uri().is_some() {
dl_button.hide();
play_button.show();
let uri = episode.local_uri().unwrap().to_owned();

View File

@ -2,7 +2,7 @@ use gtk::prelude::*;
use gtk;
use gdk_pixbuf::Pixbuf;
use diesel::prelude::*;
use diesel::prelude::SqliteConnection;
use hammond_data::dbqueries;
use std::sync::{Arc, Mutex};
@ -39,12 +39,11 @@ pub fn podcast_widget(
cover.set_from_pixbuf(&i);
}
// (pd_widget, title_label, desc_label, cover)
pd_widget
}
pub fn create_flowbox_child(title: &str, cover: Option<Pixbuf>) -> gtk::FlowBoxChild {
let build_src = include_str!("../../gtk/pd_fb_child.ui");
let build_src = include_str!("../../gtk/podcasts_child.ui");
let builder = gtk::Builder::new_from_string(build_src);
// Copy of gnome-music AlbumWidget
@ -67,6 +66,7 @@ pub fn create_flowbox_child(title: &str, cover: Option<Pixbuf>) -> gtk::FlowBoxC
let fbc = gtk::FlowBoxChild::new();
fbc.add(&box_);
info!("flowbox child created");
fbc
}
@ -75,6 +75,7 @@ pub fn podcast_liststore(connection: &SqliteConnection) -> gtk::ListStore {
let builder = gtk::Builder::new_from_string(builder);
let podcast_model: gtk::ListStore = builder.get_object("pd_store").unwrap();
// TODO: handle unwrap.
let podcasts = dbqueries::get_podcasts(connection).unwrap();
for pd in &podcasts {