[gimp/wip/Jehan/layers-dockable-refresh: 83/105] app, libgimp, libgimpwidgets: fix "Application icon missing" in tests.




commit 80e103f8ada990406391dbf9e921e3b165131084
Author: Jehan <jehan girinstud io>
Date:   Sat Oct 23 01:43:57 2021 +0200

    app, libgimp, libgimpwidgets: fix "Application icon missing" in tests.
    
    When running tests, the data are not meant to be necessarily installed.
    Therefore icons won't be found when calling gimp_widgets_init().
    
    Add some special-casing to find them relatively to the install
    directory.

 app/app.c                            |  2 +-
 app/gui/gui.c                        | 16 +++++++++++++---
 app/gui/gui.h                        |  3 ++-
 app/tests.c                          |  2 +-
 devel-docs/tools/shooter.c           |  3 ++-
 libgimp/gimpui.c                     |  2 +-
 libgimpwidgets/gimpwidgets-private.c | 37 +++++++++++++++++++++++-------------
 libgimpwidgets/gimpwidgets-private.h |  9 +++++----
 8 files changed, 49 insertions(+), 25 deletions(-)
---
diff --git a/app/app.c b/app/app.c
index 16a3a1b996..1c19b4b128 100644
--- a/app/app.c
+++ b/app/app.c
@@ -296,7 +296,7 @@ app_run (const gchar         *full_prog_name,
 
 #ifndef GIMP_CONSOLE_COMPILATION
   if (! no_interface)
-    update_status_func = gui_init (gimp, no_splash);
+    update_status_func = gui_init (gimp, no_splash, NULL);
 #endif
 
   if (! update_status_func)
diff --git a/app/gui/gui.c b/app/gui/gui.c
index fa0b6b8580..a968518fca 100644
--- a/app/gui/gui.c
+++ b/app/gui/gui.c
@@ -213,9 +213,19 @@ gui_abort (const gchar *abort_message)
   exit (EXIT_FAILURE);
 }
 
+/**
+ * gui_init:
+ * @gimp:
+ * @no_splash:
+ * @test_base_dir: a base prefix directory.
+ *
+ * @test_base_dir should be set to %NULL in all our codebase except for
+ * unit testing calls.
+ */
 GimpInitStatusFunc
-gui_init (Gimp     *gimp,
-          gboolean  no_splash)
+gui_init (Gimp        *gimp,
+          gboolean     no_splash,
+          const gchar *test_base_dir)
 {
   GimpInitStatusFunc  status_callback = NULL;
   gchar              *abort_message;
@@ -248,7 +258,7 @@ gui_init (Gimp     *gimp,
   gimp_widgets_init (gui_help_func,
                      gui_get_foreground_func,
                      gui_get_background_func,
-                     NULL);
+                     NULL, test_base_dir);
 
   g_type_class_ref (GIMP_TYPE_COLOR_SELECT);
 
diff --git a/app/gui/gui.h b/app/gui/gui.h
index 4b0435d1c1..a5cf0fecc4 100644
--- a/app/gui/gui.h
+++ b/app/gui/gui.h
@@ -23,7 +23,8 @@ void               gui_libs_init (GOptionContext *context);
 void               gui_abort     (const gchar    *abort_message);
 
 GimpInitStatusFunc gui_init      (Gimp           *gimp,
-                                  gboolean        no_splash);
+                                  gboolean        no_splash,
+                                  const gchar    *test_base_dir);
 
 gboolean           gui_recover   (gint            n_recoveries);
 
