podcasts_view further refactoring.
This commit is contained in:
parent
0ed6fee39f
commit
70d1f44147
@ -11,58 +11,7 @@
|
|||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkGrid" id="grid">
|
<placeholder/>
|
||||||
<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>
|
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
|
|||||||
53
hammond-gtk/gtk/podcasts_grid.ui
Normal file
53
hammond-gtk/gtk/podcasts_grid.ui
Normal 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>
|
||||||
@ -1,17 +1,13 @@
|
|||||||
use gtk;
|
use gtk;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
|
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::SqliteConnection;
|
||||||
use index_feed;
|
use index_feed;
|
||||||
use utils;
|
use utils;
|
||||||
|
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
pub fn get_headerbar(
|
pub fn get_headerbar(db: Arc<Mutex<SqliteConnection>>, stack: gtk::Stack) -> gtk::HeaderBar {
|
||||||
db: Arc<Mutex<SqliteConnection>>,
|
|
||||||
stack: gtk::Stack,
|
|
||||||
grid: gtk::Grid,
|
|
||||||
) -> gtk::HeaderBar {
|
|
||||||
let builder = include_str!("../gtk/headerbar.ui");
|
let builder = include_str!("../gtk/headerbar.ui");
|
||||||
let builder = gtk::Builder::new_from_string(builder);
|
let builder = gtk::Builder::new_from_string(builder);
|
||||||
|
|
||||||
@ -43,6 +39,7 @@ pub fn get_headerbar(
|
|||||||
utils::refresh_db(db_clone.clone());
|
utils::refresh_db(db_clone.clone());
|
||||||
|
|
||||||
// TODO: lock the button instead of hiding and add notification of feed added.
|
// TODO: lock the button instead of hiding and add notification of feed added.
|
||||||
|
// TODO: map the spinner
|
||||||
add_popover_clone.hide();
|
add_popover_clone.hide();
|
||||||
});
|
});
|
||||||
add_popover.hide();
|
add_popover.hide();
|
||||||
@ -50,6 +47,7 @@ pub fn get_headerbar(
|
|||||||
|
|
||||||
// TODO: make it a back arrow button, that will hide when appropriate,
|
// TODO: make it a back arrow button, that will hide when appropriate,
|
||||||
// and add a StackSwitcher when more views are added.
|
// 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));
|
home_button.connect_clicked(move |_| stack.set_visible_child(&grid));
|
||||||
|
|
||||||
// FIXME: There appears to be a memmory leak here.
|
// FIXME: There appears to be a memmory leak here.
|
||||||
|
|||||||
@ -26,26 +26,24 @@ pub mod widgets;
|
|||||||
pub mod headerbar;
|
pub mod headerbar;
|
||||||
pub mod utils;
|
pub mod utils;
|
||||||
|
|
||||||
use widgets::podcast::*;
|
use views::podcasts_view;
|
||||||
use views::podcasts_view::populate_podcasts_flowbox;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
THIS IS STILL A PROTOTYPE.
|
THIS IS STILL A PROTOTYPE.
|
||||||
THE CODE IS TERIBLE AND USES UNWRAPS EVERYWHERE.
|
THE CODE IS TERIBLE AND USES UNWRAPS EVERYWHERE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
fn build_ui() {
|
fn build_ui(app: >k::Application) {
|
||||||
let glade_src = include_str!("../gtk/foo.ui");
|
let db = Arc::new(Mutex::new(hammond_data::establish_connection()));
|
||||||
let builder = gtk::Builder::new_from_string(glade_src);
|
|
||||||
|
|
||||||
// Get the main window
|
// Get the main window
|
||||||
let window: gtk::Window = builder.get_object("window1").unwrap();
|
let window = gtk::ApplicationWindow::new(app);
|
||||||
// Get the Stack
|
window.set_default_size(1000, 600);
|
||||||
let stack: gtk::Stack = builder.get_object("stack1").unwrap();
|
app.add_window(&window);
|
||||||
|
// Setup the Stack that will magane the switche between podcasts_view and podcast_widget.
|
||||||
let db = Arc::new(Mutex::new(hammond_data::establish_connection()));
|
let stack = podcasts_view::setup_stack(db.clone());
|
||||||
let pd_widget = podcast_widget(db.clone(), None, None, None);
|
// Populate the flowbox with the Podcasts.
|
||||||
stack.add_named(&pd_widget, "pdw");
|
window.add(&stack);
|
||||||
|
|
||||||
// FIXME:
|
// FIXME:
|
||||||
// GLib-GIO-WARNING **: Your application does not implement g_application_activate()
|
// GLib-GIO-WARNING **: Your application does not implement g_application_activate()
|
||||||
@ -55,17 +53,10 @@ fn build_ui() {
|
|||||||
Inhibit(false)
|
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
|
// 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);
|
window.set_titlebar(&header);
|
||||||
|
|
||||||
populate_podcasts_flowbox(db.clone(), stack.clone(), flowbox.clone());
|
|
||||||
|
|
||||||
window.show_all();
|
window.show_all();
|
||||||
gtk::main();
|
gtk::main();
|
||||||
}
|
}
|
||||||
@ -88,8 +79,8 @@ fn main() {
|
|||||||
gio::ApplicationFlags::empty(),
|
gio::ApplicationFlags::empty(),
|
||||||
).expect("Initialization failed...");
|
).expect("Initialization failed...");
|
||||||
|
|
||||||
application.connect_startup(move |_| {
|
application.connect_startup(move |app| {
|
||||||
build_ui();
|
build_ui(app);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Not sure if this will be kept.
|
// Not sure if this will be kept.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
use hammond_data;
|
use hammond_data;
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::SqliteConnection;
|
||||||
|
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|||||||
@ -3,7 +3,7 @@ use gtk::prelude::*;
|
|||||||
use gdk_pixbuf::Pixbuf;
|
use gdk_pixbuf::Pixbuf;
|
||||||
|
|
||||||
use hammond_downloader::downloader;
|
use hammond_downloader::downloader;
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::SqliteConnection;
|
||||||
|
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
@ -22,8 +22,11 @@ pub fn populate_podcasts_flowbox(
|
|||||||
let iter = pd_model.get_iter_first().unwrap();
|
let iter = pd_model.get_iter_first().unwrap();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let title = pd_model.get_value(&iter, 1).get::<String>().unwrap();
|
let title = pd_model
|
||||||
let description = pd_model.get_value(&iter, 2).get::<String>().unwrap();
|
.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 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()));
|
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 |_| {
|
f.connect_activate(move |_| {
|
||||||
let pdw = stack_clone.get_child_by_name("pdw").unwrap();
|
let pdw = stack_clone.get_child_by_name("pdw").unwrap();
|
||||||
stack_clone.remove(&pdw);
|
stack_clone.remove(&pdw);
|
||||||
|
|
||||||
let pdw = podcast_widget(
|
let pdw = podcast_widget(
|
||||||
db_clone.clone(),
|
db_clone.clone(),
|
||||||
Some(title.as_str()),
|
Some(title.as_str()),
|
||||||
Some(description.as_str()),
|
description.as_ref().map(|x| x.as_str()),
|
||||||
pixbuf.clone(),
|
pixbuf.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
stack_clone.add_named(&pdw, "pdw");
|
stack_clone.add_named(&pdw, "pdw");
|
||||||
stack_clone.set_visible_child(&pdw);
|
stack_clone.set_visible_child(&pdw);
|
||||||
println!("Hello World!, child activated");
|
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
|
||||||
|
}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
use open;
|
use open;
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::SqliteConnection;
|
||||||
use hammond_data::dbqueries;
|
use hammond_data::dbqueries;
|
||||||
use hammond_data::models::Episode;
|
use hammond_data::models::Episode;
|
||||||
use hammond_downloader::downloader;
|
use hammond_downloader::downloader;
|
||||||
@ -37,7 +37,7 @@ fn epidose_widget(
|
|||||||
desc_label.set_text(d);
|
desc_label.set_text(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(_) = episode.local_uri() {
|
if episode.local_uri().is_some() {
|
||||||
dl_button.hide();
|
dl_button.hide();
|
||||||
play_button.show();
|
play_button.show();
|
||||||
let uri = episode.local_uri().unwrap().to_owned();
|
let uri = episode.local_uri().unwrap().to_owned();
|
||||||
|
|||||||
@ -2,7 +2,7 @@ use gtk::prelude::*;
|
|||||||
use gtk;
|
use gtk;
|
||||||
use gdk_pixbuf::Pixbuf;
|
use gdk_pixbuf::Pixbuf;
|
||||||
|
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::SqliteConnection;
|
||||||
use hammond_data::dbqueries;
|
use hammond_data::dbqueries;
|
||||||
|
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
@ -39,12 +39,11 @@ pub fn podcast_widget(
|
|||||||
cover.set_from_pixbuf(&i);
|
cover.set_from_pixbuf(&i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// (pd_widget, title_label, desc_label, cover)
|
|
||||||
pd_widget
|
pd_widget
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_flowbox_child(title: &str, cover: Option<Pixbuf>) -> gtk::FlowBoxChild {
|
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);
|
let builder = gtk::Builder::new_from_string(build_src);
|
||||||
|
|
||||||
// Copy of gnome-music AlbumWidget
|
// 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();
|
let fbc = gtk::FlowBoxChild::new();
|
||||||
fbc.add(&box_);
|
fbc.add(&box_);
|
||||||
|
info!("flowbox child created");
|
||||||
fbc
|
fbc
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,6 +75,7 @@ pub fn podcast_liststore(connection: &SqliteConnection) -> gtk::ListStore {
|
|||||||
let builder = gtk::Builder::new_from_string(builder);
|
let builder = gtk::Builder::new_from_string(builder);
|
||||||
let podcast_model: gtk::ListStore = builder.get_object("pd_store").unwrap();
|
let podcast_model: gtk::ListStore = builder.get_object("pd_store").unwrap();
|
||||||
|
|
||||||
|
// TODO: handle unwrap.
|
||||||
let podcasts = dbqueries::get_podcasts(connection).unwrap();
|
let podcasts = dbqueries::get_podcasts(connection).unwrap();
|
||||||
|
|
||||||
for pd in &podcasts {
|
for pd in &podcasts {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user