From: Friedrich Beckmann Date: Mon, 23 May 2016 15:51:54 +0000 (+0200) Subject: added help function via html if yelp is not installed X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6c9aa9259c46de52cc57493ccc80f40f3eef9b17;p=pspp added help function via html if yelp is not installed The current help system requires yelp to be installed. This patch will fallback to local html help and then internet html help via http://www.gnu.org/software/pspp if no html is installed. The browser is invoked via open (MAC), start (windows) and xdg-open (linux) --- diff --git a/src/ui/gui/help-menu.c b/src/ui/gui/help-menu.c index 61b9140d1e..a5e533bd6e 100644 --- a/src/ui/gui/help-menu.c +++ b/src/ui/gui/help-menu.c @@ -1,5 +1,5 @@ /* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2006, 2007, 2010, 2011, 2012, 2013, 2015 Free Software Foundation + Copyright (C) 2006, 2007, 2010, 2011, 2012, 2013, 2015, 2016 Free Software Foundation This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -31,6 +31,13 @@ #define _(msgid) gettext (msgid) #define N_(msgid) msgid +#ifdef __APPLE__ +#define HTMLOPENAPP "open" +#elif _WIN32 +#define HTMLOPENAPP "start" +#else +#define HTMLOPENAPP "xdg-open" +#endif static const gchar *artists[] = { "Bastián Díaz", "Hugo Alejandro", NULL}; @@ -85,27 +92,62 @@ void online_help (const char *page) { GError *err = NULL; - gchar *cmd = NULL; - + GError *htmlerr = NULL; gchar *argv[3] = { "yelp", 0, 0}; + gchar *htmlargv[3] = { HTMLOPENAPP, 0, 0}; + gchar *htmlfilename = NULL; + gchar *htmlfullname = NULL; if (page == NULL) - argv[1] = g_strdup_printf ("file://%s", relocate (DOCDIR "/pspp.xml")); + { + argv[1] = g_strdup_printf ("file://%s", relocate (DOCDIR "/pspp.xml")); + htmlfilename = g_strdup ("index.html"); + htmlargv[1] = g_strdup_printf ("file://%s", htmlfilename); + } else - argv[1] = g_strdup_printf ("file://%s#%s", relocate (DOCDIR "/pspp.xml"), page); + { + gchar **tokens = NULL; + const int maxtokens = 5; + int idx = 0; + argv[1] = g_strdup_printf ("file://%s#%s", + relocate (DOCDIR "/pspp.xml"), page); + tokens = g_strsplit (page, "#", maxtokens); + for(;tokens[idx] && idx < maxtokens;idx++); + htmlfilename = g_strdup_printf ("%s.html", tokens[idx-1]); + g_strfreev (tokens); + } - if (! g_spawn_async (NULL, argv, - NULL, G_SPAWN_SEARCH_PATH, - NULL, NULL, NULL, &err)) + htmlfullname = g_strdup_printf ("%s/%s", relocate (DOCDIR "/pspp.html"), + htmlfilename); + if (g_file_test (relocate (DOCDIR "/pspp.html"), G_FILE_TEST_EXISTS)) + htmlargv[1] = g_strdup_printf ("file://%s", htmlfullname); + else + htmlargv[1] = g_strdup_printf (PACKAGE_URL "manual/html_node/%s", + htmlfilename); + + g_free (htmlfullname); + g_free (htmlfilename); + + if (! (g_spawn_async (NULL, argv, + NULL, G_SPAWN_SEARCH_PATH, + NULL, NULL, NULL, &err) || + g_spawn_async (NULL, htmlargv, + NULL, G_SPAWN_SEARCH_PATH, + NULL, NULL, NULL, &htmlerr)) + ) { - msg (ME, _("Cannot open reference manual: %s. The PSPP user manual is " - "also available at %s"), + msg (ME, _("Cannot open reference manual via yelp: %s. " + "Cannot open via html: %s " + "The PSSP manual is also available at %s"), err->message, + htmlerr->message, PACKAGE_URL "documentation.html"); } - g_free (cmd); + g_free (argv[1]); + g_free (htmlargv[1]); g_clear_error (&err); + g_clear_error (&htmlerr); } static void