From 60a3b39339829f3f8cca50a548f92e87a47ece28 Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Mon, 6 Nov 2017 12:19:10 +0200 Subject: [PATCH] Initial implementation of #6 Gresource support. --- Cargo.lock | 9 ++++++--- hammond-gtk/Cargo.toml | 4 ++++ hammond-gtk/build.rs | 9 +++++++++ hammond-gtk/gtk/podcasts_view.ui | 2 +- hammond-gtk/src/main.rs | 1 + hammond-gtk/{gtk => src/resources}/banner.png | Bin hammond-gtk/src/resources/resources.gresource | Bin 0 -> 1848 bytes hammond-gtk/src/resources/resources.xml | 6 ++++++ hammond-gtk/src/static_resource.rs | 18 ++++++++++++++++++ hammond-gtk/src/views/podcasts_view.rs | 7 +++++-- 10 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 hammond-gtk/build.rs rename hammond-gtk/{gtk => src/resources}/banner.png (100%) create mode 100644 hammond-gtk/src/resources/resources.gresource create mode 100644 hammond-gtk/src/resources/resources.xml create mode 100644 hammond-gtk/src/static_resource.rs diff --git a/Cargo.lock b/Cargo.lock index 4a39fab..7751d92 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -552,7 +552,7 @@ dependencies = [ "rand 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rfc822_sanitizer 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rfc822_sanitizer 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "rss 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "xdg 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -580,10 +580,13 @@ dependencies = [ "gdk 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "gdk-pixbuf 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "gio 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "gio-sys 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "glib 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "glib-sys 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "gtk 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "hammond-data 0.1.0", "hammond-downloader 0.1.0", + "libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "loggerv 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "open 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1136,7 +1139,7 @@ dependencies = [ [[package]] name = "rfc822_sanitizer" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1692,7 +1695,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum relay 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f301bafeb60867c85170031bdb2fcf24c8041f33aee09e7b116a58d4e9f781c5" "checksum reqwest 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1d56dbe269dbe19d716b76ec8c3efce8ef84e974f5b7e5527463e8c0507d4e17" "checksum reqwest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "194fe0d39dea7f89738707bf70e9f3ed47e8aca47d4b2eeaad6ac7831d2d390b" -"checksum rfc822_sanitizer 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "28423a6dc1c7d5db3ab5b540965149302cdf355e5ccaa05f38e25c97a568a6fd" +"checksum rfc822_sanitizer 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "680e8305c1e0cdf836dc4bec5424e045f278c975a3cac36d1ca01c4695f9d815" "checksum rss 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "70294b2be2d620fed3939032067684c53b8ccae18e8ca0b8410447f0f07228c5" "checksum rustc-demangle 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "aee45432acc62f7b9a108cc054142dac51f979e69e71ddce7d6fc7adf29e817e" "checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" diff --git a/hammond-gtk/Cargo.toml b/hammond-gtk/Cargo.toml index 088848f..2c7800d 100644 --- a/hammond-gtk/Cargo.toml +++ b/hammond-gtk/Cargo.toml @@ -10,6 +10,10 @@ gdk = "0.6" glib = "0.3" gio = "0.2" gdk-pixbuf = "0.2" +libc = "0.2" + +gio-sys = "0.4" +glib-sys = "^0.4" loggerv = "0.4" log = "0.3" diff --git a/hammond-gtk/build.rs b/hammond-gtk/build.rs new file mode 100644 index 0000000..002fd7f --- /dev/null +++ b/hammond-gtk/build.rs @@ -0,0 +1,9 @@ +use std::process::Command; + +fn main() { + Command::new("glib-compile-resources") + .args(&["--generate", "resources.xml"]) + .current_dir("src/resources") + .status() + .unwrap(); +} diff --git a/hammond-gtk/gtk/podcasts_view.ui b/hammond-gtk/gtk/podcasts_view.ui index dc1909c..4cdc447 100644 --- a/hammond-gtk/gtk/podcasts_view.ui +++ b/hammond-gtk/gtk/podcasts_view.ui @@ -19,7 +19,7 @@ True False - start + baseline start True 5 diff --git a/hammond-gtk/src/main.rs b/hammond-gtk/src/main.rs index 637eb97..22232c5 100644 --- a/hammond-gtk/src/main.rs +++ b/hammond-gtk/src/main.rs @@ -47,6 +47,7 @@ mod widgets; mod headerbar; mod utils; +mod static_resource; use views::podcasts_view; diff --git a/hammond-gtk/gtk/banner.png b/hammond-gtk/src/resources/banner.png similarity index 100% rename from hammond-gtk/gtk/banner.png rename to hammond-gtk/src/resources/banner.png diff --git a/hammond-gtk/src/resources/resources.gresource b/hammond-gtk/src/resources/resources.gresource new file mode 100644 index 0000000000000000000000000000000000000000..1f004f0a1b8df37905c3c02a338ad619030b3188 GIT binary patch literal 1848 zcmd5-2~$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Ql~$Dr zk>`k7&{1zbMin(YeWctcNHZl}&J>!%X1@ftPNP?}L<>>r2Gwleqz}Bf@rT8?thAus zeKBNh4$=c9~7?*74EMH)Df10R~NL`%cy{9J0#v1r!(X&P<;V%%K3GREre~!? z7zsRZR>gBl;LPtI{7;BusSE0-l^~n{q7@6;zIWkR>jX99SkV7(pkkbmfn!kxHSd(* z9>2c~?Kno$(f$5o`#-UuS2Fe5h7*|Ku@^fQ;_Bs6;T)C?V3?8;o@TT^JRyNWk3xqI NHUndm + + + banner.png + + diff --git a/hammond-gtk/src/static_resource.rs b/hammond-gtk/src/static_resource.rs new file mode 100644 index 0000000..3891f64 --- /dev/null +++ b/hammond-gtk/src/static_resource.rs @@ -0,0 +1,18 @@ +extern crate gio_sys; +extern crate glib_sys; +extern crate libc; + +use std; + +// https://github.com/sunnyone/gresource-gtkrs-example/blob/master/src/static_resource.rs +// TODO: slomo mentioned that the unsafe could be removed and use a safe API instead. +pub fn init() { + let res_bytes = include_bytes!("resources/resources.gresource"); + unsafe { + // gbytes and resource will not be freed + let gbytes = + glib_sys::g_bytes_new(res_bytes.as_ptr() as *const libc::c_void, res_bytes.len()); + let resource = gio_sys::g_resource_new_from_data(gbytes, std::ptr::null_mut()); + gio_sys::g_resources_register(resource); + } +} diff --git a/hammond-gtk/src/views/podcasts_view.rs b/hammond-gtk/src/views/podcasts_view.rs index cb1a9b1..2959421 100644 --- a/hammond-gtk/src/views/podcasts_view.rs +++ b/hammond-gtk/src/views/podcasts_view.rs @@ -7,6 +7,7 @@ use hammond_data::models::Podcast; use hammond_data::index_feed::Database; use widgets::podcast::*; +use static_resource; fn show_empty_view(stack: >k::Stack) { let builder = gtk::Builder::new_from_string(include_str!("../../gtk/empty_view.ui")); @@ -61,8 +62,10 @@ fn create_flowbox_child(db: &Database, pd: &Podcast) -> gtk::FlowBoxChild { } fn configure_banner(db: &Database, pd: &Podcast, banner: >k::Image, banner_title: >k::Label) { - // TODO: use GResource instead. - let bann = Pixbuf::new_from_file_at_scale("hammond-gtk/gtk/banner.png", 256, 256, true); + // TODO: move .ui files into gresources and refactor. + static_resource::init(); + + 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);