[Xfce4-commits] <terminal:master> Find the documentation internal, fallback to online docs.

Nick Schermer noreply at xfce.org
Sun Feb 7 18:38:02 CET 2010


Updating branch refs/heads/master
         to d53055b1bb19e3e2a6239519e13257ce8e7f7cdc (commit)
       from c52e7d28b509e78a008e642e410ea5348fc5b231 (commit)

commit d53055b1bb19e3e2a6239519e13257ce8e7f7cdc
Author: Nick Schermer <nick at xfce.org>
Date:   Sun Feb 7 18:33:33 2010 +0100

    Find the documentation internal, fallback to online docs.
    
    Drop the documentation script. It breaks when the terminal
    command is modified (like in Debian). Amount of code is also
    equal.
    
    Fallback to online documentation, location is a bit ugly, but
    it's better then nothing.

 Makefile.am                            |   12 ------
 TerminalHelp.in                        |   48 --------------------------
 terminal/Makefile.am                   |    3 +-
 terminal/terminal-dialogs.c            |   59 ++++++++++++++++++++------------
 terminal/terminal-preferences-dialog.c |    2 +-
 terminal/terminal-window.c             |    4 +-
 6 files changed, 41 insertions(+), 87 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index fc95a15..a876b31 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -11,16 +11,6 @@ rpm: dist
 	rpmbuild -ta $(PACKAGE)-$(VERSION).tar.gz
 	@rm -f $(PACKAGE)-$(VERSION).tar.gz
 
-libexec_SCRIPTS = \
-	TerminalHelp
-
-TerminalHelp: TerminalHelp.in Makefile
-	rm -f TerminalHelp.gen TerminalHelp
-	sed -e "s,\@docdir\@,$(docdir),g" \
-		< $(srcdir)/TerminalHelp.in \
-		> TerminalHelp.gen
-	mv TerminalHelp.gen TerminalHelp
-
 .PHONY: ChangeLog
 
 ChangeLog: Makefile
@@ -51,7 +41,6 @@ ui_DATA = \
 
 EXTRA_DIST = \
 	HACKING \
-	TerminalHelp.in \
 	intltool-extract.in \
 	intltool-merge.in \
 	intltool-update.in \
@@ -61,7 +50,6 @@ EXTRA_DIST = \
 
 DISTCLEANFILES = \
 	Terminal.spec \
-	TerminalHelp \
 	intltool-extract \
 	intltool-merge \
 	intltool-update \
diff --git a/TerminalHelp.in b/TerminalHelp.in
deleted file mode 100644
index b135951..0000000
--- a/TerminalHelp.in
+++ /dev/null
@@ -1,48 +0,0 @@
-#!/bin/sh
-#
-# Copyright (c) 2004-2006 os-cillation e.K.
-#
-# 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
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-#
-
-HELPDIR="@docdir@"
-
-if test -n "$LC_ALL"; then
-  LC=$LC_ALL
-elif test -n "$LANG"; then
-  LC=$LANG
-else
-  LC="C"
-fi
-
-if test -n "$1"; then
-  HELPFILE="$1.html"
-else
-  HELPFILE="index.html"
-fi
-
-if test -r "$HELPDIR/$LC/$HELPFILE"; then
-  URL="$HELPDIR/$LC/$HELPFILE"
-elif test -r "$HELPDIR/`echo $LC | sed 's/\(..\)_.*/\1/'`/$HELPFILE"; then
-  URL="$HELPDIR/`echo $LC | sed 's/\(..\)_.*/\1/'`/$HELPFILE"
-else 
-  URL="$HELPDIR/C/index.html"
-fi
-
-[ -n "$2" ] && URL="$URL#$2"
-
-exec exo-open --launch WebBrowser "file://$URL"
-
-# vim:set ts=2 sw=2 et ai:
diff --git a/terminal/Makefile.am b/terminal/Makefile.am
index b8bda66..12b7de7 100644
--- a/terminal/Makefile.am
+++ b/terminal/Makefile.am
@@ -1,9 +1,8 @@
 INCLUDES = \
-	-DBINDIR=\"$(bindir)\" \
 	-DDATADIR=\"$(datadir)\" \
+	-DHELPDIR=\"$(docdir)\" \
 	-DEXO_DISABLE_DEPRECATED\
 	-DG_LOG_DOMAIN=\"Terminal\" \
-	-DLIBEXECDIR=\"$(libexecdir)\" \
 	-DPACKAGE_LOCALE_DIR=\"$(localedir)\" \
 	-DSN_API_NOT_YET_FROZEN \
 	-I$(top_srcdir) \
diff --git a/terminal/terminal-dialogs.c b/terminal/terminal-dialogs.c
index a68099b..7bec37a 100644
--- a/terminal/terminal-dialogs.c
+++ b/terminal/terminal-dialogs.c
@@ -23,6 +23,9 @@
 #ifdef HAVE_STDARG_H
 #include <stdarg.h>
 #endif