diff --git a/app/tests.c b/app/tests.c
index e71bcbee63..c1b26c4ff9 100644
--- a/app/tests.c
+++ b/app/tests.c
@@ -138,7 +138,7 @@ gimp_init_for_gui_testing_internal (gboolean  show_gui,
   gimp_set_show_gui (gimp, show_gui);
   gimp_load_config (gimp, gimprc, NULL);
   gimp_gegl_init (gimp);
-  gui_init (gimp, TRUE);
+  gui_init (gimp, TRUE, g_getenv ("GIMP_TESTING_ABS_TOP_SRCDIR"));
   gimp_init_icon_theme_for_testing ();
   gimp_initialize (gimp, gimp_status_func_dummy);
   gimp_restore (gimp, gimp_status_func_dummy, NULL);
diff --git a/devel-docs/tools/shooter.c b/devel-docs/tools/shooter.c
index b273ee9907..35453b839f 100644
--- a/devel-docs/tools/shooter.c
+++ b/devel-docs/tools/shooter.c
@@ -143,7 +143,8 @@ main (int    argc,
   gimp_widgets_init (shooter_standard_help,
                      shooter_get_foreground,
                      shooter_get_background,
-                     shooter_ensure_modules);
+                     shooter_ensure_modules,
+                     NULL);
 
   toplevels = get_all_widgets ();
 
diff --git a/libgimp/gimpui.c b/libgimp/gimpui.c
index bfb7202ee1..0037514df0 100644
--- a/libgimp/gimpui.c
+++ b/libgimp/gimpui.c
@@ -163,7 +163,7 @@ gimp_ui_init (const gchar *prog_name)
   gimp_widgets_init (gimp_ui_help_func,
                      gimp_context_get_foreground,
                      gimp_context_get_background,
-                     gimp_ensure_modules);
+                     gimp_ensure_modules, NULL);
 
   gimp_dialogs_show_help_button (gimp_show_help_button ());
 
diff --git a/libgimpwidgets/gimpwidgets-private.c b/libgimpwidgets/gimpwidgets-private.c
index b60ce358a4..d95983e660 100644
--- a/libgimpwidgets/gimpwidgets-private.c
+++ b/libgimpwidgets/gimpwidgets-private.c
@@ -60,12 +60,14 @@ gimp_widgets_init_foreign_enums (void)
 }
 
 void
