Draft of implementation using gresources safe api.
This commit is contained in:
parent
80ae1b0c88
commit
79d9f62da5
@ -3,6 +3,7 @@ name = "hammond-gtk"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Jordan Petridis <jordanpetridis@protonmail.com>"]
|
authors = ["Jordan Petridis <jordanpetridis@protonmail.com>"]
|
||||||
workspace = "../"
|
workspace = "../"
|
||||||
|
build = "build.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
gtk = { version = "0.2", features = ["v3_22"]}
|
gtk = { version = "0.2", features = ["v3_22"]}
|
||||||
@ -10,10 +11,10 @@ gdk = "0.6"
|
|||||||
glib = "0.3"
|
glib = "0.3"
|
||||||
gio = "0.2"
|
gio = "0.2"
|
||||||
gdk-pixbuf = "0.2"
|
gdk-pixbuf = "0.2"
|
||||||
libc = "0.2"
|
|
||||||
|
|
||||||
|
libc = "0.2"
|
||||||
gio-sys = "0.4"
|
gio-sys = "0.4"
|
||||||
glib-sys = "^0.4"
|
glib-sys = "0.4"
|
||||||
|
|
||||||
loggerv = "0.4"
|
loggerv = "0.4"
|
||||||
log = "0.3"
|
log = "0.3"
|
||||||
|
|||||||
@ -3,7 +3,7 @@ use std::process::Command;
|
|||||||
fn main() {
|
fn main() {
|
||||||
Command::new("glib-compile-resources")
|
Command::new("glib-compile-resources")
|
||||||
.args(&["--generate", "resources.xml"])
|
.args(&["--generate", "resources.xml"])
|
||||||
.current_dir("src/resources")
|
.current_dir("resources")
|
||||||
.status()
|
.status()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<gresources>
|
<gresources>
|
||||||
<gresource prefix="/org/gtk/hammond">
|
<gresource prefix="/org/gtk/hammond/">
|
||||||
<file>banner.png</file>
|
<file>banner.png</file>
|
||||||
</gresource>
|
</gresource>
|
||||||
</gresources>
|
</gresources>
|
||||||
@ -2,12 +2,22 @@ extern crate gio_sys;
|
|||||||
extern crate glib_sys;
|
extern crate glib_sys;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
|
|
||||||
|
use gio::{resources_register, Error, Resource};
|
||||||
|
use glib::Bytes;
|
||||||
|
|
||||||
use std;
|
use std;
|
||||||
|
|
||||||
// https://github.com/sunnyone/gresource-gtkrs-example/blob/master/src/static_resource.rs
|
pub fn init() -> Result<(), Error> {
|
||||||
// TODO: slomo mentioned that the unsafe could be removed and use a safe API instead.
|
// load the gresource binary at build time and include/link it into the final binary.
|
||||||
pub fn init() {
|
let res_bytes = include_bytes!("../resources/resources.gresource");
|
||||||
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())?;
|
||||||
|
|
||||||
|
// // Register the resource so It wont be dropped and will continue to live in memory.
|
||||||
|
// resources_register(&resource);
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
// gbytes and resource will not be freed
|
// gbytes and resource will not be freed
|
||||||
let gbytes =
|
let gbytes =
|
||||||
@ -15,4 +25,6 @@ pub fn init() {
|
|||||||
let resource = gio_sys::g_resource_new_from_data(gbytes, std::ptr::null_mut());
|
let resource = gio_sys::g_resource_new_from_data(gbytes, std::ptr::null_mut());
|
||||||
gio_sys::g_resources_register(resource);
|
gio_sys::g_resources_register(resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,6 +9,7 @@ use hammond_data::index_feed::Database;
|
|||||||
use widgets::podcast::*;
|
use widgets::podcast::*;
|
||||||
use static_resource;
|
use static_resource;
|
||||||
|
|
||||||
|
|
||||||
fn show_empty_view(stack: >k::Stack) {
|
fn show_empty_view(stack: >k::Stack) {
|
||||||
let builder = gtk::Builder::new_from_string(include_str!("../../gtk/empty_view.ui"));
|
let builder = gtk::Builder::new_from_string(include_str!("../../gtk/empty_view.ui"));
|
||||||
let view: gtk::Box = builder.get_object("empty_view").unwrap();
|
let view: gtk::Box = builder.get_object("empty_view").unwrap();
|
||||||
@ -19,6 +20,8 @@ fn show_empty_view(stack: >k::Stack) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn populate_flowbox(db: &Database, stack: >k::Stack, flowbox: >k::FlowBox) {
|
fn populate_flowbox(db: &Database, stack: >k::Stack, flowbox: >k::FlowBox) {
|
||||||
|
static_resource::init().expect("Something went wrong with the resource file initialization.");
|
||||||
|
|
||||||
let podcasts = {
|
let podcasts = {
|
||||||
let db = db.lock().unwrap();
|
let db = db.lock().unwrap();
|
||||||
dbqueries::get_podcasts(&db)
|
dbqueries::get_podcasts(&db)
|
||||||
@ -63,9 +66,12 @@ fn create_flowbox_child(db: &Database, pd: &Podcast) -> gtk::FlowBoxChild {
|
|||||||
|
|
||||||
fn configure_banner(db: &Database, pd: &Podcast, banner: >k::Image, banner_title: >k::Label) {
|
fn configure_banner(db: &Database, pd: &Podcast, banner: >k::Image, banner_title: >k::Label) {
|
||||||
// TODO: move .ui files into gresources and refactor.
|
// TODO: move .ui files into gresources and refactor.
|
||||||
static_resource::init();
|
// static_resource::init().expect("Something went wrong with the resource file
|
||||||
|
// initialization.");
|
||||||
|
info!("I RUN");
|
||||||
|
|
||||||
let bann = Pixbuf::new_from_resource_at_scale("/org/gtk/hammond/banner.png", 256, 256, true);
|
let bann = Pixbuf::new_from_resource_at_scale("/org/gtk/hammond/banner.png", 256, 256, true);
|
||||||
|
info!("{:?}", bann);
|
||||||
if let Ok(b) = bann {
|
if let Ok(b) = bann {
|
||||||
banner.set_from_pixbuf(&b);
|
banner.set_from_pixbuf(&b);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user