#6 Switched to using the safe api for GResource.
This commit is contained in:
parent
79d9f62da5
commit
944156d6fe
3
Cargo.lock
generated
3
Cargo.lock
generated
@ -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)",
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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(())
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user