[glade] GladeProject: ignore resource:// uri on file properties



commit c8f91e52cc26be18d2aff995fdd44a1689ebea55
Author: Juan Pablo Ugarte <juanpablougarte gmail com>
Date:   Mon Aug 31 16:00:07 2020 -0300

    GladeProject: ignore resource:// uri on file properties
    
    Add resources URL in file properties support to be on par with GtkBuilder
    
    Fix issue #367 "Glade removes double/triple slashes from URLs"

 gladeui/glade-project.c      | 23 +++++++++++++----------
 gladeui/glade-property-def.c |  9 +++++----
 2 files changed, 18 insertions(+), 14 deletions(-)
---
diff --git a/gladeui/glade-project.c b/gladeui/glade-project.c
index 4fb5a747..bfbcab96 100644
--- a/gladeui/glade-project.c
+++ b/gladeui/glade-project.c
@@ -2792,9 +2792,7 @@ update_project_resource_path (GladeProject *project, gchar *path)
 
           if (pspec->value_type == GDK_TYPE_PIXBUF)
             {
-              gchar *fullpath, *relpath;
               const gchar *filename;
-              GFile *fullpath_file;
               GObject *pixbuf;
 
               glade_property_get (property, &pixbuf);
@@ -2802,14 +2800,19 @@ update_project_resource_path (GladeProject *project, gchar *path)
                 continue;
 
               filename = g_object_get_data (pixbuf, "GladeFileName");
-              fullpath = glade_project_resource_fullpath (project, filename);
-              fullpath_file = g_file_new_for_path (fullpath);
-              relpath = _glade_util_file_get_relative_path (new_resource_path,
-                                                            fullpath_file);
-              g_object_set_data_full (pixbuf, "GladeFileName", relpath, g_free);
-
-              g_object_unref (fullpath_file);
-              g_free (fullpath);
+
+              if (!g_str_has_prefix (filename, "resource:///"))
+                {
+                  g_autoptr(GFile) fullpath_file = NULL;
+                  g_autofree gchar *fullpath = NULL;
+                  gchar *relpath;
+
+                  fullpath = glade_project_resource_fullpath (project, filename);
+                  fullpath_file = g_file_new_for_path (fullpath);
+                  relpath = _glade_util_file_get_relative_path (new_resource_path,
+                                                                fullpath_file);
+                  g_object_set_data_full (pixbuf, "GladeFileName", relpath, g_free);
+                }
             }
         }
     }
diff --git a/gladeui/glade-property-def.c b/gladeui/glade-property-def.c
index d5dfaf3f..8d70c43d 100644
--- a/gladeui/glade-property-def.c
+++ b/gladeui/glade-property-def.c
@@ -743,19 +743,22 @@ glade_property_def_make_object_from_string (GladePropertyDef *
                                               GladeProject * project)
 {
   GObject *object = NULL;
-  gchar *fullpath;
 
   if (string == NULL || project == NULL)
     return NULL;
 
   if (property_def->pspec->value_type == GDK_TYPE_PIXBUF)
     {
+      g_autofree gchar *fullpath = NULL;
       GdkPixbuf *pixbuf;
 
       if (*string == '\0')
         return NULL;
 
-      fullpath = glade_project_resource_fullpath (project, string);
+      if (g_str_has_prefix (string, "resource:///"))
+        fullpath = glade_project_resource_fullpath (project, &string[11]);
+      else
+        fullpath = glade_project_resource_fullpath (project, string);
 
       if ((pixbuf = gdk_pixbuf_new_from_file (fullpath, NULL)) == NULL)
         {
@@ -772,8 +775,6 @@ glade_property_def_make_object_from_string (GladePropertyDef *
           g_object_set_data_full (object, "GladeFileName",
                                   g_strdup (string), g_free);
         }
-
-      g_free (fullpath);
     }
   else if (property_def->pspec->value_type == G_TYPE_FILE)
     {


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