[libgda] Integrated some files as resources
- From: Vivien Malerba <vivien src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] Integrated some files as resources
- Date: Sun, 30 Nov 2014 22:05:54 +0000 (UTC)
commit 3f888a130d9d01aefb64a71c0f201c98993be160
Author: Vivien Malerba <malerba gnome-db org>
Date: Thu Nov 27 18:44:52 2014 +0100
Integrated some files as resources
libgda-ui/Makefile.am | 2 +-
.../data-entries/gdaui-data-cell-renderer-bin.c | 12 ++--
libgda-ui/data-entries/gdaui-entry-bin.c | 12 ++--
libgda-ui/gdaui-basic-form.c | 26 +++++---
libgda-ui/gdaui-init.c | 70 ++++++++++---------
libgda-ui/gdaui-raw-grid.c | 25 +++++---
libgda-ui/gdaui.gresource.xml | 21 ++++++
7 files changed, 101 insertions(+), 67 deletions(-)
---
diff --git a/libgda-ui/Makefile.am b/libgda-ui/Makefile.am
index da8ffe0..520746a 100644
--- a/libgda-ui/Makefile.am
+++ b/libgda-ui/Makefile.am
@@ -165,7 +165,7 @@ DTD_FILES = gdaui-layout.dtd
dtddir=$(datadir)/libgda-$(GDA_ABI_MAJOR_VERSION).$(GDA_ABI_MINOR_VERSION)/dtd
dtd_DATA=$(DTD_FILES)
-gdaui-resources.h gdaui-resources.c: $(srcdir)/gdaui.gresource.xml Makefile $(shell
$(GLIB_COMPILE_RESOURCES) --sourcedir=$(srcdir) --generate-dependencies $(srcdir)/gdaui.gresource.xml)
+gdaui-resources.h gdaui-resources.c: $(srcdir)/gdaui.gresource.xml Makefile $(shell
$(GLIB_COMPILE_RESOURCES) --generate-dependencies $(srcdir)/gdaui.gresource.xml)
$(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate --c-name _gdaui
--manual-register $<
EXTRA_DIST = $(DTD_FILES) \
diff --git a/libgda-ui/data-entries/gdaui-data-cell-renderer-bin.c
b/libgda-ui/data-entries/gdaui-data-cell-renderer-bin.c
index 103375c..5f2a4aa 100644
--- a/libgda-ui/data-entries/gdaui-data-cell-renderer-bin.c
+++ b/libgda-ui/data-entries/gdaui-data-cell-renderer-bin.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2010 David King <davidk openismus com>
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
*
@@ -21,7 +21,6 @@
#include <stdlib.h>
#include <libgda/libgda.h>
-#include <libgda/binreloc/gda-binreloc.h>
#include <glib/gi18n-lib.h>
#include <libgda/gda-enum-types.h>
#include "gdaui-data-cell-renderer-bin.h"
@@ -201,12 +200,11 @@ gdaui_data_cell_renderer_bin_class_init (GdauiDataCellRendererBinClass *class)
G_TYPE_VALUE);
if (! attach_pixbuf) {
- gchar *tmp;
- tmp = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, "pixmaps",
"bin-attachment-16x16.png", NULL);
- attach_pixbuf = gdk_pixbuf_new_from_file (tmp, NULL);
+ #define ICON_FILE "/gdaui/images/data/bin-attachment-16x16.png"
+ attach_pixbuf = gdk_pixbuf_new_from_resource (ICON_FILE, NULL);
if (!attach_pixbuf)
- g_warning ("Could not find icon file %s", tmp);
- g_free (tmp);
+ g_warning ("Could not find icon file %s in resources please report error to "
+ "http://bugzilla.gnome.org/ for the \"libgda\" product", ICON_FILE);
}
}
diff --git a/libgda-ui/data-entries/gdaui-entry-bin.c b/libgda-ui/data-entries/gdaui-entry-bin.c
index 55a20e8..a19270d 100644
--- a/libgda-ui/data-entries/gdaui-entry-bin.c
+++ b/libgda-ui/data-entries/gdaui-entry-bin.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2010 David King <davidk openismus com>
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
*
@@ -20,7 +20,6 @@
*/
#include <glib/gi18n-lib.h>
-#include <libgda/binreloc/gda-binreloc.h>
#include "gdaui-entry-bin.h"
#include "common-bin.h"
@@ -105,12 +104,11 @@ gdaui_entry_bin_class_init (GdauiEntryBinClass *class)
GTK_WIDGET_CLASS (class)->show = show;
if (! attach_pixbuf) {
- gchar *tmp;
- tmp = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, "pixmaps",
"bin-attachment-16x16.png", NULL);
- attach_pixbuf = gdk_pixbuf_new_from_file (tmp, NULL);
+ #define ICON_FILE "/gdaui/images/data/bin-attachment-16x16.png"
+ attach_pixbuf = gdk_pixbuf_new_from_resource (ICON_FILE, NULL);
if (!attach_pixbuf)
- g_warning ("Could not find icon file %s", tmp);
- g_free (tmp);
+ g_warning ("Could not find icon file %s in resources please report error to "
+ "http://bugzilla.gnome.org/ for the \"libgda\" product", ICON_FILE);
}
}
diff --git a/libgda-ui/gdaui-basic-form.c b/libgda-ui/gdaui-basic-form.c
index 6727418..150ef6d 100644
--- a/libgda-ui/gdaui-basic-form.c
+++ b/libgda-ui/gdaui-basic-form.c
@@ -32,7 +32,6 @@
#include <libgda-ui/gdaui-data-selector.h>
#include <libgda-ui/gdaui-raw-form.h>
#include <libgda-ui/gdaui-easy.h>
-#include <libgda/binreloc/gda-binreloc.h>
#include <libgda/gda-debug-macros.h>
#define SPACING 3
@@ -2228,15 +2227,22 @@ gdaui_basic_form_set_layout_from_file (GdauiBasicForm *form, const gchar *file_n
xmlDtdPtr dtd = NULL;
- gchar *file = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, "dtd", "gdaui-layout.dtd", NULL);
- if (g_file_test (file, G_FILE_TEST_EXISTS))
- dtd = xmlParseDTD (NULL, BAD_CAST file);
- if (dtd == NULL) {
- g_warning (_("'%s' DTD not parsed successfully. "
- "XML data layout validation will not be "
- "performed (some errors may occur)"), file);
- }
- g_free (file);
+ GBytes *bytes;
+ bytes = g_resources_lookup_data ("/gdaui/gdaui-layout.dtd", G_RESOURCE_LOOKUP_FLAGS_NONE, NULL);
+ if (bytes) {
+ xmlParserInputBufferPtr ibuffer;
+ gsize size;
+ const char *data;
+ data = (const char *) g_bytes_get_data (bytes, &size);
+ ibuffer = xmlParserInputBufferCreateMem (data, size, XML_CHAR_ENCODING_NONE);
+ dtd = xmlIOParseDTD (NULL, ibuffer, XML_CHAR_ENCODING_NONE);
+ /* No need to call xmlFreeParserInputBuffer (ibuffer), because xmlIOParseDTD() does it */
+ g_bytes_unref (bytes);
+ }
+
+ if (! dtd)
+ g_warning ("DTD not parsed successfully, please report error to "
+ "http://bugzilla.gnome.org/ for the \"libgda\" product");
/* Get the root element node */
xmlNodePtr root_node = NULL;
diff --git a/libgda-ui/gdaui-init.c b/libgda-ui/gdaui-init.c
index df32803..60fc5b4 100644
--- a/libgda-ui/gdaui-init.c
+++ b/libgda-ui/gdaui-init.c
@@ -73,16 +73,9 @@ gdaui_init (void)
return;
}
- /*
- gchar *str;
- gdaui_gbr_init ();
- str = gdaui_gbr_get_locale_dir_path ();
- bindtextdomain (GETTEXT_PACKAGE, str);
- g_free (str);
- */
-
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+ _gdaui_register_resource ();
gda_init ();
if (! gdaui_plugins_hash)
gdaui_plugins_hash = init_plugins_hash ();
@@ -90,7 +83,6 @@ gdaui_init (void)
/* initialize CSS */
GBytes *css_data;
GError *error = NULL;
- _gdaui_register_resource ();
css_data = g_resources_lookup_data ("/gdaui/gdaui.css", G_RESOURCE_LOOKUP_FLAGS_NONE, &error);
if (css_data) {
GtkCssProvider *css_provider;
@@ -114,7 +106,6 @@ gdaui_init (void)
error && error->message ? error->message : _("No detail"));
g_clear_error (&error);
}
- _gdaui_unregister_resource ();
initialized = TRUE;
}
@@ -399,16 +390,17 @@ init_plugins_hash (void)
plugin->entry_create_func = entry_string_create_func;
plugin->cell_create_func = cell_textual_create_func;
g_hash_table_insert (hash, plugin->plugin_name, plugin);
- file = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, "ui", "gdaui-entry-string.xml", NULL);
- if (! g_file_test (file, G_FILE_TEST_EXISTS)) {
- g_message ("Could not find file '%s': '%s' data entry will not report any possible option",
- file, plugin->plugin_name);
- }
- else {
- gsize len;
- g_file_get_contents (file, &(plugin->options_xml_spec), &len, NULL);
+ GBytes *bytes;
+ bytes = g_resources_lookup_data ("/gdaui/data-entries/gdaui-entry-string.xml",
G_RESOURCE_LOOKUP_FLAGS_NONE, NULL);
+ if (bytes) {
+ const char *data;
+ data = (const char *) g_bytes_get_data (bytes, NULL);
+ plugin->options_xml_spec = g_strdup (data);
+ g_bytes_unref (bytes);
}
- g_free (file);
+ else
+ g_message ("Could not load data entry specifications for the '%s' plugin, please report error
to "
+ "http://bugzilla.gnome.org/ for the \"libgda\" product", plugin->plugin_name);
plugin = g_new0 (GdauiPlugin, 1);
plugin->plugin_name = "integer";
@@ -429,13 +421,17 @@ init_plugins_hash (void)
plugin->entry_create_func = entry_number_create_func;
plugin->cell_create_func = cell_textual_create_func;
g_hash_table_insert (hash, plugin->plugin_name, plugin);
- file = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, "ui", "gdaui-entry-integer.xml", NULL);
- xmlChar *xml_spec = get_spec_with_isocodes (file);
- if (xml_spec) {
- plugin->options_xml_spec = g_strdup ((gchar*) xml_spec);
- xmlFree (xml_spec);
+
+ bytes = g_resources_lookup_data ("/gdaui/data-entries/gdaui-entry-integer.xml",
G_RESOURCE_LOOKUP_FLAGS_NONE, NULL);
+ if (bytes) {
+ const char *data;
+ data = (const char *) g_bytes_get_data (bytes, NULL);
+ plugin->options_xml_spec = g_strdup (data);
+ g_bytes_unref (bytes);
}
- g_free (file);
+ else
+ g_message ("Could not load data entry specifications for the '%s' plugin, please report error
to "
+ "http://bugzilla.gnome.org/ for the \"libgda\" product", plugin->plugin_name);
plugin = g_new0 (GdauiPlugin, 1);
plugin->plugin_name = "number";
@@ -450,13 +446,20 @@ init_plugins_hash (void)
plugin->entry_create_func = entry_number_create_func;
plugin->cell_create_func = cell_textual_create_func;
g_hash_table_insert (hash, plugin->plugin_name, plugin);
- file = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, "ui", "gdaui-entry-number.xml", NULL);
- xml_spec = get_spec_with_isocodes (file);
- if (xml_spec) {
- plugin->options_xml_spec = g_strdup ((gchar*) xml_spec);
+
+ bytes = g_resources_lookup_data ("/gdaui/data-entries/gdaui-entry-number.xml",
G_RESOURCE_LOOKUP_FLAGS_NONE, NULL);
+ if (bytes) {
+ const char *data;
+ data = (const char *) g_bytes_get_data (bytes, NULL);
+ xmlChar *xml_spec;
+ xml_spec = get_spec_with_isocodes (data);
+ plugin->options_xml_spec = g_strdup ((gchar *) xml_spec);
+ g_bytes_unref (bytes);
xmlFree (xml_spec);
}
- g_free (file);
+ else
+ g_message ("Could not load data entry specifications for the '%s' plugin, please report error
to "
+ "http://bugzilla.gnome.org/ for the \"libgda\" product", plugin->plugin_name);
plugin = g_new0 (GdauiPlugin, 1);
plugin->plugin_name = "textual";
@@ -695,7 +698,7 @@ find_child_node_from_name (xmlNodePtr parent, const gchar *name, const gchar *at
}
static xmlChar *
-get_spec_with_isocodes (const gchar *file)
+get_spec_with_isocodes (const gchar *data_spec)
{
xmlDocPtr spec, isocodes = NULL;
xmlChar *retval = NULL;
@@ -722,9 +725,10 @@ get_spec_with_isocodes (const gchar *file)
/*
* Load spec string
*/
- spec = xmlParseFile (file);
+ spec = xmlParseDoc (BAD_CAST data_spec);
if (!spec) {
- g_warning ("Can't load '%s' file", file);
+ g_warning ("Can't parse XML data, please report error to "
+ "http://bugzilla.gnome.org/ for the \"libgda\" product");
goto cleanup;
}
diff --git a/libgda-ui/gdaui-raw-grid.c b/libgda-ui/gdaui-raw-grid.c
index 1656b3b..1fbf22f 100644
--- a/libgda-ui/gdaui-raw-grid.c
+++ b/libgda-ui/gdaui-raw-grid.c
@@ -2727,15 +2727,22 @@ gdaui_raw_grid_set_layout_from_file (GdauiRawGrid *grid, const gchar *file_name,
xmlDtdPtr dtd = NULL;
- gchar *file = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, "dtd", "gdaui-layout.dtd", NULL);
- if (g_file_test (file, G_FILE_TEST_EXISTS))
- dtd = xmlParseDTD (NULL, BAD_CAST file);
- if (dtd == NULL) {
- g_warning (_("'%s' DTD not parsed successfully. "
- "XML data layout validation will not be "
- "performed (some errors may occur)"), file);
- }
- g_free (file);
+ GBytes *bytes;
+ bytes = g_resources_lookup_data ("/gdaui/gdaui-layout.dtd", G_RESOURCE_LOOKUP_FLAGS_NONE, NULL);
+ if (bytes) {
+ xmlParserInputBufferPtr ibuffer;
+ gsize size;
+ const char *data;
+ data = (const char *) g_bytes_get_data (bytes, &size);
+ ibuffer = xmlParserInputBufferCreateMem (data, size, XML_CHAR_ENCODING_NONE);
+ dtd = xmlIOParseDTD (NULL, ibuffer, XML_CHAR_ENCODING_NONE);
+ /* No need to call xmlFreeParserInputBuffer (ibuffer), because xmlIOParseDTD() does it */
+ g_bytes_unref (bytes);
+ }
+
+ if (! dtd)
+ g_warning ("DTD not parsed successfully, please report error to "
+ "http://bugzilla.gnome.org/ for the \"libgda\" product");
/* Get the root element node */
xmlNodePtr root_node = NULL;
diff --git a/libgda-ui/gdaui.gresource.xml b/libgda-ui/gdaui.gresource.xml
index b47086e..d473440 100644
--- a/libgda-ui/gdaui.gresource.xml
+++ b/libgda-ui/gdaui.gresource.xml
@@ -3,4 +3,25 @@
<gresource prefix="/gdaui">
<file compressed="true">gdaui.css</file>
</gresource>
+ <gresource prefix="/gdaui">
+ <file compressed="true">gdaui-layout.dtd</file>
+ </gresource>
+ <gresource prefix="/gdaui/images">
+ <file compressed="no">data/gdaui-generic.png</file>
+ </gresource>
+ <gresource prefix="/gdaui/images">
+ <file compressed="no">data/bin-attachment-16x16.png</file>
+ </gresource>
+ <gresource prefix="/gdaui">
+ <file compressed="true">data-entries/gdaui-entry-string.xml</file>
+ </gresource>
+ <gresource prefix="/gdaui">
+ <file compressed="true">data-entries/gdaui-entry-integer.xml</file>
+ </gresource>
+ <gresource prefix="/gdaui">
+ <file compressed="true">data-entries/gdaui-entry-number.xml</file>
+ </gresource>
+ <gresource prefix="/gdaui/glade">
+ <file compressed="no">data/server_operation.xml</file>
+ </gresource>
</gresources>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]