[gimp] app: popup error at startup when some fonts fail to load.



commit e796e3a50ac4bb15e657d1c57f29afd76f5d1381
Author: Jehan <jehan girinstud io>
Date:   Tue May 1 02:54:36 2018 +0200

    app: popup error at startup when some fonts fail to load.
    
    As proposed on IRC. This will allow people to debug their fonts (for
    instance when there are permission issues or whatnot) by knowing the
    list of problematic fonts in an error dialog at startup (and not only on
    terminal).

 app/actions/fonts-commands.c |    2 +-
 app/app.c                    |   16 ++++++-
 app/core/gimp.c              |   16 ++++++-
 app/core/gimp.h              |    3 +-
 app/pdb/fonts-cmds.c         |    2 +-
 app/tests.c                  |    4 +-
 app/text/gimp-fonts.c        |   93 ++++++++++++++++++++++++++++++++---------
 app/text/gimp-fonts.h        |   13 +++---
 8 files changed, 112 insertions(+), 37 deletions(-)
---
diff --git a/app/actions/fonts-commands.c b/app/actions/fonts-commands.c
index 149cfef..0763161 100644
--- a/app/actions/fonts-commands.c
+++ b/app/actions/fonts-commands.c
@@ -39,5 +39,5 @@ fonts_refresh_cmd_callback (GtkAction *action,
   GimpContext *context = action_data_get_context (data);
 
   if (context)
-    gimp_fonts_load (context->gimp, NULL);
+    gimp_fonts_load (context->gimp, NULL, NULL);
 }
diff --git a/app/app.c b/app/app.c
index 23bec66..9fe49f4 100644
--- a/app/app.c
+++ b/app/app.c
@@ -189,7 +189,8 @@ app_run (const gchar         *full_prog_name,
   GFile              *gimpdir;
   const gchar        *abort_message;
   GimpLangRc         *temprc;
-  gchar              *language = NULL;
+  gchar              *language   = NULL;
+  GError             *font_error = NULL;
 
   if (filenames && filenames[0] && ! filenames[1] &&
       g_file_test (filenames[0], G_FILE_TEST_IS_DIR))
@@ -326,7 +327,7 @@ app_run (const gchar         *full_prog_name,
 
   /*  Load all data files
    */
-  gimp_restore (gimp, update_status_func);
+  gimp_restore (gimp, update_status_func, &font_error);
 
   /*  enable autosave late so we don't autosave when the
    *  monitor resolution is set in gui_init()
@@ -379,6 +380,10 @@ app_run (const gchar         *full_prog_name,
                    */
                   gimp_image_dirty (image, GIMP_DIRTY_IMAGE);
                 }
+              else
+                {
+                  g_error_free (error);
+                }
 
               g_object_unref (file);
             }
@@ -411,6 +416,13 @@ app_run (const gchar         *full_prog_name,
             }
         }
     }
+  if (font_error)
+    {
+      gimp_message_literal (gimp, NULL,
+                            GIMP_MESSAGE_INFO,
+                            font_error->message);
+      g_error_free (font_error);
+    }
 
   if (run_loop)
     gimp_batch_run (gimp, batch_interpreter, batch_commands);
diff --git a/app/core/gimp.c b/app/core/gimp.c
index 85896bb..17c688a 100644
--- a/app/core/gimp.c
+++ b/app/core/gimp.c
@@ -769,9 +769,19 @@ gimp_initialize (Gimp               *gimp,
   g_signal_emit (gimp, gimp_signals[INITIALIZE], 0, status_callback);
 }
 
+/**
+ * gimp_restore:
+ * @gimp: a #Gimp object
+ * @error: a #GError for uncessful loading.
+ *
+ * This function always succeeds. If present, @error may be filled for
+ * possible feedback on data which failed to load. It doesn't imply any
+ * fatale error.
+ **/
 void
-gimp_restore (Gimp               *gimp,
-              GimpInitStatusFunc  status_callback)
+gimp_restore (Gimp                *gimp,
+              GimpInitStatusFunc   status_callback,
+              GError             **error)
 {
   g_return_if_fail (GIMP_IS_GIMP (gimp));
   g_return_if_fail (status_callback != NULL);
@@ -790,7 +800,7 @@ gimp_restore (Gimp               *gimp,
   if (! gimp->no_fonts)
     {
       status_callback (NULL, _("Fonts (this may take a while)"), 0.7);
-      gimp_fonts_load (gimp, status_callback);
+      gimp_fonts_load (gimp, status_callback, error);
     }
 
   /*  initialize the template list  */
diff --git a/app/core/gimp.h b/app/core/gimp.h
index ad5d6e4..c5fc6e2 100644
--- a/app/core/gimp.h
+++ b/app/core/gimp.h
@@ -175,7 +175,8 @@ void           gimp_load_config            (Gimp                *gimp,
 void           gimp_initialize             (Gimp                *gimp,
                                             GimpInitStatusFunc   status_callback);
 void           gimp_restore                (Gimp                *gimp,
-                                            GimpInitStatusFunc   status_callback);
+                                            GimpInitStatusFunc   status_callback,
+                                            GError             **error);
 gboolean       gimp_is_restored            (Gimp                *gimp);
 
 void           gimp_exit                   (Gimp                *gimp,
diff --git a/app/pdb/fonts-cmds.c b/app/pdb/fonts-cmds.c
index e9aed2c..b599e4d 100644
--- a/app/pdb/fonts-cmds.c
+++ b/app/pdb/fonts-cmds.c
@@ -46,7 +46,7 @@ fonts_refresh_invoker (GimpProcedure         *procedure,
                        const GimpValueArray  *args,
                        GError               **error)
 {
-  gimp_fonts_load (gimp, NULL);
+  gimp_fonts_load (gimp, NULL, error);
 
   return gimp_procedure_get_return_values (procedure, TRUE, NULL);
 }
diff --git a/app/tests.c b/app/tests.c
index bb52e38..6843bf0 100644
--- a/app/tests.c
+++ b/app/tests.c
@@ -72,7 +72,7 @@ gimp_init_for_testing (void)
 
   gimp_gegl_init (gimp);
   gimp_initialize (gimp, gimp_status_func_dummy);
-  gimp_restore (gimp, gimp_status_func_dummy);
+  gimp_restore (gimp, gimp_status_func_dummy, NULL);
 
   return gimp;
 }
@@ -128,7 +128,7 @@ gimp_init_for_gui_testing_internal (gboolean  show_gui,
   gui_init (gimp, TRUE);
   gimp_init_icon_theme_for_testing ();
   gimp_initialize (gimp, gimp_status_func_dummy);
-  gimp_restore (gimp, gimp_status_func_dummy);
+  gimp_restore (gimp, gimp_status_func_dummy, NULL);
 
   return gimp;
 }
diff --git a/app/text/gimp-fonts.c b/app/text/gimp-fonts.c
index d708d87..2f66030 100644
--- a/app/text/gimp-fonts.c
+++ b/app/text/gimp-fonts.c
@@ -45,10 +45,14 @@ static gboolean gimp_fonts_load_fonts_conf       (FcConfig     *config,
                                                   GFile        *fonts_conf);
 static void     gimp_fonts_add_directories       (Gimp         *gimp,
                                                   FcConfig     *config,
-                                                  GList        *path);
+                                                  GList        *path,
+                                                  GError      **error);
 static void     gimp_fonts_recursive_add_fontdir (FcConfig     *config,
                                                   GFile        *path,
                                                   GError      **error);
+static void     gimp_fonts_notify_font_path      (GObject      *gobject,
+                                                  GParamSpec   *pspec,
+                                                  Gimp         *gimp);
 
 
 void
@@ -65,9 +69,9 @@ gimp_fonts_set_config (Gimp *gimp)
 {
   g_return_if_fail (GIMP_IS_GIMP (gimp));
 
-  g_signal_connect_swapped (gimp->config, "notify::font-path",
-                            G_CALLBACK (gimp_fonts_load),
-                            gimp);
+  g_signal_connect (gimp->config, "notify::font-path",
+                    G_CALLBACK (gimp_fonts_notify_font_path),
+                    gimp);
 }
 
 void
@@ -79,7 +83,7 @@ gimp_fonts_exit (Gimp *gimp)
     {
       if (gimp->config)
         g_signal_handlers_disconnect_by_func (gimp->config,
-                                              G_CALLBACK (gimp_fonts_load),
+                                              G_CALLBACK (gimp_fonts_notify_font_path),
                                               gimp);
 
       g_clear_object (&gimp->fonts);
@@ -117,8 +121,9 @@ gimp_fonts_load_thread (GimpFontsLoadFuncData *data)
 }
 
 void
-gimp_fonts_load (Gimp               *gimp,
-                 GimpInitStatusFunc  status_callback)
+gimp_fonts_load (Gimp                *gimp,
+                 GimpInitStatusFunc   status_callback,
+                 GError             **error)
 {
   FcConfig *config;
   GFile    *fonts_conf;
@@ -149,7 +154,7 @@ gimp_fonts_load (Gimp               *gimp,
     goto cleanup;
 
   path = gimp_config_path_expand_to_files (gimp->config->font_path, FALSE);
-  gimp_fonts_add_directories (gimp, config, path);
+  gimp_fonts_add_directories (gimp, config, path, error);
   g_list_free_full (path, (GDestroyNotify) g_object_unref);
 
   if (status_callback)
@@ -235,10 +240,10 @@ gimp_fonts_load_fonts_conf (FcConfig *config,
 static void
 gimp_fonts_add_directories (Gimp      *gimp,
                             FcConfig  *config,
-                            GList     *path)
+                            GList     *path,
+                            GError   **error)
 {
-  GList  *list;
-  GError *error = NULL;
+  GList *list;
 
   g_return_if_fail (config != NULL);
 
@@ -251,14 +256,16 @@ gimp_fonts_add_directories (Gimp      *gimp,
        * the list, but are unusable and output many errors.
        * See bug 748553.
        */
-      gimp_fonts_recursive_add_fontdir (config, list->data, &error);
+      gimp_fonts_recursive_add_fontdir (config, list->data, error);
     }
-  if (error)
+  if (error && *error)
     {
-      gimp_message_literal (gimp, NULL,
-                            GIMP_MESSAGE_INFO,
-                            error->message);
-      g_error_free (error);
+      gchar *font_list = g_strdup ((*error)->message);
+
+      g_clear_error (error);
+      g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+                   _("Some fonts failed to load:\n%s"), font_list);
+      g_free (font_list);
     }
 }
 
@@ -323,15 +330,17 @@ gimp_fonts_recursive_add_fontdir (FcConfig  *config,
                     {
                       if (*error)
                         {
+                          gchar *current_message = g_strdup ((*error)->message);
+
                           g_clear_error (error);
-                          g_set_error_literal (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
-                                               _("Some fonts failed to load."));
+                          g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+                                       "%s\n- %s", current_message, path);
+                          g_free (current_message);
                         }
                       else
                         {
                           g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
-                                       _("Loading font file '%s' failed."),
-                                       path);
+                                       "- %s", path);
                         }
                     }
                 }
@@ -342,4 +351,46 @@ gimp_fonts_recursive_add_fontdir (FcConfig  *config,
           g_object_unref (info);
         }
     }
+  else
+    {
+      if (error)
+        {
+          gchar *path = g_file_get_path (file);
+
+          if (*error)
+            {
+              gchar *current_message = g_strdup ((*error)->message);
+
+              g_clear_error (error);
+              g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+                           "%s\n- %s%s", current_message, path,
+                           G_DIR_SEPARATOR_S);
+              g_free (current_message);
+            }
+          else
+            {
+              g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+                           "- %s%s", path, G_DIR_SEPARATOR_S);
+            }
+          g_free (path);
+        }
+    }
+}
+
+static void
+gimp_fonts_notify_font_path (GObject    *gobject,
+                             GParamSpec *pspec,
+                             Gimp       *gimp)
+{
+  GError *error = NULL;
+
+  gimp_fonts_load (gimp, NULL, &error);
+
+  if (error)
+    {
+      gimp_message_literal (gimp, NULL,
+                            GIMP_MESSAGE_INFO,
+                            error->message);
+      g_error_free (error);
+    }
 }
diff --git a/app/text/gimp-fonts.h b/app/text/gimp-fonts.h
index efb2e55..1928ce2 100644
--- a/app/text/gimp-fonts.h
+++ b/app/text/gimp-fonts.h
@@ -19,13 +19,14 @@
 #define __GIMP_FONTS_H__
 
 
-void   gimp_fonts_init       (Gimp               *gimp);
-void   gimp_fonts_set_config (Gimp               *gimp);
-void   gimp_fonts_exit       (Gimp               *gimp);
+void   gimp_fonts_init       (Gimp                *gimp);
+void   gimp_fonts_set_config (Gimp                *gimp);
+void   gimp_fonts_exit       (Gimp                *gimp);
 
-void   gimp_fonts_load       (Gimp               *gimp,
-                              GimpInitStatusFunc  status_callback);
-void   gimp_fonts_reset      (Gimp               *gimp);
+void   gimp_fonts_load       (Gimp                *gimp,
+                              GimpInitStatusFunc   status_callback,
+                              GError             **error);
+void   gimp_fonts_reset      (Gimp                *gimp);
 
 
 #endif  /* __GIMP_FONTS_H__ */


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