[gedit-plugins] drawspaces: use GResource



commit e9e54b10d3d3a2c7c09ab261ea4c6c3075acbb04
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Sat Mar 3 09:28:37 2012 +0100

    drawspaces: use GResource

 configure.ac                                      |    7 +++-
 plugins/drawspaces/Makefile.am                    |   15 +++++--
 plugins/drawspaces/gedit-drawspaces-plugin.c      |   44 +++++++--------------
 plugins/drawspaces/gedit-drawspaces.gresource.xml |    6 +++
 4 files changed, 38 insertions(+), 34 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index a9e5fba..f300818 100644
--- a/configure.ac
+++ b/configure.ac
@@ -76,9 +76,14 @@ PKG_CHECK_MODULES(GEDIT, [
 dnl ================================================================
 dnl GSettings stuff
 dnl ================================================================
-
 GLIB_GSETTINGS
 
+dnl ================================================================
+dnl GResource stuff
+dnl ================================================================
+GLIB_COMPILE_RESOURCES=`$PKG_CONFIG --variable glib_compile_resources gio-2.0`
+AC_SUBST(GLIB_COMPILE_RESOURCES)
+
 # ================================================================
 # Plugins
 # ================================================================
diff --git a/plugins/drawspaces/Makefile.am b/plugins/drawspaces/Makefile.am
index 166673f..5e0489c 100644
--- a/plugins/drawspaces/Makefile.am
+++ b/plugins/drawspaces/Makefile.am
@@ -9,15 +9,19 @@ INCLUDES = \
 
 plugin_LTLIBRARIES = libdrawspaces.la
 
+BUILT_SOURCES = \
+	gedit-drawspaces-resources.c
+
 libdrawspaces_la_SOURCES = \
 	gedit-drawspaces-plugin.h				\
-	gedit-drawspaces-plugin.c				
+	gedit-drawspaces-plugin.c				\
+	$(BUILT_SOURCES)
 
 libdrawspaces_la_LDFLAGS = $(PLUGIN_LIBTOOL_FLAGS)
 libdrawspaces_la_LIBADD = $(GEDIT_LIBS)
 
-uidir = $(GEDIT_PLUGINS_DATA_DIR)/drawspaces
-ui_DATA = gedit-drawspaces-plugin.ui
+gedit-drawspaces-resources.c: gedit-drawspaces.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir=$(srcdir) --generate-dependencies $(srcdir)/gedit-drawspaces.gresource.xml)
+	$(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate-source $(srcdir)/gedit-drawspaces.gresource.xml
 
 # Plugin Info
 
@@ -32,7 +36,10 @@ gsettings_SCHEMAS = org.gnome.gedit.plugins.drawspaces.gschema.xml
 @INTLTOOL_XML_NOMERGE_RULE@
 @GSETTINGS_RULES@
 
-EXTRA_DIST = $(plugin_in_files) $(ui_DATA) org.gnome.gedit.plugins.drawspaces.gschema.xml.in.in
+EXTRA_DIST = \
+	$(plugin_in_files) \
+	org.gnome.gedit.plugins.drawspaces.gschema.xml.in.in \
+	gedit-drawspaces-plugin.ui
 
 CLEANFILES = $(plugin_DATA) $(gsettings_SCHEMAS)
 DISTCLEANFILES = $(plugin_DATA) $(gsettings_SCHEMAS)
diff --git a/plugins/drawspaces/gedit-drawspaces-plugin.c b/plugins/drawspaces/gedit-drawspaces-plugin.c
index 7fd337d..eae973d 100644
--- a/plugins/drawspaces/gedit-drawspaces-plugin.c
+++ b/plugins/drawspaces/gedit-drawspaces-plugin.c
@@ -488,10 +488,7 @@ static DrawspacesConfigureWidget *
 get_configuration_widget (GeditDrawspacesPlugin *plugin)
 {
 	DrawspacesConfigureWidget *widget = NULL;
-	gboolean ret;
-	GtkWidget *error_widget;
-	gchar *datadir;
-	gchar *filename;
+	GtkBuilder *builder;
 
 	gchar *root_objects[] = {
 		"content",
@@ -503,31 +500,20 @@ get_configuration_widget (GeditDrawspacesPlugin *plugin)
 	widget->flags = g_settings_get_flags (widget->settings,
 					      SETTINGS_KEY_DRAW_SPACES);
 
-	datadir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin));
-	filename = g_build_filename (datadir, UI_FILE, NULL);
-
-	ret = gedit_utils_get_ui_objects_with_translation_domain (filename,
-	                                                          GETTEXT_PACKAGE,
-					                          root_objects,
-					                          &error_widget,
-					                          "content", &widget->content,
-					                          "check_button_draw_tabs", &widget->draw_tabs,
-					                          "check_button_draw_spaces", &widget->draw_spaces,
-					                          "check_button_draw_new_lines", &widget->draw_newline,
-					                          "check_button_draw_nbsp", &widget->draw_nbsp,
-					                          "check_button_draw_leading", &widget->draw_leading,
-					                          "check_button_draw_text", &widget->draw_text,
-					                          "check_button_draw_trailing", &widget->draw_trailing,
-					                          NULL);
-
-	g_free (datadir);
-	g_free (filename);
-
-	if (!ret)
-	{
-		widget->content = error_widget;
-		return widget;
-	}
+	builder = gtk_builder_new ();
+	gtk_builder_set_translation_domain (builder, GETTEXT_PACKAGE);
+	gtk_builder_add_objects_from_resource (builder, "/org/gnome/gedit/plugins/drawspaces/ui/gedit-drawspaces-plugin.ui",
+	                                       root_objects, NULL);
+	widget->content = GTK_WIDGET (gtk_builder_get_object (builder, "content"));
+	g_object_ref (widget->content);
+	widget->draw_tabs = GTK_WIDGET (gtk_builder_get_object (builder, "check_button_draw_tabs"));
+	widget->draw_spaces = GTK_WIDGET (gtk_builder_get_object (builder, "check_button_draw_spaces"));
+	widget->draw_newline = GTK_WIDGET (gtk_builder_get_object (builder, "check_button_draw_new_lines"));
+	widget->draw_nbsp = GTK_WIDGET (gtk_builder_get_object (builder, "check_button_draw_nbsp"));
+	widget->draw_leading = GTK_WIDGET (gtk_builder_get_object (builder, "check_button_draw_leading"));
+	widget->draw_text = GTK_WIDGET (gtk_builder_get_object (builder, "check_button_draw_text"));
+	widget->draw_trailing = GTK_WIDGET (gtk_builder_get_object (builder, "check_button_draw_trailing"));
+	g_object_unref (builder);
 
 	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget->draw_tabs),
 				      widget->flags & GTK_SOURCE_DRAW_SPACES_TAB);
diff --git a/plugins/drawspaces/gedit-drawspaces.gresource.xml b/plugins/drawspaces/gedit-drawspaces.gresource.xml
new file mode 100644
index 0000000..24f2247
--- /dev/null
+++ b/plugins/drawspaces/gedit-drawspaces.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/org/gnome/gedit/plugins/drawspaces/ui">
+    <file preprocess="xml-stripblanks">gedit-drawspaces-plugin.ui</file>
+  </gresource>
+</gresources>



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