[glade3] Use gtk_show_uri() to show help and urls



commit 23aa3575b61c4a3ed57868b7fe46d0d40865bbb2
Author: Javier Jardón <jjardon gnome org>
Date:   Wed Jun 9 04:09:58 2010 +0200

    Use gtk_show_uri() to show help and urls

 ChangeLog             |    7 ++-
 gladeui/glade-utils.c |  158 ++++++++++---------------------------------------
 src/glade-window.c    |  158 ++-----------------------------------------------
 3 files changed, 43 insertions(+), 280 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 6906c97..ef43534 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,9 @@
-2010-05-01  Javier Jardón <jjardon gnome org>
+2010-06-10  Javier Jardón <jjardon gnome org>
+
+	* gladeui/glade-utils.c: Use gtk_show_uri() instead custom code
+	* src/glade-window.c: Use the same api (based in gtk_show_uri()) to show the help and urls.
+
+2010-06-10  Javier Jardón <jjardon gnome org>
 
 	* src/glade-window.c: Fix the user and developer url location
 
diff --git a/gladeui/glade-utils.c b/gladeui/glade-utils.c
index f8a6954..dfd5e22 100644
--- a/gladeui/glade-utils.c
+++ b/gladeui/glade-utils.c
@@ -1780,127 +1780,6 @@ glade_util_object_is_loading (GObject *object)
 	return glade_project_is_loading (project);
 }
 
