[gnome-calculator] Use gresources for .ui files



commit 8f28648326d5910a85d5874ca01e24ad9b6963d6
Author: Paolo Borelli <pborelli gnome org>
Date:   Sat Apr 13 19:34:29 2013 +0200

    Use gresources for .ui files
    
    https://bugzilla.gnome.org/show_bug.cgi?id=697961

 configure.ac                        |  2 ++
 data/Makefile.am                    | 17 +++++++++--------
 data/gnome-calculator.gresource.xml |  9 +++++++++
 src/Makefile.am                     |  8 +++++++-
 src/math-buttons.vala               | 16 ++++++++--------
 5 files changed, 35 insertions(+), 17 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index f841184..ef1bc69 100644
--- a/configure.ac
+++ b/configure.ac
@@ -9,6 +9,8 @@ GNOME_MAINTAINER_MODE_DEFINES
 AM_PROG_VALAC([0.18.0])
 AM_PROG_CC_C_O
 
+AC_PATH_PROG(GLIB_COMPILE_RESOURCES, glib-compile-resources)
+
 GLIB_GSETTINGS
 
 dnl ###########################################################################
diff --git a/data/Makefile.am b/data/Makefile.am
index 40e7052..1f9e635 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -1,10 +1,3 @@
-uidir = $(pkgdatadir)
-ui_DATA = \
-       buttons-basic.ui \
-       buttons-advanced.ui \
-       buttons-financial.ui \
-       buttons-programming.ui
-
 gsettings_SCHEMAS = org.gnome.calculator.gschema.xml
 @INTLTOOL_XML_NOMERGE_RULE@
 @GSETTINGS_RULES@
@@ -16,7 +9,15 @@ Utilities_DATA = $(Utilities_in_files:.desktop.in=.desktop)
 
 man1_MANS = gnome-calculator.1 gcalccmd.1
 
-EXTRA_DIST = $(ui_DATA) org.gnome.calculator.gschema.xml.in gcalctool.desktop.in $(man1_MANS)
+EXTRA_DIST = \
+       buttons-basic.ui \
+       buttons-advanced.ui \
+       buttons-financial.ui \
+       buttons-programming.ui \
+       gnome-calculator.gresource.xml \
+       org.gnome.calculator.gschema.xml.in \
+       gcalctool.desktop.in \
+       $(man1_MANS)
 
 DISTCLEANFILES = \
        Makefile.in \
diff --git a/data/gnome-calculator.gresource.xml b/data/gnome-calculator.gresource.xml
new file mode 100644
index 0000000..3a9d73d
--- /dev/null
+++ b/data/gnome-calculator.gresource.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/org/gnome/calculator">
+    <file preprocess="xml-stripblanks">buttons-advanced.ui</file>
+    <file preprocess="xml-stripblanks">buttons-basic.ui</file>
+    <file preprocess="xml-stripblanks">buttons-financial.ui</file>
+    <file preprocess="xml-stripblanks">buttons-programming.ui</file>
+  </gresource>
+</gresources>
diff --git a/src/Makefile.am b/src/Makefile.am
index 1db2399..8616061 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -11,6 +11,11 @@ INCLUDES = \
        $(WARN_CFLAGS) \
        $(GNOME_CALCULATOR_CFLAGS)
 
+BUILT_SOURCES = resources.c
+
+resources.c: $(top_srcdir)/data/gnome-calculator.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) 
--generate-dependencies --sourcedir=$(top_srcdir)/data/ $(top_srcdir)/data/gnome-calculator.gresource.xml)
+       $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(top_srcdir)/data/ --generate-source $<
+
 gnome_calculator_SOURCES = \
        config.vapi \
        fixes.vapi \
@@ -30,7 +35,8 @@ gnome_calculator_SOURCES = \
        math-window.vala \
        number.vala \
        serializer.vala \
-       unit.vala
+       unit.vala \
+       $(BUILT_SOURCES)
 
 gnome_calculator_VALAFLAGS = \
        --target-glib 2.32 \
diff --git a/src/math-buttons.vala b/src/math-buttons.vala
index 8994c77..6b1418b 100644
--- a/src/math-buttons.vala
+++ b/src/math-buttons.vala
@@ -234,7 +234,7 @@ public class MathButtons : Gtk.Box
                                    "syd_dialog", "term_dialog", "adjustment1", "adjustment2", null };
 
         Gtk.Builder builder;
-        string builder_filename;
+        string builder_resource;
         switch (mode)
         {
         default:
@@ -242,37 +242,37 @@ public class MathButtons : Gtk.Box
             if (bas_panel != null)
                 return bas_panel;
             builder = basic_ui = new Gtk.Builder ();
-            builder_filename = Path.build_filename (UI_DIR, "buttons-basic.ui");
+            builder_resource = "buttons-basic.ui";
             break;
         case ButtonMode.ADVANCED:
             if (adv_panel != null)
                 return adv_panel;
             builder = advanced_ui = new Gtk.Builder ();
-            builder_filename = Path.build_filename (UI_DIR, "buttons-advanced.ui");
+            builder_resource = "buttons-advanced.ui";
             break;
         case ButtonMode.FINANCIAL:
             if (fin_panel != null)
                 return fin_panel;
             builder = financial_ui = new Gtk.Builder ();
-            builder_filename = Path.build_filename (UI_DIR, "buttons-financial.ui");
+            builder_resource = "buttons-financial.ui";
             break;
         case ButtonMode.PROGRAMMING:
             if (prog_panel != null)
                 return prog_panel;
             builder = programming_ui = new Gtk.Builder ();
-            builder_filename = Path.build_filename (UI_DIR, "buttons-programming.ui");            
+            builder_resource = "buttons-programming.ui";
             break;
         }
 
-        // FIXME: Show dialog if failed to load
         try
         {
-            builder.add_objects_from_file (builder_filename, objects);
+            builder.add_objects_from_resource ("/org/gnome/calculator/%s".printf(builder_resource), objects);
         }
         catch (Error e)
         {
-            warning ("Error loading button UI: %s", e.message);
+            error ("Error loading button UI: %s", e.message);
         }
+
         var panel = builder.get_object ("button_panel") as Gtk.Widget;
         pack_end (panel, true, true, 0);
 


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