[gnome-games] libgames-support: Add more help methods



commit 46925045d7b3ff8dbfd5da2dc1b7e9e25ba223af
Author: Christian Persch <chpe gnome org>
Date:   Sat Jun 27 19:15:03 2009 +0200

    libgames-support: Add more help methods
    
    Generalise the hildon help support to all platforms. We now support the
    following methods to show help to the user:
    - ghelp: URIs, loaded in Yelp
    - pregenerated (by gnome-doc-tool) HTML/XHTML files, loaded in the
      browser
    - online help from library.gnome.org

 configure.in                  |   65 ++++++++++++++--
 libgames-support/games-help.c |  168 +++++++++++++++++++++++++++++++++++++----
 libgames-support/games-help.h |    2 +-
 3 files changed, 212 insertions(+), 23 deletions(-)
---
diff --git a/configure.in b/configure.in
index e9daaeb..9e85acc 100644
--- a/configure.in
+++ b/configure.in
@@ -221,12 +221,6 @@ fi
 AC_DEFINE_UNQUOTED([LSB_DISTRIBUTOR],["$LSB_DISTRIBUTOR"],[The distributor ID])
 AC_DEFINE_UNQUOTED([LSB_DISTRIBUTION],["$LSB_DISTRIBUTION"],[The full distribution description])
 
-# *************
-# Documentation
-# *************
-
-GNOME_DOC_INIT([0.10.0],[have_gdu=yes],[have_gdu=no])
-
 dnl ****************************************************************************
 dnl * Python 2.4
 dnl ****************************************************************************
@@ -936,6 +930,64 @@ if test "$platform_win32" = "yes" -a "$os_win32" = "yes"; then
   fi
 fi
 
+# *************
+# Documentation
+# *************
+
+# We support various ways to present help to the user:
+# ghelp: using the ghelp: protocol, most likely displaying in Yelp
+# file: showing html or xhtml files in the web browser
+# library: in the web browser loaded remotedly from library.gnome.org
+#
+# Note that for help using [x]html files, we can't use gnome-doc-utils.make
+# since it doesn't currently support this. The packager will have to use
+# gnome-doc-tool directly to build the documentation in the right format.
+# The help files must be installed in $(pkgdatadir)/$(DOC_MODULE)/$(LOCALE) .
+
+AC_MSG_CHECKING([which help method to use])
+AC_ARG_WITH([help-method],
+  [AS_HELP_STRING([--with-help-method],[which help method to use (ghelp|file|library; default: ghelp)])],
+  [],
+  [case "$with_platform" in
+     hildon) with_help_method=file ;;
+     *) if test "$platform_win32" = "yes"; then
+           with_help_method=file
+         else
+           with_help_method=ghelp
+         fi ;;
+   esac])
+AC_MSG_RESULT([$with_help_method])
+
+case "$with_help_method" in
+  ghelp) AC_DEFINE([WITH_HELP_METHOD_GHELP],[1],[Define to use help using ghelp]) ;;
+  file) AC_DEFINE([WITH_HELP_METHOD_FILE],[1],[Define to use help using file]) ;;
+  library) AC_DEFINE([WITH_HELP_METHOD_LIBRARY],[1],[Define to use help using library.gnome.org]) ;;
+  *) AC_MSG_ERROR([unknown help method "$with_help_method"]) ;;
+esac
+
+if test "$with_help_method" = "file"; then
+  AC_MSG_CHECKING([for help file format])
+  AC_ARG_WITH([help-file-format],
+    [AS_HELP_STRING([--with-help-file-format],[which file format to use for help (html|xhtml; default: html)])],
+    [case "$with_help_file_format" in
+       html|xhtml) ;;
+       *) AC_MSG_ERROR([unknown help file format "$with_help_file_format"]) ;;
+     esac],
+    [with_help_file_format=html])
+  AC_MSG_RESULT([$with_help_file_format])
+
+  AC_DEFINE_UNQUOTED([HELP_FILE_FORMAT],["$with_help_file_format"],[The help file format])
+fi
+
+GNOME_DOC_INIT([0.10.0],
+  [have_gdu=yes],
+  [have_gdu=no
+   if test "$with_help_method" = "ghelp"; then
+     AC_MSG_ERROR([ghelp requested, but gnome-doc-utils not found!])
+   fi])
+
+AM_CONDITIONAL([BUILD_HELP],[test "$with_help_method" = "ghelp"])
+
 # **********
 # Unit tests
 # **********