-#ifdef G_OS_WIN32
-
-static gboolean
-glade_util_url_show_win32 (const gchar *url)
-{
-	HINSTANCE h;
-	
-	h = ShellExecuteA (NULL, "open", url, NULL, NULL, SW_SHOWNORMAL);
-	
-	if ((int)h <= 32)
-		return FALSE;
-
-	return TRUE;
-}
-
-#else
-
-/* pilfered from Beast - birnetutils.cc */
-static gboolean
-glade_util_url_show_unix (const gchar *url)
-{
-	static struct {
-	const gchar   *prg, *arg1, *prefix, *postfix;
-	gboolean       asyncronous; /* start asyncronously and check exit code to catch launch errors */
-	volatile gboolean disabled;
-	} browsers[] = {
-
-	/* configurable, working browser launchers */
-	{ "gnome-open",             NULL,           "", "", 0 }, /* opens in background, correct exit_code */
-	{ "exo-open",               NULL,           "", "", 0 }, /* opens in background, correct exit_code */
-
-	/* non-configurable working browser launchers */
-	{ "kfmclient",              "openURL",      "", "", 0 }, /* opens in background, correct exit_code */
-	{ "gnome-moz-remote",       "--newwin",     "", "", 0 }, /* opens in background, correct exit_code */
-
-#if 0   /* broken/unpredictable browser launchers */
-	{ "browser-config",         NULL,            "", "", 0 }, /* opens in background (+ sleep 5), broken exit_code (always 0) */
-	{ "xdg-open",               NULL,            "", "", 0 }, /* opens in foreground (first browser) or background, correct exit_code */
-	{ "sensible-browser",       NULL,            "", "", 0 }, /* opens in foreground (first browser) or background, correct exit_code */
-	{ "htmlview",               NULL,            "", "", 0 }, /* opens in foreground (first browser) or background, correct exit_code */
-#endif
-
-	/* direct browser invocation */
-	{ "x-www-browser",          NULL,           "", "", 1 }, /* opens in foreground, browser alias */
-	{ "firefox",                NULL,           "", "", 1 }, /* opens in foreground, correct exit_code */
-	{ "mozilla-firefox",        NULL,           "", "", 1 }, /* opens in foreground, correct exit_code */
-	{ "mozilla",                NULL,           "", "", 1 }, /* opens in foreground, correct exit_code */
-	{ "konqueror",              NULL,           "", "", 1 }, /* opens in foreground, correct exit_code */
-	{ "opera",                  "-newwindow",   "", "", 1 }, /* opens in foreground, correct exit_code */
-	{ "epiphany",               NULL,           "", "", 1 }, /* opens in foreground, correct exit_code */	
-	{ "galeon",                 NULL,           "", "", 1 }, /* opens in foreground, correct exit_code */
-	{ "amaya",                  NULL,           "", "", 1 }, /* opens in foreground, correct exit_code */
-	{ "dillo",                  NULL,           "", "", 1 }, /* opens in foreground, correct exit_code */
-
-	};
-  
-	guint i;
-	for (i = 0; i < G_N_ELEMENTS (browsers); i++)
-
-		if (!browsers[i].disabled)
-		{
-		        gchar *args[128] = { 0, };
-		        guint n = 0;
-		        gchar *string;
-		        gchar fallback_error[64] = "Ok";
-		        gboolean success;
-
-		        args[n++] = (gchar*) browsers[i].prg;
-		        
-		        if (browsers[i].arg1)
-		        	args[n++] = (gchar*) browsers[i].arg1;
-		        
-		        string = g_strconcat (browsers[i].prefix, url, browsers[i].postfix, NULL);
-		        args[n] = string;
-        
-		        if (!browsers[i].asyncronous) /* start syncronously and check exit code */
-			{
-				gint exit_status = -1;
-				success = g_spawn_sync (NULL, /* cwd */
-		                                        args,
-		                                        NULL, /* envp */
-		                                        G_SPAWN_SEARCH_PATH,
-		                                        NULL, /* child_setup() */
-		                                        NULL, /* user_data */
-		                                        NULL, /* standard_output */
-		                                        NULL, /* standard_error */
-		                                        &exit_status,
-		                                        NULL);
-		                success = success && !exit_status;
-		            
-				if (exit_status)
-					g_snprintf (fallback_error, sizeof (fallback_error), "exitcode: %u", exit_status);
-
-			}
-		        else
-			{
-				success = g_spawn_async (NULL, /* cwd */
-							 args,
-							 NULL, /* envp */
-							 G_SPAWN_SEARCH_PATH,
-							 NULL, /* child_setup() */
-							 NULL, /* user_data */
-							 NULL, /* child_pid */
-							 NULL);
-			}
-			
-			g_free (string);
-			if (success)
-				return TRUE;
-			browsers[i].disabled = TRUE;
-	}
-	
-	/* reset all disabled states if no browser could be found */
-	for (i = 0; i < G_N_ELEMENTS (browsers); i++)
-		browsers[i].disabled = FALSE;
-		     
-	return FALSE;	
-}
-
-#endif
-
 /**
  * glade_util_url_show:
  * @url: An URL to display
@@ -1908,18 +1787,43 @@ glade_util_url_show_unix (const gchar *url)
  * Portable function for showing an URL @url in a web browser.
  *
  * Returns: TRUE if a web browser was successfully launched, or FALSE
- * 
+ *
  */
 gboolean
 glade_util_url_show (const gchar *url)
 {
+	GtkWidget *widget;
+	GError *error = NULL;
+	gboolean ret;
+
 	g_return_val_if_fail (url != NULL, FALSE);
 
-#ifdef G_OS_WIN32
-	return glade_util_url_show_win32 (url);
-#else
-	return glade_util_url_show_unix (url);
-#endif
+	widget = glade_app_get_window ();
+
+	ret = gtk_show_uri (gtk_widget_get_screen (widget),
+	                    url,
+	                    gtk_get_current_event_time (),
+	                    &error);
+	if (error != NULL)
+	{
+		GtkWidget *dialog_widget;
+
+		dialog_widget = gtk_message_dialog_new (GTK_WINDOW (widget),
+		                                        GTK_DIALOG_DESTROY_WITH_PARENT,
+		                                        GTK_MESSAGE_ERROR,
+		                                        GTK_BUTTONS_CLOSE,
+		                                        "%s", _("Could not show link:"));
+		gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog_widget),
+		                                          "%s", error->message);
+		g_error_free (error);
+
+		g_signal_connect (dialog_widget, "response",
+		                  G_CALLBACK (gtk_widget_destroy), NULL);
+
+		gtk_window_present (GTK_WINDOW (dialog_widget));
+	}
+
+	return ret;
 }
 
 /**
diff --git a/src/glade-window.c b/src/glade-window.c
index 2339e7c..608ddda 100644
--- a/src/glade-window.c
+++ b/src/glade-window.c
@@ -148,101 +148,6 @@ static void glade_window_config_save (GladeWindow *window);
 
 G_DEFINE_TYPE (GladeWindow, glade_window, GTK_TYPE_WINDOW)
 
-static void
-about_dialog_activate_link_func (GtkAboutDialog *dialog, const gchar *link, GladeWindow *window)
-{
-	GtkWidget *warning_dialog;
-	gboolean retval;
-	
-	retval = glade_util_url_show (link);
-	
-	if (!retval)
-	{
-		warning_dialog = gtk_message_dialog_new (GTK_WINDOW (dialog),
-							 GTK_DIALOG_MODAL,
-							 GTK_MESSAGE_ERROR,
-							 GTK_BUTTONS_OK,
-							 _("Could not display the URL '%s'"),
-							 link);
-						 
-		gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (warning_dialog),
-							  _("No suitable web browser could be found."));
-						 	
-		gtk_window_set_title (GTK_WINDOW (warning_dialog), "");
-		
-		g_signal_connect_swapped (warning_dialog, "response",
-					  G_CALLBACK (gtk_widget_destroy),
-					  warning_dialog);
-				
-		gtk_widget_show (warning_dialog);
-	}	
-
-}
-
-/* locates the help file "glade.xml" with respect to current locale */
-static gchar*
-locate_help_file ()
-{
-	const gchar* const* locales = g_get_language_names ();
-
-	/* check if user manual has been installed, if not, GLADE_GNOMEHELPDIR is empty */
-	if (strlen (GLADE_GNOMEHELPDIR) == 0)
-		return NULL;
-
-	for (; *locales; locales++)
-	{
-		gchar *path;
-		
-		path = g_build_path (G_DIR_SEPARATOR_S, GLADE_GNOMEHELPDIR, "glade", *locales, "glade.xml", NULL);
-
-		if (g_file_test (path, G_FILE_TEST_EXISTS))
-		{
-			return (path);
-		}
-		g_free (path);
-	}
-	
-	return NULL;
-}
-
-static gboolean
-help_show (const gchar *link_id)
-{
-	gchar *file, *url, *command;
-	gboolean retval;
-	gint exit_status = -1;
-	GError *error = NULL; 	
-
-	file = locate_help_file ();
-	if (file == NULL)
-		return FALSE;
-
-	if (link_id != NULL) {
-		url = g_strconcat ("ghelp://", file, "?", link_id, NULL);
-	} else {
-		url = g_strconcat ("ghelp://", file, NULL);	
-	}
-
-	command = g_strconcat ("gnome-open ", url, NULL);
-			
-	retval = g_spawn_command_line_sync (command,
-					    NULL,
-					    NULL,
-					    &exit_status,
-					    &error);
-
-	if (!retval) {
-		g_error_free (error);
-		error = NULL;
-	}		
-	
-	g_free (command);
-	g_free (file);
-	g_free (url);
-	
-	return retval && !exit_status;
-}
-
 
 /* the following functions are taken from gedit-utils.c */
 
