changeset 6861:4ae5d9c3d9ec

[gaim-migrate @ 7407] You know the thing that checked if the manual browser command was valid? I moved the funcion that does the actual checking into util.c It's pretty generic, I guess. I moved the check (the call to that function) to browser.c, so it checks for a valid browser when you click on a link. The old way used to really annoy me, because you would get multiple error boxes about the browser being invalid. Herman, I tried to keep things compiling on Windows. I didn't want to #ifdef the program_is_valid() function in util.c--I don't see any reason why it wouldn't compile in Windows. But if there's a problem with it feel free to #ifdef that puppy. Also, Nathan, I'm going to quiz you later on my townhousemates, so please bring a number two pencil and make sure you eat a healthy breakfast. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Tue, 16 Sep 2003 04:57:36 +0000
parents 82607477da69
children 0f8868b69e8a
files src/browser.c src/gtkprefs.c src/util.c src/util.h
diffstat 4 files changed, 53 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
--- a/src/browser.c	Tue Sep 16 04:49:51 2003 +0000
+++ b/src/browser.c	Tue Sep 16 04:57:36 2003 +0000
@@ -567,11 +567,9 @@
 		web_command = gaim_prefs_get_string("/gaim/gtk/browsers/command");
 
 		if (web_command == NULL || *web_command == '\0') {
-			gaim_notify_error(NULL, NULL,
-							  _("Unable to launch your browser because "
-								"the 'Manual' browser command has been "
-								"chosen, but no command has been set."),
-							  NULL);
+			gaim_notify_error(NULL, NULL, _("Unable to open URL"),
+							  _("The 'Manual' browser command has been "
+								"chosen, but no command has been set."));
 			return NULL;
 		}
 
@@ -586,12 +584,18 @@
 		}
 	}
 
-	if (!g_spawn_command_line_async(command, &error)) {
+	if (!program_is_valid(command)) {
+		gchar *tmp = g_strdup_printf(_("The browser \"%s\" is invalid."), 
+						command);
+		gaim_notify_error(NULL, NULL, _("Unable to open URL"), tmp);
+		g_free(tmp);
+
+	} else if (!g_spawn_command_line_async(command, &error)) {
 		char *tmp = g_strdup_printf(
-				_("There was an error launching your chosen browser: %s"),
+				_("Error launching \"command\": %s"),
 				error->message);
 
-		gaim_notify_error(NULL, NULL, tmp, NULL);
+		gaim_notify_error(NULL, NULL, _("Unable to open URL"), tmp);
 
 		g_free(tmp);
 		g_error_free(error);
--- a/src/gtkprefs.c	Tue Sep 16 04:49:51 2003 +0000
+++ b/src/gtkprefs.c	Tue Sep 16 04:57:36 2003 +0000
@@ -101,10 +101,6 @@
 static void delete_prefs(GtkWidget *, void *);
 static void update_plugin_list(void *data);
 
-#ifndef _WIN32
-static gboolean program_is_valid(const char *);
-#endif
-
 void set_default_away(GtkWidget *, gpointer);
 
 static void
@@ -1204,48 +1200,9 @@
 }
 
 #ifndef _WIN32
-static gboolean program_is_valid(const char *program) 
-{
-	GError *error = NULL;
-	char **argv; 
-	gchar *progname;
-	gboolean is_valid = FALSE;
-
-	if (program == NULL || *program == '\0') {
-		return FALSE;
-	}
-
-	if (!g_shell_parse_argv(program, NULL, &argv, &error)) {
-		gaim_debug(GAIM_DEBUG_ERROR, "program_is_valid",
-				   "Could not parse program '%s': %s\n",
-				   program, error->message);
-		g_error_free(error);
-		return FALSE;
-	}
-
-	if (argv == NULL) {
-		return FALSE;
-	}
-
-	progname = g_find_program_in_path(argv[0]);
-	is_valid = (progname != NULL);
-
-	g_strfreev(argv);
-	g_free(progname);
-	
-	return is_valid;
-}
-
 static gboolean manual_browser_set(GtkWidget *entry, GdkEventFocus *event, gpointer data) {
 	const char *program = gtk_entry_get_text(GTK_ENTRY(entry));
 
-	if (!program_is_valid(program)) {
-		char *error = g_strdup_printf(_("The entered manual browser "
-						"'%s' is not valid. Hyperlinks will "
-						"not work."), program); 
-		gaim_notify_warning(NULL, NULL, error, NULL);
-	}
-
 	gaim_prefs_set_string("/gaim/gtk/browsers/command", program);
 
 	/* carry on normally */
--- a/src/util.c	Tue Sep 16 04:49:51 2003 +0000
+++ b/src/util.c	Tue Sep 16 04:57:36 2003 +0000
@@ -853,6 +853,38 @@
 	return fp;
 }
 
+gboolean program_is_valid(const char *program) 
+{
+	GError *error = NULL;
+	char **argv; 
+	gchar *progname;
+	gboolean is_valid = FALSE;
+
+	if (program == NULL || *program == '\0') {
+		return FALSE;
+	}
+
+	if (!g_shell_parse_argv(program, NULL, &argv, &error)) {
+		gaim_debug(GAIM_DEBUG_ERROR, "program_is_valid",
+				   "Could not parse program '%s': %s\n",
+				   program, error->message);
+		g_error_free(error);
+		return FALSE;
+	}
+
+	if (argv == NULL) {
+		return FALSE;
+	}
+
+	progname = g_find_program_in_path(argv[0]);
+	is_valid = (progname != NULL);
+
+	g_strfreev(argv);
+	g_free(progname);
+	
+	return is_valid;
+}
+
 char *gaim_try_conv_to_utf8(const char *str)
 {
 	gsize converted;
--- a/src/util.h	Tue Sep 16 04:49:51 2003 +0000
+++ b/src/util.h	Tue Sep 16 04:57:36 2003 +0000
@@ -261,6 +261,15 @@
 FILE *gaim_mkstemp(gchar **path);
 
 /**
+ * Checks if the given program name is valid and executable.
+ *
+ * @parm program The file name of the application.
+ *
+ * @return True if the program is runable.
+ */
+gboolean program_is_valid(const char *program);
+
+/**
  * Attempts to convert a string to UTF-8 from an unknown encoding.
  *
  * This function checks the locale and tries sane defaults.