Commit 698d3e50 authored by Daniel García Moreno's avatar Daniel García Moreno

Merge branch 'alatiera/fractal-master'

parents 24222e6f 0623f06c
......@@ -6,3 +6,4 @@ Makefile
_build
Cargo.lock
vendor
*.gresource
......@@ -2,6 +2,7 @@
authors = ["Daniel Garcia <danigm@wadobo.com>"]
name = "fractal"
version = "0.1.0"
build = "build.rs"
[dependencies]
gdk = "0.6.0"
......
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::Path;
use std::process::Command;
fn main() {
let out_dir = env::var("OUT_DIR").unwrap();
let fractal_res = env::var("FRACTAL_RES").unwrap_or(String::from("res"));
let dest_path = Path::new(&out_dir).join("config.rs");
let mut f = File::create(&dest_path).unwrap();
let code = format!("
mod config {{
pub fn datadir(res: &str) -> String {{
let out = String::from(\"{}/\");
out + res
}}
}}
", fractal_res);
f.write_all(code.as_bytes()).unwrap();
// Compile Gresource
Command::new("glib-compile-resources")
.args(&["--generate", "resources.xml"])
.current_dir("res")
.status()
.unwrap();
}
......@@ -11,27 +11,24 @@ fractal_minor_version = version_array[1].to_int()
fractal_version_micro = version_array[2].to_int()
fractal_prefix = get_option('prefix')
fractal_datadir = join_paths(fractal_prefix, get_option('datadir'), 'fractal')
fractal_bindir = join_paths(fractal_prefix, get_option('bindir'))
install_data('res/app.css', install_dir : fractal_datadir)
install_data('res/fractal.svg', install_dir : fractal_datadir)
install_data('res/main_window.glade', install_dir : fractal_datadir)
install_data('res/fractal.svg', install_dir : get_option('datadir') + '/icons')
install_data('res/org.gnome.Fractal.desktop', install_dir : get_option('datadir') + '/applications')
cargo = find_program('cargo', required: false)
gresource = find_program('glib-compile-resources', required: false)
cargo_vendor = find_program('cargo-vendor', required: false)
cargo_script = find_program('scripts/cargo.sh')
cargo_script = find_program('scripts/release.sh')
cargo_release = custom_target('cargo-build',
build_by_default: true,
build_always: true,
output: ['fractal'],
install: true,
install_dir: fractal_bindir,
command: ['FRACTAL_RES=' + fractal_datadir, cargo_script, '@CURRENT_SOURCE_DIR@', '@OUTPUT@'])
command: [cargo_script, '@CURRENT_SOURCE_DIR@', '@OUTPUT@'])
cargo = find_program('cargo-vendor', required: false)
run_target('release', command: ['scripts/release.sh',
meson.project_name() + '-' + fractal_version
])
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/gnome/fractal/">
<file preprocess="xml-stripblanks">main_window.glade</file>
<file preprocess="xml-stripblanks">fractal.svg</file>
<file>app.css</file>
</gresource>
</gresources>
extern crate glib;
extern crate gtk;
extern crate gio;
extern crate gdk_pixbuf;
extern crate secret_service;
extern crate chrono;
......@@ -22,7 +20,9 @@ use std::sync::mpsc::{Sender, Receiver};
use std::collections::HashMap;
use std::process::Command;
use self::gio::ApplicationExt;
use gio::ApplicationExt;
use glib;
use gio;
use self::gdk_pixbuf::Pixbuf;
use self::gtk::prelude::*;
......@@ -43,9 +43,6 @@ use widgets;
use cache;
include!(concat!(env!("OUT_DIR"), "/config.rs"));
#[derive(Debug)]
pub enum Error {
SecretServiceError,
......@@ -1271,7 +1268,7 @@ impl App {
let bk = Backend::new(tx);
let apptx = bk.run();
let gtk_builder = gtk::Builder::new_from_file(&config::datadir("main_window.glade"));
let gtk_builder = gtk::Builder::new_from_resource("/org/gnome/fractal/main_window.glade");
let window: gtk::Window = gtk_builder
.get_object("main_window")
.expect("Couldn't find main_window in ui file.");
......@@ -1305,7 +1302,8 @@ impl App {
.expect("Couldn't find main_window in ui file.");
window.set_title("Fractal");
let _ = window.set_icon_from_file(&config::datadir("fractal.svg"));
let pxbf = Pixbuf::new_from_resource("/org/gnome/fractal/fractal.svg").unwrap();
window.set_icon(&pxbf);
window.show_all();
let op = self.op.clone();
......@@ -1606,10 +1604,7 @@ impl App {
glib::set_prgname(Some("fractal"));
let provider = gtk::CssProvider::new();
let uri = config::datadir("app.css");
if let Err(_) = provider.load_from_path(&uri) {
println!("Error: Failed to add application style");
}
provider.load_from_resource("/org/gnome/fractal/app.css");
gtk::StyleContext::add_provider_for_screen(&gdk::Screen::get_default().unwrap(), &provider, 600);
}
}
......
extern crate glib;
extern crate gio;
#[macro_use]
extern crate serde_json;
#[macro_use]
......@@ -11,10 +15,12 @@ mod cache;
mod backend;
mod model;
mod app;
mod static_resources;
use app::App;
fn main() {
static_resources::init().expect("GResource initialization failed.");
App::new();
}
use gio::{resources_register, Error, Resource};
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!("../res/resources.gresource");
// Create Resource, it will live as long the value lives.
// TODO: change it into Bytes::From_static once the fix lands
// https://bugzilla.gnome.org/show_bug.cgi?id=790030
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);
Ok(())
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment