[gimp] app: split sanity check into early/late stages, to fix gegl translation



commit d37fb8aa5c915b57d07da2f2e48fac36e75e7a64
Author: Ell <ell_se yahoo com>
Date:   Thu Jun 15 09:30:45 2017 -0400

    app: split sanity check into early/late stages, to fix gegl translation
    
    The GEGL ops sanity check causes all ops to be initialized.  The
    strings used by their properties will pick the translation selected
    at the time of the check.  It must therefore run after language
    intiailization, otherwise the selected translation would correspond
    to the system locale, even if the user selected a different language
    in the preferences.
    
    Split the sanity check into early and late stages.  The early stage
    is run before the call to app_run(), as it did before, while the
    late stage is run during app_run(), after the configuration has been
    loaded.  Currently, the GEGL ops check is the only late-stage check;
    all other checks are performed during the early stage.

 app/app.c    |    9 ++++
 app/main.c   |    2 +-
 app/sanity.c |  138 +++++++++++++++++++++++++++++++++++-----------------------
 app/sanity.h |    3 +-
 4 files changed, 96 insertions(+), 56 deletions(-)
---
diff --git a/app/app.c b/app/app.c
index aeaa2f0..775e379 100644
--- a/app/app.c
+++ b/app/app.c
@@ -64,6 +64,7 @@
 #include "app.h"
 #include "errors.h"
 #include "language.h"
+#include "sanity.h"
 #include "gimp-debug.h"
 
 #include "gimp-intl.h"