@@ -1116,6 +1168,7 @@ fi
 echo "
     Games to be compiled:  ${gamelist}
 
+    Help method:           ${with_help_method} ${with_help_file_format}
     Using SM Client:       ${with_smclient}
     Using RSVG:            ${have_rsvg}
     Card theme formats:    ${with_card_theme_formats}
diff --git a/libgames-support/games-help.c b/libgames-support/games-help.c
index 52fe13c..9461070 100644
--- a/libgames-support/games-help.c
+++ b/libgames-support/games-help.c
@@ -18,13 +18,95 @@
 
 #include <config.h>
 
+#include <string.h>
+
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
 
+#ifdef HAVE_HILDON
+#include <libosso.h>
+
+#ifdef HAVE_MAEMO_3
+#include <osso-browser-interface.h>
+#else
+#include <tablet-browser-interface.h>
+#endif /* HAVE_MAEMO_3 */
+#endif /* HAVE_HILDON */
+
+#ifdef G_OS_WIN32
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <io.h>
+#endif /* G_OS_WIN32 */
+
+#include "games-runtime.h"
+
 #include "games-help.h"
 
+static gboolean
+show_uri (GdkScreen *screen,
+          const char *uri,
+          guint32 timestamp,
+          GError **error)
+{
+#if 0 // def HAVE_HILDON
+  osso_rpc_run_with_defaults (data->osso_context,
+                              "osso_browser",
+                              OSSO_BROWSER_OPEN_NEW_WINDOW_REQ,
+                              NULL,
+                              DBUS_TYPE_STRING, uri,
+                              DBUS_TYPE_INVALID);
+  return TRUE;
+#else
+
+#ifdef G_OS_WIN32
+  ShellExecute (NULL, "open", uri, NULL, NULL, SW_SHOWNORMAL);
+  return TRUE;
+#else /* !G_OS_WIN32 */
+
+#if GTK_CHECK_VERSION (2, 14, 0)
+  return gtk_show_uri (screen, uri, timestamp, error);
+#else /* GTK+ < 2.14 */
+  char *argv[3] = { (char *) "xdg-open", (char *) uri, NULL };
+ 
+  if (gdk_spawn_on_screen (screen,
+                           NULL /* working directory */,
+                           argv,
+                           NULL /* environment */,
+                           G_SPAWN_SEARCH_PATH,
+                           NULL, NULL,
+                           NULL,
+                           error))
+    return TRUE;
+
+  g_clear_error (error);
+
+  /* Try falling back to gnome-open */
+  argv[0] = (char *) "gnome-open";
+  if (gdk_spawn_on_screen (screen,
+                           NULL /* working directory */,
+                           argv,
+                           NULL /* environment */,
+                           G_SPAWN_SEARCH_PATH,
+                           NULL, NULL,
+                           NULL,
+                           error))
+    return TRUE;
+
+  g_set_error (error, G_SPAWN_ERROR, G_SPAWN_ERROR_FAILED,
+               "%s", "Failed to show help");
+  return FALSE;
+#endif /* GTK+ >= 2.14 */
+#endif /* G_OS_WIN32 */
+#endif /* HAVE_HILDON */
+}
+
 /**
  * games_help_display:
+ * @window: a #GdkWindow get the #GdkScreen from, and to use
+ *   as parent window for an error dialogue
+ * @doc_module: the doc module name (same as DOC_MODULE from help/Makefile.am)
+ * @section: a section name, or %NULL
  *
  * Opens help or displays error dialog when unable to open help.
  *
@@ -35,41 +117,95 @@
  */
 void
 games_help_display (GtkWidget *window,
-                    const char *app_name,
+                    const char *doc_module,
                     const char *section)
 {
-#if GTK_CHECK_VERSION (2, 14, 0)
   GdkScreen *screen;
   GError *error = NULL;
-  char *help_string;
+  char *help_uri;
+
+  g_return_if_fail (doc_module != NULL);
 
   screen = gtk_widget_get_screen (GTK_WIDGET (window));
 
-  if (section) {
-    help_string = g_strconcat ("ghelp:", app_name, "?", section, NULL);
+#if defined(WITH_HELP_METHOD_GHELP)
+  if (section != NULL) {
+    help_uri = g_strdup_printf ("ghelp:%s?%s", doc_module, section);
+  } else {
+    help_uri = g_strdup_printf ("ghelp:%s", doc_module);
+  }
+#elif defined(WITH_HELP_METHOD_FILE)
+  const char *help_dir;
+  const char * const *langs;
+  guint i;
+
+  langs = g_get_language_names ();
+  help_dir = games_runtime_get_directory (GAMES_RUNTIME_GAME_HELP_DIRECTORY);
+
+  help_uri = NULL;
+  for (i = 0; langs[i] != NULL; ++i) {
+    const char *lang = langs[i];
+    char *help_file_name, *path;
+
+    /* Filter out variants */
+    if (strchr (lang, '.') != NULL ||
+        strchr (lang, '@') != NULL)
+      continue;
+
+    help_file_name = g_strdup_printf ("%s." HELP_FILE_FORMAT,
+                                      section ? section : doc_module);
+    path = g_build_filename (help_dir,
+                             lang,
+                             help_file_name,
+                             NULL);
+    g_free (help_file_name);
+
+    if (g_file_test (path, G_FILE_TEST_EXISTS)) {
+      help_uri = g_filename_to_uri (path, NULL, NULL);
+      g_free (path);
+      break;
+    }
+
+    g_free (path);
+  }
+
+  if (help_uri == NULL) {
+    error = g_error_new (G_IO_ERROR,
+                         G_IO_ERROR_NOT_FOUND,
+                         /* %s.%s is the game name + the extension HTML or XHTML, e.g. Klondike.html" */
+                         _("Help file â??%s.%sâ?? not found"),
+                         section ? section : doc_module,
+                         HELP_FILE_FORMAT);
+    goto err;
+  }
+    
+#elif defined(WITH_HELP_METHOD_LIBRARY)
+  if (section != NULL) {
+    help_uri = g_strdup_printf ("http://library.gnome.org/users/%s/stable/%s.html";, doc_module, section);
   } else {
-    help_string = g_strconcat ("ghelp:", app_name, NULL);
+    help_uri = g_strdup_printf ("http://library.gnome.org/users/%s/stable/";, doc_module);
   }
+#endif
 
-  gtk_show_uri (screen, help_string, gtk_get_current_event_time (), &error);
+  show_uri (screen, help_uri, gtk_get_current_event_time (), &error);
+
+#if defined(WITH_HELP_METHOD_FILE)
+err:
+#endif
 
   if (error != NULL) {
     GtkWidget *d;
     d = gtk_message_dialog_new (GTK_WINDOW (window), 
-                              GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
-                              GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, 
-                              "%s", _("Unable to open help file"));
+                                GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+                                GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, 
+                                "%s", _("Unable to open help file"));
     gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (d),
-                              "%s", error->message);
+                                              "%s", error->message);
     g_signal_connect (d, "response", G_CALLBACK (gtk_widget_destroy), NULL);
     gtk_window_present (GTK_WINDOW (d));
 
     g_error_free (error);
   }
 
-  g_free(help_string);
-
-#else /* GTK+ < 2.14 */
-#error FIXME: games_help_display unimplemented on hildon!
-#endif /* GTK+ >= 2.14 */
+  g_free (help_uri);
 }
diff --git a/libgames-support/games-help.h b/libgames-support/games-help.h
index fa033da..288d4b9 100644
--- a/libgames-support/games-help.h
+++ b/libgames-support/games-help.h
@@ -24,7 +24,7 @@
 G_BEGIN_DECLS
 
 void games_help_display (GtkWidget *window,
-                         const char *app_name,
+                         const char *doc_module,
                          const char *section);
 
 G_END_DECLS



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