Re: [Nautilus-list] [PATCH] for bug 43302
- From: Gaute Lindkvist <lindkvis stud ntnu no>
- To: Alex Larsson <alexl redhat com>
- Cc: <nautilus-list lists eazel com>
- Subject: Re: [Nautilus-list] [PATCH] for bug 43302
- Date: Tue, 23 Apr 2002 21:32:25 +0200 (CEST)
First. I think I fixed all the issues mentioned above.
> + if (status < 0) {
> + return NAUTILUS_THEME_INSTALL_FAILED;
> + }
> + else if (status != 0) {
> + return NAUTILUS_THEME_INSTALL_FAILED;
> + }
> The first if seems unnecessary.
Here I have to disagree. system() returns -1 if the fork fails, see the
manpage for system. This might not happen very often, but if it does,
we're better safe than sorry.
> You also have to move the creation of the user themes directory above the
> handling of tar:ed themes.
>
This I did. Now it will create the themes-directory for all cases.
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 2002/04/17 20:35:00 1.42
+++ libnautilus-private/nautilus-theme.c 2002/04/23 19:28:10
@@ -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 */
@@ -722,27 +723,12 @@ nautilus_theme_install_user_theme (const
char *theme_xml_path;
char *user_themes_directory;
char *theme_destination_path;
+ char *command;
+ char *mime_type;
- 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;
- }
-
+ user_themes_directory = nautilus_theme_get_user_themes_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);
-
- 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 +742,66 @@ nautilus_theme_install_user_theme (const
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)) {
+ 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 -)",
+ theme_to_install_path,
+ user_themes_directory);
+ } else if (strcmp (mime_type, "application/x-tar") == 0) {
+ /* vanilla tarball */
+ command = g_strdup_printf ("cd %s && tar -xf %s",
+ user_themes_directory,
+ 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 -)",
+ theme_to_install_path,
+ user_themes_directory);
+ } else {
+ /* unsupported mime-type */
+ command = NULL;
+ }
+ if (command != NULL) {
+ 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_NOT_A_THEME_FILE;
+ }
+ } 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;
+ }
+
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 +809,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 2002/02/21 19:26:47 1.7
+++ libnautilus-private/nautilus-theme.h 2002/04/23 19:28:10
@@ -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 2002/04/22 09:44:48 1.69
+++ src/nautilus-theme-selector.c 2002/04/23 19:28:12
@@ -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]