@@ -179,6 +180,7 @@ app_run (const gchar         *full_prog_name,
   GMainLoop          *run_loop;
   GFile              *default_folder = NULL;
   GFile              *gimpdir;
+  const gchar        *abort_message;
 
   if (filenames && filenames[0] && ! filenames[1] &&
       g_file_test (filenames[0], G_FILE_TEST_IS_DIR))
@@ -253,6 +255,13 @@ app_run (const gchar         *full_prog_name,
   /*  change the locale if a language if specified  */
   language_init (gimp->config->language);
 
+  /*  run the late-stage sanity check.  it's important that this check is run
+   *  after the call to language_init() (see comment in sanity_check_late().)
+   */
+  abort_message = sanity_check_late ();
+  if (abort_message)
+    app_abort (no_interface, abort_message);
+
   /*  initialize lowlevel stuff  */
   gimp_gegl_init (gimp);
 
diff --git a/app/main.c b/app/main.c
index 9387931..339439d 100644
--- a/app/main.c
+++ b/app/main.c
@@ -536,7 +536,7 @@ main (int    argc,
     }
 #endif
 
-  abort_message = sanity_check ();
+  abort_message = sanity_check_early ();
   if (abort_message)
     app_abort (no_interface, abort_message);
 
diff --git a/app/sanity.c b/app/sanity.c
index c42fcdb..2b2a021 100644
--- a/app/sanity.c
+++ b/app/sanity.c
@@ -33,6 +33,7 @@
 #include "gimp-intl.h"
 
 
+/*  early-stage tests  */
 static gchar * sanity_check_gimp              (void);
 static gchar * sanity_check_glib              (void);
 static gchar * sanity_check_cairo             (void);
@@ -44,16 +45,22 @@ static gchar * sanity_check_lcms              (void);
 static gchar * sanity_check_gexiv2            (void);
 static gchar * sanity_check_babl              (void);
 static gchar * sanity_check_gegl              (void);
-static gchar * sanity_check_gegl_ops          (void);
 static gchar * sanity_check_filename_encoding (void);
 
+/*  late-stage tests  */
+static gchar * sanity_check_gegl_ops          (void);
+
 
 /*  public functions  */
 
+/* early-stage sanity check, performed before the call to app_run(). */
 const gchar *
-sanity_check (void)
+sanity_check_early (void)
 {
-  gchar *abort_message = sanity_check_gimp ();
+  gchar *abort_message = NULL;
+
+  if (! abort_message)
+    abort_message = sanity_check_gimp ();
 
   if (! abort_message)
     abort_message = sanity_check_glib ();
@@ -86,10 +93,27 @@ sanity_check (void)
     abort_message = sanity_check_gegl ();
 
   if (! abort_message)
-    abort_message = sanity_check_gegl_ops ();
+    abort_message = sanity_check_filename_encoding ();
 
+  return abort_message;
+}
+
+/* late-stage sanity check, performed during app_run(), after the user
+ * configuration has been loaded.
+ */
+const gchar *
+sanity_check_late (void)
+{
+  gchar *abort_message = NULL;
+
+  /* the gegl ops test initializes all gegl ops; in particular, it initializes
+   * all the strings used by their properties, which appear in the ui.  it
+   * must be run after we've called language_init(), potentially overriding
+   * LANGUAGE according to the user config, or else all affected strings would
+   * use the translation corresponding to the system locale, regardless.
+   */
   if (! abort_message)
-    abort_message = sanity_check_filename_encoding ();
+    abort_message = sanity_check_gegl_ops ();
 
   return abort_message;
 }
@@ -97,6 +121,9 @@ sanity_check (void)
 
 /*  private functions  */
 
+
+/*  early-stage tests  */
+
 static gboolean
 sanity_check_version (guint major_version, guint required_major,
                       guint minor_version, guint required_minor,
@@ -521,6 +548,58 @@ sanity_check_gegl (void)
 }
 
 static gchar *
+sanity_check_filename_encoding (void)
+{
+  gchar  *result;
+  GError *error = NULL;
+
+  result = g_filename_to_utf8 ("", -1, NULL, NULL, &error);
+
+  if (! result)
+    {
+      gchar *msg =
+        g_strdup_printf
+        (_("The configured filename encoding cannot be converted to UTF-8: "
+           "%s\n\n"
+           "Please check the value of the environment variable "
+           "G_FILENAME_ENCODING."),
+         error->message);
+
+      g_error_free (error);
+
+      return msg;
+    }
+
+  g_free (result);
+
+  result = g_filename_to_utf8 (gimp_directory (), -1, NULL, NULL, &error);
+
+  if (! result)
+    {
+      gchar *msg =
+        g_strdup_printf
+        (_("The name of the directory holding the GIMP user configuration "
+           "cannot be converted to UTF-8: "
+           "%s\n\n"
+           "Your filesystem probably stores files in an encoding "
+           "other than UTF-8 and you didn't tell GLib about this. "
+           "Please set the environment variable G_FILENAME_ENCODING."),
+         error->message);
+
+      g_error_free (error);
+
+      return msg;
+    }
+
+  g_free (result);
+
+  return NULL;
+}
+
+
+/*  late-stage tests  */
+
+static gchar *
 sanity_check_gegl_ops (void)
 {
   static const gchar *required_ops[] =
@@ -658,52 +737,3 @@ sanity_check_gegl_ops (void)
 
   return NULL;
 }
-
-static gchar *
-sanity_check_filename_encoding (void)
-{
-  gchar  *result;
-  GError *error = NULL;
-
-  result = g_filename_to_utf8 ("", -1, NULL, NULL, &error);
-
-  if (! result)
-    {
-      gchar *msg =
-        g_strdup_printf
-        (_("The configured filename encoding cannot be converted to UTF-8: "
-           "%s\n\n"
-           "Please check the value of the environment variable "
-           "G_FILENAME_ENCODING."),
-         error->message);
-
-      g_error_free (error);
-
-      return msg;
-    }
-
-  g_free (result);
-
-  result = g_filename_to_utf8 (gimp_directory (), -1, NULL, NULL, &error);
-
-  if (! result)
-    {
-      gchar *msg =
-        g_strdup_printf
-        (_("The name of the directory holding the GIMP user configuration "
-           "cannot be converted to UTF-8: "
-           "%s\n\n"
-           "Your filesystem probably stores files in an encoding "
-           "other than UTF-8 and you didn't tell GLib about this. "
-           "Please set the environment variable G_FILENAME_ENCODING."),
-         error->message);
-
-      g_error_free (error);
-
-      return msg;
-    }
-
-  g_free (result);
-
-  return NULL;
-}
diff --git a/app/sanity.h b/app/sanity.h
index fda05ba..b2e7490 100644
--- a/app/sanity.h
+++ b/app/sanity.h
@@ -23,7 +23,8 @@
 #endif
 
 
-const gchar * sanity_check (void);
+const gchar * sanity_check_early (void);
+const gchar * sanity_check_late  (void);
 
 
 #endif /* __SANITY_H__ */


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