On Mo, 2005-09-26 at 12:28 +0200, Alexander Larsson wrote: > Its sort of strange that the metafile system special-cases a specific > key entry like this. It would make more sense to e.g. store the custom > icon with a relative filename. That would work for more cases than the > prefix of the uri being identical too. For instance when there are > symlinks etc involved. Do you prefer the attached patch? -- Christian Neumair <chris gnome-de org>
Index: libnautilus-private/nautilus-file.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-file.c,v
retrieving revision 1.377
diff -u -p -r1.377 nautilus-file.c
--- libnautilus-private/nautilus-file.c 12 Dec 2005 16:59:10 -0000 1.377
+++ libnautilus-private/nautilus-file.c 18 Dec 2005 21:41:10 -0000
@@ -2766,19 +2766,35 @@ char *
nautilus_file_get_custom_icon (NautilusFile *file)
{
char *uri;
+ char *dir_uri;
+ char *custom_icon;
+ char *tmp;
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), NULL);
-
- uri = NULL;
+ g_assert (NAUTILUS_IS_FILE (file));
/* Metadata takes precedence */
uri = nautilus_file_get_metadata (file, NAUTILUS_METADATA_KEY_CUSTOM_ICON, NULL);
+ if (uri != NULL && nautilus_file_is_directory (file)) {
+ /* The relative resolution code will truncate
+ * the URI basename without a trailing "/".
+ * */
+ tmp = nautilus_file_get_uri (file);
+ dir_uri = g_strconcat (tmp, "/", NULL);
+ g_free (tmp);
- if (uri == NULL && file->details->got_link_info) {
- uri = g_strdup (file->details->custom_icon);
- }
+ custom_icon = gnome_vfs_uri_make_full_from_relative (dir_uri, uri);
- return uri;
+ g_free (dir_uri);
+ g_free (uri);
+ } else {
+ custom_icon = uri;
+ }
+
+ if (custom_icon == NULL && file->details->got_link_info) {
+ custom_icon = g_strdup (file->details->custom_icon);
+ }
+
+ return custom_icon;
}
Index: src/file-manager/fm-properties-window.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-properties-window.c,v
retrieving revision 1.224
diff -u -p -r1.224 fm-properties-window.c
--- src/file-manager/fm-properties-window.c 12 Dec 2005 16:59:11 -0000 1.224
+++ src/file-manager/fm-properties-window.c 18 Dec 2005 21:41:10 -0000
@@ -460,7 +460,6 @@ fm_properties_window_drag_data_received
guint info, guint time)
{
char **uris;
- char *path;
gboolean exactly_one;
GtkImage *image;
GtkWindow *window;
@@ -485,9 +484,7 @@ fm_properties_window_drag_data_received
window);
} else {
if (uri_is_local_image (uris[0])) {
- path = gnome_vfs_get_local_path_from_uri (uris[0]);
- set_icon (path, FM_PROPERTIES_WINDOW (window));
- g_free (path);
+ set_icon (uris[0], FM_PROPERTIES_WINDOW (window));
} else {
if (eel_is_remote_uri (uris[0])) {
eel_show_error_dialog
@@ -3720,27 +3717,67 @@ real_finalize (GObject *object)
G_OBJECT_CLASS (parent_class)->finalize (object);
}
+/* converts
+ * file://foo/foobar/foofoo/bar
+ * to
+ * foofoo/bar
+ * if
+ * file://foo/foobar
+ * is the parent
+ *
+ * It does not resolve any symlinks.
+ * */
+static char *
+make_relative_uri_from_full (const char *uri,
+ const char *base_uri)
+{
+ g_assert (uri != NULL);
+ g_assert (base_uri != NULL);
+
+ if (g_str_has_prefix (uri, base_uri)) {
+ uri += strlen (base_uri);
+ if (*uri != '/') {
+ return NULL;
+ }
+
+ while (*uri == '/') {
+ uri++;
+ }
+
+ if (*uri != '\0') {
+ return g_strdup (uri);
+ }
+ }
+
+ return NULL;
+}
+
/* icon selection callback to set the image of the file object to the selected file */
static void
-set_icon (const char* icon_path, FMPropertiesWindow *properties_window)
+set_icon (const char* icon_uri, FMPropertiesWindow *properties_window)
{
NautilusFile *file;
- char *icon_uri;
GnomeDesktopItem *ditem;
+ char *icon;
+ char *icon_path;
char *file_uri;
-
- g_return_if_fail (properties_window != NULL);
- g_return_if_fail (FM_IS_PROPERTIES_WINDOW (properties_window));
+ g_assert (icon_uri != NULL);
+ g_assert (FM_IS_PROPERTIES_WINDOW (properties_window));
+
+ icon_path = gnome_vfs_get_local_path_from_uri (icon_uri);
+ /* we don't allow remote URIs */
if (icon_path != NULL) {
GList *l;
-
- icon_uri = gnome_vfs_get_uri_from_local_path (icon_path);
+
for (l = properties_window->details->original_files; l != NULL; l = l->next) {
file = NAUTILUS_FILE (l->data);
+
file_uri = nautilus_file_get_uri (file);
-
+
if (nautilus_file_is_mime_type (file, "application/x-desktop")) {
+ icon = g_strdup (icon_path);
+
ditem = gnome_desktop_item_new_from_uri (file_uri,
0,
NULL);
@@ -3755,15 +3792,20 @@ set_icon (const char* icon_path, FMPrope
NAUTILUS_FILE_ATTRIBUTE_CUSTOM_ICON);
}
} else {
+ icon = make_relative_uri_from_full (icon_uri, file_uri);
+ if (icon == NULL) {
+ icon = g_strdup (icon_uri);
+ }
- nautilus_file_set_metadata (file, NAUTILUS_METADATA_KEY_CUSTOM_ICON, NULL, icon_uri);
+ nautilus_file_set_metadata (file, NAUTILUS_METADATA_KEY_CUSTOM_ICON, NULL, icon);
nautilus_file_set_metadata (file, NAUTILUS_METADATA_KEY_ICON_SCALE, NULL, NULL);
}
g_free (file_uri);
-
+ g_free (icon);
}
- g_free (icon_uri);
+
+ g_free (icon_path);
}
}
Attachment:
signature.asc
Description: This is a digitally signed message part