[seahorse] build: Bundle data files as GResource



commit 9d12b992eb28f4a205a5e4fa67597068babc2690
Author: Daiki Ueno <dueno src gnome org>
Date:   Fri Jul 17 10:47:53 2015 +0900

    build: Bundle data files as GResource
    
    To make it possible to test UI changes without installing UI files,
    bundle them in the seahorse executable, using GResource.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=752516

 Makefile.am                       |   11 +++------
 common/catalog.vala               |    4 +-
 common/config.vapi                |    1 -
 common/util.vala                  |    4 +-
 configure.ac                      |    3 ++
 gkr/Makefile.am                   |    2 +-
 gkr/gkr-item-properties.vala      |    4 +-
 gkr/gkr-keyring-properties.vala   |    4 +-
 libseahorse/Makefile.am           |   40 ++++++++++++++++++++++++++++++++++--
 libseahorse/seahorse-widget.c     |   19 ++++++-----------
 pgp/Makefile.am                   |    2 +-
 pkcs11/Makefile.am                |    2 +-
 pkcs11/pkcs11-request.vala        |    4 +-
 pkcs11/seahorse-pkcs11-generate.c |    4 +-
 src/Makefile.am                   |    4 +-
 src/seahorse-generate-select.c    |    4 +-
 src/seahorse-main.c               |    3 ++
 ssh/Makefile.am                   |    2 +-
 18 files changed, 74 insertions(+), 43 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index ad7b94c..4028df5 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -31,7 +31,7 @@ DISTCLEANFILES = \
     intltool-extract \
     intltool-merge \
     intltool-update
-    
+
 DISTCHECK_CONFIGURE_FLAGS = \
     --disable-scrollkeeper \
     --disable-update-mime-database \
@@ -71,16 +71,15 @@ man_MANS =
 pkgdatadir = $(datadir)/seahorse
 localedir = $(datadir)/locale
 
-uidir = $(datadir)/seahorse/ui/
-ui_DATA =
+ui_files =
 
 seahorselibexecbindir = $(libdir)/seahorse/
 seahorselibexecbin_PROGRAMS =
 
 BUILT_SOURCES =
 CLEANFILES = $(BUILT_SOURCES)
-EXTRA_DIST += $(ui_DATA)
-DISTCLEANFILES +=
+EXTRA_DIST += $(ui_files)
+MAINTAINERCLEANFILES =
 
 AM_CPPFLAGS = \
        -I$(top_builddir) \
