From 8c2538546bee0290d01a04883ad6d61bb7804362 Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Sun, 22 Nov 2020 13:40:34 +0000 Subject: [PATCH] Bug 128772 - Account Help Button does not work When pressing the help button, the following uri is created... ghelp:gnucash-help?acct-create and used to open the gnome help app. This segfaults in the '?' as ghelp:gnucash-help does work. To fix this use the full path to the help files. --- gnucash/gnome-utils/gnc-gnome-utils.c | 62 +++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 3 deletions(-) diff --git a/gnucash/gnome-utils/gnc-gnome-utils.c b/gnucash/gnome-utils/gnc-gnome-utils.c index b750a011fa..ba95c7c48d 100644 --- a/gnucash/gnome-utils/gnc-gnome-utils.c +++ b/gnucash/gnome-utils/gnc-gnome-utils.c @@ -236,6 +236,61 @@ gnc_add_css_file (void) g_object_unref (provider_fallback); } +/* This function fixes an issue with yelp that it does not work with the + * ?anchor varient, see https://gitlab.gnome.org/GNOME/yelp/issues/116 + */ +static gchar * +gnc_gnome_help_yelp_anchor_fix (const char *file_name, const char *anchor) +{ + const gchar * const *sdatadirs = g_get_system_data_dirs (); + const gchar * const *langs = g_get_language_names (); + gchar *lookfor = g_strconcat ("gnome/help/", file_name, NULL); + gchar *help_path = NULL; + gchar *help_file = NULL; + gchar *full_path = NULL; + gchar *uri = NULL; + + for (; *sdatadirs; sdatadirs++) + { + gchar *filepath = g_build_filename (*sdatadirs, lookfor, NULL); + if (g_file_test (filepath, G_FILE_TEST_EXISTS)) + help_path = g_strdup (filepath); + g_free (filepath); + } + g_free (lookfor); + + if (!help_path) + { + gnc_error_dialog (NULL, "%s\n%s", _(msg_no_help_found), _(msg_no_help_reason)); + PERR("Unable to find 'gnome/help' directory"); + return NULL; + } + + // add the file extension, currently .xml + help_file = g_strconcat (file_name, ".xml", NULL); + + for (; *langs; langs++) + { + gchar *filename = g_build_filename (help_path, *langs, help_file, NULL); + if (g_file_test (filename, G_FILE_TEST_EXISTS)) + full_path = g_strdup (filename); + g_free (filename); + } + g_free (help_path); + g_free (help_file); + + if (full_path) + uri = g_strconcat ("ghelp:", full_path, "?", anchor, NULL); + else + { + gnc_error_dialog (NULL, "%s\n%s", _(msg_no_help_found), _(msg_no_help_reason)); + PERR("Unable to find valid help language directory"); + return NULL; + } + g_free (full_path); + return uri; +} + #ifdef MAC_INTEGRATION /* Don't be alarmed if this function looks strange to you: It's @@ -418,16 +473,17 @@ gnc_gnome_help (const char *file_name, const char *anchor) { GError *error = NULL; gchar *uri = NULL; - gboolean success; + gboolean success = TRUE; if (anchor) - uri = g_strconcat ("ghelp:", file_name, "?", anchor, NULL); + uri = gnc_gnome_help_yelp_anchor_fix (file_name, anchor); else uri = g_strconcat ("ghelp:", file_name, NULL); DEBUG ("Attempting to opening help uri %s", uri); - success = gtk_show_uri_on_window (NULL, uri, gtk_get_current_event_time (), &error); + if (uri) + success = gtk_show_uri_on_window (NULL, uri, gtk_get_current_event_time (), &error); g_free (uri); if (success)