[patch] nautilus-theme.[c-h] cleanup



hi

another patch cleaning up nautilus theme handling code.

Is there any plan about what to do with the theming stuff that is left
on nautilus? 

what has been thought about the zoom control?

Diego
Index: libnautilus-private/nautilus-theme.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-theme.c,v
retrieving revision 1.47
diff -u -r1.47 nautilus-theme.c
--- libnautilus-private/nautilus-theme.c	10 Oct 2002 14:39:55 -0000	1.47
+++ libnautilus-private/nautilus-theme.c	10 Nov 2002 21:09:52 -0000
@@ -80,19 +80,6 @@
 	return g_strdup (theme_from_preferences);
 }
 
-/* set the current theme */
-void
-nautilus_theme_set_theme (const char *new_theme)
-{
-	char *old_theme;
-	
-	old_theme = nautilus_theme_get_theme ();
-	if (eel_strcmp (old_theme, new_theme)) {
-		eel_preferences_set (NAUTILUS_PREFERENCES_THEME, new_theme);
-	}
-	g_free (old_theme);
-}
-
 /* load and parse a theme file */
 static xmlDocPtr
 load_theme_document (const char *theme_name)
@@ -287,393 +274,6 @@
 	return image_path;
 }
 
-/* create a pixbuf that represents the passed in theme name */
-GdkPixbuf *
-nautilus_theme_make_preview_pixbuf (const char *theme_name)
-{
-	char *pixbuf_file, *theme_preview_name;
-	char *user_themes_directory;
-	GdkPixbuf *pixbuf;
-	
-	/* first, see if we can find an explicit preview */
-	theme_preview_name = g_strdup_printf ("%s/%s", theme_name, "theme_preview.png");
-	pixbuf_file = nautilus_pixmap_file (theme_preview_name);
-	if (pixbuf_file != NULL) {
-		pixbuf = gdk_pixbuf_new_from_file (pixbuf_file, NULL);
-		g_free (theme_preview_name);
-		g_free (pixbuf_file);
-		return pixbuf;
-	} else {
-		/* try the user directory */
-		user_themes_directory = nautilus_theme_get_user_themes_directory ();
-		pixbuf_file = g_build_filename (user_themes_directory, theme_preview_name, NULL);
-		g_free (user_themes_directory);
-		
-		if (g_file_test (pixbuf_file, G_FILE_TEST_EXISTS)) {
-			pixbuf = gdk_pixbuf_new_from_file (pixbuf_file, NULL);
-			g_free (pixbuf_file);
-			g_free (theme_preview_name);
-			return pixbuf;
-		}  else {
-			g_free (pixbuf_file);
-		}
-	}
-	
-	/* couldn't find a custom one, so try for a directory */	
-	g_free (theme_preview_name);
-	theme_preview_name = g_strdup_printf ("%s/%s", theme_name, "i-directory.png");
-	pixbuf_file = nautilus_pixmap_file (theme_preview_name);
-	g_free (theme_preview_name);
-	
-	if (pixbuf_file == NULL) {
-		theme_preview_name = g_strdup_printf ("%s/%s", theme_name, "i-directory.svg");
-		pixbuf_file = nautilus_pixmap_file (theme_preview_name);
-		g_free (theme_preview_name);
-	}
-	
-	/* try the user directory if necessary */
-	if (pixbuf_file == NULL) {
-		user_themes_directory = nautilus_theme_get_user_themes_directory ();
-		theme_preview_name = g_strdup_printf ("%s/i-directory.png", theme_name);
-		pixbuf_file = g_build_filename (user_themes_directory, theme_preview_name, NULL);
-		g_free (theme_preview_name);
-		
-		if (!g_file_test (pixbuf_file, G_FILE_TEST_EXISTS)) {
-			g_free (pixbuf_file);
-			theme_preview_name = g_strdup_printf ("%s/i-directory.svg", theme_name);
-			pixbuf_file = g_build_filename (user_themes_directory, theme_preview_name, NULL);
-			g_free (theme_preview_name);
-		
-			if (!g_file_test (pixbuf_file, G_FILE_TEST_EXISTS)) {
-				g_free (pixbuf_file);
-				pixbuf_file = NULL;
-			}
-		}
-		
-		g_free (user_themes_directory);		
-	}
-	
-	/* if we can't find anything, return NULL */
-	if (pixbuf_file == NULL) {
-		return NULL;
-	}
-	
-	pixbuf = NULL;
-	
-	/* load the icon that we found and return it */
-	if (eel_istr_has_suffix (pixbuf_file, ".svg")) {
-		pixbuf = rsvg_pixbuf_from_file (pixbuf_file, NULL);
-	} else {
-		pixbuf = gdk_pixbuf_new_from_file (pixbuf_file, NULL);
-	}
-	
-	g_free (pixbuf_file);
-	return pixbuf;
-}
-
-typedef struct 
-{
-	char *name;
-	char *path;
-	char *display_name;
-	char *description;
-	GdkPixbuf *preview_pixbuf;
-	gboolean builtin;
-} ThemeAttibutes;
-
-/* Test for the presence of an icon file */
-static gboolean
-vfs_file_exists (const char *file_uri)
-{
-	GnomeVFSResult result;
-	GnomeVFSFileInfo *file_info;
-	
-	file_info = gnome_vfs_file_info_new ();
-	result = gnome_vfs_get_file_info (file_uri, file_info, 0);
-	gnome_vfs_file_info_unref (file_info);
-
-	return result == GNOME_VFS_OK;
-}
-
-static char*
-theme_get_property (const char *themes_location_uri,
-		    const char *theme_name,
-		    const char *property)
-{
-	char *theme_file_uri;
-	char *theme_file_name;
- 	xmlDocPtr theme_document;
-	xmlChar *xml_result;
-	char *result;
-
-	g_return_val_if_fail (themes_location_uri != NULL, NULL);
-	g_return_val_if_fail (theme_name != NULL, NULL);
-	g_return_val_if_fail (property != NULL, NULL);
-
-	xml_result = NULL;
-	result = NULL;
-
-	theme_file_uri = g_strdup_printf ("%s/%s/%s.xml",
-					  themes_location_uri,
-					  theme_name,
-					  theme_name);
-
-	theme_file_name = gnome_vfs_get_local_path_from_uri (theme_file_uri);
-	g_free (theme_file_uri);
-
-	g_return_val_if_fail (g_file_test (theme_file_name,
-					   G_FILE_TEST_EXISTS), NULL);
-	
-	/* read the xml document */
-	theme_document = xmlParseFile (theme_file_name);
-	g_free (theme_file_name);
-	g_return_val_if_fail (theme_document != NULL, NULL);
-		
-	/* fetch the property, if any */		
-	xml_result = eel_xml_get_property_translated (xmlDocGetRootElement (theme_document),
-						      property);
-	xmlFreeDoc (theme_document);
-	
-	/* Convert the xml char* to a regular char* to get allocators matched */
-	if (xml_result != NULL) {
-		result = g_strdup (xml_result);
-		xmlFree (xml_result);
-	}
-
-	return result;
-}
-
-static char*
-theme_get_name_property (const char *themes_location_uri,
-			 const char *theme_name)
-{
-	char *name;
-
-	g_return_val_if_fail (theme_name != NULL, NULL);
-	g_return_val_if_fail (themes_location_uri != NULL, NULL);
-
-	name = theme_get_property (themes_location_uri, theme_name, "name");
-	
-	if (name == NULL) {
-		name = g_strdup (theme_name);
-	}
-
-	return name;
-}
-
-static char*
-theme_get_description_property (const char *themes_location_uri,
-				const char *theme_name)
-{
-	char *description;
-
-	g_return_val_if_fail (themes_location_uri != NULL, NULL);
-	g_return_val_if_fail (theme_name != NULL, NULL);
-
-	description = theme_get_property (themes_location_uri, theme_name, "description");
-	
-	if (description == NULL) {
-		description = g_strdup_printf (_("No description available for the \"%s\" theme"), theme_name);
-	}
-
-	return description;
-}
-
-static GList *
-theme_list_prepend (GList *theme_list,
-		    const char *themes_location_uri,
-		    const char *theme_name,
-		    gboolean builtin)
-{
-	ThemeAttibutes *attributes;
-	GdkPixbuf *unscaled_preview_pixbuf;
-
-	g_return_val_if_fail (theme_name != NULL, NULL);
-	g_return_val_if_fail (themes_location_uri != NULL, NULL);
-	
-	unscaled_preview_pixbuf = nautilus_theme_make_preview_pixbuf (theme_name);
-
-	if (unscaled_preview_pixbuf == NULL) {
-		return theme_list;
-	}
-	
-	attributes = g_new0 (ThemeAttibutes, 1);
-	attributes->name = g_strdup (theme_name);
-	attributes->path = g_build_filename (themes_location_uri, theme_name, NULL);
-
-	attributes->preview_pixbuf = eel_gdk_pixbuf_scale_down_to_fit (unscaled_preview_pixbuf,
-								       THEME_PREVIEW_ICON_WIDTH,
-								       THEME_PREVIEW_ICON_HEIGHT);
-	g_object_unref (unscaled_preview_pixbuf);
-
-	attributes->builtin = builtin;
-
-	attributes->display_name = theme_get_name_property (themes_location_uri, theme_name);
-	attributes->description = theme_get_description_property (themes_location_uri, theme_name);
-
-	return g_list_prepend (theme_list, attributes);
-}
-
-static gboolean 
-has_theme_xml (const char *theme_location_uri,
-	       const char *theme_name)
-{
-	char *xml_uri;
-	gboolean ret;
-	
-	xml_uri = g_strdup_printf ("%s/%s/%s.xml", 
-				   theme_location_uri,
-				   theme_name, theme_name);
-
-	ret = vfs_file_exists (xml_uri);
-	g_free (xml_uri);
-	
-	return ret;
-}
-
-static GList *
-theme_get_themes_for_location (const char *themes_location_uri,
-			       gboolean builtin)
-{
-	GnomeVFSResult result;
-	GnomeVFSFileInfo *file_info;
-	GList *possible_theme_directories;
-	GList *node;
-	GList *themes;
-	
-	g_return_val_if_fail (themes_location_uri != NULL, NULL);
-
-	possible_theme_directories = NULL;
-	result = gnome_vfs_directory_list_load (&possible_theme_directories,
-						themes_location_uri,
-						GNOME_VFS_FILE_INFO_FOLLOW_LINKS);
-	
-	if (result != GNOME_VFS_OK) {
-		return NULL;
-	}
-
-	themes = NULL;
-	for (node = possible_theme_directories; node != NULL; node = node->next) {
-		g_assert (node->data != NULL);
-
-		file_info = node->data;
-
-		if ((file_info->type == GNOME_VFS_FILE_TYPE_DIRECTORY)
-		    && (file_info->name[0] != '.')) {
-			if (has_theme_xml (themes_location_uri, file_info->name )) {
-				themes = theme_list_prepend (themes,
-							     themes_location_uri,
-							     file_info->name,
-							     builtin);
-			}
-		}
-	}
-
-	return g_list_reverse (themes);
-}
-
-static GList *
-theme_get_builtin_themes (void)
-{
-	char *pixmap_directory;
-	char *builtin_themes_location_uri;
-	GList *builtin_themes;
-	
-	pixmap_directory = nautilus_get_pixmap_directory ();
-	builtin_themes_location_uri = gnome_vfs_get_uri_from_local_path (pixmap_directory);
-	builtin_themes = theme_get_themes_for_location (builtin_themes_location_uri, TRUE);
-	g_free (pixmap_directory);
-	g_free (builtin_themes_location_uri);
-
-	return builtin_themes;
-}
-
-static GList *
-theme_get_user_themes (void)
-{
-	char *user_themes_location;
-	char *user_themes_location_uri;
-	GList *user_themes;
-
-	user_themes_location = nautilus_theme_get_user_themes_directory ();
-	user_themes_location_uri = gnome_vfs_get_uri_from_local_path (user_themes_location);
-	user_themes = theme_get_themes_for_location (user_themes_location_uri, FALSE);
-	g_free (user_themes_location);
-	g_free (user_themes_location_uri);
-
-	return user_themes;
-}
-
-static void
-theme_list_invoke_callback (GList *theme_list,
-			    NautilusThemeCallback callback,
-			    gpointer callback_data)
-{
-	GList *node;
-	const ThemeAttibutes *attributes;
-
-	g_return_if_fail (callback != NULL);
-
-	for (node = theme_list; node != NULL; node = node->next) {
-		g_assert (node->data != NULL);
-		attributes = node->data;
-
-		g_assert (attributes->name != NULL);
-		g_assert (attributes->path != NULL);
-		g_assert (attributes->display_name != NULL);
-		g_assert (attributes->description != NULL);
-		g_assert (attributes->preview_pixbuf != NULL);
-
-		(* callback) (attributes->name,
-			      attributes->path,
-			      attributes->display_name,
-			      attributes->description,
-			      attributes->preview_pixbuf,
-			      attributes->builtin,
-			      callback_data);
-	}
-}
-
-static void
-attributes_free (gpointer data,
-		 gpointer user_data)
-{
-	ThemeAttibutes *attributes;
-
-	g_return_if_fail (data != NULL);
-
-	attributes = data;
-
-	g_free (attributes->name);
-	g_free (attributes->path);
-	g_free (attributes->display_name);
-	g_free (attributes->description);
-	if (attributes->preview_pixbuf != NULL) {
-		g_object_unref (attributes->preview_pixbuf);
-	}
-
-	g_free (attributes);
-}
-
-void
-nautilus_theme_for_each_theme (NautilusThemeCallback callback,
-			       gpointer callback_data)
-{
-	GList *builtin_themes;
-	GList *user_themes;
-
-	g_return_if_fail (callback != NULL);
-
-	builtin_themes = theme_get_builtin_themes ();
- 	user_themes = theme_get_user_themes ();
-
-	theme_list_invoke_callback (builtin_themes, callback, callback_data);
-	theme_list_invoke_callback (user_themes, callback, callback_data);
-
-	eel_g_list_free_deep_custom (builtin_themes, attributes_free, NULL);
-	eel_g_list_free_deep_custom (user_themes, attributes_free, NULL);
-}
-
 char *
 nautilus_theme_get_user_themes_directory (void)
 {
@@ -685,148 +285,4 @@
 	g_free (user_directory);
 
 	return user_themes_directory;
-}
-
-/* Remove the given theme name from from Nautilus. */
-GnomeVFSResult
-nautilus_theme_remove_user_theme (const char *theme_to_remove_name)
-{
-	char *user_themes_directory;
-	char *theme_to_remove_path;
-	GnomeVFSResult result;
-	GList *uri_list;
-
-	g_return_val_if_fail (theme_to_remove_name != NULL, GNOME_VFS_ERROR_BAD_PARAMETERS);
-
-	user_themes_directory = nautilus_theme_get_user_themes_directory ();
-	theme_to_remove_path = g_build_filename (user_themes_directory, theme_to_remove_name, NULL);
-	g_free (user_themes_directory);
-	
-	uri_list = g_list_prepend (NULL, gnome_vfs_uri_new (theme_to_remove_path));			
-	g_free (theme_to_remove_path);
-
-	result = gnome_vfs_xfer_delete_list (uri_list, GNOME_VFS_XFER_RECURSIVE,
-					     GNOME_VFS_XFER_ERROR_MODE_ABORT,
-					     NULL, NULL);
-	gnome_vfs_uri_list_free (uri_list);
-
-	return result;
-}
-
-/* Install the theme found at the given path (if valid). */
-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;
-	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,
-						   GNOME_VFS_PERM_USER_ALL
-						   | GNOME_VFS_PERM_GROUP_ALL
-						   | GNOME_VFS_PERM_OTHER_READ);
-
-		if (result != GNOME_VFS_OK) {
-			g_free (user_themes_directory);
-			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 = g_build_filename (user_themes_directory, theme_name, NULL);
-	theme_xml_path = g_strdup_printf ("%s/%s.xml",
-					  theme_to_install_path,
-					  theme_name);
-	g_free (user_themes_directory);
-	g_free (theme_name);
-	if (!g_file_test (theme_xml_path, G_FILE_TEST_EXISTS)) {
-		g_free (theme_destination_path);
-		g_free (theme_xml_path);
-		return NAUTILUS_THEME_INSTALL_NOT_A_THEME_DIRECTORY;
-	}
-	g_free (theme_xml_path);
-	result = eel_copy_uri_simple (theme_to_install_path, theme_destination_path);
-	if (result != GNOME_VFS_OK) {
-		g_free (theme_destination_path);
-		return NAUTILUS_THEME_INSTALL_FAILED;
-	}
-
-	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.8
diff -u -r1.8 nautilus-theme.h
--- libnautilus-private/nautilus-theme.h	26 Apr 2002 19:07:11 -0000	1.8
+++ libnautilus-private/nautilus-theme.h	10 Nov 2002 21:09:52 -0000
@@ -37,30 +37,8 @@
 				       gboolean builtin,
 				       gpointer callback_data);
 
