From 944156d6fec4c2d8872239434574829cfcd7ce27 Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Mon, 6 Nov 2017 14:56:59 +0200 Subject: [PATCH] #6 Switched to using the safe api for GResource. --- Cargo.lock | 3 --- hammond-gtk/Cargo.toml | 4 ---- hammond-gtk/src/static_resource.rs | 27 +++++++------------------- hammond-gtk/src/views/podcasts_view.rs | 5 +---- 4 files changed, 8 insertions(+), 31 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7751d92..71d473f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -580,13 +580,10 @@ 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)", diff --git a/hammond-gtk/Cargo.toml b/hammond-gtk/Cargo.toml index 3669145..21ee5b5 100644 --- a/hammond-gtk/Cargo.toml +++ b/hammond-gtk/Cargo.toml @@ -12,10 +12,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" open = "1.2" diff --git a/hammond-gtk/src/static_resource.rs b/hammond-gtk/src/static_resource.rs index e7d2a76..e8e9c4d 100644 --- a/hammond-gtk/src/static_resource.rs +++ b/hammond-gtk/src/static_resource.rs @@ -1,30 +1,17 @@ -extern crate gio_sys; -extern crate glib_sys; -extern crate libc; - use gio::{resources_register, Error, Resource}; -use glib::Bytes; - -use std; +// 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. - // let resource = Resource::new_from_data(&Bytes::from(&res_bytes))?; - // let resource = Resource::new_from_data(&res_bytes.into())?; + // 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())?; - // // Register the resource so It wont be dropped and will continue to live in memory. - // resources_register(&resource); - - 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); - } + // Register the resource so It wont be dropped and will continue to live in memory. + resources_register(&resource); Ok(()) } diff --git a/hammond-gtk/src/views/podcasts_view.rs b/hammond-gtk/src/views/podcasts_view.rs index cae5817..edcfb29 100644 --- a/hammond-gtk/src/views/podcasts_view.rs +++ b/hammond-gtk/src/views/podcasts_view.rs @@ -66,12 +66,9 @@ 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: move .ui files into gresources and refactor. - // static_resource::init().expect("Something went wrong with the resource file - // initialization."); - info!("I RUN"); + 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); - info!("{:?}", bann); if let Ok(b) = bann { banner.set_from_pixbuf(&b);