[Nautilus-list] [PATCH] for bug 43302



That is.. add themes from .tar.gz-files.

This patch let's you add themes from .tar-files, .tar.gz and .tar.bz2.
Most of it is just ripped from the .tar.gz-handler in the
gtk-theme-capplet and adjusted for Nautilus.
I added a FIXME since there should probably be a better way of finding out
if the file is bz2 or not, but it should work fine for now.

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	23 Apr 2002 13:19:08 -0000
@@ -718,11 +718,72 @@ NautilusThemeInstallResult
 nautilus_theme_install_user_theme (const char *theme_to_install_path)
 {
 	GnomeVFSResult result;
+	GnomeVFSHandle *handle;
+	GnomeVFSFileSize bytes_read;
 	char *theme_name;
 	char *theme_xml_path;
 	char *user_themes_directory;
 	char *theme_destination_path;
+	char command[4096];
+	int size;
+	guint bufsize = 1024;
+	guchar buf[bufsize];
 
+	user_themes_directory = nautilus_theme_get_user_themes_directory ();
+
+	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);
+		
+		if (result == GNOME_VFS_OK) {
+			result = gnome_vfs_read (handle, buf, bufsize - 1, &bytes_read);
+			if (bytes_read != bufsize - 1) {
+				return NAUTILUS_THEME_INSTALL_FAILED;
+			}
+			size = strlen (theme_to_install_path);
+			gnome_vfs_handle_destroy (handle);
+			if ((buf[0] == 31) && (buf[1] == 139)) {
+				/*gzipped tarball */
+				g_snprintf(command, sizeof(command),
+					   "gzip -d -c < %s | (cd %s ; tar -xf -)", 
+					   theme_to_install_path, user_themes_directory);
+			}
+			else if ((buf[257] == 'u') && (buf[258] == 's') && (buf[259] == 't') &&
+				 (buf[260] == 'a') && (buf[261] == 'r')) {
+				/*vanilla tarball */
+				g_snprintf(command, sizeof(command), 
+					   "cd %s && tar -xf %s", 
+					   user_themes_directory, theme_to_install_path);
+			} 
+			/* FIXME: a more proper way to check for a bz2-file */
+			else if (theme_to_install_path[size-3] == 'b' && theme_to_install_path[size-2] == 'z' && theme_to_install_path[size-1] == '2') {
+				g_snprintf(command, sizeof(command),
+					   "bzip2 -d -c < %s | (cd %s ; tar -xf -)", 
+					   theme_to_install_path, user_themes_directory);
+			}
+			else {
+				command[0] = '\0';
+			}
+			if (*command) {
+				
+				gint status = system(command);
+				if (status < 0) {
+					return NAUTILUS_THEME_INSTALL_FAILED;
+				}
+				else if (status != 0) {
+					return NAUTILUS_THEME_INSTALL_FAILED;
+				}
+				else {
+					return NAUTILUS_THEME_INSTALL_OK; 
+				}
+			}
+			else {
+				return NAUTILUS_THEME_INSTALL_FAILED;
+			}
+		}
+		else {
+			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;
@@ -730,19 +791,6 @@ nautilus_theme_install_user_theme (const
 
 	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);
-
-	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,
@@ -756,11 +804,19 @@ nautilus_theme_install_user_theme (const
 			return NAUTILUS_THEME_INSTALL_FAILED_USER_THEMES_DIRECTORY_CREATION;
 		}
 	}
-	
 	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);
+		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 +824,6 @@ nautilus_theme_install_user_theme (const
 	}
 
 	g_free (theme_destination_path);
-
+	
 	return NAUTILUS_THEME_INSTALL_OK;
 }


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