-/* The result of a theme install operation. */
-typedef enum
-{
-	/* Theme installed OK */
-	NAUTILUS_THEME_INSTALL_OK,
-
-	/* The given path is not a vaild theme directory */
-	NAUTILUS_THEME_INSTALL_NOT_A_THEME_DIRECTORY,
-
-	/* Failed to create the user themes directory ~/.nautilus/themes */
-	NAUTILUS_THEME_INSTALL_FAILED_USER_THEMES_DIRECTORY_CREATION,
-
-	/* Failed to install the theme */
-	NAUTILUS_THEME_INSTALL_FAILED,
-	
-	/* Not a proper tar-ball */
-	NAUTILUS_THEME_INSTALL_NOT_A_THEME_FILE
-
-
-} NautilusThemeInstallResult;
-
-/* get and set the current theme */
+/* get the current theme */
 char                      *nautilus_theme_get_theme                 (void);
-void                       nautilus_theme_set_theme                 (const char            *new_theme);
 
 
 /* fetch data from the current theme */
@@ -78,21 +56,7 @@
 /* like get_image_path, put use the passed in theme instead of the current one */
 char                      *nautilus_theme_get_image_path_from_theme (const char            *image_name,
 								     const char            *theme_name);
-
-/* create a pixbuf to represent the theme */
-GdkPixbuf                 *nautilus_theme_make_preview_pixbuf       (const char            *theme_name);
-
 /* Return the directory where user themes are stored */
 char                      *nautilus_theme_get_user_themes_directory (void);
-
-/* Invoke the given callback for each theme available to Nautilus */
-void                       nautilus_theme_for_each_theme            (NautilusThemeCallback  callback,
-								     gpointer               callback_data);
-
-/* Remove a user theme from Nautilus. */
-GnomeVFSResult             nautilus_theme_remove_user_theme         (const char            *theme_to_remove_name);
-
-/* Install the theme found at the given path (if valid). */
-NautilusThemeInstallResult nautilus_theme_install_user_theme        (const char            *theme_to_install_path);
 
 #endif /* NAUTILUS_THEME_H */

Attachment: signature.asc
Description: This is a digitally signed message part



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