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



Memo to self:
Please attach patch BEFORE you write the body. That way you
will actually remember to attach the patch.
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	25 Apr 2002 00:31:46 -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,20 @@ 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;
+	char *quoted_user_path;
+	char *quoted_theme_path;
+	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 +741,88 @@ 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);
+		gnome_vfs_close (handle);
+		/* Did 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) {
+			quoted_theme_path = g_shell_quote (theme_to_install_path);
+			quoted_user_path = g_shell_quote (user_themes_directory);
+			
+			if (strcmp (mime_type, "application/x-compressed-tar") == 0) {
+				/* gzipped tarball */
+				command = g_strdup_printf ("gzip -d -c < %s | (cd %s ; tar -xf -)", 
+							   quoted_theme_path,
+							   quoted_user_path
+							   );
+			} else if (strcmp (mime_type, "application/x-tar") == 0) {
+				/* vanilla tarball */
+				command = g_strdup_printf ("cd %s && tar -xf %s", 
+							   quoted_user_path, 
+							   quoted_theme_path
+							   );
+					   
+			} else if (strcmp (mime_type, "application/x-bzip") == 0) {
+				/* bzipped tarball */
+				command = g_strdup_printf ("bzip2 -d -c < %s | (cd %s ; tar -xf -)", 
+							   quoted_theme_path, 
+							   quoted_user_path
+							   );
+			} else {
+				/* unsupported mime-type */
+				command = NULL;
+			}
+			g_free (user_themes_directory);
+			g_free (quoted_theme_path);
+			g_free (quoted_user_path);
+			g_free (mime_type);
+			if (command != NULL) {
+				status = system (command);
+				g_free (command);
+				if (status != 0) {
+					return NAUTILUS_THEME_INSTALL_FAILED;
+				} else {
+					return NAUTILUS_THEME_INSTALL_OK; 
+				}
+			} else {
+				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 +830,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	25 Apr 2002 00:31:46 -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	25 Apr 2002 00:31:48 -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,
Index: src/file-manager/fm-list-model.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-list-model.c,v
retrieving revision 1.12
diff -p -u -r1.12 fm-list-model.c
--- src/file-manager/fm-list-model.c	24 Apr 2002 00:16:50 -0000	1.12
+++ src/file-manager/fm-list-model.c	25 Apr 2002 00:31:50 -0000
@@ -719,7 +719,7 @@ fm_list_model_get_sort_column_id_from_at
 char *
 fm_list_model_get_attribute_from_sort_column_id (int sort_column_id)
 {
-	int i;
+	guint i;
 
 	for (i = 0; i < G_N_ELEMENTS (attributes); i++) {
 		if (attributes[i].sort_column_id == sort_column_id) {


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