Re: [Nautilus-list] [PATCH] for bug 43302



Then now...

Here is the patch that fixes all the beforementioned issues. As an added
bonus it also checks to see if we have permission to read the file.

If this is ok, you have to commit it for me, since I do not have
cvs-access.
If not, lets try one more time ;-).

Gaute
Index: libnautilus-private/nautilus-theme.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-theme.c,v
retrieving revision 1.42
diff -p -u -r1.42 nautilus-theme.c
--- libnautilus-private/nautilus-theme.c	17 Apr 2002 20:35:00 -0000	1.42
+++ libnautilus-private/nautilus-theme.c	24 Apr 2002 15:54:26 -0000
@@ -41,6 +41,7 @@
 #include <libgnome/gnome-util.h>
 #include <libgnome/gnome-util.h>
 #include <libgnomevfs/gnome-vfs.h>
+#include <libgnomevfs/gnome-vfs-mime-utils.h>
 #include <librsvg/rsvg.h>
 
 /* static globals to hold the last accessed theme files */
@@ -717,32 +718,18 @@ nautilus_theme_remove_user_theme (const 
 NautilusThemeInstallResult
 nautilus_theme_install_user_theme (const char *theme_to_install_path)
 {
+	GnomeVFSHandle *handle;
 	GnomeVFSResult result;
 	char *theme_name;
 	char *theme_xml_path;
 	char *user_themes_directory;
 	char *theme_destination_path;
-
-	if (theme_to_install_path == NULL
-	    || !g_file_test (theme_to_install_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
-		return NAUTILUS_THEME_INSTALL_NOT_A_THEME_DIRECTORY;
-	}
-
-	theme_name = eel_uri_get_basename (theme_to_install_path);
-	g_return_val_if_fail (theme_name != NULL, GNOME_VFS_ERROR_BAD_PARAMETERS);
-	
-	theme_xml_path = g_strdup_printf ("%s/%s.xml",
-					  theme_to_install_path,
-					  theme_name);
-
-	if (!g_file_test (theme_xml_path, G_FILE_TEST_EXISTS)) {
-		g_free (theme_name);
-		return NAUTILUS_THEME_INSTALL_NOT_A_THEME_DIRECTORY;
-	}
-	g_free (theme_xml_path);
+	char *command;
+	char *mime_type;
+	int status;
 
 	user_themes_directory = nautilus_theme_get_user_themes_directory ();
-
+	
 	/* Create the user themes directory if it doesn't exist */
 	if (!g_file_test (user_themes_directory, G_FILE_TEST_EXISTS)) {
 		result = gnome_vfs_make_directory (user_themes_directory,
@@ -752,15 +739,79 @@ nautilus_theme_install_user_theme (const
 
 		if (result != GNOME_VFS_OK) {
 			g_free (user_themes_directory);
-			g_free (theme_name);
 			return NAUTILUS_THEME_INSTALL_FAILED_USER_THEMES_DIRECTORY_CREATION;
 		}
 	}
+
+	if (theme_to_install_path != NULL && g_file_test (theme_to_install_path, G_FILE_TEST_IS_REGULAR)) {
+		result = gnome_vfs_open (&handle, theme_to_install_path, GNOME_VFS_OPEN_READ);
+		/* Do we manage to read the file? */
+		if (result != GNOME_VFS_OK) {
+			g_free (user_themes_directory);
+			return NAUTILUS_THEME_INSTALL_FAILED;
+		}
+		mime_type = gnome_vfs_get_mime_type (theme_to_install_path);
+		if (mime_type != NULL) {
+		
+			if (strcmp (mime_type, "application/x-compressed-tar") == 0) {
+				/* gzipped tarball */
+				command = g_strdup_printf ("gzip -d -c < %s | (cd %s ; tar -xf -)", 
+							   g_shell_quote (theme_to_install_path), 
+							   g_shell_quote (user_themes_directory));
+			} else if (strcmp (mime_type, "application/x-tar") == 0) {
+				/* vanilla tarball */
+				command = g_strdup_printf ("cd %s && tar -xf %s", 
+							  g_shell_quote (user_themes_directory), 
+							  g_shell_quote (theme_to_install_path));
+					   
+			} else if (strcmp (mime_type, "application/x-bzip") == 0) {
+				/* bzipped tarball */
+				command = g_strdup_printf ("bzip2 -d -c < %s | (cd %s ; tar -xf -)", 
+							  g_shell_quote (theme_to_install_path), 
+							  g_shell_quote (user_themes_directory));
+			} else {
+				/* unsupported mime-type */
+				command = NULL;
+			}
+			if (command != NULL) {
+				g_free (user_themes_directory);
+				status = system (command);
+				if (status != 0) {
+					return NAUTILUS_THEME_INSTALL_FAILED;
+				} else {
+					return NAUTILUS_THEME_INSTALL_OK; 
+				}
+			} else {
+				g_free (user_themes_directory);
+				return NAUTILUS_THEME_INSTALL_NOT_A_THEME_FILE;
+			}
+		} else {
+			g_free (user_themes_directory);
+			return NAUTILUS_THEME_INSTALL_FAILED;
+		}
+	}
+
+	if (theme_to_install_path == NULL
+	    || !g_file_test (theme_to_install_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
+		return NAUTILUS_THEME_INSTALL_NOT_A_THEME_DIRECTORY;
+	}
 	
+	theme_name = eel_uri_get_basename (theme_to_install_path);
+	g_return_val_if_fail (theme_name != NULL, GNOME_VFS_ERROR_BAD_PARAMETERS);
 	theme_destination_path = nautilus_make_path (user_themes_directory, theme_name);
+	theme_xml_path = g_strdup_printf ("%s/%s.xml",
+					  theme_to_install_path,
+					  theme_name);
+	
+	if (!g_file_test (theme_xml_path, G_FILE_TEST_EXISTS)) {
+		g_free (theme_name);
+		g_free (theme_destination_path);
+		g_free (theme_xml_path);
+		return NAUTILUS_THEME_INSTALL_NOT_A_THEME_DIRECTORY;
+	}
+	g_free (theme_xml_path);
 	g_free (user_themes_directory);
 	g_free (theme_name);
-	
 	result = eel_copy_uri_simple (theme_to_install_path, theme_destination_path);
 	if (result != GNOME_VFS_OK) {
 		g_free (theme_destination_path);
@@ -768,6 +819,6 @@ nautilus_theme_install_user_theme (const
 	}
 
 	g_free (theme_destination_path);
-
+	
 	return NAUTILUS_THEME_INSTALL_OK;
 }
Index: libnautilus-private/nautilus-theme.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-theme.h,v
retrieving revision 1.7
diff -p -u -r1.7 nautilus-theme.h
--- libnautilus-private/nautilus-theme.h	21 Feb 2002 19:26:47 -0000	1.7
+++ libnautilus-private/nautilus-theme.h	24 Apr 2002 15:54:26 -0000
@@ -50,7 +50,12 @@ typedef enum
 	NAUTILUS_THEME_INSTALL_FAILED_USER_THEMES_DIRECTORY_CREATION,
 
 	/* Failed to install the theme */
-	NAUTILUS_THEME_INSTALL_FAILED
+	NAUTILUS_THEME_INSTALL_FAILED,
+	
+	/* Not a proper tar-ball */
+	NAUTILUS_THEME_INSTALL_NOT_A_THEME_FILE
+
+
 } NautilusThemeInstallResult;
 
 /* get and set the current theme */
Index: src/nautilus-theme-selector.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-theme-selector.c,v
retrieving revision 1.69
diff -p -u -r1.69 nautilus-theme-selector.c
--- src/nautilus-theme-selector.c	22 Apr 2002 09:44:48 -0000	1.69
+++ src/nautilus-theme-selector.c	24 Apr 2002 15:54:29 -0000
@@ -152,7 +152,13 @@ file_selection_ok_clicked_callback (GtkW
 				       theme_selector->details->parent_window);
 		g_free (message);
 		break;
-
+	case NAUTILUS_THEME_INSTALL_NOT_A_THEME_FILE:
+		message = g_strdup_printf (_("Sorry, but \"%s\" is not a valid theme file."),
+					   selected_path);
+		eel_show_error_dialog (message, _("Couldn't add theme"),
+				       theme_selector->details->parent_window);
+		g_free (message);
+		break;
 	case NAUTILUS_THEME_INSTALL_OK:
 		/* Re populate the theme lists to match the stored state */
 		theme_selector_populate_list (theme_selector->details->theme_selector,


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