[gimp] app: consistently treat GimpColorConfig profile paths as config paths



commit 0524b60228084aee37391bfc785f2d97d0955d67
Author: Michael Natterer <mitch gimp org>
Date:   Sat Oct 1 00:29:44 2016 +0200

    app: consistently treat GimpColorConfig profile paths as config paths
    
    and use gimp_file_new_for_config_path() and _get_config_path() when
    dealing with them. We used a weird mix of config paths and plain
    (filesystem encoded) paths, waiting to to break on umlauts or
    whatever. The code in gimpcolorconfig.c was particularly bad.

 app/pdb/plug-in-compat-cmds.c       |   82 ++++++++-----
 app/widgets/gimpwidgets-utils.c     |    4 +-
 libgimpconfig/gimpcolorconfig.c     |  247 ++++++++++++++++++++++-------------
 modules/display-filter-proof.c      |   22 ++-
 tools/pdbgen/pdb/plug_in_compat.pdb |   90 ++++++++-----
 5 files changed, 280 insertions(+), 165 deletions(-)
---
diff --git a/app/pdb/plug-in-compat-cmds.c b/app/pdb/plug-in-compat-cmds.c
index 243299a..1892ae2 100644
--- a/app/pdb/plug-in-compat-cmds.c
+++ b/app/pdb/plug-in-compat-cmds.c
@@ -1987,18 +1987,26 @@ plug_in_icc_profile_apply_invoker (GimpProcedure         *procedure,
           GimpColorProfile *p    = NULL;
 
           if (profile)
-            file = g_file_new_for_path (profile);
+            {
+              file = g_file_new_for_path (profile);
+            }
           else if (image->gimp->config->color_management->rgb_profile)
-            file = g_file_new_for_path (image->gimp->config->color_management->rgb_profile);
-
-          if (file)
             {
-              p = gimp_color_profile_new_from_file (file, error);
+              file = gimp_file_new_for_config_path (image->gimp->config->color_management->rgb_profile, 
error);
 
-              if (! p)
-                success = FALSE;
+              if (file)
+                {
+                  p = gimp_color_profile_new_from_file (file, error);
+
+                  if (! p)
+                    success = FALSE;
 
-              g_object_unref (file);
+                  g_object_unref (file);
+                }
+              else
+                {
+                  success = FALSE;
+                }
             }
 
           if (success)
@@ -2043,16 +2051,20 @@ plug_in_icc_profile_apply_rgb_invoker (GimpProcedure         *procedure,
           GimpColorProfile *p    = NULL;
 
           if (image->gimp->config->color_management->rgb_profile)
-            file = g_file_new_for_path (image->gimp->config->color_management->rgb_profile);
-
-          if (file)
             {
-              p = gimp_color_profile_new_from_file (file, error);
+              file = gimp_file_new_for_config_path (image->gimp->config->color_management->rgb_profile, 
error);
 
-              if (! p)
-                success = FALSE;
+              if (file)
+                {
+                  p = gimp_color_profile_new_from_file (file, error);
 
-              g_object_unref (file);
+                  if (! p)
+                    success = FALSE;
+
+                  g_object_unref (file);
+                }
+              else
+                success = FALSE;
             }
 
           if (success)
@@ -2095,18 +2107,24 @@ plug_in_icc_profile_set_invoker (GimpProcedure         *procedure,
           GimpColorProfile *p    = NULL;
 
           if (profile)
-            file = g_file_new_for_path (profile);
+            {
+              file = g_file_new_for_path (profile);
+            }
           else if (image->gimp->config->color_management->rgb_profile)
-            file = g_file_new_for_path (image->gimp->config->color_management->rgb_profile);
-
-          if (file)
             {
-              p = gimp_color_profile_new_from_file (file, error);
+              file = gimp_file_new_for_config_path (image->gimp->config->color_management->rgb_profile, 
error);
 
-              if (! p)
-                success = FALSE;
+              if (file)
+                {
+                  p = gimp_color_profile_new_from_file (file, error);
+
+                  if (! p)
+                    success = FALSE;
 
-              g_object_unref (file);
+                  g_object_unref (file);
+                }
+              else
+                success = FALSE;
             }
 
           if (success)
@@ -2157,16 +2175,20 @@ plug_in_icc_profile_set_rgb_invoker (GimpProcedure         *procedure,
           GimpColorProfile *p    = NULL;
 
           if (image->gimp->config->color_management->rgb_profile)
-            file = g_file_new_for_path (image->gimp->config->color_management->rgb_profile);
-
-          if (file)
             {
-              p = gimp_color_profile_new_from_file (file, error);
+              file = gimp_file_new_for_config_path (image->gimp->config->color_management->rgb_profile, 
error);
 
-              if (! p)
-                success = FALSE;
+              if (file)
+                {
+                  p = gimp_color_profile_new_from_file (file, error);
 
-              g_object_unref (file);
+                  if (! p)
+                    success = FALSE;
+
+                  g_object_unref (file);
+                }
+              else
+                success = FALSE;
             }
 
           if (success)
diff --git a/app/widgets/gimpwidgets-utils.c b/app/widgets/gimpwidgets-utils.c
index ffb5076..3b9472e 100644
--- a/app/widgets/gimpwidgets-utils.c
+++ b/app/widgets/gimpwidgets-utils.c
@@ -1470,14 +1470,14 @@ gimp_color_profile_store_add_defaults (GimpColorProfileStore  *store,
 
       if (base_type == GIMP_GRAY)
         {
-          file = g_file_new_for_path (config->gray_profile);
+          file = gimp_file_new_for_config_path (config->gray_profile, NULL);
 
           label = g_strdup_printf (_("Preferred grayscale (%s)"),
                                    gimp_color_profile_get_label (profile));
         }
       else
         {
-          file = g_file_new_for_path (config->rgb_profile);
+          file = gimp_file_new_for_config_path (config->rgb_profile, NULL);
 
           label = g_strdup_printf (_("Preferred RGB (%s)"),
                                    gimp_color_profile_get_label (profile));
diff --git a/libgimpconfig/gimpcolorconfig.c b/libgimpconfig/gimpcolorconfig.c
index 074b9d0..a4fb5a9 100644
--- a/libgimpconfig/gimpcolorconfig.c
+++ b/libgimpconfig/gimpcolorconfig.c
@@ -643,21 +643,25 @@ gimp_color_config_get_rgb_color_profile (GimpColorConfig  *config,
 
   if (config->rgb_profile)
     {
-      GFile *file = g_file_new_for_path (config->rgb_profile);
+      GFile *file = gimp_file_new_for_config_path (config->rgb_profile,
+                                                   error);
 
-      profile = gimp_color_profile_new_from_file (file, error);
-
-      if (profile && ! gimp_color_profile_is_rgb (profile))
+      if (file)
         {
-          g_object_unref (profile);
-          profile = NULL;
+          profile = gimp_color_profile_new_from_file (file, error);
 
-          g_set_error (error, GIMP_CONFIG_ERROR, 0,
-                       _("Color profile '%s' is not for RGB color space."),
-                       gimp_file_get_utf8_name (file));
-        }
+          if (profile && ! gimp_color_profile_is_rgb (profile))
+            {
+              g_object_unref (profile);
+              profile = NULL;
+
+              g_set_error (error, GIMP_CONFIG_ERROR, 0,
+                           _("Color profile '%s' is not for RGB color space."),
+                           gimp_file_get_utf8_name (file));
+            }
 
-      g_object_unref (file);
+          g_object_unref (file);
+        }
     }
 
   return profile;
@@ -681,21 +685,25 @@ gimp_color_config_get_gray_color_profile (GimpColorConfig  *config,
 
   if (config->gray_profile)
     {
-      GFile *file = g_file_new_for_path (config->gray_profile);
-
-      profile = gimp_color_profile_new_from_file (file, error);
+      GFile *file = gimp_file_new_for_config_path (config->gray_profile,
+                                                   error);
 
-      if (profile && ! gimp_color_profile_is_gray (profile))
+      if (file)
         {
-          g_object_unref (profile);
-          profile = NULL;
+          profile = gimp_color_profile_new_from_file (file, error);
 
-          g_set_error (error, GIMP_CONFIG_ERROR, 0,
-                       _("Color profile '%s' is not for GRAY color space."),
-                       gimp_file_get_utf8_name (file));
-        }
+          if (profile && ! gimp_color_profile_is_gray (profile))
+            {
+              g_object_unref (profile);
+              profile = NULL;
+
+              g_set_error (error, GIMP_CONFIG_ERROR, 0,
+                           _("Color profile '%s' is not for GRAY color space."),
+                           gimp_file_get_utf8_name (file));
+            }
 
-      g_object_unref (file);
+          g_object_unref (file);
+        }
     }
 
   return profile;
@@ -719,21 +727,25 @@ gimp_color_config_get_cmyk_color_profile (GimpColorConfig  *config,
 
   if (config->cmyk_profile)
     {
-      GFile *file = g_file_new_for_path (config->cmyk_profile);
+      GFile *file = gimp_file_new_for_config_path (config->cmyk_profile,
+                                                   error);
 
-      profile = gimp_color_profile_new_from_file (file, error);
-
-      if (profile && ! gimp_color_profile_is_cmyk (profile))
+      if (file)
         {
-          g_object_unref (profile);
-          profile = NULL;
+          profile = gimp_color_profile_new_from_file (file, error);
 
-          g_set_error (error, GIMP_CONFIG_ERROR, 0,
-                       _("Color profile '%s' is not for CMYK color space."),
-                       gimp_file_get_utf8_name (file));
-        }
+          if (profile && ! gimp_color_profile_is_cmyk (profile))
+            {
+              g_object_unref (profile);
+              profile = NULL;
+
+              g_set_error (error, GIMP_CONFIG_ERROR, 0,
+                           _("Color profile '%s' is not for CMYK color space."),
+                           gimp_file_get_utf8_name (file));
+            }
 
-      g_object_unref (file);
+          g_object_unref (file);
+        }
     }
 
   return profile;
@@ -757,10 +769,15 @@ gimp_color_config_get_display_color_profile (GimpColorConfig  *config,
 
   if (config->display_profile)
     {
-      GFile *file = g_file_new_for_path (config->display_profile);
+      GFile *file = gimp_file_new_for_config_path (config->display_profile,
+                                                   error);
 
-      profile = gimp_color_profile_new_from_file (file, error);
-      g_object_unref (file);
+      if (file)
+        {
+          profile = gimp_color_profile_new_from_file (file, error);
+
+          g_object_unref (file);
+        }
     }
 
   return profile;
@@ -784,10 +801,15 @@ gimp_color_config_get_simulation_color_profile (GimpColorConfig  *config,
 
   if (config->printer_profile)
     {
-      GFile *file = g_file_new_for_path (config->printer_profile);
+      GFile *file = gimp_file_new_for_config_path (config->printer_profile,
+                                                   error);
 
-      profile = gimp_color_profile_new_from_file (file, error);
-      g_object_unref (file);
+      if (file)
+        {
+          profile = gimp_color_profile_new_from_file (file, error);
+
+          g_object_unref (file);
+        }
     }
 
   return profile;
@@ -805,29 +827,38 @@ gimp_color_config_set_rgb_profile (GimpColorConfig  *config,
 
   if (filename)
     {
-      GimpColorProfile *profile;
-      GFile            *file = g_file_new_for_path (filename);
+      GFile *file = gimp_file_new_for_config_path (filename, error);
 
-      profile = gimp_color_profile_new_from_file (file, error);
-
-      if (profile)
+      if (file)
         {
-          if (! gimp_color_profile_is_rgb (profile))
+          GimpColorProfile *profile;
+
+          profile = gimp_color_profile_new_from_file (file, error);
+
+          if (profile)
+            {
+              if (! gimp_color_profile_is_rgb (profile))
+                {
+                  g_set_error (error, GIMP_CONFIG_ERROR, 0,
+                               _("Color profile '%s' is not for RGB "
+                                 "color space."),
+                               gimp_file_get_utf8_name (file));
+                  success = FALSE;
+                }
+
+              g_object_unref (profile);
+            }
+          else
             {
-              g_set_error (error, GIMP_CONFIG_ERROR, 0,
-                           _("Color profile '%s' is not for RGB color space."),
-                           gimp_file_get_utf8_name (file));
               success = FALSE;
             }
 
-          g_object_unref (profile);
+          g_object_unref (file);
         }
       else
         {
           success = FALSE;
         }
-
-      g_object_unref (file);
     }
 
   if (success)
@@ -846,29 +877,38 @@ gimp_color_config_set_gray_profile (GimpColorConfig  *config,
 
   if (filename)
     {
-      GimpColorProfile *profile;
-      GFile            *file = g_file_new_for_path (filename);
-
-      profile = gimp_color_profile_new_from_file (file, error);
+      GFile *file = gimp_file_new_for_config_path (filename, error);
 
-      if (profile)
+      if (file)
         {
-          if (! gimp_color_profile_is_gray (profile))
+          GimpColorProfile *profile;
+
+          profile = gimp_color_profile_new_from_file (file, error);
+
+          if (profile)
+            {
+              if (! gimp_color_profile_is_gray (profile))
+                {
+                  g_set_error (error, GIMP_CONFIG_ERROR, 0,
+                               _("Color profile '%s' is not for GRAY "
+                                 "color space."),
+                               gimp_file_get_utf8_name (file));
+                  success = FALSE;
+                }
+
+              g_object_unref (profile);
+            }
+          else
             {
-              g_set_error (error, GIMP_CONFIG_ERROR, 0,
-                           _("Color profile '%s' is not for GRAY color space."),
-                           gimp_file_get_utf8_name (file));
               success = FALSE;
             }
 
-          g_object_unref (profile);
+          g_object_unref (file);
         }
       else
         {
           success = FALSE;
         }
-
-      g_object_unref (file);
     }
 
   if (success)
@@ -887,29 +927,38 @@ gimp_color_config_set_cmyk_profile (GimpColorConfig  *config,
 
   if (filename)
     {
-      GimpColorProfile *profile;
-      GFile            *file = g_file_new_for_path (filename);
-
-      profile = gimp_color_profile_new_from_file (file, error);
+      GFile *file = gimp_file_new_for_config_path (filename, error);
 
-      if (profile)
+      if (file)
         {
-          if (! gimp_color_profile_is_cmyk (profile))
+          GimpColorProfile *profile;
+
+          profile = gimp_color_profile_new_from_file (file, error);
+
+          if (profile)
+            {
+              if (! gimp_color_profile_is_cmyk (profile))
+                {
+                  g_set_error (error, GIMP_CONFIG_ERROR, 0,
+                               _("Color profile '%s' is not for CMYK "
+                                 "color space."),
+                               gimp_file_get_utf8_name (file));
+                  success = FALSE;
+                }
+
+              g_object_unref (profile);
+            }
+          else
             {
-              g_set_error (error, GIMP_CONFIG_ERROR, 0,
-                           _("Color profile '%s' is not for CMYK color space."),
-                           gimp_file_get_utf8_name (file));
               success = FALSE;
             }
 
-          g_object_unref (profile);
+          g_object_unref (file);
         }
       else
         {
           success = FALSE;
         }
-
-      g_object_unref (file);
     }
 
   if (success)
@@ -928,21 +977,29 @@ gimp_color_config_set_display_profile (GimpColorConfig  *config,
 
   if (filename)
     {
-      GimpColorProfile *profile;
-      GFile            *file = g_file_new_for_path (filename);
+      GFile *file = gimp_file_new_for_config_path (filename, error);
 
-      profile = gimp_color_profile_new_from_file (file, error);
-
-      if (profile)
+      if (file)
         {
-          g_object_unref (profile);
+          GimpColorProfile *profile;
+
+          profile = gimp_color_profile_new_from_file (file, error);
+
+          if (profile)
+            {
+              g_object_unref (profile);
+            }
+          else
+            {
+              success = FALSE;
+            }
+
+          g_object_unref (file);
         }
       else
         {
           success = FALSE;
         }
-
-      g_object_unref (file);
     }
 
   if (success)
@@ -961,21 +1018,29 @@ gimp_color_config_set_simulation_profile (GimpColorConfig  *config,
 
   if (filename)
     {
-      GimpColorProfile *profile;
-      GFile            *file = g_file_new_for_path (filename);
+      GFile *file = gimp_file_new_for_config_path (filename, error);
 
-      profile = gimp_color_profile_new_from_file (file, error);
-
-      if (profile)
+      if (file)
         {
-          g_object_unref (profile);
+          GimpColorProfile *profile;
+
+          profile = gimp_color_profile_new_from_file (file, error);
+
+          if (profile)
+            {
+              g_object_unref (profile);
+            }
+          else
+            {
+              success = FALSE;
+            }
+
+          g_object_unref (file);
         }
       else
         {
           success = FALSE;
         }
-
-      g_object_unref (file);
     }
 
   if (success)
diff --git a/modules/display-filter-proof.c b/modules/display-filter-proof.c
index ade18e3..bd79ee0 100644
--- a/modules/display-filter-proof.c
+++ b/modules/display-filter-proof.c
@@ -264,7 +264,7 @@ cdisplay_proof_profile_changed (GtkWidget     *combo,
 
   if (file)
     {
-      path = g_file_get_path (file);
+      path = gimp_file_get_config_path (file, NULL);
       g_object_unref (file);
     }
 
@@ -303,11 +303,13 @@ cdisplay_proof_configure (GimpColorDisplay *display)
 
   if (proof->profile)
     {
-      GFile *file = g_file_new_for_path (proof->profile);
+      GFile *file = gimp_file_new_for_config_path (proof->profile, NULL);
 
       gimp_color_profile_combo_box_set_active_file (GIMP_COLOR_PROFILE_COMBO_BOX (combo),
                                                     file, NULL);
-      g_object_unref (file);
+
+      if (file)
+        g_object_unref (file);
     }
 
   gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
@@ -332,9 +334,9 @@ cdisplay_proof_configure (GimpColorDisplay *display)
 static void
 cdisplay_proof_changed (GimpColorDisplay *display)
 {
-  CdisplayProof    *proof = CDISPLAY_PROOF (display);
+  CdisplayProof    *proof         = CDISPLAY_PROOF (display);
+  GimpColorProfile *proof_profile = NULL;
   GimpColorProfile *rgb_profile;
-  GimpColorProfile *proof_profile;
   GFile            *file;
 
   if (proof->transform)
@@ -348,9 +350,13 @@ cdisplay_proof_changed (GimpColorDisplay *display)
 
   rgb_profile = gimp_color_profile_new_rgb_srgb ();
 
-  file = g_file_new_for_path (proof->profile);
-  proof_profile = gimp_color_profile_new_from_file (file, NULL);
-  g_object_unref (file);
+  file = gimp_file_new_for_config_path (proof->profile, NULL);
+
+  if (file)
+    {
+      proof_profile = gimp_color_profile_new_from_file (file, NULL);
+      g_object_unref (file);
+    }
 
   if (proof_profile)
     {
diff --git a/tools/pdbgen/pdb/plug_in_compat.pdb b/tools/pdbgen/pdb/plug_in_compat.pdb
index 0af91c2..b934eed 100644
--- a/tools/pdbgen/pdb/plug_in_compat.pdb
+++ b/tools/pdbgen/pdb/plug_in_compat.pdb
@@ -1878,19 +1878,27 @@ HELP
       GimpColorProfile *p    = NULL;
 
       if (profile)
-        file = g_file_new_for_path (profile);
+        {
+          file = g_file_new_for_path (profile);
+        }
       else if (image->gimp->config->color_management->rgb_profile)
-        file = g_file_new_for_path (image->gimp->config->color_management->rgb_profile);
-
-      if (file)
         {
-          p = gimp_color_profile_new_from_file (file, error);
+          file = gimp_file_new_for_config_path (image->gimp->config->color_management->rgb_profile, error);
 
-          if (! p)
-           success = FALSE;
+          if (file)
+            {
+              p = gimp_color_profile_new_from_file (file, error);
 
-          g_object_unref (file);
-       }
+              if (! p)
+                success = FALSE;
+
+              g_object_unref (file);
+           }
+          else
+            {
+              success = FALSE;
+            }
+        }
 
       if (success)
         {
@@ -1942,17 +1950,21 @@ HELP
       GimpColorProfile *p    = NULL;
 
       if (image->gimp->config->color_management->rgb_profile)
-        file = g_file_new_for_path (image->gimp->config->color_management->rgb_profile);
-
-      if (file)
         {
-          p = gimp_color_profile_new_from_file (file, error);
+          file = gimp_file_new_for_config_path (image->gimp->config->color_management->rgb_profile, error);
 
-          if (! p)
-           success = FALSE;
+          if (file)
+            {
+              p = gimp_color_profile_new_from_file (file, error);
 
-          g_object_unref (file);
-       }
+              if (! p)
+                success = FALSE;
+
+              g_object_unref (file);
+            }
+          else
+            success = FALSE;
+        }
 
       if (success)
         {
@@ -2000,19 +2012,25 @@ HELP
       GimpColorProfile *p    = NULL;
 
       if (profile)
-        file = g_file_new_for_path (profile);
+        {
+          file = g_file_new_for_path (profile);
+        }
       else if (image->gimp->config->color_management->rgb_profile)
-        file = g_file_new_for_path (image->gimp->config->color_management->rgb_profile);
-
-      if (file)
         {
-          p = gimp_color_profile_new_from_file (file, error);
+          file = gimp_file_new_for_config_path (image->gimp->config->color_management->rgb_profile, error);
 
-          if (! p)
-           success = FALSE;
+          if (file)
+            {
+              p = gimp_color_profile_new_from_file (file, error);
 
-          g_object_unref (file);
-       }
+              if (! p)
+                success = FALSE;
+
+              g_object_unref (file);
+           }
+          else
+            success = FALSE;
+        }
 
       if (success)
         {
@@ -2069,17 +2087,21 @@ HELP
       GimpColorProfile *p    = NULL;
 
       if (image->gimp->config->color_management->rgb_profile)
-        file = g_file_new_for_path (image->gimp->config->color_management->rgb_profile);
-
-      if (file)
         {
-          p = gimp_color_profile_new_from_file (file, error);
+          file = gimp_file_new_for_config_path (image->gimp->config->color_management->rgb_profile, error);
 
-          if (! p)
-           success = FALSE;
+          if (file)
+            {
+              p = gimp_color_profile_new_from_file (file, error);
 
-          g_object_unref (file);
-       }
+              if (! p)
+                success = FALSE;
+
+              g_object_unref (file);
+            }
+          else
+            success = FALSE;
+        }
 
       if (success)
         {


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