[goffice] ui: fall back on glib resources if go resource doesn't exist



commit 11b7959ba24156b55199f9db3b634d98cc459188
Author: Morten Welinder <terra gnome org>
Date:   Tue May 15 13:42:35 2018 -0400

    ui: fall back on glib resources if go resource doesn't exist

 goffice/gtk/goffice-gtk.c |   23 +++++++++++++++++++++--
 1 files changed, 21 insertions(+), 2 deletions(-)
---
diff --git a/goffice/gtk/goffice-gtk.c b/goffice/gtk/goffice-gtk.c
index c058c76..7295359 100644
--- a/goffice/gtk/goffice-gtk.c
+++ b/goffice/gtk/goffice-gtk.c
@@ -191,12 +191,31 @@ go_gtk_builder_load (char const *uifile,
                gtk_builder_set_translation_domain (gui, domain);
 
        if (strncmp (uifile, "res:", 4) == 0) {
+               const char *resname = uifile + 4;
                size_t len;
-               gconstpointer data = go_rsm_lookup (uifile + 4, &len);
-               GsfInput *src = data
+               gconstpointer data;
+               GsfInput *src;
+               GBytes *bytes = NULL;
+
+               // First try go resources
+               data = go_rsm_lookup (resname, &len);
+
+               // Then try glib
+               if (!data) {
+                       bytes = g_resources_lookup_data (resname, 0, NULL);
+                       if (bytes) {
+                               data = g_bytes_get_data (bytes, NULL);
+                               len = g_bytes_get_size (bytes);
+                       }
+               }
+
+               src = data
                        ? gsf_input_memory_new (data, len, FALSE)
                        : NULL;
                ok = apply_ui_from_file (gui, src, NULL, &error);
+
+               if (bytes)
+                       g_bytes_unref (bytes);
        } else if (strncmp (uifile, "data:", 5) == 0) {
                const char *data = uifile + 5;
                GsfInput *src = gsf_input_memory_new (data, strlen (data), FALSE);


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