@@ -1978,75 +1883,27 @@ toggle_tabs_cb (GtkAction *action, GladeWindow *window)
 static void
 show_help_cb (GtkAction *action, GladeWindow *window)
 {
-	GtkWidget *dialog;
 	gboolean retval;
-	
-	retval = help_show (NULL);
+
+	retval = glade_util_url_show ("ghelp:glade");
 	if (retval)
 		return;
-	
-	/* fallback to displaying online user manual */ 
-	retval = glade_util_url_show (URL_USER_MANUAL);	
-
-	if (!retval)
-	{
-		dialog = gtk_message_dialog_new (GTK_WINDOW (window),
-						 GTK_DIALOG_MODAL,
-						 GTK_MESSAGE_ERROR,
-						 GTK_BUTTONS_OK,
-						 _("Could not display the online user manual"));
-						 
-		gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
-							  _("No suitable web browser executable could be found "
-							    "to be executed and to display the URL: %s"),
-							    URL_USER_MANUAL);
-						 	
-		gtk_window_set_title (GTK_WINDOW (dialog), "");
 
-		g_signal_connect_swapped (dialog, "response",
-					  G_CALLBACK (gtk_widget_destroy),
-					  dialog);
-
-		gtk_widget_show (dialog);
-		
-	}
+	/* fallback to displaying online user manual */
+	glade_util_url_show (URL_USER_MANUAL);
 }
 
 static void 
 show_developer_manual_cb (GtkAction *action, GladeWindow *window)
 {
-	GtkWidget *dialog;
-	gboolean retval;
-	
 	if (glade_util_have_devhelp ())
 	{
 		glade_util_search_devhelp ("gladeui", NULL, NULL);
 		return;	
 	}
-	
-	retval = glade_util_url_show (URL_DEVELOPER_MANUAL);	
 
-	if (!retval)
-	{
-		dialog = gtk_message_dialog_new (GTK_WINDOW (window),
-						 GTK_DIALOG_MODAL,
-						 GTK_MESSAGE_ERROR,
-						 GTK_BUTTONS_OK,
-						 _("Could not display the online developer reference manual"));
-						 
-		gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
-							  _("No suitable web browser executable could be found "
-							    "to be executed and to display the URL: %s"),
-							    URL_DEVELOPER_MANUAL);
-						 	
-		gtk_window_set_title (GTK_WINDOW (dialog), "");
-
-		g_signal_connect_swapped (dialog, "response",
-					  G_CALLBACK (gtk_widget_destroy),
-					  dialog);
-
-		gtk_widget_show (dialog);
-	}	
+	/* fallback to displaying online developer manual */
+	glade_util_url_show (URL_DEVELOPER_MANUAL);
 }
 
 static void 
@@ -3472,9 +3329,6 @@ glade_window_init (GladeWindow *window)
 			  G_CALLBACK (clipboard_notify_handler_cb),
 			  window);
 
-	
-	gtk_about_dialog_set_url_hook ((GtkAboutDialogActivateLinkFunc) about_dialog_activate_link_func, window, NULL);
-
 	glade_app_set_window (GTK_WIDGET (window));
 
 	accel_group = gtk_ui_manager_get_accel_group(priv->ui);



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