@@ -88,8 +87,6 @@ AM_CPPFLAGS = \
        -I$(top_builddir)/common \
        -I$(top_srcdir)/common \
        -DPKGDATADIR=\""$(pkgdatadir)/"\" \
-       -DUIDIR=\""$(uidir)"\" \
-       -DSEAHORSE_UIDIR=\""$(uidir)/"\" \
        -DLOCALEDIR=\"$(localedir)\" \
        -DGETTEXT_PACKAGE=\""seahorse\"" \
        -DEXECDIR=\""$(seahorselibexecbindir)"\" \
diff --git a/common/catalog.vala b/common/catalog.vala
index 65e8904..01eba7c 100644
--- a/common/catalog.vala
+++ b/common/catalog.vala
@@ -87,8 +87,8 @@ public abstract class Catalog : Gtk.Window {
 
                /* The widgts get added in an idle loop later */
                try {
-                       var path = GLib.Path.build_filename(Config.UIDIR, 
"seahorse-%s.ui".printf(this.ui_name));
-                       this._ui_manager.add_ui_from_file(path);
+                       var path = "/org/gnome/Seahorse/seahorse-%s.ui".printf(this.ui_name);
+                       this._ui_manager.add_ui_from_resource(path);
                } catch (GLib.Error err) {
                        GLib.warning("couldn't load ui description for '%s': %s",
                                     this.ui_name, err.message);
diff --git a/common/config.vapi b/common/config.vapi
index 4de8348..072645e 100644
--- a/common/config.vapi
+++ b/common/config.vapi
@@ -2,7 +2,6 @@
 namespace Config
 {
        public const string PKGDATADIR;
-       public const string UIDIR;
 
        public const string VERSION;
        public const string PACKAGE;
diff --git a/common/util.vala b/common/util.vala
index de378d5..62ecb62 100644
--- a/common/util.vala
+++ b/common/util.vala
@@ -63,13 +63,13 @@ namespace Util {
        public Gtk.Builder load_built_contents(Gtk.Container? frame,
                                               string name) {
                var builder = new Gtk.Builder();
-               string path = GLib.Path.build_filename(Config.UIDIR, "seahorse-%s.xml".printf(name));
+               string path = "/org/gnome/Seahorse/seahorse-%s.xml".printf(name);
 
                if (frame != null && frame is Gtk.Dialog)
                        frame = ((Gtk.Dialog)frame).get_content_area();
 
                try {
-                       builder.add_from_file(path);
+                       builder.add_from_resource(path);
                        var obj = builder.get_object(name);
                        if (obj == null) {
                                GLib.critical("Couldn't find object named %s in %s", name, path);
diff --git a/configure.ac b/configure.ac
index bf34ea9..d462604 100644
--- a/configure.ac
+++ b/configure.ac
@@ -89,6 +89,9 @@ PKG_CHECK_MODULES(SEAHORSE, gmodule-2.0 gio-2.0 gthread-2.0 gtk+-3.0 >= $GTK_REQ
 SEAHORSE_CFLAGS="$SEAHORSE_CFLAGS -DGCR_API_SUBJECT_TO_CHANGE -DGCK_API_SUBJECT_TO_CHANGE"
 SEAHORSE_CFLAGS="$SEAHORSE_CFLAGS -DGTK_VERSION_MAX_ALLOWED=$GTK_MAX"
 
+GLIB_COMPILE_RESOURCES=`$PKG_CONFIG --variable glib_compile_resources gio-2.0`
+AC_SUBST(GLIB_COMPILE_RESOURCES)
+
 # User documentation
 YELP_HELP_INIT
 
diff --git a/gkr/Makefile.am b/gkr/Makefile.am
index ba5a996..1294cdf 100644
--- a/gkr/Makefile.am
+++ b/gkr/Makefile.am
@@ -44,7 +44,7 @@ EXTRA_DIST += \
        $(gkr_VALA) \
        $(NULL)
 
-ui_DATA += \
+ui_files += \
        gkr/seahorse-add-keyring.xml \
        gkr/seahorse-gkr-add-item.xml \
        gkr/seahorse-gkr-item-properties.xml \
diff --git a/gkr/gkr-item-properties.vala b/gkr/gkr-item-properties.vala
index 71cb766..3604cc2 100644
--- a/gkr/gkr-item-properties.vala
+++ b/gkr/gkr-item-properties.vala
@@ -33,8 +33,8 @@ public class ItemProperties : Gtk.Dialog {
        construct {
                this._builder = new Gtk.Builder();
                try {
-                       string path = GLib.Path.build_filename(Config.UIDIR, 
"seahorse-gkr-item-properties.xml");
-                       this._builder.add_from_file(path);
+                       string path = "/org/gnome/Seahorse/seahorse-gkr-item-properties.xml";
+                       this._builder.add_from_resource(path);
                } catch (GLib.Error err) {
                        GLib.critical ("%s", err.message);
                }
diff --git a/gkr/gkr-keyring-properties.vala b/gkr/gkr-keyring-properties.vala
index 3fc7f07..7bbc46b 100644
--- a/gkr/gkr-keyring-properties.vala
+++ b/gkr/gkr-keyring-properties.vala
@@ -27,8 +27,8 @@ public class KeyringProperties : Gtk.Dialog {
        construct {
                this._builder = new Gtk.Builder();
                try {
-                       string path = GLib.Path.build_filename(Config.UIDIR, "seahorse-gkr-keyring.xml");
-                       this._builder.add_from_file(path);
+                       string path = "/org/gnome/Seahorse/seahorse-gkr-keyring.xml";
+                       this._builder.add_from_resource(path);
                } catch (GLib.Error err) {
                        GLib.critical ("%s", err.message);
                }
diff --git a/libseahorse/Makefile.am b/libseahorse/Makefile.am
index 8936395..60a59f1 100644
--- a/libseahorse/Makefile.am
+++ b/libseahorse/Makefile.am
@@ -15,9 +15,13 @@ $(dbus_shell_search_provider_built_sources) : Makefile.am $(srcdir)/libseahorse/
 MARSHAL_SRCS = \
        seahorse-marshal.c seahorse-marshal.h
 
+RESOURCES_SRCS = \
+       seahorse-resources.c seahorse-resources.h
+
 BUILT_SOURCES += \
        $(dbus_shell_search_provider_built_sources) \
-       $(MARSHAL_SRCS)
+       $(MARSHAL_SRCS) \
+       $(RESOURCES_SRCS)
 
 noinst_LIBRARIES += libseahorse.a
 
@@ -48,6 +52,7 @@ libseahorse_a_SOURCES = \
        libseahorse/seahorse-widget.c libseahorse/seahorse-widget.h \
        $(dbus_shell_search_provider_built_sources) \
        $(MARSHAL_SRCS) \
+       $(RESOURCES_SRCS) \
        $(KEYSERVER_SRCS)
 
 seahorse-marshal.h: libseahorse/seahorse-marshal.list $(GLIB_GENMARSHAL)
@@ -57,7 +62,32 @@ seahorse-marshal.c: libseahorse/seahorse-marshal.list $(GLIB_GENMARSHAL)
        $(AM_V_GEN) echo "#include \"seahorse-marshal.h\"" > $@ && \
        $(GLIB_GENMARSHAL) $< --body --prefix=seahorse_marshal >> $@
 
-ui_DATA += \
+seahorse-resources.h: libseahorse/seahorse.gresource.xml $(ui_files)
+       $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ \
+               --sourcedir=$(srcdir) --generate-header --manual-register $<
+
+seahorse-resources.c: libseahorse/seahorse.gresource.xml $(ui_files)
+       $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ \
+               --sourcedir=$(srcdir) --generate-source --manual-register $<
+
+libseahorse/seahorse.gresource.xml: Makefile.am
+       $(AM_V_GEN) echo "<?xml version='1.0' encoding='UTF-8'?>" > $@; \
+       echo "<gresources>" >> $@; \
+       echo "  <gresource prefix='/org/gnome/Seahorse'>" >> $@; \
+       list='$(ui_files)'; \
+       for f in $$list; do \
+         n=`basename $$f`; \
+         case "$$n" in \
+         *.xml) \
+           echo "    <file alias='"$$n"' preprocess='xml-stripblanks'>$$f</file>" >> $@ ;; \
+         *) \
+           echo "    <file alias='"$$n"'>$$f</file>" >> $@ ;; \
+         esac; \
+       done; \
+       echo "  </gresource>" >> $@; \
+       echo "</gresources>" >> $@;
+
+ui_files += \
        libseahorse/seahorse-prefs.xml \
        libseahorse/seahorse-add-keyserver.xml \
        libseahorse/seahorse-progress.xml \
@@ -65,4 +95,8 @@ ui_DATA += \
 
 EXTRA_DIST += \
        libseahorse/seahorse-marshal.list \
-       libseahorse/org.gnome.ShellSearchProvider2.xml
+       libseahorse/org.gnome.ShellSearchProvider2.xml \
+       libseahorse/seahorse.gresource.xml
+
+MAINTAINERCLEANFILES += \
+       libseahorse/seahorse.gresource.xml
diff --git a/libseahorse/seahorse-widget.c b/libseahorse/seahorse-widget.c
index 49284e4..3d3a572 100644
--- a/libseahorse/seahorse-widget.c
+++ b/libseahorse/seahorse-widget.c
@@ -150,7 +150,6 @@ class_init (SeahorseWidgetClass *klass)
 {
        GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
        GtkCssProvider *css_provider;
-       GError *error = NULL;
 
        parent_class = g_type_class_peek_parent (klass);
 
@@ -169,14 +168,10 @@ class_init (SeahorseWidgetClass *klass)
                                         NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
 
        css_provider = gtk_css_provider_new ();
-       if (gtk_css_provider_load_from_path (css_provider, SEAHORSE_UIDIR "seahorse.css", &error)) {
-               gtk_style_context_add_provider_for_screen (gdk_screen_get_default (),
-                                                          GTK_STYLE_PROVIDER (css_provider),
-                                                          GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
-       } else {
-               g_warning ("couldn't load %s file: %s", SEAHORSE_UIDIR "seahorse.css", error->message);
-               g_error_free (error);
-       }
+       gtk_css_provider_load_from_resource (css_provider, "/org/gnome/Seahorse/seahorse.css");
+       gtk_style_context_add_provider_for_screen (gdk_screen_get_default (),
+                                                  GTK_STYLE_PROVIDER (css_provider),
+                                                  GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
        g_object_unref (css_provider);
 }
 
@@ -268,10 +263,10 @@ object_set_property (GObject *object, guint prop_id, const GValue *value, GParam
     case PROP_NAME:
         g_return_if_fail (swidget->name == NULL);
         swidget->name = g_value_dup_string (value);
-        path = g_strdup_printf ("%sseahorse-%s.xml",
-                                SEAHORSE_UIDIR, swidget->name);
+        path = g_strdup_printf ("/org/gnome/Seahorse/seahorse-%s.xml",
+                                swidget->name);
         swidget->gtkbuilder = gtk_builder_new ();
-        gtk_builder_add_from_file (swidget->gtkbuilder, path, &error);
+        gtk_builder_add_from_resource (swidget->gtkbuilder, path, &error);
         if (error)
           {
             g_warning ("Error parsing %s: %s\n", path, error->message);
diff --git a/pgp/Makefile.am b/pgp/Makefile.am
index d13852f..6bc7e74 100644
--- a/pgp/Makefile.am
+++ b/pgp/Makefile.am
@@ -69,7 +69,7 @@ seahorselibexecbin_PROGRAMS += xloadimage
 
 xloadimage_SOURCES = pgp/seahorse-xloadimage.c
 
-ui_DATA += \
+ui_files += \
        pgp/seahorse-add-subkey.xml \
        pgp/seahorse-add-uid.xml \
        pgp/seahorse-expires.xml \
diff --git a/pkcs11/Makefile.am b/pkcs11/Makefile.am
index 27ced64..cff3de5 100644
--- a/pkcs11/Makefile.am
+++ b/pkcs11/Makefile.am
@@ -46,6 +46,6 @@ EXTRA_DIST += \
        $(pkcs11_VALA) \
        $(NULL)
 
-ui_DATA += \
+ui_files += \
        pkcs11/seahorse-pkcs11-generate.xml \
        pkcs11/seahorse-pkcs11-request.xml
diff --git a/pkcs11/pkcs11-request.vala b/pkcs11/pkcs11-request.vala
index d676ea3..f5960cf 100644
--- a/pkcs11/pkcs11-request.vala
+++ b/pkcs11/pkcs11-request.vala
@@ -34,9 +34,9 @@ public class Request : Gtk.Dialog {
 
        construct {
                var builder = new Gtk.Builder();
-               var path = Config.UIDIR + "seahorse-pkcs11-request.xml";
+               var path = "/org/gnome/Seahorse/seahorse-pkcs11-request.xml";
                try {
-                       builder.add_from_file(path);
+                       builder.add_from_resource(path);
                } catch (GLib.Error err) {
                        GLib.warning("couldn't load ui file: %s", path);
                        return;
diff --git a/pkcs11/seahorse-pkcs11-generate.c b/pkcs11/seahorse-pkcs11-generate.c
index ccadc45..86dbcc5 100644
--- a/pkcs11/seahorse-pkcs11-generate.c
+++ b/pkcs11/seahorse-pkcs11-generate.c
@@ -351,8 +351,8 @@ seahorse_pkcs11_generate_constructed (GObject *obj)
        G_OBJECT_CLASS (seahorse_pkcs11_generate_parent_class)->constructed (obj);
 
        builder = gtk_builder_new ();
-       path = UIDIR "/seahorse-pkcs11-generate.xml";
-       gtk_builder_add_from_file (builder, path, &error);
+       path = "/org/gnome/Seahorse/seahorse-pkcs11-generate.xml";
+       gtk_builder_add_from_resource (builder, path, &error);
        if (error != NULL) {
                g_warning ("couldn't load ui file: %s", path);
                g_clear_error (&error);
diff --git a/src/Makefile.am b/src/Makefile.am
index 3d17714..6dca4fa 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -41,7 +41,7 @@ seahorse_LDADD = \
        libeggtreemultidnd.a \
        $(SEAHORSE_LIBS)
 
-ui_DATA += \
+ui_files += \
        src/seahorse-key-manager.ui \
        src/seahorse-key-manager.xml \
        src/seahorse-change-passphrase.xml \
@@ -51,7 +51,7 @@ man_MANS += src/seahorse.1
 
 EXTRA_DIST += \
        $(man_MANS) \
-       $(ui_DATA) \
+       $(ui_files) \
        $(NULL)
 
 CLEANFILES += *.xmlp* *.bak \
diff --git a/src/seahorse-generate-select.c b/src/seahorse-generate-select.c
index bcfed6b..c152add 100644
--- a/src/seahorse-generate-select.c
+++ b/src/seahorse-generate-select.c
@@ -208,8 +208,8 @@ seahorse_generate_select_constructed (GObject *obj)
        }
 
        builder = gtk_builder_new ();
-       path = SEAHORSE_UIDIR "/seahorse-generate-select.xml";
-       gtk_builder_add_from_file (builder, path, &error);
+       path = "/org/gnome/Seahorse/seahorse-generate-select.xml";
+       gtk_builder_add_from_resource (builder, path, &error);
        if (error != NULL) {
                g_warning ("couldn't load ui file: %s", path);
                g_clear_error (&error);
diff --git a/src/seahorse-main.c b/src/seahorse-main.c
index e692ba5..b5ad1d5 100644
--- a/src/seahorse-main.c
+++ b/src/seahorse-main.c
@@ -23,6 +23,7 @@
 #include "seahorse-key-manager.h"
 
 #include "seahorse-common.h"
+#include "seahorse-resources.h"
 
 #include "libseahorse/seahorse-application.h"
 #include "libseahorse/seahorse-servers.h"
@@ -86,6 +87,8 @@ main (int argc, char **argv)
        g_type_init ();
 #endif
 
+       seahorse_register_resource ();
+
        application = seahorse_application_new ();
        g_signal_connect (application, "activate", G_CALLBACK (on_application_activate), NULL);
        g_signal_connect (application, "startup", G_CALLBACK (on_application_startup), NULL);
diff --git a/ssh/Makefile.am b/ssh/Makefile.am
index c7b436a..e2aa192 100644
--- a/ssh/Makefile.am
+++ b/ssh/Makefile.am
@@ -24,7 +24,7 @@ seahorse_ssh_askpass_SOURCES = \
 seahorse_ssh_askpass_LDADD = \
        $(SEAHORSE_LIBS)
 
-ui_DATA += \
+ui_files += \
        ssh/seahorse-ssh-key-properties.xml \
        ssh/seahorse-ssh-generate.xml \
        ssh/seahorse-ssh-upload.xml



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