[gnome-games] libgames-support: Add games_help_display_full variant



commit afbe589b545ad82bf99d13522a8c51c69599220d
Author: Christian Persch <chpe gnome org>
Date:   Fri Jul 3 20:26:48 2009 +0200

    libgames-support: Add games_help_display_full variant
    
    Add a variant of games_help_display that returns a GError on failure.

 libgames-support/games-help.c |   65 ++++++++++++++++++++++++----------------
 libgames-support/games-help.h |    5 +++
 libgames-support/games-show.h |    8 ++--
 3 files changed, 48 insertions(+), 30 deletions(-)
---
diff --git a/libgames-support/games-help.c b/libgames-support/games-help.c
index b4ea536..cc53985 100644
--- a/libgames-support/games-help.c
+++ b/libgames-support/games-help.c
@@ -30,29 +30,28 @@
 #include "games-help.h"
 
 /**
- * games_help_display:
+ * games_help_display_full:
  * @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
+ * @error: a #GError location, or %NULL
  *
- * Opens help or displays error dialog when unable to open help.
- *
- * @window: toplevel window
- * @application: name used for the help file
- * @section: section to open, or %NULL
+ * Opens help or returns an error.
  *
+ * Returns: %TRUE on success, or %FALSE on failure with @error filled in
  */
-void
-games_help_display (GtkWidget *window,
-                    const char *doc_module,
-                    const char *section)
+gboolean
+games_help_display_full (GtkWidget *window,
+                         const char *doc_module,
+                         const char *section,
+                         GError **error)
 {
   GdkScreen *screen;
-  GError *error = NULL;
   char *help_uri;
+  gboolean ret;
 
-  g_return_if_fail (doc_module != NULL);
+  g_return_val_if_fail (doc_module != NULL, TRUE);
 
   screen = gtk_widget_get_screen (GTK_WIDGET (window));
 
@@ -109,13 +108,13 @@ games_help_display (GtkWidget *window,
   }
 
   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;
+    g_set_error (error,
+                 g_quark_from_static_string ("games-help-error"), 0,
+                 /* %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);
+    return FALSE;
   }
     
 #elif defined(WITH_HELP_METHOD_LIBRARY)
@@ -126,18 +125,32 @@ games_help_display (GtkWidget *window,
   }
 #endif
 
-  games_show_uri (screen, help_uri, gtk_get_current_event_time (), &error);
+  ret = games_show_uri (screen, help_uri, gtk_get_current_event_time (), error);
 
-#if defined(WITH_HELP_METHOD_FILE)
-err:
-#endif
+  g_free (help_uri);
+  return ret;
+}
 
-  if (error != NULL) {
+/**
+ * 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.
+ */
+void
+games_help_display (GtkWidget *window,
+                    const char *doc_module,
+                    const char *section)
+{
+  GError *error = NULL;
+
+  if (!games_help_display_full (window, doc_module, section, &error)) {
     games_show_error (window, error,
                       _("Could not show help for â??%sâ??"),
                       section ? section : g_get_application_name ());
     g_error_free (error);
   }
-
-  g_free (help_uri);
 }
diff --git a/libgames-support/games-help.h b/libgames-support/games-help.h
index 288d4b9..327880c 100644
--- a/libgames-support/games-help.h
+++ b/libgames-support/games-help.h
@@ -27,6 +27,11 @@ void games_help_display (GtkWidget *window,
                          const char *doc_module,
                          const char *section);
 
+gboolean games_help_display_full (GtkWidget *window,
+                                  const char *doc_module,
+                                  const char *section,
+                                  GError **error);
+
 G_END_DECLS
 
 #endif /* !GAMES_HELP_H */
diff --git a/libgames-support/games-show.h b/libgames-support/games-show.h
index 3a270ee..721d442 100644
--- a/libgames-support/games-show.h
+++ b/libgames-support/games-show.h
@@ -24,10 +24,10 @@
 
 G_BEGIN_DECLS
 
-gboolean games_show_uri (GdkScreen   *screen,
-                         const gchar *uri,
-                         guint32      timestamp,
-                         GError     **error);
+gboolean games_show_uri (GdkScreen *screen,
+                         const char *uri,
+                         guint32 timestamp,
+                         GError **error);
 
 void games_show_error (GtkWidget *window,
                        GError *error,



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