[gnome-boxes] Use GResource for style data



commit 825a39ef99ae12ed034bb2f5fda9db067fcdb249
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Tue Dec 17 22:03:35 2013 +0000

    Use GResource for style data
    
    Put all style data (CSS and assets) into the app binary, using GResource.

 configure.ac                   |    3 +++
 data/Makefile.am               |    9 +++++----
 data/gnome-boxes.gresource.xml |    9 +++++++++
 data/gtk-style.css             |    2 +-
 data/icons/Makefile.am         |    8 --------
 src/Makefile.am                |   13 ++++++++++++-
 src/app.vala                   |   17 ++++++-----------
 src/sidebar.vala               |    3 ++-
 src/util-app.vala              |   15 +++++++++++++++
 src/util.vala                  |    4 ----
 10 files changed, 53 insertions(+), 30 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index a2b9ecd..1581ab4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -42,6 +42,9 @@ GOBJECT_INTROSPECTION_REQUIRE([0.9.6])
 # Mallard help
 YELP_HELP_INIT
 
+# GResource
+AC_PATH_PROG(GLIB_COMPILE_RESOURCES, glib-compile-resources)
+
 # GSettings support
 GLIB_GSETTINGS
 
diff --git a/data/Makefile.am b/data/Makefile.am
index 8f6adda..2468a6a 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -18,9 +18,6 @@ appdata_in_file = gnome-boxes.appdata.xml.in
 appdata_DATA = $(appdata_in_file:.xml.in=.xml)
 @INTLTOOL_XML_RULE@
 
-styledir         = $(datadir)/gnome-boxes/style
-style_DATA       = gtk-style.css
-
 sourcedir         = $(datadir)/gnome-boxes/sources
 source_DATA       = QEMU_Session
 
@@ -44,13 +41,17 @@ logosdb_DATA= gnome-boxes-logos-db.xml
 disk.img:
        rm -f disk.img && qemu-img create -f raw disk.img 1440k && mkfs.msdos -s 1 disk.img
 
+gresource_file = gnome-boxes.gresource.xml
+resource_files = $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies $(gresource_file))
+
 EXTRA_DIST =                                   \
        gnome-boxes.desktop.in                  \
        gnome-boxes-search-provider.ini.in      \
        org.gnome.boxes.gschema.xml.in          \
+       $(gresource_file)                       \
+       $(resource_files)                       \
        $(desktop_in_files)                     \
        $(source_DATA)                          \
-       $(style_DATA)                           \
        $(unattended_DATA)                      \
        $(searchprovider_DATA)                  \
        $(logosdb_DATA)                         \
diff --git a/data/gnome-boxes.gresource.xml b/data/gnome-boxes.gresource.xml
new file mode 100644
index 0000000..00d5144
--- /dev/null
+++ b/data/gnome-boxes.gresource.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/org/gnome/Boxes">
+    <file>gtk-style.css</file>
+    <file>icons/boxes-arrow.svg</file>
+    <file>icons/boxes-dark.png</file>
+    <file>icons/boxes-gray.png</file>
+  </gresource>
+</gresources>
diff --git a/data/gtk-style.css b/data/gtk-style.css
index bd0bffc..367ae92 100644
--- a/data/gtk-style.css
+++ b/data/gtk-style.css
@@ -22,7 +22,7 @@ BoxesMiniGraph {
     background-color: @boxes_selected_color;
     border-width: 2px 8px 2px 0;
     border-color: transparent;
-    border-image-source: url("assets/boxes-arrow.svg");
+    border-image-source: url("icons/boxes-arrow.svg");
     border-image-slice: 0 8 0 0;
     border-image-width: 2px 8px 2px 0;
     border-image-repeat: stretch;
diff --git a/data/icons/Makefile.am b/data/icons/Makefile.am
index e834a65..af1aaf8 100644
--- a/data/icons/Makefile.am
+++ b/data/icons/Makefile.am
@@ -17,20 +17,12 @@ noinst_DATA =                                       \
        gnome-boxes.svg                         \
        $(NULL)
 
-assetsdir = $(datadir)/gnome-boxes/style/assets
-assets_DATA =                                  \
-       boxes-arrow.svg                         \
-       boxes-dark.png                          \
-       boxes-gray.png                          \
-       $(NULL)
-
 imagesdir = $(datadir)/gnome-boxes/pixmaps
 images_DATA =                                  \
        boxes-create.png                        \
        $(NULL)
 
 EXTRA_DIST =                                   \
-       $(assets_DATA)                          \
        $(images_DATA)                          \
        $(public_icons)                         \
        $(noinst_DATA)                          \
diff --git a/src/Makefile.am b/src/Makefile.am
index da1d380..e207e5c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -12,6 +12,8 @@ AM_CPPFLAGS =                                         \
        -I$(top_srcdir)/libgd                           \
        $(NULL)
 
+gresource_file = $(top_srcdir)/data/gnome-boxes.gresource.xml
+
 AM_VALAFLAGS =                                         \
        --enable-experimental                           \
        --target-glib= GLIB_MIN_VERSION@                \
@@ -38,6 +40,7 @@ AM_VALAFLAGS =                                                \
        --pkg linux                                     \
        --pkg spice-client-gtk-3.0                      \
        --pkg tracker-sparql-$(TRACKER_VERSION)         \
+       --gresources $(gresource_file)                  \
        $(VALA_DEBUG_FLAGS)                             \
        $(NULL)
 
@@ -73,12 +76,20 @@ libcommon_vala.stamp: $(libcommon_a_VALASOURCES)
 common.vapi libcommon.h: libcommon_vala.stamp
 $(libcommon_a_SOURCES): libcommon_vala.stamp
 
+resource_files = $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies --sourcedir=$(top_srcdir)/data 
$(gresource_file))
+resources.c: $(gresource_file) $(resource_files)
+       $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(top_srcdir)/data --generate-source $<
+
 MAINTAINERCLEANFILES += $(libcommon_a_SOURCES) $(libcommon_a_DEPENDENCIES)