-gimp_widgets_init (GimpHelpFunc          standard_help_func,
-                   GimpGetColorFunc      get_foreground_func,
-                   GimpGetColorFunc      get_background_func,
-                   GimpEnsureModulesFunc ensure_modules_func)
+gimp_widgets_init (GimpHelpFunc           standard_help_func,
+                   GimpGetColorFunc       get_foreground_func,
+                   GimpGetColorFunc       get_background_func,
+                   GimpEnsureModulesFunc  ensure_modules_func,
+                   const gchar           *test_base_dir)
 {
-  GList       *icons = NULL;
+  GList       *icons   = NULL;
+  const gchar *cat_dir;
   gchar       *base_dir;
   gchar       *path;
   GdkPixbuf   *pixbuf;
@@ -85,11 +87,20 @@ gimp_widgets_init (GimpHelpFunc          standard_help_func,
 
   gimp_icons_init ();
 
+  if (test_base_dir)
+    {
+      cat_dir  = "";
+      base_dir = g_build_filename (test_base_dir, "desktop", NULL);
+    }
+  else
+    {
+      cat_dir  = "apps";
 #ifdef ENABLE_RELOCATABLE_RESOURCES
-  base_dir = g_build_filename (gimp_installation_directory (), "share", "icons", "hicolor", NULL);
+      base_dir = g_build_filename (gimp_installation_directory (), "share", "icons", "hicolor", NULL);
 #else
-  base_dir = g_build_filename (DATAROOTDIR, "icons", "hicolor", NULL);
+      base_dir = g_build_filename (DATAROOTDIR, "icons", "hicolor", NULL);
 #endif
+    }
 
   /* Loading the application icons. Unfortunately GTK doesn't know how
    * to load any size from a single SVG, so we have to generate common
@@ -98,7 +109,7 @@ gimp_widgets_init (GimpHelpFunc          standard_help_func,
    * then the application icon is dependant to the theme and for now at
    * least, we want the installed icon.
    */
-  path   = g_build_filename (base_dir, "16x16/apps/gimp.png", NULL);
+  path   = g_build_filename (base_dir, "16x16", cat_dir, "gimp.png", NULL);
   pixbuf = gdk_pixbuf_new_from_file (path, &error);
   if (pixbuf)
     icons = g_list_prepend (icons, pixbuf);
@@ -107,7 +118,7 @@ gimp_widgets_init (GimpHelpFunc          standard_help_func,
   g_clear_error (&error);
   g_free (path);
 
-  path   = g_build_filename (base_dir, "32x32/apps/gimp.png", NULL);
+  path   = g_build_filename (base_dir, "32x32", cat_dir, "gimp.png", NULL);
   pixbuf = gdk_pixbuf_new_from_file (path, &error);
   if (pixbuf)
     icons = g_list_prepend (icons, pixbuf);
@@ -116,7 +127,7 @@ gimp_widgets_init (GimpHelpFunc          standard_help_func,
   g_clear_error (&error);
   g_free (path);
 
-  path   = g_build_filename (base_dir, "48x48/apps/gimp.png", NULL);
+  path   = g_build_filename (base_dir, "48x48", cat_dir, "gimp.png", NULL);
   pixbuf = gdk_pixbuf_new_from_file (path, &error);
   if (pixbuf)
     icons = g_list_prepend (icons, pixbuf);
@@ -125,7 +136,7 @@ gimp_widgets_init (GimpHelpFunc          standard_help_func,
   g_clear_error (&error);
   g_free (path);
 
-  path   = g_build_filename (base_dir, "64x64/apps/gimp.png", NULL);
+  path   = g_build_filename (base_dir, "64x64", cat_dir, "gimp.png", NULL);
   pixbuf = gdk_pixbuf_new_from_file (path, &error);
   if (pixbuf)
     icons = g_list_prepend (icons, pixbuf);
@@ -134,7 +145,7 @@ gimp_widgets_init (GimpHelpFunc          standard_help_func,
   g_clear_error (&error);
   g_free (path);
 
-  path   = g_build_filename (base_dir, "scalable/apps/gimp.svg", NULL);
+  path   = g_build_filename (base_dir, "scalable", cat_dir, "gimp.svg", NULL);
   pixbuf = gdk_pixbuf_new_from_file_at_size (path, 128, 128, &error);
   if (pixbuf)
     {
@@ -167,7 +178,7 @@ gimp_widgets_init (GimpHelpFunc          standard_help_func,
     }
   g_free (path);
 
-  path   = g_build_filename (base_dir, "256x256/apps/gimp.png", NULL);
+  path   = g_build_filename (base_dir, "256x256", cat_dir, "gimp.png", NULL);
   pixbuf = gdk_pixbuf_new_from_file (path, &error);
   if (pixbuf)
     icons = g_list_prepend (icons, pixbuf);
diff --git a/libgimpwidgets/gimpwidgets-private.h b/libgimpwidgets/gimpwidgets-private.h
index 4cb1245112..cd6feedf47 100644
--- a/libgimpwidgets/gimpwidgets-private.h
+++ b/libgimpwidgets/gimpwidgets-private.h
@@ -36,10 +36,11 @@ extern GimpEnsureModulesFunc _gimp_ensure_modules_func;
 G_BEGIN_DECLS
 
 
-void  gimp_widgets_init (GimpHelpFunc          standard_help_func,
-                         GimpGetColorFunc      get_foreground_func,
-                         GimpGetColorFunc      get_background_func,
-                         GimpEnsureModulesFunc ensure_modules_func);
+void  gimp_widgets_init (GimpHelpFunc           standard_help_func,
+                         GimpGetColorFunc       get_foreground_func,
+                         GimpGetColorFunc       get_background_func,
+                         GimpEnsureModulesFunc  ensure_modules_func,
+                         const gchar           *test_base_dir);
 
 
 G_END_DECLS


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