+#ifdef HAVE_LOCALE_H
+#include <locale.h>
+#endif
 
 #include <exo/exo.h>
 
@@ -218,8 +221,10 @@ terminal_dialogs_show_help (gpointer     parent,
 {
   GdkScreen *screen;
   GError    *error = NULL;
-  gchar     *command;
-  gchar     *tmp;
+  gchar     *filename;
+  gchar     *locale;
+  gboolean   exists;
+  gchar     *uri;
 
   /* determine the screen on which to launch the help */
   if (G_UNLIKELY (parent == NULL))
@@ -229,37 +234,47 @@ terminal_dialogs_show_help (gpointer     parent,
   else
     screen = gtk_widget_get_screen (GTK_WIDGET (parent));
 
-  /* generate the command for the documentation browser */
-  command = g_strdup (LIBEXECDIR G_DIR_SEPARATOR_S "TerminalHelp");
+  /* use index page */
+  if (page == NULL)
+    page = "index.html";
 
-  /* check if a page is given */
-  if (G_UNLIKELY (page != NULL))
-    {
-      /* append page as second parameter */
-      tmp = g_strconcat (command, " ", page, NULL);
-      g_free (command);
-      command = tmp;
+  /* get the locale of the user */
+  locale = g_strdup (setlocale (LC_MESSAGES, NULL));
+  if (G_LIKELY (locale != NULL))
+    locale = g_strdelimit (locale, "._", '\0');
+  else
+    locale = g_strdup ("C");
 
-      /* check if an offset is given */
-      if (G_UNLIKELY (offset != NULL))
-        {
-          /* append offset as third parameter */
-          tmp = g_strconcat (command, " ", offset, NULL);
-          g_free (command);
-          command = tmp;
-        }
+  /* check if the help page exists on the system */
+  filename = g_build_filename (HELPDIR, locale, page, NULL);
+  exists = g_file_test (filename, G_FILE_TEST_EXISTS);
+  if (!exists && strcmp (locale, "C") != 0)
+    {
+      g_free (filename);
+      filename = g_build_filename (HELPDIR, "C", page, NULL);
+      exists = g_file_test (filename, G_FILE_TEST_EXISTS);
     }
 
+  /* build the full uri, fallback to online docs if nothing was found */
+  if (G_LIKELY (exists))
+    uri = g_strconcat ("file://", filename, "#", offset, NULL);
+  else
+    uri = g_strconcat ("http://foo-projects.org/~nick/docs/terminal/?lang=",
+                       locale, "&page=", page, "&offset=", offset, NULL);
+
+  g_free (filename);
+  g_free (locale);
+
   /* try to run the documentation browser */
-  if (!gdk_spawn_command_line_on_screen (screen, command, &error))
+  if (!exo_execute_preferred_application_on_screen ("WebBrowser", uri, NULL,
+                                                    NULL, screen, &error))
     {
       /* display an error message to the user */
       terminal_dialogs_show_error (parent, error, _("Failed to open the documentation browser"));
       g_error_free (error);
     }
 
-  /* cleanup */
-  g_free (command);
+  g_free (uri);
 }
 
 
diff --git a/terminal/terminal-preferences-dialog.c b/terminal/terminal-preferences-dialog.c
index 42cffcd..5be77c9 100644
--- a/terminal/terminal-preferences-dialog.c
+++ b/terminal/terminal-preferences-dialog.c
@@ -251,7 +251,7 @@ terminal_preferences_dialog_response (GtkWidget                 *widget,
   if (G_UNLIKELY (response == 1))
     {
       /* open the "Preferences" section of the user manual */
-      terminal_dialogs_show_help (widget, "preferences", NULL);
+      terminal_dialogs_show_help (widget, "preferences.html", NULL);
     }
   else
     {
diff --git a/terminal/terminal-window.c b/terminal/terminal-window.c
index d4cbee7..dd57aff 100644
--- a/terminal/terminal-window.c
+++ b/terminal/terminal-window.c
@@ -1527,7 +1527,7 @@ title_dialog_response (GtkWidget *dialog,
   if (response == GTK_RESPONSE_HELP)
     {
       /* open the "Set Title" paragraph in the "Usage" section */
-      terminal_dialogs_show_help (GTK_WIDGET (dialog), "usage", "set-title");
+      terminal_dialogs_show_help (GTK_WIDGET (dialog), "usage.html", "set-title");
     }
   else
     {
@@ -1619,7 +1619,7 @@ terminal_window_action_report_bug (GtkAction       *action,
                                    TerminalWindow  *window)
 {
   /* open the "Support" section of the user manual */
-  terminal_dialogs_show_help (GTK_WIDGET (window), "support", NULL);
+  terminal_dialogs_show_help (GTK_WIDGET (window), "support.html", NULL);
 }
 
 



More information about the Xfce4-commits mailing list