[gnome-games] libgames-support: Add games_show_uri()



commit 1cc210c26adda6d79470bec45f065a02dfd98723
Author: Christian Persch <chpe gnome org>
Date:   Fri Jul 3 19:27:51 2009 +0200

    libgames-support: Add games_show_uri()
    
    Implement a helper function to open a URI. On gtk+ >= 2.14, this just
    uses gtk_show_uri(). Otherwise, on hildon, it uses osso to show the URI
    in the browser, and otherwise uses xdg-open with a fallback to
    gnome-open.
    Supported URI schemes are file:, http[s]:. On the gnome platform, ghelp:
    is supported as well.

 libgames-support/Makefile.am  |    2 +
 libgames-support/games-help.c |   78 +--------------------------
 libgames-support/games-show.c |  115 +++++++++++++++++++++++++++++++++++++++++
 libgames-support/games-show.h |   35 ++++++++++++
 4 files changed, 155 insertions(+), 75 deletions(-)
---
diff --git a/libgames-support/Makefile.am b/libgames-support/Makefile.am
index a270f09..ca66742 100644
--- a/libgames-support/Makefile.am
+++ b/libgames-support/Makefile.am
@@ -93,6 +93,8 @@ libgames_support_la_SOURCES +=		\
 	games-setgid-io.h		\
 	games-scores-backend.c		\
 	games-scores-backend.h		\
+	games-show.c			\
+	games-show.h			\
 	$(NULL)
 endif
 
diff --git a/libgames-support/games-help.c b/libgames-support/games-help.c
index 1b5ddb6..51264f3 100644
--- a/libgames-support/games-help.c
+++ b/libgames-support/games-help.c
@@ -1,5 +1,6 @@
 /*
  *  Copyright © 2008 Thomas H.P. Andersen <phomes gmail com>
+ *  Copyright © 2007, 2008, 2009 Christian Persch
  *
  *  This runtime is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU Lesser General Public License as published by
@@ -23,84 +24,11 @@
 #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-show.h"
 #include "games-runtime.h"
 
 #include "games-help.h"
 
-static gboolean
-show_uri (GdkScreen *screen,
-          const char *uri,
-          guint32 timestamp,
-          GError **error)
-{
-#ifdef HAVE_HILDON
-  osso_rpc_run_with_defaults (games_runtime_get_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
@@ -189,7 +117,7 @@ games_help_display (GtkWidget *window,
   }
 #endif
 
-  show_uri (screen, help_uri, gtk_get_current_event_time (), &error);
+  games_show_uri (screen, help_uri, gtk_get_current_event_time (), &error);
 
 #if defined(WITH_HELP_METHOD_FILE)
 err:
diff --git a/libgames-support/games-show.c b/libgames-support/games-show.c
new file mode 100644
index 0000000..a186481
--- /dev/null
+++ b/libgames-support/games-show.c
@@ -0,0 +1,115 @@
+/*
+ *  Copyright © 2008 Thomas H.P. Andersen <phomes gmail com>
+ *  Copyright © 2007, 2008, 2009 Christian Persch
+ *
+ *  This runtime is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Lesser General Public License as published by
+ *  the Free Software Foundation; either version 2.1, or (at your option)
+ *  any later version.
+ *
+ *  This runtime is distributed in the hope runtime 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 Lesser General Public License
+ *  along with this runtime; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <config.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-show.h"
+
+/**
+ * games_show_uri:
+ * @screen: screen to show the uri on or %NULL for the default screen
+ * @uri: the uri to show
+ * @timestamp: a timestamp to prevent focus stealing.
+ * @error: a #GError that is returned in case of errors
+ *
+ * This is a convenience function for launching the default application
+ * to show the uri.
+ * Ideally the timestamp is taken from the event triggering
+ * the gtk_show_uri() call, or use gtk_get_current_event_time().
+ *
+ * Returns: %TRUE on success, %FALSE on error.
+ */
+gboolean
+games_show_uri (GdkScreen *screen,
+                const char *uri,
+                guint32 timestamp,
+                GError **error)
+{
+#ifdef HAVE_HILDON
+  osso_rpc_run_with_defaults (games_runtime_get_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 */
+}
diff --git a/libgames-support/games-show.h b/libgames-support/games-show.h
new file mode 100644
index 0000000..a1519f4
--- /dev/null
+++ b/libgames-support/games-show.h
@@ -0,0 +1,35 @@
+/*
+ *  Copyright © 2008 Thomas H.P. Andersen <phomes gmail com>
+ *  Copyright © 2007, 2008, 2009 Christian Persch
+ *
+ *  This runtime is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Lesser General Public License as published by
+ *  the Free Software Foundation; either version 2.1, or (at your option)
+ *  any later version.
+ *
+ *  This runtime is distributed in the hope runtime 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 Lesser General Public License
+ *  along with this runtime; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef GAMES_SHOW_H
+#define GAMES_SHOW_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+gboolean games_show_uri (GdkScreen   *screen,
+                         const gchar *uri,
+                         guint32      timestamp,
+                         GError     **error);
+
+
+G_END_DECLS
+
+#endif /* !GAMES_SHOW_H */



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