diff --git a/hammond-gtk/gtk/foo.ui b/hammond-gtk/gtk/foo.ui
index 23d2e19..d2a0dbe 100644
--- a/hammond-gtk/gtk/foo.ui
+++ b/hammond-gtk/gtk/foo.ui
@@ -11,58 +11,7 @@
True
False
-
-
- page0
- page0
-
+
diff --git a/hammond-gtk/gtk/pd_fb_child.ui b/hammond-gtk/gtk/podcasts_child.ui
similarity index 100%
rename from hammond-gtk/gtk/pd_fb_child.ui
rename to hammond-gtk/gtk/podcasts_child.ui
diff --git a/hammond-gtk/gtk/podcasts_grid.ui b/hammond-gtk/gtk/podcasts_grid.ui
new file mode 100644
index 0000000..3096326
--- /dev/null
+++ b/hammond-gtk/gtk/podcasts_grid.ui
@@ -0,0 +1,53 @@
+
+
+
+
+
+ True
+ False
+ True
+ True
+
+
+ True
+ False
+ vertical
+
+
+ True
+ True
+ in
+
+
+ True
+ False
+
+
+ FlowBox1
+ 600
+ 600
+ True
+ False
+ True
+ 5
+ 5
+ 25
+
+
+
+
+
+
+ True
+ True
+ 0
+
+
+
+
+ 0
+ 0
+
+
+
+
diff --git a/hammond-gtk/src/headerbar.rs b/hammond-gtk/src/headerbar.rs
index 9ee110d..460a24e 100644
--- a/hammond-gtk/src/headerbar.rs
+++ b/hammond-gtk/src/headerbar.rs
@@ -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>,
- stack: gtk::Stack,
- grid: gtk::Grid,
-) -> gtk::HeaderBar {
+pub fn get_headerbar(db: Arc>, 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.
diff --git a/hammond-gtk/src/main.rs b/hammond-gtk/src/main.rs
index c6ff799..1b162ff 100644
--- a/hammond-gtk/src/main.rs
+++ b/hammond-gtk/src/main.rs
@@ -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: >k::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.
diff --git a/hammond-gtk/src/utils.rs b/hammond-gtk/src/utils.rs
index 649e443..b89d312 100644
--- a/hammond-gtk/src/utils.rs
+++ b/hammond-gtk/src/utils.rs
@@ -1,5 +1,5 @@
use hammond_data;
-use diesel::prelude::*;
+use diesel::prelude::SqliteConnection;
use std::thread;
use std::sync::{Arc, Mutex};
diff --git a/hammond-gtk/src/views/podcasts_view.rs b/hammond-gtk/src/views/podcasts_view.rs
index c390d77..54eee07 100644
--- a/hammond-gtk/src/views/podcasts_view.rs
+++ b/hammond-gtk/src/views/podcasts_view.rs
@@ -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::().unwrap();
- let description = pd_model.get_value(&iter, 2).get::().unwrap();
+ let title = pd_model
+ .get_value(&iter, 1)
+ .get::()
+ .unwrap_or_default();
+ let description = pd_model.get_value(&iter, 2).get::();
let image_uri = pd_model.get_value(&iter, 4).get::();
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>, 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>, 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>) -> gtk::Stack {
+ let stack = gtk::Stack::new();
+ setup_podcast_widget(db.clone(), stack.clone());
+ setup_podcasts_grid(db.clone(), stack.clone());
+ stack
+}
diff --git a/hammond-gtk/src/widgets/episode.rs b/hammond-gtk/src/widgets/episode.rs
index a0a61ae..23ea5ca 100644
--- a/hammond-gtk/src/widgets/episode.rs
+++ b/hammond-gtk/src/widgets/episode.rs
@@ -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();
diff --git a/hammond-gtk/src/widgets/podcast.rs b/hammond-gtk/src/widgets/podcast.rs
index 38c6dbc..b76a1ae 100644
--- a/hammond-gtk/src/widgets/podcast.rs
+++ b/hammond-gtk/src/widgets/podcast.rs
@@ -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) -> 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) -> 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 {