changeset 12483:54448bd2ccc7

[gaim-migrate @ 14795] Allow the file transfer window open button to work in environments other than win32 and GNOME. In KDE, we do The Right Thing. Otherwise, we fall back the browser. committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Wed, 14 Dec 2005 19:06:27 +0000
parents bd5b3f82dd8e
children 74e33b6d8d74
files src/gtkft.c src/util.c src/util.h
diffstat 3 files changed, 78 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/src/gtkft.c	Wed Dec 14 18:24:11 2005 +0000
+++ b/src/gtkft.c	Wed Dec 14 19:06:27 2005 +0000
@@ -298,8 +298,7 @@
 			gtk_widget_set_sensitive(dialog->open_button, FALSE);
 		}
 #else
-		/* If using GNOME, use gnome-open */
-		if (gaim_xfer_get_type(xfer) == GAIM_XFER_RECEIVE && gaim_running_gnome()) {
+		if (gaim_xfer_get_type(xfer) == GAIM_XFER_RECEIVE) {
 			gtk_widget_set_sensitive(dialog->open_button, TRUE);
 		} else {
 			gtk_widget_set_sensitive (dialog->open_button, FALSE);
@@ -450,36 +449,52 @@
 				gaim_xfer_get_local_filename(dialog->selected_xfer), code);
 	}
 #else
-	/* If using GNOME, use gnome-open */
+	const char *filename = gaim_xfer_get_local_filename(dialog->selected_xfer);
+	char *command = NULL;
+	char *tmp = NULL;
+	GError *error = NULL;
+
 	if (gaim_running_gnome())
 	{
-		char *command = NULL;
-		char *tmp = NULL;
-		GError *error = NULL;
+		char *escaped = g_shell_quote(filename);
+		command = g_strdup_printf("gnome-open %s", escaped);
+		g_free(escaped);
+	}
+	else if (gaim_running_kde())
+	{
+		char *escaped = g_shell_quote(filename);
 
-		command = g_strdup_printf("gnome-open \"%s\"",
-				gaim_xfer_get_local_filename(dialog->selected_xfer));
+		if (gaim_str_has_suffix(filename, ".desktop"))
+			command = g_strdup_printf("kfmclient openURL %s 'text/plain'", escaped);
+		else
+			command = g_strdup_printf("kfmclient openURL %s", escaped);
+		g_free(escaped);
+	}
+	else
+	{
+		gaim_notify_uri(NULL, filename);
+		return;
+	}
 
-		if (gaim_program_is_valid(command))
+	if (gaim_program_is_valid(command))
+	{
+		gint exit_status;
+		if (!g_spawn_command_line_sync(command, NULL, NULL, &exit_status, &error))
 		{
-			gint exit_status;
-			if (!g_spawn_command_line_sync(command, NULL, NULL, &exit_status, &error))
-			{
-				tmp = g_strdup_printf(_("Error launching %s: %s"),
-								gaim_xfer_get_local_filename(dialog->selected_xfer),
-								error->message);
-				gaim_notify_error(dialog, NULL, _("Unable to open file."), tmp);
-				g_free(tmp);
-				g_error_free(error);
-			}
-			if (exit_status != 0)
-			{
-				char *primary = g_strdup_printf(_("Error running %s"), command);
-				char *secondary = g_strdup_printf(_("Process returned error code %d"),
-										exit_status);
-				gaim_notify_error(dialog, NULL, primary, secondary);
-				g_free(tmp);
-			}
+			tmp = g_strdup_printf(_("Error launching %s: %s"),
+							gaim_xfer_get_local_filename(dialog->selected_xfer),
+							error->message);
+			gaim_notify_error(dialog, NULL, _("Unable to open file."), tmp);
+			g_free(tmp);
+			g_error_free(error);
+		}
+		if (exit_status != 0)
+		{
+			char *primary = g_strdup_printf(_("Error running %s"), command);
+			char *secondary = g_strdup_printf(_("Process returned error code %d"),
+									exit_status);
+			gaim_notify_error(dialog, NULL, primary, secondary);
+			g_free(tmp);
 		}
 	}
 #endif
--- a/src/util.c	Wed Dec 14 18:24:11 2005 +0000
+++ b/src/util.c	Wed Dec 14 19:06:27 2005 +0000
@@ -2231,14 +2231,33 @@
 gaim_running_gnome(void)
 {
 	gchar *tmp = g_find_program_in_path("gnome-open");
-	if ((g_getenv("GNOME_DESKTOP_SESSION_ID") != NULL) &&
-		(tmp != NULL))
-	{
-		g_free(tmp);
+
+	if (tmp == NULL)
+		return FALSE;
+	g_free(tmp);
+
+	return (g_getenv("GNOME_DESKTOP_SESSION_ID") != NULL);
+}
+
+gboolean
+gaim_running_kde(void)
+{
+	gchar *tmp = g_find_program_in_path("kfmclient");
+	const char *session;
+
+	if (tmp == NULL)
+		return FALSE;
+	g_free(tmp);
+
+	session = g_getenv("KDE_FULL_SESSION");
+	if (session != NULL && !strcmp(session, "true"))
 		return TRUE;
-	}
-	g_free(tmp);
-	return FALSE;
+
+	/* If you run Gaim from Konsole under !KDE, this will provide a
+	 * a false positive.  Since we do the GNOME checks first, this is
+	 * only a problem if you're running something !(KDE || GNOME) and
+	 * you run Gaim from Konsole. This really shouldn't be a problem. */
+	return ((g_getenv("KDEDIR") != NULL) || g_getenv("KDEDIRS") != NULL);
 }
 
 char *
--- a/src/util.h	Wed Dec 14 18:24:11 2005 +0000
+++ b/src/util.h	Wed Dec 14 19:06:27 2005 +0000
@@ -475,18 +475,25 @@
  *
  * @param program The file name of the application.
  *
- * @return True if the program is runable.
+ * @return TRUE if the program is runable.
  */
 gboolean gaim_program_is_valid(const char *program);
 
 /**
- * Check if running Gnome.
+ * Check if running GNOME.
  *
- * @return TRUE if running Gnome, FALSE otherwise.
+ * @return TRUE if running GNOME, FALSE otherwise.
  */
 gboolean gaim_running_gnome(void);
 
 /**
+ * Check if running KDE.
+ *
+ * @return TRUE if running KDE, FALSE otherwise.
+ */
+gboolean gaim_running_kde(void);
+
+/**
  * Returns the IP address from a socket file descriptor.
  *
  * @param fd The socket file descriptor.