Index: gnome-theme-installer.c
===================================================================
RCS file: /cvs/gnome/gnome-control-center/capplets/theme-switcher/gnome-theme-installer.c,v
retrieving revision 1.16
diff -u -r1.16 gnome-theme-installer.c
--- gnome-theme-installer.c	8 Feb 2005 22:42:10 -0000	1.16
+++ gnome-theme-installer.c	2 Jun 2005 21:52:12 -0000
@@ -40,6 +40,7 @@
 	gchar *theme_tmp_dir;
 	gchar *target_tmp_dir;
 	gchar *user_message;
+	gchar *gzip, *bzip2, *tar;
 } theme_properties;
 
 
@@ -139,14 +140,15 @@
 transfer_done_targz_idle_cb (gpointer data)
 {
 	int status;
-	gchar *command, *filename;
+	gchar *command;
 	theme_properties *theme_props = data;
 		
 	/* this should be something more clever and nonblocking */
-	filename = g_shell_quote(theme_props->filename);
-	command = g_strdup_printf ("sh -c 'cd \"%s\"; /bin/gzip -d -c < \"%s\" | /bin/tar xf - '",
-				    theme_props->target_tmp_dir, filename);
-	g_free(filename);
+	command = g_strdup_printf ("sh -c 'cd \"%s\"; %s -d -c < \"%s\" | %s xf - '",
+				theme_props->target_tmp_dir, 
+				theme_props->gzip,
+				g_shell_quote(theme_props->filename),
+				theme_props->tar);
 	if (g_spawn_command_line_sync (command, NULL, NULL, &status, NULL) && status == 0) {
 		g_free (command);
 		return TRUE;
@@ -171,14 +173,15 @@
 transfer_done_tarbz2_idle_cb (gpointer data)
 {
 	int status;
-	gchar *command, *filename;
+	gchar *command;
 	theme_properties *theme_props = data;
 	
-	filename = g_shell_quote(theme_props->filename);
 	/* this should be something more clever and nonblocking */
-	command = g_strdup_printf ("sh -c 'cd \"%s\"; /usr/bin/bzip2 -d -c < \"%s\" | /bin/tar xf - '",
-				   theme_props->target_tmp_dir, filename);
-	g_free (filename);
+	command = g_strdup_printf ("sh -c 'cd \"%s\"; %s -d -c < \"%s\" | %s xf - '",
+				   theme_props->target_tmp_dir, 
+				   theme_props->bzip2, 
+				   g_shell_quote(theme_props->filename),
+				   theme_props->tar);
 	if (g_spawn_command_line_sync (command, NULL, NULL, &status, NULL) && status == 0) {
 		g_free (command);
 		return TRUE;
@@ -189,36 +192,25 @@
 }
 
 static void
-transfer_done_cb (GtkWidget *dlg, gchar *path)
+transfer_done_cb (GtkWidget *dlg, theme_properties *theme_props)
 {
 	GtkWidget *dialog;
-	int len = strlen (path);
-	gchar *command,**dir, *first_line, *filename;
+	gchar *command,**dir, *first_line;
 	int status,theme_type;
-	theme_properties *theme_props;
 	GnomeVFSURI *theme_source_dir, *theme_dest_dir;
 	
 	gtk_widget_destroy (dlg);
 	
-	theme_props = g_new(theme_properties,1);
-	
-	theme_props->target_tmp_dir = g_strdup_printf ("%s/.themes/.theme-%u", 
-				 			g_get_home_dir(), 
-							g_random_int());
-		
-	
-	if (path && len > 7 && ( (!strcmp (path + len - 7, ".tar.gz")) || (!strcmp (path + len - 4, ".tgz")) )) {
-		filename = g_shell_quote (path);
-		command = g_strdup_printf ("sh -c '/bin/gzip -d -c < \"%s\" | /bin/tar ft -  | head -1'",
-					    filename);
-		theme_props->filetype=TARGZ;
-		g_free (filename);
-	} else if (path && len > 8 && !strcmp (path + len - 8, ".tar.bz2")) {
-		filename = g_shell_quote (path);
-		command = g_strdup_printf ("sh -c '/usr/bin/bzip2 -d -c < \"%s\" | /bin/tar ft - | head -1'",
-					    filename);
-		theme_props->filetype=TARBZ;
-		g_free (filename);
+	if (theme_props->filetype==TARGZ) {
+		command = g_strdup_printf ("sh -c '%s -d -c < \"%s\" | %s ft -  | head -1'",
+					theme_props->gzip,
+					g_shell_quote(theme_props->filename),
+					theme_props->tar);
+	} else if (theme_props->filetype==TARBZ) {
+		command = g_strdup_printf ("sh -c '%s -d -c < \"%s\" | %s ft - | head -1'",
+					theme_props->bzip2,
+					g_shell_quote (theme_props->filename),
+					theme_props->tar);
 	} else {
 		dialog = gtk_message_dialog_new (NULL,
 						GTK_DIALOG_MODAL,
@@ -227,7 +219,7 @@
 						_("This theme is not in a supported format."));
 		gtk_dialog_run (GTK_DIALOG (dialog));
 		gtk_widget_destroy (dialog);		
-		gnome_vfs_unlink(path);		
+		gnome_vfs_unlink(theme_props->filename);		
 		g_free (theme_props->target_tmp_dir);
 		g_free (theme_props);
 		return;	
@@ -250,28 +242,7 @@
 		return;	
 	}
 	
-	/* Uncompress the file in the temp directory */
-	theme_props->filename=g_strdup(path);
-	
 	if (theme_props->filetype == TARBZ ) {
-		if (!g_file_test ("/usr/bin/bzip2", G_FILE_TEST_EXISTS)) {
-			GtkWidget *dialog;
-				
-			dialog = gtk_message_dialog_new (NULL,
-						GTK_DIALOG_MODAL,
-						GTK_MESSAGE_ERROR,
-						GTK_BUTTONS_OK,
-						_("Can not install theme. \nThe bzip2 utility is not installed."));
-			gtk_dialog_run (GTK_DIALOG (dialog));
-			gtk_widget_destroy (dialog);
-			gnome_vfs_unlink(path);			
-			g_free (command);
-			g_free (theme_props->target_tmp_dir);
-			g_free (theme_props->filename);
-			g_free (theme_props);
-			return;	
-		}
-		
 		if (!transfer_done_tarbz2_idle_cb(theme_props)) {
 			GtkWidget *dialog;
 				
@@ -292,23 +263,6 @@
 	}
 	
 	if (theme_props->filetype == TARGZ ) {
-		if (!g_file_test ("/bin/gzip", G_FILE_TEST_EXISTS)) {
-			GtkWidget *dialog;
-
-			dialog = gtk_message_dialog_new (NULL,
-						GTK_DIALOG_MODAL,
-						GTK_MESSAGE_ERROR,
-						GTK_BUTTONS_OK,
-						_("Can not install themes. \nThe gzip utility is not installed."));
-			gtk_dialog_run (GTK_DIALOG (dialog));
-			gtk_widget_destroy (dialog);
-			gnome_vfs_unlink(path);
-			g_free (command);
-			g_free (theme_props->target_tmp_dir);
-			g_free (theme_props->filename);
-			g_free (theme_props);
-			return;	
-		}
 		if (!transfer_done_targz_idle_cb(theme_props)) {
 			GtkWidget *dialog;
 				
@@ -441,12 +395,12 @@
 {
 	GladeXML *dialog = data;
 	GtkWidget *dlg;
-	gchar *filename, *path, *base;
+	gchar *filename, *base;
 	GList *src, *target;
 	GnomeVFSURI *src_uri;
 	const gchar *raw;
-	gboolean icon_theme;
 	gchar *temppath;
+	theme_properties *theme_props;
 
 	if (response_id == GTK_RESPONSE_HELP) {
 		capplet_help (GTK_WINDOW (widget),
@@ -456,7 +410,6 @@
 	}
 
 	if (response_id == 0) {
-		icon_theme = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget), "icon_theme"));
 		raw = gtk_entry_get_text (GTK_ENTRY (gnome_file_entry_gtk_entry (GNOME_FILE_ENTRY (WID ("install_theme_picker")))));
 		if (raw == NULL || strlen (raw) <= 0)	{
 			GtkWidget *dialog;
@@ -491,34 +444,88 @@
 		src_uri = gnome_vfs_uri_new (filename);
 		base = gnome_vfs_uri_extract_short_name (src_uri);
 		src = g_list_append (NULL, src_uri);
-		if (icon_theme)
-			path = g_build_filename (g_get_home_dir (), ".icons", NULL);
-		else
-			path = g_build_filename (g_get_home_dir (), ".themes", NULL);
+		
+		theme_props = g_new(theme_properties,1);
+		theme_props->target_tmp_dir = g_strdup_printf ("%s/.themes/.theme-%u", 
+								g_get_home_dir(), 
+								g_random_int());
+		
+		theme_props->filename = g_build_filename (g_get_home_dir (), ".themes", NULL);
 
-		if (access (path, X_OK | W_OK) != 0) {
+		if (access (theme_props->filename, X_OK | W_OK) != 0) {
                         GtkWidget *dialog;
 
                         dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL,
                                                           GTK_MESSAGE_ERROR,
                                                           GTK_BUTTONS_OK,
-                                                          _("Insufficient permissions to install the theme in:\n%s"), path);
+                                                          _("Insufficient permissions to install the theme in:\n%s"), theme_props->filename);
 			gtk_dialog_run (GTK_DIALOG (dialog));
 			gtk_widget_destroy (dialog);
-			g_free (path);
+			g_free (theme_props);
 			return;
-                } 
-		
+			} 
+
+		if (! (theme_props->tar = g_find_program_in_path("tar"))) {
+			GtkWidget *dialog;
+
+			dialog = gtk_message_dialog_new (NULL,
+							GTK_DIALOG_MODAL,
+							GTK_MESSAGE_ERROR,
+							GTK_BUTTONS_OK,
+							_("Can not install themes. \nThe tar utility is not installed."));
+			gtk_dialog_run (GTK_DIALOG (dialog));
+			gtk_widget_destroy (dialog);
+			gnome_vfs_unlink(theme_props->filename);
+			g_free (theme_props->target_tmp_dir);
+			g_free (theme_props->filename);
+			g_free (theme_props);
+			return;	
+		}
+				
 		while(TRUE) {
 		  	gchar *file_tmp;
 			GtkWidget *dialog;
 		  	int len = strlen (base);
 		  
-		  	if (base && len > 7 && ( (!strcmp (base + len - 7, ".tar.gz")) || (!strcmp (base + len - 4, ".tgz")) ))
-		    		file_tmp = g_strdup_printf("gnome-theme-%d.tar.gz", rand ());
-		  	else if (base && len > 8 && !strcmp (base + len - 8, ".tar.bz2"))
-		    		file_tmp = g_strdup_printf("gnome-theme-%d.tar.bz2", rand ());
-		  	else {
+		  	if (base && len > 7 && ( (!strcmp (base + len - 7, ".tar.gz")) || (!strcmp (base + len - 4, ".tgz")) )) {
+				file_tmp = g_strdup_printf("gnome-theme-%d.tar.gz", rand ());
+				theme_props->filetype=TARGZ;
+				if (! (theme_props->gzip = g_find_program_in_path("gzip"))) {
+					GtkWidget *dialog;
+
+					dialog = gtk_message_dialog_new (NULL,
+									GTK_DIALOG_MODAL,
+									GTK_MESSAGE_ERROR,
+									GTK_BUTTONS_OK,
+									_("Can not install themes. \nThe gzip utility is not installed."));
+					gtk_dialog_run (GTK_DIALOG (dialog));
+					gtk_widget_destroy (dialog);
+					gnome_vfs_unlink(theme_props->filename);
+					g_free (theme_props->target_tmp_dir);
+					g_free (theme_props->filename);
+					g_free (theme_props);
+					return;	
+				}
+			}
+		  	else if (base && len > 8 && !strcmp (base + len - 8, ".tar.bz2")) {
+				file_tmp = g_strdup_printf("gnome-theme-%d.tar.bz2", rand ());
+				theme_props->filetype=TARBZ;
+				if  (! (theme_props->bzip2 = g_find_program_in_path("bzip2"))) {	
+					GtkWidget *dialog;
+					dialog = gtk_message_dialog_new (NULL,
+									GTK_DIALOG_MODAL,
+									GTK_MESSAGE_ERROR,
+									GTK_BUTTONS_OK,
+									_("Can not install theme. \nThe bzip2 utility is not installed."));
+					gtk_dialog_run (GTK_DIALOG (dialog));
+					gtk_widget_destroy (dialog);
+					gnome_vfs_unlink(theme_props->filename);			
+					g_free (theme_props->target_tmp_dir);
+					g_free (theme_props->filename);
+					g_free (theme_props);
+					return;	
+				}
+			} else {
 				dialog = gtk_message_dialog_new (NULL,
 						GTK_DIALOG_MODAL,
 						GTK_MESSAGE_ERROR,
@@ -526,14 +533,14 @@
 						_("The file format is invalid."));
 				gtk_dialog_run (GTK_DIALOG (dialog));
 				gtk_widget_destroy (dialog);		
-				g_free (path);		
+				g_free (theme_props);		
 		    		return;
 			}
 		  
-		    	path = g_build_filename (g_get_home_dir (), ".themes", file_tmp, NULL);
+			theme_props->filename = g_build_filename (g_get_home_dir (), ".themes", file_tmp, NULL);
 		  
 		  	g_free(file_tmp);
-		  	if (!gnome_vfs_uri_exists (gnome_vfs_uri_new (path)))
+		  	if (!gnome_vfs_uri_exists (gnome_vfs_uri_new (theme_props->filename)))
 		    		break;
 		}
 		
@@ -543,7 +550,7 @@
 		 * situation.
 		 */
 		temppath = g_build_filename (filename, ".themes", NULL);
-		if (!strcmp(temppath, path))	{
+		if (!strcmp(temppath, theme_props->filename))	{
 			GtkWidget *dialog;
 
 			dialog = gtk_message_dialog_new (NULL,
@@ -557,14 +564,12 @@
 			g_free (base);
 			g_free (filename);
 			g_free(temppath);
-			g_free (path);
+			g_free (theme_props);
 			return;
 		}
 		g_free(temppath);
 
-
-
-		target = g_list_append (NULL, gnome_vfs_uri_new (path));
+		target = g_list_append (NULL, gnome_vfs_uri_new (theme_props->filename));
 
 		dlg = file_transfer_dialog_new ();
 		file_transfer_dialog_wrap_async_xfer (FILE_TRANSFER_DIALOG (dlg),
@@ -578,9 +583,9 @@
 		g_free (base);
 		g_free (filename);
 		g_signal_connect (G_OBJECT (dlg), "cancel",
-				  G_CALLBACK (transfer_cancel_cb), path);
+				  G_CALLBACK (transfer_cancel_cb), theme_props);
 		g_signal_connect (G_OBJECT (dlg), "done",
-				  G_CALLBACK (transfer_done_cb), path);
+				  G_CALLBACK (transfer_done_cb), theme_props);
 		gtk_widget_show (dlg);
 	}
 }
@@ -596,19 +601,6 @@
 		return;
 
 	running_theme_install = TRUE;
-
-	if (!g_file_test ("/bin/tar", G_FILE_TEST_EXISTS)) {
-		GtkWidget *dialog;
-
-		dialog = gtk_message_dialog_new (NULL,
-						GTK_DIALOG_MODAL,
-						GTK_MESSAGE_ERROR,
-						GTK_BUTTONS_OK,
-						_("Cannot install theme.\nThe tar program is not installed on your system."));
-		gtk_dialog_run (GTK_DIALOG (dialog));
-		gtk_widget_destroy (dialog);
-		return;
-	}
 
 	dialog = glade_xml_new (GLADEDIR "/theme-install.glade", NULL, NULL);
 	widget = WID ("install_dialog");
