[gnome-dictionary] Move UI definitions to GResource
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-dictionary] Move UI definitions to GResource
- Date: Sun, 1 Mar 2015 17:14:58 +0000 (UTC)
commit 65ae8966068a0807c3a8e12a4e9344e163a7e488
Author: Emmanuele Bassi <ebassi gnome org>
Date: Sun Mar 1 17:08:30 2015 +0000
Move UI definitions to GResource
We still install the UI definitions on the file system, and then we load
them every time it's needed. The current best practice for this kind of
files is to use the GResource API inside GIO, and have them compiled
inside the binary. This helps with performance and relocatability.
configure.ac | 8 ++++++--
data/Makefile.am | 11 -----------
libgdict/Makefile.am | 4 ++--
po/POTFILES.in | 6 +++---
src/Makefile.am | 12 ++++++++++++
src/gdict-app.c | 10 +---------
src/gdict-pref-dialog.c | 11 ++---------
src/gdict-source-dialog.c | 12 ++----------
src/gdict.gresource.xml | 8 ++++++++
{data => src}/gnome-dictionary-menus.ui | 0
{data => src}/gnome-dictionary-preferences.ui | 0
{data => src}/gnome-dictionary-source.ui | 0
12 files changed, 36 insertions(+), 46 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index ab6d346..9bc6b39 100644
--- a/configure.ac
+++ b/configure.ac
@@ -31,8 +31,12 @@ AC_SUBST(GETTEXT_PACKAGE)
AM_GLIB_GNU_GETTEXT
-AC_PATH_PROG(GLIB_GENMARSHAL, [glib-genmarshal])
-AC_PATH_PROG(GLIB_MKENUMS, [glib-mkenums])
+GLIB_MKENUMS=`$PKG_CONFIG --variable glib_mkenums glib-2.0`
+GLIB_GENMARSHAL=`$PKG_CONFIG --variable glib_genmarshal glib-2.0`
+GLIB_COMPILE_RESOURCES=`$PKG_CONFIG --variable glib_compile_resources gio-2.0`
+AC_SUBST(GLIB_MKENUMS)
+AC_SUBST(GLIB_GENMARSHAL)
+AC_SUBST(GLIB_COMPILE_RESOURCES)
# Before making a release, the LT_VERSION string should be modified.
# The string is of the form C:R:A.
diff --git a/data/Makefile.am b/data/Makefile.am
index 10b3c94..103782f 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -43,17 +43,6 @@ dictsource_DATA = $(dictsource_in_files:.desktop.in=.desktop)
EXTRA_DIST += $(dictsource_in_files)
-builderdir = $(datadir)/gnome-dictionary
-builder_DATA = \
- gnome-dictionary-preferences.ui \
- gnome-dictionary-source.ui \
- gnome-dictionary-menus.ui \
- $(NULL)
-
-EXTRA_DIST += \
- $(builder_DATA) \
- $(NULL)
-
gsettings_SCHEMAS = org.gnome.dictionary.gschema.xml
CLEANFILES += $(gsettings_SCHEMAS) \
$(dictsource_DATA) \
diff --git a/libgdict/Makefile.am b/libgdict/Makefile.am
index 652c659..0b11438 100644
--- a/libgdict/Makefile.am
+++ b/libgdict/Makefile.am
@@ -117,14 +117,14 @@ endif
gdict-marshal.h: stamp-gdict-marshal.h
@true
-stamp-gdict-marshal.h: gdict-marshal.list $(GLIB_GENMARSHAL) Makefile
+stamp-gdict-marshal.h: gdict-marshal.list Makefile
$(AM_V_GEN)$(GLIB_GENMARSHAL) \
$(srcdir)/gdict-marshal.list --header --prefix=gdict_marshal >> xgen-gmh \
&& ( cmp -s xgen-gmh gdict-marshal.h || cp xgen-gmh gdict-marshal.h ) \
&& rm -f xgen-gmh \
&& echo timestamp > $@
-gdict-marshal.c: gdict-marshal.list $(GLIB_GENMARSHAL) Makefile
+gdict-marshal.c: gdict-marshal.list Makefile
$(AM_V_GEN)( echo "#include \"gdict-marshal.h\""; echo; \
$(GLIB_GENMARSHAL) \
$(srcdir)/gdict-marshal.list --body --prefix=gdict_marshal ) >> xgen-gmc \
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 6ef2ea2..9325b6d 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -2,9 +2,9 @@
# Please keep this file sorted alphabetically.
data/default.desktop.in
data/org.gnome.Dictionary.appdata.xml.in
-[type: gettext/glade]data/gnome-dictionary-menus.ui
-[type: gettext/glade]data/gnome-dictionary-preferences.ui
-[type: gettext/glade]data/gnome-dictionary-source.ui
+[type: gettext/glade]src/gnome-dictionary-menus.ui
+[type: gettext/glade]src/gnome-dictionary-preferences.ui
+[type: gettext/glade]src/gnome-dictionary-source.ui
data/org.gnome.Dictionary.desktop.in.in
data/org.gnome.dictionary.gschema.xml.in.in
data/spanish.desktop.in
diff --git a/src/Makefile.am b/src/Makefile.am
index e5b44f2..6ebe48e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -2,6 +2,8 @@ NULL =
bin_PROGRAMS = gnome-dictionary
+BUILT_SOURCES = gdict-resources.c
+
gnome_dictionary_CPPFLAGS = \
-DPREFIX=\""$(prefix)"\" \
-DSYSCONFDIR=\""$(sysconfdir)"\" \
@@ -39,7 +41,17 @@ gnome_dictionary_SOURCES = \
main.c \
$(NULL)
+nodist_gnome_dictionary_SOURCES = gdict-resources.c
+
gnome_dictionary_LDADD = $(top_builddir)/libgdict/libgdict-1.0.la $(GDICT_LIBS) $(LIBM)
gnome_dictionary_DEPENDENCIES = $(top_builddir)/libgdict/libgdict-1.0.la
+CLEANFILES = gdict-resources.c
+EXTRA_DIST = gdict.gresource.xml $(resource_files)
+
+resource_files = $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir=$(srcdir) --generate-dependencies
$(srcdir)/gdict.gresource.xml)
+
+gdict-resources.c: gdict.gresource.xml $(resource_files)
+ $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate-source $<
+
-include $(top_srcdir)/git.mk
diff --git a/src/gdict-app.c b/src/gdict-app.c
index 25159be..db3eb9a 100644
--- a/src/gdict-app.c
+++ b/src/gdict-app.c
@@ -327,15 +327,7 @@ gdict_startup (GApplication *application,
app_entries, G_N_ELEMENTS (app_entries),
application);
- if (!gtk_builder_add_from_file (builder,
- PKGDATADIR "/gnome-dictionary-menus.ui",
- &error))
- {
- g_warning ("Building menus failed: %s", error->message);
- g_error_free (error);
-
- return;
- }
+ gtk_builder_add_from_resource (builder, "/org/gnome/Dictionary/gnome-dictionary-menus.ui", NULL);
gtk_application_set_menubar (GTK_APPLICATION (application),
G_MENU_MODEL (gtk_builder_get_object (builder, "menubar")));
diff --git a/src/gdict-pref-dialog.c b/src/gdict-pref-dialog.c
index 3aaee56..7604b11 100644
--- a/src/gdict-pref-dialog.c
+++ b/src/gdict-pref-dialog.c
@@ -39,7 +39,7 @@
#include "gdict-pref-dialog.h"
#include "gdict-common.h"
-#define GDICT_PREFERENCES_UI PKGDATADIR "/gnome-dictionary-preferences.ui"
+#define GDICT_PREFERENCES_UI "/org/gnome/Dictionary/gnome-dictionary-preferences.ui"
#define DEFAULT_MIN_WIDTH 220
#define DEFAULT_MIN_HEIGHT 330
@@ -622,7 +622,6 @@ static void
gdict_pref_dialog_init (GdictPrefDialog *dialog)
{
gchar *font;
- GError *error = NULL;
gtk_window_set_default_size (GTK_WINDOW (dialog),
DEFAULT_MIN_WIDTH,
@@ -643,13 +642,7 @@ gdict_pref_dialog_init (GdictPrefDialog *dialog)
/* get the UI from the GtkBuilder file */
dialog->builder = gtk_builder_new ();
- gtk_builder_add_from_file (dialog->builder, GDICT_PREFERENCES_UI, &error);
-
- if (error) {
- g_critical ("Unable to load the preferences user interface: %s", error->message);
- g_error_free (error);
- g_assert_not_reached ();
- }
+ gtk_builder_add_from_resource (dialog->builder, GDICT_PREFERENCES_UI, NULL);
/* the main widget */
gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
diff --git a/src/gdict-source-dialog.c b/src/gdict-source-dialog.c
index eeb2066..a9ba180 100644
--- a/src/gdict-source-dialog.c
+++ b/src/gdict-source-dialog.c
@@ -38,7 +38,7 @@
#include "gdict-source-dialog.h"
#include "gdict-common.h"
-#define GDICT_SOURCE_UI PKGDATADIR "/gnome-dictionary-source.ui"
+#define GDICT_SOURCE_UI "/org/gnome/Dictionary/gnome-dictionary-source.ui"
/*********************
* GdictSourceDialog *
@@ -574,7 +574,6 @@ gdict_source_dialog_constructor (GType type,
GObject *object;
GdictSourceDialog *dialog;
GtkWidget *vbox;
- GError *error = NULL;
object = G_OBJECT_CLASS (gdict_source_dialog_parent_class)->constructor (type,
n_construct_properties,
@@ -586,14 +585,7 @@ gdict_source_dialog_constructor (GType type,
/* get the UI from the GtkBuilder file */
dialog->builder = gtk_builder_new ();
- gtk_builder_add_from_file (dialog->builder, GDICT_SOURCE_UI, &error);
-
- if (error) {
- g_critical ("Unable to load the user interface definition file: %s",
- error->message);
- g_error_free (error);
- g_assert_not_reached ();
- }
+ gtk_builder_add_from_resource (dialog->builder, GDICT_SOURCE_UI, NULL);
/* the main widget */
gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
diff --git a/src/gdict.gresource.xml b/src/gdict.gresource.xml
new file mode 100644
index 0000000..59b4b3e
--- /dev/null
+++ b/src/gdict.gresource.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+ <gresource prefix="/org/gnome/Dictionary">
+ <file preprocess="xml-stripblanks">gnome-dictionary-menus.ui</file>
+ <file preprocess="xml-stripblanks">gnome-dictionary-preferences.ui</file>
+ <file preprocess="xml-stripblanks">gnome-dictionary-source.ui</file>
+ </gresource>
+</gresources>
diff --git a/data/gnome-dictionary-menus.ui b/src/gnome-dictionary-menus.ui
similarity index 100%
rename from data/gnome-dictionary-menus.ui
rename to src/gnome-dictionary-menus.ui
diff --git a/data/gnome-dictionary-preferences.ui b/src/gnome-dictionary-preferences.ui
similarity index 100%
rename from data/gnome-dictionary-preferences.ui
rename to src/gnome-dictionary-preferences.ui
diff --git a/data/gnome-dictionary-source.ui b/src/gnome-dictionary-source.ui
similarity index 100%
rename from data/gnome-dictionary-source.ui
rename to src/gnome-dictionary-source.ui
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]