[gnome-games] libgames-support: Add about dialogue hooks
- From: Christian Persch <chpe src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnome-games] libgames-support: Add about dialogue hooks
- Date: Thu, 9 Jul 2009 23:11:30 +0000 (UTC)
commit 7f69cd5de56af718d90f51f2867125f2d2e6b924
Author: Christian Persch <chpe gnome org>
Date: Fri Jul 3 20:06:00 2009 +0200
libgames-support: Add about dialogue hooks
Implement about dialogue hooks in games-runtime (for gtk < 2.17).
aisleriot/sol.c | 77 --------------------------------------
libgames-support/games-runtime.c | 69 ++++++++++++++++++++++++++++++++++
2 files changed, 69 insertions(+), 77 deletions(-)
---
diff --git a/aisleriot/sol.c b/aisleriot/sol.c
index 5c2325d..f83c152 100644
--- a/aisleriot/sol.c
+++ b/aisleriot/sol.c
@@ -82,78 +82,6 @@ typedef struct {
#endif /* HAVE_HILDON */
} AppData;
-#if !GTK_CHECK_VERSION (2, 17, 0)
-
-static void
-about_url_hook (GtkAboutDialog *about,
- const char *uri,
- gpointer user_data)
-{
-#if defined(HAVE_MAEMO)
- AppData *data = (AppData *) user_data;
-
- 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);
-
-#elif defined (G_OS_WIN32)
- ShellExecute( NULL, "open", uri, NULL, NULL, SW_SHOWNORMAL );
-#else
-
- GdkScreen *screen;
- GError *error = NULL;
-
- screen = gtk_widget_get_screen (GTK_WIDGET (about));
-
- if (!gtk_show_uri (screen, uri, gtk_get_current_event_time (), &error)) {
- GtkWidget *dialog;
-
- dialog = gtk_message_dialog_new (GTK_WINDOW (about),
- GTK_DIALOG_DESTROY_WITH_PARENT |
- GTK_DIALOG_MODAL,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_CLOSE,
- "%s", _("Could not show link"));
- gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
- "%s", error->message);
- g_error_free (error);
-
- gtk_window_set_title (GTK_WINDOW (dialog), "");
- gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
-
- g_signal_connect (dialog, "response",
- G_CALLBACK (gtk_widget_destroy), NULL);
-
- gtk_window_present (GTK_WINDOW (dialog));
- }
-#endif /* HAVE_MAEMO */
-}
-
-static void
-about_email_hook (GtkAboutDialog *about,
- const char *email_address,
- gpointer user_data)
-{
- char *escaped, *uri;
-
-#if GLIB_CHECK_VERSION (2, 16, 0)
- escaped = g_uri_escape_string (email_address, NULL, FALSE);
-#else
- /* Not really correct, but the best we can do */
- escaped = g_strdup (email_address);
-#endif
- uri = g_strdup_printf ("mailto:%s", escaped);
- g_free (escaped);
-
- about_url_hook (about, uri, user_data);
- g_free (uri);
-}
-
-#endif /* GTK < 2.17.0 */
-
static char *
variation_to_game_file (const char *variation)
{
@@ -411,11 +339,6 @@ main_prog (void *closure, int argc, char *argv[])
games_stock_init ();
-#if !GTK_CHECK_VERSION (2, 17, 0)
- gtk_about_dialog_set_url_hook (about_url_hook, &data, NULL);
- gtk_about_dialog_set_email_hook (about_email_hook, &data, NULL);
-#endif
-
data.window = AISLERIOT_WINDOW (aisleriot_window_new ());
g_signal_connect (data.window, "destroy",
G_CALLBACK (gtk_main_quit), NULL);
diff --git a/libgames-support/games-runtime.c b/libgames-support/games-runtime.c
index 0c29641..aa32e92 100644
--- a/libgames-support/games-runtime.c
+++ b/libgames-support/games-runtime.c
@@ -31,6 +31,7 @@
#endif /* G_OS_WIN32 */
#include <glib/gi18n.h>
+#include <gtk/gtk.h>
#include "games-debug.h"
#include "games-profile.h"
@@ -248,6 +249,69 @@ static const DerivedDirectory derived_directories[] = {
typedef int _assertion[G_N_ELEMENTS (derived_directories) + GAMES_RUNTIME_FIRST_DERIVED_DIRECTORY == GAMES_RUNTIME_LAST_DIRECTORY ? 1 : -1];
+#if !GTK_CHECK_VERSION (2, 17, 0)
+/* Since version 2.17.0, gtk has default about dialogue hook functions
+ * using gtk_show_uri(). For earlier versions, we need to implement
+ * our own hooks.
+ */
+
+static void
+about_url_hook (GtkAboutDialog *about,
+ const char *uri,
+ gpointer user_data)
+{
+ GdkScreen *screen;
+ GError *error = NULL;
+
+ screen = gtk_widget_get_screen (GTK_WIDGET (about));
+
+ if (!games_show_uri (screen, uri, gtk_get_current_event_time (), &error)) {
+ GtkWidget *dialog;
+
+ dialog = gtk_message_dialog_new (GTK_WINDOW (about),
+ GTK_DIALOG_DESTROY_WITH_PARENT |
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ "%s", _("Could not show link"));
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+ "%s", error->message);
+ g_error_free (error);
+
+ gtk_window_set_title (GTK_WINDOW (dialog), "");
+ gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
+
+ g_signal_connect (dialog, "response",
+ G_CALLBACK (gtk_widget_destroy), NULL);
+
+ gtk_window_present (GTK_WINDOW (dialog));
+ }
+}
+
+static void
+about_email_hook (GtkAboutDialog *about,
+ const char *email_address,
+ gpointer user_data)
+{
+ char *uri;
+
+#if GLIB_CHECK_VERSION (2, 16, 0)
+ char *escaped_email_address;
+
+ escaped_email_address = g_uri_escape_string (email_address, NULL, FALSE);
+ uri = g_strdup_printf ("mailto:%s", escaped_email_address);
+ g_free (escaped_email_address);
+#else
+ /* Not really correct, but the best we can do */
+ uri = g_strdup_printf ("mailto:%s", escaped);
+#endif
+
+ about_url_hook (about, uri, user_data);
+ g_free (uri);
+}
+
+#endif /* GTK < 2.17.0 */
+
/* public API */
/**
@@ -336,6 +400,11 @@ games_runtime_init (const char *name)
#endif
gpl_version = 2;
+#if !GTK_CHECK_VERSION (2, 17, 0)
+ gtk_about_dialog_set_url_hook (about_url_hook, NULL, NULL);
+ gtk_about_dialog_set_email_hook (about_email_hook, NULL, NULL);
+#endif
+
_games_profile_end ("games_runtime_init");
return retval;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]