Completed #6, switch to gresource instead of include_str! macro.

This commit is contained in:
Jordan Petridis 2017-11-06 17:17:55 +02:00
parent 944156d6fe
commit 8d17d30c82
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
13 changed files with 21 additions and 20 deletions

View File

@ -2,5 +2,11 @@
<gresources>
<gresource prefix="/org/gtk/hammond/">
<file>banner.png</file>
<file preprocess="xml-stripblanks">gtk/episode_widget.ui</file>
<file preprocess="xml-stripblanks">gtk/podcast_widget.ui</file>
<file preprocess="xml-stripblanks">gtk/empty_view.ui</file>
<file preprocess="xml-stripblanks">gtk/podcasts_view.ui</file>
<file preprocess="xml-stripblanks">gtk/podcasts_child.ui</file>
<file preprocess="xml-stripblanks">gtk/headerbar.ui</file>
</gresource>
</gresources>

View File

@ -8,7 +8,7 @@ use podcasts_view::update_podcasts_view;
use utils;
pub fn get_headerbar(db: &Database, stack: &gtk::Stack) -> gtk::HeaderBar {
let builder = gtk::Builder::new_from_string(include_str!("../gtk/headerbar.ui"));
let builder = gtk::Builder::new_from_resource("/org/gtk/hammond/gtk/headerbar.ui");
let header: gtk::HeaderBar = builder.get_object("headerbar1").unwrap();
let home_button: gtk::Button = builder.get_object("homebutton").unwrap();

View File

@ -108,6 +108,7 @@ fn build_ui(app: &gtk::Application) {
fn main() {
// TODO: make the the logger a cli -vv option
loggerv::init_with_level(LogLevel::Info).unwrap();
static_resource::init().expect("Something went wrong with the resource file initialization.");
hammond_data::init().expect("Hammond Initialazation failed.");
let application = gtk::Application::new(

View File

@ -1,14 +1,14 @@
use gio::{resources_register, Error, Resource};
// use glib::Bytes;
use glib::Bytes;
pub fn init() -> Result<(), Error> {
// load the gresource binary at build time and include/link it into the final binary.
let res_bytes = include_bytes!("../resources/resources.gresource");
// Create Resource it will live as long the value lives.
// Both are equivelent.
// let resource = Resource::new_from_data(&Bytes::from(&res_bytes.as_ref()))?;
let resource = Resource::new_from_data(&res_bytes.as_ref().into())?;
let gbytes = Bytes::from(&res_bytes.as_ref());
let resource = Resource::new_from_data(&gbytes)?;
// let resource = Resource::new_from_data(&res_bytes.as_ref().into())?;
// Register the resource so It wont be dropped and will continue to live in memory.
resources_register(&resource);

View File

@ -7,11 +7,9 @@ use hammond_data::models::Podcast;
use hammond_data::index_feed::Database;
use widgets::podcast::*;
use static_resource;
fn show_empty_view(stack: &gtk::Stack) {
let builder = gtk::Builder::new_from_string(include_str!("../../gtk/empty_view.ui"));
let builder = gtk::Builder::new_from_resource("/org/gtk/hammond/gtk/empty_view.ui");
let view: gtk::Box = builder.get_object("empty_view").unwrap();
stack.add_named(&view, "empty");
stack.set_visible_child_name("empty");
@ -20,8 +18,6 @@ fn show_empty_view(stack: &gtk::Stack) {
}
fn populate_flowbox(db: &Database, stack: &gtk::Stack, flowbox: &gtk::FlowBox) {
static_resource::init().expect("Something went wrong with the resource file initialization.");
let podcasts = {
let db = db.lock().unwrap();
dbqueries::get_podcasts(&db)
@ -39,7 +35,7 @@ fn populate_flowbox(db: &Database, stack: &gtk::Stack, flowbox: &gtk::FlowBox) {
}
fn create_flowbox_child(db: &Database, pd: &Podcast) -> gtk::FlowBoxChild {
let builder = gtk::Builder::new_from_string(include_str!("../../gtk/podcasts_child.ui"));
let builder = gtk::Builder::new_from_resource("/org/gtk/hammond/gtk/podcasts_child.ui");
// Copy of gnome-music AlbumWidget
let box_: gtk::Box = builder.get_object("fb_child").unwrap();
@ -65,9 +61,6 @@ fn create_flowbox_child(db: &Database, pd: &Podcast) -> gtk::FlowBoxChild {
}
fn configure_banner(db: &Database, pd: &Podcast, banner: &gtk::Image, banner_title: &gtk::Label) {
// TODO: move .ui files into gresources and refactor.
static_resource::init().expect("Something went wrong with the resource file initialization.");
let bann = Pixbuf::new_from_resource_at_scale("/org/gtk/hammond/banner.png", 256, 256, true);
if let Ok(b) = bann {
banner.set_from_pixbuf(&b);
@ -101,7 +94,7 @@ fn on_flowbox_child_activate(db: &Database, stack: &gtk::Stack, parent: &Podcast
}
fn setup_podcasts_flowbox(db: &Database, stack: &gtk::Stack) {
let builder = gtk::Builder::new_from_string(include_str!("../../gtk/podcasts_view.ui"));
let builder = gtk::Builder::new_from_resource("/org/gtk/hammond/gtk/podcasts_view.ui");
let fb_parent: gtk::Box = builder.get_object("fb_parent").unwrap();
let flowbox: gtk::FlowBox = builder.get_object("flowbox").unwrap();
@ -120,7 +113,7 @@ pub fn setup_stack(db: &Database) -> gtk::Stack {
}
pub fn update_podcasts_view(db: &Database, stack: &gtk::Stack) {
let builder = gtk::Builder::new_from_string(include_str!("../../gtk/podcasts_view.ui"));
let builder = gtk::Builder::new_from_resource("/org/gtk/hammond/gtk/podcasts_view.ui");
let fb_parent: gtk::Box = builder.get_object("fb_parent").unwrap();
let flowbox: gtk::FlowBox = builder.get_object("flowbox").unwrap();

View File

@ -25,7 +25,7 @@ thread_local!(static GLOBAL: Foo = RefCell::new(None));
fn epidose_widget(db: &Database, episode: &mut Episode, pd_title: &str) -> gtk::Box {
// This is just a prototype and will be reworked probably.
let builder = gtk::Builder::new_from_string(include_str!("../../gtk/episode_widget.ui"));
let builder = gtk::Builder::new_from_resource("/org/gtk/hammond/gtk/episode_widget.ui");
let ep: gtk::Box = builder.get_object("episode_box").unwrap();
let download_button: gtk::Button = builder.get_object("download_button").unwrap();

View File

@ -14,7 +14,7 @@ use podcasts_view::update_podcasts_view;
pub fn podcast_widget(db: &Database, stack: &gtk::Stack, pd: &Podcast) -> gtk::Box {
// Adapted from gnome-music AlbumWidget
let builder = gtk::Builder::new_from_string(include_str!("../../gtk/podcast_widget.ui"));
let builder = gtk::Builder::new_from_resource("/org/gtk/hammond/gtk/podcast_widget.ui");
let pd_widget: gtk::Box = builder.get_object("podcast_widget").unwrap();
let cover: gtk::Image = builder.get_object("cover").unwrap();
@ -111,8 +111,8 @@ pub fn get_pixbuf_from_path(img_path: Option<&str>, pd_title: &str) -> Option<Pi
}
pub fn setup_podcast_widget(stack: &gtk::Stack) {
let buidler = gtk::Builder::new_from_string(include_str!("../../gtk/podcast_widget.ui"));
let pd_widget: gtk::Box = buidler.get_object("podcast_widget").unwrap();
let builder = gtk::Builder::new_from_resource("/org/gtk/hammond/gtk/podcast_widget.ui");
let pd_widget: gtk::Box = builder.get_object("podcast_widget").unwrap();
stack.add_named(&pd_widget, "pdw");
}
@ -125,4 +125,5 @@ pub fn update_podcast_widget(db: &Database, stack: &gtk::Stack, pd: &Podcast) {
stack.remove(&old);
stack.add_named(&pdw, "pdw");
stack.set_visible_child_name(&vis);
old.destroy();
}