[devhelp] use resources to handle ui data



commit b57bb13e466ebdbceb611b190b82778d27be3d21
Author: Thomas Bechtold <thomasbechtold jpberlin de>
Date:   Fri Feb 1 10:32:32 2013 +0100

    use resources to handle ui data

 .gitignore                                |    2 ++
 data/Makefile.am                          |    2 +-
 data/ui/.cvsignore                        |    3 ---
 data/ui/Makefile.am                       |    4 ----
 po/POTFILES.in                            |    2 +-
 src/Makefile.am                           |   12 ++++++++++++
 data/ui/devhelp.builder => src/devhelp.ui |    0
 src/dh-app.c                              |    8 +++-----
 src/dh-util.c                             |    7 +++++--
 src/dh-window.c                           |    8 +++-----
 src/dh.gresource.xml                      |    6 ++++++
 11 files changed, 33 insertions(+), 21 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 27933f9..e0ce0b5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -51,4 +51,6 @@ libtool
 /src/dh-marshal.h
 /src/dh-enum-types.c
 /src/dh-enum-types.h
+/src/dh-resources.c
+/src/dh-resources.h
 /stamp-h1
diff --git a/data/Makefile.am b/data/Makefile.am
index b332329..5c750d1 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = ui dtd icons
+SUBDIRS = dtd icons
 
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = libdevhelp-3.0.pc
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 24247b2..726eb83 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -2,7 +2,7 @@
 # Please keep this file sorted alphabetically.
 data/devhelp.desktop.in.in
 [type: gettext/gsettings]data/org.gnome.devhelp.gschema.xml
-[type: gettext/glade]data/ui/devhelp.builder
+[type: gettext/glade]src/devhelp.ui
 misc/gedit-plugin/devhelp.desktop.in
 misc/gedit-plugin/devhelp.py
 src/dh-app.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 4b70e5d..6be4815 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -5,17 +5,27 @@ dh-marshal.c: dh-marshal.list
 	$(AM_V_GEN) echo "#include \"dh-marshal.h\"" > $@ && \
 	$(GLIB_GENMARSHAL) $< --body --prefix=_dh_marshal dh-marshal.list >> $@
 
+resource_files = $(shell glib-compile-resources --sourcedir=$(srcdir) --generate-dependencies $(srcdir)/dh.gresource.xml)
+dh-resources.c: dh.gresource.xml $(resource_files)
+	glib-compile-resources --target=$@ --sourcedir=$(srcdir) --generate-source --c-name dh $(srcdir)/dh.gresource.xml
+dh-resources.h: dh.gresource.xml $(resource_files)
+	glib-compile-resources --target=$@ --sourcedir=$(srcdir) --generate-header --c-name dh $(srcdir)/dh.gresource.xml
+
 BUILT_SOURCES = 		\
 	dh-marshal.h		\
 	dh-marshal.c		\
 	dh-enum-types.h		\
 	dh-enum-types.c		\
+	dh-resources.c	 	\
+	dh-resources.h 		\
 	$(NULL)
 
 EXTRA_DIST =			\
 	dh-marshal.list		\
 	dh-enum-types.c.template \
 	dh-enum-types.h.template \
+	$(resource_files)	\
+	dh.gresource.xml	\
 	$(NULL)
 
 AM_CPPFLAGS = 						\
@@ -93,6 +103,8 @@ libdevhelp_3_la_SOURCES =				\
 	dh-util.h					\
 	dh-settings.c					\
 	dh-settings.h					\
+	dh-resources.c				 	\
+	dh-resources.h 					\
 	eggfindbar.c					\
 	eggfindbar.h
 
diff --git a/data/ui/devhelp.builder b/src/devhelp.ui
similarity index 100%
rename from data/ui/devhelp.builder
rename to src/devhelp.ui
diff --git a/src/dh-app.c b/src/dh-app.c
index 819d754..780ea6c 100644
--- a/src/dh-app.c
+++ b/src/dh-app.c
@@ -301,10 +301,9 @@ setup_menu (DhApp *self)
 
         builder = gtk_builder_new ();
 
-        path = dh_util_build_data_filename ("devhelp", "ui", "devhelp.builder", NULL);
-        if (!gtk_builder_add_from_file (builder, path, &error)) {
-                g_error ("Cannot create builder from '%s': %s",
-                         path, error ? error->message : "unknown error");
+        if (!gtk_builder_add_from_resource (builder, "/org/gnome/devhelp/devhelp.ui", &error)) {
+                g_error ("%s",error ? error->message : "unknown error");
+                g_clear_error (&error);
         }
 
         model = G_MENU_MODEL (gtk_builder_get_object (builder, "app-menu"));
@@ -313,7 +312,6 @@ setup_menu (DhApp *self)
         model = G_MENU_MODEL (gtk_builder_get_object (builder, "window-menu"));
         gtk_application_set_menubar (GTK_APPLICATION (self), model);
 
-        g_free (path);
         g_object_unref (builder);
 }
 
diff --git a/src/dh-util.c b/src/dh-util.c
index 12a9670..c24480b 100644
--- a/src/dh-util.c
+++ b/src/dh-util.c
@@ -40,11 +40,14 @@ get_builder_file (const gchar *filename,
         GtkBuilder  *builder;
         const char  *name;
         GObject    **object_ptr;
+        GError      *error = NULL;
 
         builder = gtk_builder_new ();
-        if (!gtk_builder_add_from_file (builder, filename, NULL)) {
-                g_warning ("Couldn't find necessary UI file '%s'", filename);
+
+        if (!gtk_builder_add_from_resource (builder, "/org/gnome/devhelp/devhelp.ui", &error)) {
+                g_warning ("Couldn't add resource: %s", error ? error->message : "unknown");
                 g_object_unref (builder);
+                g_clear_error (&error);
                 return NULL;
         }
 
diff --git a/src/dh-window.c b/src/dh-window.c
index 3010286..30d86f9 100644
--- a/src/dh-window.c
+++ b/src/dh-window.c
@@ -871,12 +871,10 @@ dh_window_init (DhWindow *window)
 
         /* Setup builder */
         priv->builder = gtk_builder_new ();
-        path = dh_util_build_data_filename ("devhelp", "ui", "devhelp.builder", NULL);
-        if (!gtk_builder_add_from_file (priv->builder, path, &error)) {
-                g_error ("Cannot create builder from '%s': %s",
-                         path, error ? error->message : "unknown error");
+        if (!gtk_builder_add_from_resource (priv->builder, "/org/gnome/devhelp/devhelp.ui", &error)) {
+                g_error ("Cannot add resource to builder: %s", error ? error->message : "unknown error");
+                g_clear_error (&error);
         }
-        g_free (path);
 
         priv->main_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
         gtk_widget_show (priv->main_box);
diff --git a/src/dh.gresource.xml b/src/dh.gresource.xml
new file mode 100644
index 0000000..6d6ea52
--- /dev/null
+++ b/src/dh.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/org/gnome/devhelp">
+    <file>devhelp.ui</file>
+  </gresource>
+</gresources>
\ No newline at end of file



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