added help function via html if yelp is not installed
authorFriedrich Beckmann <friedrich.beckmann@gmx.de>
Mon, 23 May 2016 15:51:54 +0000 (17:51 +0200)
committerFriedrich Beckmann <friedrich.beckmann@gmx.de>
Mon, 23 May 2016 15:51:54 +0000 (17:51 +0200)
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)

src/ui/gui/help-menu.c

index 61b9140d1e5e11b0e400b88f62d171188950659e..a5e533bd6ecbc66d5720514c9fd6e8d6a044aa51 100644 (file)
@@ -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
 #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