-EXTRA_DIST += $(libcommon_a_DEPENDENCIES) $(libcommon_a_VALASOURCES)
+BUILT_SOURCES += resources.c
+EXTRA_DIST += $(libcommon_a_DEPENDENCIES) \
+             $(libcommon_a_VALASOURCES)  \
+             $(gresource_file)
 
 bin_PROGRAMS = gnome-boxes
 
 gnome_boxes_SOURCES =                          \
+       $(BUILT_SOURCES)                        \
        clutter-widget.vala                     \
        app.vala                                \
        collection-view.vala                    \
diff --git a/src/app.vala b/src/app.vala
index 1014503..53564e3 100644
--- a/src/app.vala
+++ b/src/app.vala
@@ -462,16 +462,10 @@ private class Boxes.App: Boxes.UI {
         Gtk.Window.set_default_icon_name ("gnome-boxes");
         Gtk.Settings.get_default ().gtk_application_prefer_dark_theme = true;
 
-        var provider = new Gtk.CssProvider ();
-        try {
-            var sheet = Boxes.get_style ("gtk-style.css");
-            provider.load_from_path (sheet);
-            Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (),
-                                                      provider,
-                                                      600);
-        } catch (GLib.Error error) {
-            warning (error.message);
-        }
+        var provider = Boxes.load_css ("gtk-style.css");
+        Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (),
+                                                  provider,
+                                                  600);
 
         window = new Gtk.ApplicationWindow (application);
         window.show_menubar = false;
@@ -553,9 +547,10 @@ private class Boxes.App: Boxes.UI {
         var background = new GtkClutter.Texture ();
         background.name = "background";
         try {
-            var pixbuf = new Gdk.Pixbuf.from_file (get_style ("assets/boxes-dark.png"));
+            var pixbuf = load_asset ("boxes-dark.png");
             background.set_from_pixbuf (pixbuf);
         } catch (GLib.Error e) {
+            warning ("Failed to load asset 'boxes-dark.png': %s", e.message);
         }
         background.set_repeat (true, true);
         background.x_align = Clutter.ActorAlign.FILL;
diff --git a/src/sidebar.vala b/src/sidebar.vala
index 614c03c..947efe7 100644
--- a/src/sidebar.vala
+++ b/src/sidebar.vala
@@ -71,9 +71,10 @@ private class Boxes.Sidebar: Boxes.UI {
         var background = new GtkClutter.Texture ();
         background.name = "sidebar-background";
         try {
-            var pixbuf = new Gdk.Pixbuf.from_file (get_style ("assets/boxes-gray.png"));
+            var pixbuf = load_asset ("boxes-gray.png");
             background.set_from_pixbuf (pixbuf);
         } catch (GLib.Error e) {
+            warning ("Failed to load asset 'boxes-gray.png': %s", e.message);
         }
         background.set_repeat (true, true);
         background.set_margin_right (shadow_width);
diff --git a/src/util-app.vala b/src/util-app.vala
index f4e2b54..2c33f1d 100644
--- a/src/util-app.vala
+++ b/src/util-app.vala
@@ -5,6 +5,21 @@ using Linux;
 
 namespace Boxes {
 
+    public Gtk.CssProvider load_css (string css) {
+        var provider = new CssProvider ();
+        try {
+            var file = File.new_for_uri("resource:///org/gnome/Boxes/" + css);
+            provider.load_from_file (file);
+        } catch (GLib.Error e) {
+            warning ("loading css: %s", e.message);
+        }
+        return provider;
+    }
+
+    public Gdk.Pixbuf load_asset (string asset) throws GLib.Error {
+        return new Gdk.Pixbuf.from_resource ("/org/gnome/Boxes/icons/" + asset);
+    }
+
     public Clutter.Color gdk_rgba_to_clutter_color (Gdk.RGBA gdk_rgba) {
         Clutter.Color color = {
             (uint8) (gdk_rgba.red * 255).clamp (0, 255),
diff --git a/src/util.vala b/src/util.vala
index e31a49c..2c5e0cd 100644
--- a/src/util.vala
+++ b/src/util.vala
@@ -13,10 +13,6 @@ namespace Boxes {
         return Path.build_filename (DATADIR, Config.PACKAGE_TARNAME, file_name);
     }
 
-    public string get_style (string? file_name = null) {
-        return Path.build_filename (get_pkgdata (), "style", file_name);
-    }
-
     public string get_pixmap (string? file_name = null) {
         return Path.build_filename (get_pkgdata (), "pixmaps", file_name);
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]