diff options
29 files changed, 1120 insertions, 1060 deletions
@@ -1,3 +1,137 @@ +2000-10-12 Maciej Stachowiak <mjs@eazel.com> + + * libnautilus-extensions/nautilus-directory-metafile.h, + libnautilus-extensions/nautilus-directory-metafile.c + (nautilus_directory_get_metadata, nautilus_directory_set_metadata, + nautilus_directory_get_metadata_list, + nautilus_directory_set_metadata_list, + nautilus_directory_get_boolean_metadata, + nautilus_directory_set_boolean_metadata, + nautilus_directory_get_integer_metadata, + nautilus_directory_set_integer__metadata): Bye bye to directory + metadata. + (set_metadata_string_in_metafile): don't worry about the directory + metadata case any more. + (nautilus_directory_get_boolean_file_metadata, + nautilus_directory_set_boolean_file_metadata, + nautilus_directory_get_integer_file_metadata, + nautilus_directory_set_integer_file_metadata): Helper functions + for implementing NautilusFile metadata convenience wrappers. + + * libnautilus-extensions/nautilus-file.h, + libnautilus-extensions/nautilus-file.c: + (nautilus_file_get_boolean_metadata, + nautilus_file_get_integer_metadata, + nautilus_file_set_boolean_metadata, + nautilus_file_set_integer_metadata): Convenience wrappers for + boolean or integer file metadata. + + * libnautilus-extensions/nautilus-directory.h, + libnautilus-extensions/nautilus-directory.c + (nautilus_directory_initialize_class, + nautilus_directory_emit_metadata_changed): removed + "metadata_changed" signal. + (got_metadata_callback): Don't assert the file list is NULL. + (nautilus_self_check_directory): Use file metadata API. + + * libnautilus-extensions/nautilus-metadata.h: No more + per-directory metadata, it's all per file now. + + * libnautilus-extensions/nautilus-directory-background.h, + libnautilus-extensions/nautilus-directory-background.c + (nautilus_file_background_set_desktop, + nautilus_file_background_is_desktop, + nautilus_file_background_peek_theme_source, + nautilus_file_background_get_default_settings, + nautilus_file_background_read_desktop_settings, + nautilus_file_background_write_desktop_settings, + nautilus_file_background_write_desktop_default_settings, + call_settings_changed, nautilus_file_background_event_filter, + desktop_background_destroyed_callback, + nautilus_file_background_receive_root_window_changes, + nautilus_file_update_root_window, nautilus_file_background_is_set, + background_changed_callback, saved_settings_changed_callback, + nautilus_file_background_theme_changed, background_reset_callback, + background_destroyed_callback, + nautilus_connect_background_to_file_metadata, + nautilus_connect_desktop_background_to_file_metadata, + nautilus_connect_background_to_file_metadata_by_uri): Work off of + file metadata, not directory metadata, and thus take a + NautilusFile not a NautilusDirectory. + + * libnautilus-extensions/nautilus-mime-actions.c: + (nautilus_file_wait_for_metadata, + nautilus_mime_get_default_action_type_for_uri, + nautilus_mime_get_default_application_for_uri_internal, + nautilus_mime_get_default_component_for_uri_internal, + nautilus_mime_get_short_list_applications_for_uri, + nautilus_mime_get_short_list_components_for_uri, + nautilus_mime_get_all_applications_for_uri, + nautilus_mime_get_all_components_for_uri, + nautilus_mime_set_default_action_type_for_uri, + nautilus_mime_set_default_application_for_uri, + nautilus_mime_set_default_component_for_uri, + nautilus_mime_set_short_list_applications_for_uri, + nautilus_mime_set_short_list_components_for_uri, + nautilus_mime_extend_all_applications_for_uri, + nautilus_mime_remove_from_all_applications_for_uri, + get_explicit_content_view_iids_from_metafile): Use file metadata, + not directory metadata. + + * src/file-manager/fm-directory-view.h, + src/file-manager/fm-directory-view.c + (fm_directory_view_get_directory_as_file): Function to access the + NautilusFile we now keep around that represents the directory + itself. + (fm_directory_view_initialize_class, files_have_any_custom_images, + compute_menu_item_info, fm_directory_view_activate_file, + fm_directory_view_load_uri, metadata_ready_callback, + disconnect_model_handlers, fm_directory_view_real_is_read_only, + showing_trash_directory): Use file metadata, not directory + metadata, and use the new `directory_as_file' field where + appropriate. + (finish_loading_uri): Monitor more files attributes (the ones + needed to get an icon, plus ones we might actually display in a + directory view. + + * src/file-manager/fm-desktop-icon-view.c + (fm_desktop_icon_view_create_background_context_menu_items): Use + file metadata not directory metadata. + + * src/file-manager/fm-icon-view.h, + src/file-manager/fm-icon-view.c: (set_sort_criterion, + tighter_layout_callback, fm_icon_view_get_directory_sort_by, + fm_icon_view_real_get_directory_sort_by, + fm_icon_view_set_directory_sort_by, + fm_icon_view_real_set_directory_sort_by, + fm_icon_view_get_directory_sort_reversed, + fm_icon_view_real_get_directory_sort_reversed, + fm_icon_view_set_directory_sort_reversed, + fm_icon_view_real_set_directory_sort_reversed, + fm_icon_view_get_directory_auto_layout, + fm_icon_view_real_get_directory_auto_layout, + fm_icon_view_set_directory_auto_layout, + fm_icon_view_real_set_directory_auto_layout, + fm_icon_view_get_directory_tighter_layout, + fm_icon_view_real_get_directory_tighter_layout, + fm_icon_view_set_directory_tighter_layout, + fm_icon_view_real_set_directory_tighter_layout, set_sort_reversed, + fm_icon_view_begin_loading, fm_icon_view_set_zoom_level, + sort_direction_callback, layout_changed_callback, + icon_container_preview_callback, icon_position_changed_callback): + Use file metadata not directory metadata. + + * src/file-manager/fm-list-view.c: (fm_list_view_begin_loading, + fm_list_view_set_zoom_level, fm_list_view_sort_items): Use file + metadata not directory metadata. + + * src/file-manager/fm-search-list-view.c (real_adding_file): Tweak + the code that monitors file attributes. + + * components/music/nautilus-music-view.c + (nautilus_music_view_update_from_uri): Use the new + nautilus_file_background API. + 2000-10-12 Pavel Cisler <pavel@eazel.com> * libnautilus-extensions/nautilus-icon-container.c: diff --git a/components/music/nautilus-music-view.c b/components/music/nautilus-music-view.c index 66e8f0259..384f8556b 100644 --- a/components/music/nautilus-music-view.c +++ b/components/music/nautilus-music-view.c @@ -1275,7 +1275,7 @@ nautilus_music_view_update_from_uri (NautilusMusicView *music_view, const char * image_count = 0; /* connect the music view background to directory metadata */ - nautilus_connect_background_to_directory_metadata_by_uri (GTK_WIDGET (music_view), uri); + nautilus_connect_background_to_file_metadata_by_uri (GTK_WIDGET (music_view), uri); /* iterate through the directory, collecting mp3 files and extracting id3 data if present */ diff --git a/libnautilus-extensions/nautilus-directory-background.c b/libnautilus-extensions/nautilus-directory-background.c index 8c87c8d19..175b9d711 100644 --- a/libnautilus-extensions/nautilus-directory-background.c +++ b/libnautilus-extensions/nautilus-directory-background.c @@ -2,7 +2,7 @@ /* nautilus-directory-background.c: Helper for the background of a widget - that is viewing a particular directory. + that is viewing a particular location. Copyright (C) 2000 Eazel, Inc. @@ -42,32 +42,35 @@ #include <libgnome/gnome-util.h> #include <libgnomevfs/gnome-vfs-utils.h> -static void background_changed_callback (NautilusBackground *background, NautilusDirectory *directory); -static void background_reset_callback (NautilusBackground *background, NautilusDirectory *directory); +static void background_changed_callback (NautilusBackground *background, + NautilusFile *file); +static void background_reset_callback (NautilusBackground *background, + NautilusFile *file); -static void saved_settings_changed_callback (NautilusDirectory *directory, NautilusBackground *background); +static void saved_settings_changed_callback (NautilusFile *file, + NautilusBackground *background); -static void nautilus_directory_background_receive_root_window_changes (NautilusBackground *background); +static void nautilus_file_background_receive_root_window_changes (NautilusBackground *background); -static const char *default_theme_source = "directory"; +static const char *default_theme_source = "file"; static const char *desktop_theme_source = "desktop"; void -static nautilus_directory_background_set_desktop (NautilusBackground *background) +static nautilus_file_background_set_desktop (NautilusBackground *background) { gtk_object_set_data (GTK_OBJECT (background), "theme_source", (gpointer) desktop_theme_source); - nautilus_directory_background_receive_root_window_changes (background); + nautilus_file_background_receive_root_window_changes (background); } static gboolean -nautilus_directory_background_is_desktop (NautilusBackground *background) +nautilus_file_background_is_desktop (NautilusBackground *background) { /* == works because we're carful to always use the same string. */ return gtk_object_get_data (GTK_OBJECT (background), "theme_source") == desktop_theme_source; } -static const char *nautilus_directory_background_peek_theme_source (NautilusBackground *background) +static const char *nautilus_file_background_peek_theme_source (NautilusBackground *background) { char *theme_source; @@ -110,20 +113,20 @@ theme_image_path_to_uri (char *image_file) */ static void -nautilus_directory_background_get_default_settings (const char* theme_source, - char **color, - char **image, - NautilusBackgroundImagePlacement *placement, - gboolean *combine) +nautilus_file_background_get_default_settings (const char* theme_source, + char **color, + char **image, + NautilusBackgroundImagePlacement *placement, + gboolean *combine) { char *combine_str; char *image_local_path; *placement = NAUTILUS_BACKGROUND_TILED; - *color = nautilus_theme_get_theme_data (theme_source, NAUTILUS_METADATA_KEY_DIRECTORY_BACKGROUND_COLOR); + *color = nautilus_theme_get_theme_data (theme_source, NAUTILUS_METADATA_KEY_LOCATION_BACKGROUND_COLOR); - image_local_path = nautilus_theme_get_theme_data (theme_source, NAUTILUS_METADATA_KEY_DIRECTORY_BACKGROUND_IMAGE); + image_local_path = nautilus_theme_get_theme_data (theme_source, NAUTILUS_METADATA_KEY_LOCATION_BACKGROUND_IMAGE); *image = theme_image_path_to_uri (image_local_path); g_free (image_local_path); @@ -153,10 +156,10 @@ enum { }; static void -nautilus_directory_background_read_desktop_settings (char **color, - char **image, - NautilusBackgroundImagePlacement *placement, - gboolean *combine) +nautilus_file_background_read_desktop_settings (char **color, + char **image, + NautilusBackgroundImagePlacement *placement, + gboolean *combine) { int image_alignment; char* image_local_path; @@ -172,7 +175,7 @@ nautilus_directory_background_read_desktop_settings (char **color, gboolean no_start_color; gboolean no_end_color; - nautilus_directory_background_get_default_settings (desktop_theme_source, &default_color, &default_image_file, &default_placement, combine); + nautilus_file_background_get_default_settings (desktop_theme_source, &default_color, &default_image_file, &default_placement, combine); /* note - value of combine comes from the theme, not currently setable in gnome_config */ image_local_path = gnome_config_get_string ("/Background/Default/wallpaper=none"); @@ -233,7 +236,7 @@ nautilus_directory_background_read_desktop_settings (char **color, } static void -nautilus_directory_background_write_desktop_settings (char *color, char *image, NautilusBackgroundImagePlacement placement, gboolean combine) +nautilus_file_background_write_desktop_settings (char *color, char *image, NautilusBackgroundImagePlacement placement, gboolean combine) { char *end_color; char *start_color; @@ -315,29 +318,29 @@ nautilus_directory_background_write_desktop_settings (char *color, char *image, } static void -nautilus_directory_background_write_desktop_default_settings () +nautilus_file_background_write_desktop_default_settings () { char *color; char *image; gboolean combine; NautilusBackgroundImagePlacement placement; - nautilus_directory_background_get_default_settings (desktop_theme_source, &color, &image, &placement, &combine); - nautilus_directory_background_write_desktop_settings (color, image, placement, combine); + nautilus_file_background_get_default_settings (desktop_theme_source, &color, &image, &placement, &combine); + nautilus_file_background_write_desktop_settings (color, image, placement, combine); } static int call_settings_changed (NautilusBackground *background) { - NautilusDirectory *directory; - directory = gtk_object_get_data (GTK_OBJECT (background), "nautilus_background_directory"); - if (directory) { - saved_settings_changed_callback (directory, background); + NautilusFile *file; + file = gtk_object_get_data (GTK_OBJECT (background), "nautilus_background_file"); + if (file) { + saved_settings_changed_callback (file, background); } return FALSE; } static GdkFilterReturn -nautilus_directory_background_event_filter (GdkXEvent *gdk_xevent, GdkEvent *event, gpointer data) +nautilus_file_background_event_filter (GdkXEvent *gdk_xevent, GdkEvent *event, gpointer data) { XEvent *xevent; NautilusBackground *background; @@ -366,16 +369,16 @@ nautilus_directory_background_event_filter (GdkXEvent *gdk_xevent, GdkEvent *eve static void desktop_background_destroyed_callback (NautilusBackground *background, void *georgeWBush) { - gdk_window_remove_filter (GDK_ROOT_PARENT(), nautilus_directory_background_event_filter, background); + gdk_window_remove_filter (GDK_ROOT_PARENT(), nautilus_file_background_event_filter, background); } static void -nautilus_directory_background_receive_root_window_changes (NautilusBackground *background) +nautilus_file_background_receive_root_window_changes (NautilusBackground *background) { XWindowAttributes attribs = { 0 }; /* set up a filter on the root window to get notified about property changes */ - gdk_window_add_filter (GDK_ROOT_PARENT(), nautilus_directory_background_event_filter, background); + gdk_window_add_filter (GDK_ROOT_PARENT(), nautilus_file_background_event_filter, background); gdk_error_trap_push (); @@ -514,7 +517,7 @@ image_loading_done_callback (NautilusBackground *background, gboolean successful } static void -nautilus_directory_update_root_window (NautilusBackground *background) +nautilus_file_update_root_window (NautilusBackground *background) { if (nautilus_background_is_loaded (background)) { image_loading_done_callback (background, TRUE, GINT_TO_POINTER (FALSE)); @@ -528,7 +531,7 @@ nautilus_directory_update_root_window (NautilusBackground *background) /* return true if the background is not in the default state */ gboolean -nautilus_directory_background_is_set (NautilusBackground *background) +nautilus_file_background_is_set (NautilusBackground *background) { char *color; char *image; @@ -547,8 +550,8 @@ nautilus_directory_background_is_set (NautilusBackground *background) combine = nautilus_background_get_combine_mode (background); placement = nautilus_background_get_image_placement (background); - nautilus_directory_background_get_default_settings ( - nautilus_directory_background_peek_theme_source (background), + nautilus_file_background_get_default_settings ( + nautilus_file_background_peek_theme_source (background), &default_color, &default_image, &default_placement, &default_combine); is_set = (default_color != NULL && nautilus_strcmp (color, default_color) != 0) || @@ -567,41 +570,41 @@ nautilus_directory_background_is_set (NautilusBackground *background) /* handle the background changed signal */ static void background_changed_callback (NautilusBackground *background, - NautilusDirectory *directory) + NautilusFile *file) { char *color, *image; g_assert (NAUTILUS_IS_BACKGROUND (background)); - g_assert (NAUTILUS_IS_DIRECTORY (directory)); - g_assert (gtk_object_get_data (GTK_OBJECT (background), "nautilus_background_directory") - == directory); + g_assert (NAUTILUS_IS_FILE (file)); + g_assert (gtk_object_get_data (GTK_OBJECT (background), "nautilus_background_file") + == file); color = nautilus_background_get_color (background); image = nautilus_background_get_image_uri (background); - if (nautilus_directory_background_is_desktop (background)) { - nautilus_directory_background_write_desktop_settings (color, image, nautilus_background_get_image_placement (background), nautilus_background_get_combine_mode (background)); + if (nautilus_file_background_is_desktop (background)) { + nautilus_file_background_write_desktop_settings (color, image, nautilus_background_get_image_placement (background), nautilus_background_get_combine_mode (background)); } else { /* Block the other handler while we are writing metadata so it doesn't * try to change the background. */ - gtk_signal_handler_block_by_func (GTK_OBJECT (directory), + gtk_signal_handler_block_by_func (GTK_OBJECT (file), saved_settings_changed_callback, background); - nautilus_directory_set_metadata (directory, - NAUTILUS_METADATA_KEY_DIRECTORY_BACKGROUND_COLOR, - NULL, - color); + nautilus_file_set_metadata (file, + NAUTILUS_METADATA_KEY_LOCATION_BACKGROUND_COLOR, + NULL, + color); - nautilus_directory_set_metadata (directory, - NAUTILUS_METADATA_KEY_DIRECTORY_BACKGROUND_IMAGE, - NULL, - image); + nautilus_file_set_metadata (file, + NAUTILUS_METADATA_KEY_LOCATION_BACKGROUND_IMAGE, + NULL, + image); /* Unblock the handler. */ - gtk_signal_handler_unblock_by_func (GTK_OBJECT (directory), + gtk_signal_handler_unblock_by_func (GTK_OBJECT (file), saved_settings_changed_callback, background); } @@ -609,43 +612,43 @@ background_changed_callback (NautilusBackground *background, g_free (color); g_free (image); - if (nautilus_directory_background_is_desktop (background)) { - nautilus_directory_update_root_window (background); + if (nautilus_file_background_is_desktop (background)) { + nautilus_file_update_root_window (background); } } -/* handle the directory changed signal */ +/* handle the file changed signal */ static void -saved_settings_changed_callback (NautilusDirectory *directory, - NautilusBackground *background) +saved_settings_changed_callback (NautilusFile *file, + NautilusBackground *background) { char *color; char *image; gboolean combine; NautilusBackgroundImagePlacement placement; - g_assert (NAUTILUS_IS_DIRECTORY (directory)); + g_assert (NAUTILUS_IS_FILE (file)); g_assert (NAUTILUS_IS_BACKGROUND (background)); - g_assert (gtk_object_get_data (GTK_OBJECT (background), "nautilus_background_directory") - == directory); + g_assert (gtk_object_get_data (GTK_OBJECT (background), "nautilus_background_file") + == file); - if (nautilus_directory_background_is_desktop (background)) { - nautilus_directory_background_read_desktop_settings (&color, &image, &placement, &combine); + if (nautilus_file_background_is_desktop (background)) { + nautilus_file_background_read_desktop_settings (&color, &image, &placement, &combine); } else { - color = nautilus_directory_get_metadata (directory, - NAUTILUS_METADATA_KEY_DIRECTORY_BACKGROUND_COLOR, - NULL); - image = nautilus_directory_get_metadata (directory, - NAUTILUS_METADATA_KEY_DIRECTORY_BACKGROUND_IMAGE, - NULL); + color = nautilus_file_get_metadata (file, + NAUTILUS_METADATA_KEY_LOCATION_BACKGROUND_COLOR, + NULL); + image = nautilus_file_get_metadata (file, + NAUTILUS_METADATA_KEY_LOCATION_BACKGROUND_IMAGE, + NULL); placement = NAUTILUS_BACKGROUND_TILED; /* non-tiled only avail for desktop, at least for now */ combine = FALSE; /* only from theme, at least for now */ /* if there's none, read the default from the theme */ if (color == NULL && image == NULL) { - nautilus_directory_background_get_default_settings ( - nautilus_directory_background_peek_theme_source (background), - &color, &image, &placement, &combine); + nautilus_file_background_get_default_settings + (nautilus_file_background_peek_theme_source (background), + &color, &image, &placement, &combine); } } @@ -654,7 +657,7 @@ saved_settings_changed_callback (NautilusDirectory *directory, */ gtk_signal_handler_block_by_func (GTK_OBJECT (background), background_changed_callback, - directory); + file); nautilus_background_set_color (background, color); nautilus_background_set_image_uri (background, image); @@ -663,8 +666,8 @@ saved_settings_changed_callback (NautilusDirectory *directory, /* Unblock the handler. */ gtk_signal_handler_unblock_by_func (GTK_OBJECT (background), - background_changed_callback, - directory); + background_changed_callback, + file); g_free (color); g_free (image); @@ -672,190 +675,180 @@ saved_settings_changed_callback (NautilusDirectory *directory, /* handle the theme changing */ static void -nautilus_directory_background_theme_changed (gpointer user_data) +nautilus_file_background_theme_changed (gpointer user_data) { - NautilusDirectory *directory; + NautilusFile *file; NautilusBackground *background; background = NAUTILUS_BACKGROUND (user_data); - directory = gtk_object_get_data (GTK_OBJECT (background), "nautilus_background_directory"); - if (directory) { - saved_settings_changed_callback (directory, background); + file = gtk_object_get_data (GTK_OBJECT (background), "nautilus_background_file"); + if (file) { + saved_settings_changed_callback (file, background); } } /* handle the background reset signal by setting values from the current theme */ static void background_reset_callback (NautilusBackground *background, - NautilusDirectory *directory) + NautilusFile *file) { - if (nautilus_directory_background_is_desktop (background)) { - nautilus_directory_background_write_desktop_default_settings (); + if (nautilus_file_background_is_desktop (background)) { + nautilus_file_background_write_desktop_default_settings (); } else { /* Block the other handler while we are writing metadata so it doesn't * try to change the background. */ - gtk_signal_handler_block_by_func (GTK_OBJECT (directory), + gtk_signal_handler_block_by_func (GTK_OBJECT (file), saved_settings_changed_callback, background); /* reset the metadata */ - nautilus_directory_set_metadata (directory, - NAUTILUS_METADATA_KEY_DIRECTORY_BACKGROUND_COLOR, - NULL, - NULL); - - nautilus_directory_set_metadata (directory, - NAUTILUS_METADATA_KEY_DIRECTORY_BACKGROUND_IMAGE, - NULL, - NULL); + nautilus_file_set_metadata (file, + NAUTILUS_METADATA_KEY_LOCATION_BACKGROUND_COLOR, + NULL, + NULL); + + nautilus_file_set_metadata (file, + NAUTILUS_METADATA_KEY_LOCATION_BACKGROUND_IMAGE, + NULL, + NULL); /* Unblock the handler. */ - gtk_signal_handler_unblock_by_func (GTK_OBJECT (directory), + gtk_signal_handler_unblock_by_func (GTK_OBJECT (file), saved_settings_changed_callback, background); } - saved_settings_changed_callback (directory, background); + saved_settings_changed_callback (file, background); /* We don't want the default reset handler running. * It will set color and image_uri to NULL. */ gtk_signal_emit_stop_by_name (GTK_OBJECT (background), "reset"); - if (nautilus_directory_background_is_desktop (background)) { - nautilus_directory_update_root_window (background); + if (nautilus_file_background_is_desktop (background)) { + nautilus_file_update_root_window (background); } } /* handle the background destroyed signal */ static void background_destroyed_callback (NautilusBackground *background, - NautilusDirectory *directory) + NautilusFile *file) { - gtk_signal_disconnect_by_func (GTK_OBJECT (directory), + gtk_signal_disconnect_by_func (GTK_OBJECT (file), GTK_SIGNAL_FUNC (saved_settings_changed_callback), background); - nautilus_directory_file_monitor_remove (directory, background); + nautilus_file_monitor_remove (file, background); nautilus_preferences_remove_callback (NAUTILUS_PREFERENCES_THEME, - nautilus_directory_background_theme_changed, + nautilus_file_background_theme_changed, background); } -/* key routine that hooks up a background and directory */ +/* key routine that hooks up a background and location */ void -nautilus_connect_background_to_directory_metadata (GtkWidget *widget, - NautilusDirectory *directory) +nautilus_connect_background_to_file_metadata (GtkWidget *widget, + NautilusFile *file) { NautilusBackground *background; - gpointer old_directory; + gpointer old_file; GList *attributes; /* Get at the background object we'll be connecting. */ background = nautilus_get_widget_background (widget); - /* Check if it is already connected. */ - old_directory = gtk_object_get_data (GTK_OBJECT (background), "nautilus_background_directory"); - if (old_directory == directory) { + old_file = gtk_object_get_data (GTK_OBJECT (background), "nautilus_background_file"); + if (old_file == file) { return; } /* Disconnect old signal handlers. */ - if (old_directory != NULL) { - g_assert (NAUTILUS_IS_DIRECTORY (old_directory)); + if (old_file != NULL) { + g_assert (NAUTILUS_IS_FILE (old_file)); gtk_signal_disconnect_by_func (GTK_OBJECT (background), GTK_SIGNAL_FUNC (background_changed_callback), - old_directory); + old_file); gtk_signal_disconnect_by_func (GTK_OBJECT (background), GTK_SIGNAL_FUNC (background_destroyed_callback), - old_directory); + old_file); gtk_signal_disconnect_by_func (GTK_OBJECT (background), GTK_SIGNAL_FUNC (background_reset_callback), - old_directory); - gtk_signal_disconnect_by_func (GTK_OBJECT (old_directory), + old_file); + gtk_signal_disconnect_by_func (GTK_OBJECT (old_file), GTK_SIGNAL_FUNC (saved_settings_changed_callback), background); - nautilus_directory_file_monitor_remove (old_directory, background); + nautilus_file_monitor_remove (old_file, background); nautilus_preferences_remove_callback (NAUTILUS_PREFERENCES_THEME, - nautilus_directory_background_theme_changed, - background); + nautilus_file_background_theme_changed, + background); } /* Attach the new directory. */ - nautilus_directory_ref (directory); + nautilus_file_ref (file); gtk_object_set_data_full (GTK_OBJECT (background), - "nautilus_background_directory", - directory, - (GtkDestroyNotify) nautilus_directory_unref); + "nautilus_background_file", + file, + (GtkDestroyNotify) nautilus_file_unref); /* Connect new signal handlers. */ - if (directory != NULL) { + if (file != NULL) { gtk_signal_connect (GTK_OBJECT (background), "settings_changed", GTK_SIGNAL_FUNC (background_changed_callback), - directory); + file); gtk_signal_connect (GTK_OBJECT (background), "destroy", GTK_SIGNAL_FUNC (background_destroyed_callback), - directory); + file); gtk_signal_connect (GTK_OBJECT (background), "reset", GTK_SIGNAL_FUNC (background_reset_callback), - directory); - gtk_signal_connect (GTK_OBJECT (directory), - "metadata_changed", + file); + gtk_signal_connect (GTK_OBJECT (file), + "changed", GTK_SIGNAL_FUNC (saved_settings_changed_callback), background); - /* arrange to receive directory metadata */ - /* FIXME bugzilla.eazel.com 2551: - * This says we want to monitor the file - * metadata, and it has the side effect of monitoring - * the file list. We want to monitor the directory - * metadata, which would not mean monitoring the file - * list. This may require a change to the - * NautilusDirectory API. - */ - + /* arrange to receive file metadata */ attributes = g_list_append (NULL, NAUTILUS_FILE_ATTRIBUTE_METADATA); - nautilus_directory_file_monitor_add (directory, - background, - attributes, FALSE); + nautilus_file_monitor_add (file, + background, + attributes); g_list_free (attributes); /* arrange for notification when the theme changes */ nautilus_preferences_add_callback (NAUTILUS_PREFERENCES_THEME, - nautilus_directory_background_theme_changed, background); + nautilus_file_background_theme_changed, background); } - /* Update the background based on the directory metadata. */ - saved_settings_changed_callback (directory, background); + /* Update the background based on the file metadata. */ + saved_settings_changed_callback (file, background); } void -nautilus_connect_desktop_background_to_directory_metadata (GtkWidget *widget, - NautilusDirectory *directory) +nautilus_connect_desktop_background_to_file_metadata (GtkWidget *widget, + NautilusFile *file) { - nautilus_directory_background_set_desktop (nautilus_get_widget_background (widget)); + nautilus_file_background_set_desktop (nautilus_get_widget_background (widget)); /* Strictly speaking, we don't need to know about metadata changes, since * the desktop setting aren't stored there. But, hooking up to metadata * changes is actually a small part of what this fn does, and we do need * the other stuff (hooked up to background & theme changes). Being notified - * of metadata changes on the directory is a waste, but won't hurt, so I don't + * of metadata changes on the file is a waste, but won't hurt, so I don't * think it's worth refactoring the fn at this point. */ - nautilus_connect_background_to_directory_metadata (widget, directory); + nautilus_connect_background_to_file_metadata (widget, file); } void -nautilus_connect_background_to_directory_metadata_by_uri (GtkWidget *widget, - const char *uri) +nautilus_connect_background_to_file_metadata_by_uri (GtkWidget *widget, + const char *uri) { - NautilusDirectory *directory; - directory = nautilus_directory_get (uri); - nautilus_connect_background_to_directory_metadata (widget, directory); - nautilus_directory_unref (directory); + NautilusFile *file; + file = nautilus_file_get (uri); + nautilus_connect_background_to_file_metadata (widget, file); + nautilus_file_unref (file); } diff --git a/libnautilus-extensions/nautilus-directory-background.h b/libnautilus-extensions/nautilus-directory-background.h index 46d2032d6..9adf6ea4d 100644 --- a/libnautilus-extensions/nautilus-directory-background.h +++ b/libnautilus-extensions/nautilus-directory-background.h @@ -25,14 +25,14 @@ */ #include <gtk/gtkwidget.h> -#include "nautilus-directory.h" +#include "nautilus-file.h" #include "nautilus-background.h" -void nautilus_connect_background_to_directory_metadata (GtkWidget *widget, - NautilusDirectory *directory); -void nautilus_connect_desktop_background_to_directory_metadata (GtkWidget *widget, - NautilusDirectory *directory); -void nautilus_connect_background_to_directory_metadata_by_uri (GtkWidget *widget, - const char *uri); -gboolean nautilus_directory_background_is_set (NautilusBackground *background); +void nautilus_connect_background_to_file_metadata (GtkWidget *widget, + NautilusFile *file); +void nautilus_connect_desktop_background_to_file_metadata (GtkWidget *widget, + NautilusFile *file); +void nautilus_connect_background_to_file_metadata_by_uri (GtkWidget *widget, + const char *uri); +gboolean nautilus_file_background_is_set (NautilusBackground *background); diff --git a/libnautilus-extensions/nautilus-directory-metafile.c b/libnautilus-extensions/nautilus-directory-metafile.c index 1e205e6cd..83d164961 100644 --- a/libnautilus-extensions/nautilus-directory-metafile.c +++ b/libnautilus-extensions/nautilus-directory-metafile.c @@ -172,13 +172,9 @@ set_metadata_string_in_metafile (NautilusDirectory *directory, xmlAttr *property_node; /* If the data in the metafile is already correct, do nothing. */ - if (file_name == NULL) { - old_metadata = nautilus_directory_get_metadata - (directory, key, default_metadata); - } else { - old_metadata = nautilus_directory_get_file_metadata - (directory, file_name, key, default_metadata); - } + old_metadata = nautilus_directory_get_file_metadata + (directory, file_name, key, default_metadata); + old_metadata_matches = nautilus_strcmp (old_metadata, metadata) == 0; g_free (old_metadata); if (old_metadata_matches) { @@ -536,29 +532,6 @@ nautilus_directory_metafile_destroy (NautilusDirectory *directory) destroy_metadata_changes_hash_table (directory->details->metadata_changes); } -char * -nautilus_directory_get_metadata (NautilusDirectory *directory, - const char *key, - const char *default_metadata) -{ - g_return_val_if_fail (key != NULL, g_strdup (default_metadata)); - g_return_val_if_fail (key[0] != '\0', g_strdup (default_metadata)); - - /* It's legal to call this on a NULL directory. */ - if (directory == NULL) { - return g_strdup (default_metadata); - } - - g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), g_strdup (default_metadata)); - - if (directory->details->metafile_read) { - return get_metadata_string_from_metafile - (directory, NULL, key, default_metadata); - } else { - return get_metadata_string_from_table - (directory, NULL, key, default_metadata); - } -} char * nautilus_directory_get_file_metadata (NautilusDirectory *directory, @@ -582,31 +555,6 @@ nautilus_directory_get_file_metadata (NautilusDirectory *directory, } -GList * -nautilus_directory_get_metadata_list (NautilusDirectory *directory, - const char *list_key, - const char *list_subkey) -{ - g_return_val_if_fail (list_key != NULL, NULL); - g_return_val_if_fail (list_key[0] != '\0', NULL); - g_return_val_if_fail (list_subkey != NULL, NULL); - g_return_val_if_fail (list_subkey[0] != '\0', NULL); - - /* It's legal to call this on a NULL directory. */ - if (directory == NULL) { - return NULL; - } - - g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), NULL); - - if (directory->details->metafile_read) { - return get_metadata_list_from_metafile - (directory, NULL, list_key, list_subkey); - } else { - return get_metadata_list_from_table - (directory, NULL, list_key, list_subkey); - } -} GList * nautilus_directory_get_file_metadata_list (NautilusDirectory *directory, @@ -631,58 +579,6 @@ nautilus_directory_get_file_metadata_list (NautilusDirectory *directory, } } -void -nautilus_directory_set_metadata (NautilusDirectory *directory, - const char *key, - const char *default_metadata, - const char *metadata) -{ - MetadataValue *value; - - g_return_if_fail (NAUTILUS_IS_DIRECTORY (directory)); - g_return_if_fail (key != NULL); - g_return_if_fail (key[0] != '\0'); - - if (directory->details->metafile_read) { - if (set_metadata_string_in_metafile (directory, NULL, key, - default_metadata, metadata)) { - nautilus_directory_emit_metadata_changed (directory); - } - } else { - value = metadata_value_new (default_metadata, metadata); - if (set_metadata_eat_value (directory, NULL, key, NULL, value)) { - nautilus_directory_emit_metadata_changed (directory); - } - } -} - -void -nautilus_directory_set_metadata_list (NautilusDirectory *directory, - const char *list_key, - const char *list_subkey, - GList *list) -{ - MetadataValue *value; - - g_return_if_fail (NAUTILUS_IS_DIRECTORY (directory)); - g_return_if_fail (list_key != NULL); - g_return_if_fail (list_key[0] != '\0'); - g_return_if_fail (list_subkey != NULL); - g_return_if_fail (list_subkey[0] != '\0'); - - if (directory->details->metafile_read) { - if (set_metadata_list_in_metafile (directory, NULL, - list_key, list_subkey, list)) { - nautilus_directory_emit_metadata_changed (directory); - } - } else { - value = metadata_value_new_list (list); - if (set_metadata_eat_value (directory, NULL, - list_key, list_subkey, value)) { - nautilus_directory_emit_metadata_changed (directory); - } - } -} gboolean nautilus_directory_set_file_metadata (NautilusDirectory *directory, @@ -831,16 +727,19 @@ nautilus_directory_metafile_apply_pending_changes (NautilusDirectory *directory) directory->details->metadata_changes = NULL; } + + gboolean -nautilus_directory_get_boolean_metadata (NautilusDirectory *directory, - const char *key, - gboolean default_metadata) +nautilus_directory_get_boolean_file_metadata (NautilusDirectory *directory, + const char *file_name, + const char *key, + gboolean default_metadata) { char *result_as_string; gboolean result; - result_as_string = nautilus_directory_get_metadata - (directory, key, + result_as_string = nautilus_directory_get_file_metadata + (directory, file_name, key, default_metadata ? "true" : "false"); g_strdown (result_as_string); @@ -859,30 +758,32 @@ nautilus_directory_get_boolean_metadata (NautilusDirectory *directory, return result; } -void -nautilus_directory_set_boolean_metadata (NautilusDirectory *directory, - const char *key, - gboolean default_metadata, - gboolean metadata) -{ - nautilus_directory_set_metadata - (directory, key, +gboolean +nautilus_directory_set_boolean_file_metadata (NautilusDirectory *directory, + const char *file_name, + const char *key, + gboolean default_metadata, + gboolean metadata) +{ + return nautilus_directory_set_file_metadata + (directory, file_name, key, default_metadata ? "true" : "false", metadata ? "true" : "false"); } int -nautilus_directory_get_integer_metadata (NautilusDirectory *directory, - const char *key, - int default_metadata) +nautilus_directory_get_integer_file_metadata (NautilusDirectory *directory, + const char *file_name, + const char *key, + int default_metadata) { char *result_as_string; char *default_as_string; int result; default_as_string = g_strdup_printf ("%d", default_metadata); - result_as_string = nautilus_directory_get_metadata - (directory, key, default_as_string); + result_as_string = nautilus_directory_get_file_metadata + (directory, file_name, key, default_as_string); /* Handle oddball case of non-existent directory */ if (result_as_string == NULL) { @@ -897,11 +798,12 @@ nautilus_directory_get_integer_metadata (NautilusDirectory *directory, } -void -nautilus_directory_set_integer_metadata (NautilusDirectory *directory, - const char *key, - int default_metadata, - int metadata) +gboolean +nautilus_directory_set_integer_file_metadata (NautilusDirectory *directory, + const char *file_name, + const char *key, + int default_metadata, + int metadata) { char *value_as_string; char *default_as_string; @@ -909,14 +811,16 @@ nautilus_directory_set_integer_metadata (NautilusDirectory *directory, value_as_string = g_strdup_printf ("%d", metadata); default_as_string = g_strdup_printf ("%d", default_metadata); - nautilus_directory_set_metadata - (directory, key, + return nautilus_directory_set_file_metadata + (directory, file_name, key, default_as_string, value_as_string); g_free (value_as_string); g_free (default_as_string); } + + static void copy_file_metadata_for_key (NautilusDirectory *source_directory, const char *source_file_name, diff --git a/libnautilus-extensions/nautilus-directory-metafile.h b/libnautilus-extensions/nautilus-directory-metafile.h index 330ac9aa1..3aa6f254c 100644 --- a/libnautilus-extensions/nautilus-directory-metafile.h +++ b/libnautilus-extensions/nautilus-directory-metafile.h @@ -34,6 +34,15 @@ GList * nautilus_directory_get_file_metadata_list (NautilusDirectory *d const char *file_name, const char *list_key, const char *list_subkey); +gboolean nautilus_directory_get_boolean_file_metadata (NautilusDirectory *directory, + const char *file_name, + const char *key, + gboolean default_metadata); +int nautilus_directory_get_integer_file_metadata (NautilusDirectory *directory, + const char *file_name, + const char *key, + int default_metadata); + gboolean nautilus_directory_set_file_metadata (NautilusDirectory *directory, const char *file_name, const char *key, @@ -44,6 +53,17 @@ gboolean nautilus_directory_set_file_metadata_list (NautilusDirectory *d const char *list_key, const char *list_subkey, GList *list); +gboolean nautilus_directory_set_boolean_file_metadata (NautilusDirectory *directory, + const char *file_name, + const char *key, + gboolean default_metadata, + gboolean metadata); +gboolean nautilus_directory_set_integer_file_metadata (NautilusDirectory *directory, + const char *file_name, + const char *key, + int default_metadata, + int metadata); + void nautilus_directory_copy_file_metadata (NautilusDirectory *source_directory, const char *source_file_name, NautilusDirectory *destination_directory, diff --git a/libnautilus-extensions/nautilus-directory.c b/libnautilus-extensions/nautilus-directory.c index 7ecbcf8af..5ab99d517 100644 --- a/libnautilus-extensions/nautilus-directory.c +++ b/libnautilus-extensions/nautilus-directory.c @@ -46,7 +46,6 @@ enum { FILES_ADDED, FILES_CHANGED, - METADATA_CHANGED, DONE_LOADING, LAST_SIGNAL }; @@ -99,13 +98,6 @@ nautilus_directory_initialize_class (NautilusDirectoryClass *klass) GTK_SIGNAL_OFFSET (NautilusDirectoryClass, files_changed), gtk_marshal_NONE__POINTER, GTK_TYPE_NONE, 1, GTK_TYPE_POINTER); - signals[METADATA_CHANGED] = - gtk_signal_new ("metadata_changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (NautilusDirectoryClass, metadata_changed), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); signals[DONE_LOADING] = gtk_signal_new ("done_loading", GTK_RUN_LAST, @@ -659,10 +651,6 @@ nautilus_directory_emit_change_signals_deep (NautilusDirectory *directory, void nautilus_directory_emit_metadata_changed (NautilusDirectory *directory) { - /* Tell that the directory metadata has changed. */ - gtk_signal_emit (GTK_OBJECT (directory), - signals[METADATA_CHANGED]); - /* Say that all the files have changed. * We could optimize this to only mention files that * have metadata, but this is a fine rough cut for now. @@ -1284,7 +1272,6 @@ static void got_metadata_callback (NautilusDirectory *directory, GList *files, gpointer callback_data) { g_assert (NAUTILUS_IS_DIRECTORY (directory)); - g_assert (files == NULL); g_assert (callback_data == &data_dummy); got_metadata_flag = TRUE; @@ -1311,9 +1298,11 @@ void nautilus_self_check_directory (void) { NautilusDirectory *directory; + NautilusFile *file; GList *attributes; directory = nautilus_directory_get ("file:///etc"); + file = nautilus_file_get ("file:///etc/passwd"); NAUTILUS_CHECK_INTEGER_RESULT (g_hash_table_size (directories), 1); @@ -1332,23 +1321,23 @@ nautilus_self_check_directory (void) gtk_main_iteration (); } - nautilus_directory_set_metadata (directory, "TEST", "default", "value"); - NAUTILUS_CHECK_STRING_RESULT (nautilus_directory_get_metadata (directory, "TEST", "default"), "value"); + nautilus_file_set_metadata (file, "TEST", "default", "value"); + NAUTILUS_CHECK_STRING_RESULT (nautilus_file_get_metadata (file, "TEST", "default"), "value"); - nautilus_directory_set_boolean_metadata (directory, "TEST_BOOLEAN", TRUE, TRUE); - NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_directory_get_boolean_metadata (directory, "TEST_BOOLEAN", TRUE), TRUE); - nautilus_directory_set_boolean_metadata (directory, "TEST_BOOLEAN", TRUE, FALSE); - NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_directory_get_boolean_metadata (directory, "TEST_BOOLEAN", TRUE), FALSE); - NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_directory_get_boolean_metadata (NULL, "TEST_BOOLEAN", TRUE), TRUE); + nautilus_file_set_boolean_metadata (file, "TEST_BOOLEAN", TRUE, TRUE); + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_file_get_boolean_metadata (file, "TEST_BOOLEAN", TRUE), TRUE); + nautilus_file_set_boolean_metadata (file, "TEST_BOOLEAN", TRUE, FALSE); + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_file_get_boolean_metadata (file, "TEST_BOOLEAN", TRUE), FALSE); + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_file_get_boolean_metadata (NULL, "TEST_BOOLEAN", TRUE), TRUE); - nautilus_directory_set_integer_metadata (directory, "TEST_INTEGER", 0, 17); - NAUTILUS_CHECK_INTEGER_RESULT (nautilus_directory_get_integer_metadata (directory, "TEST_INTEGER", 0), 17); - nautilus_directory_set_integer_metadata (directory, "TEST_INTEGER", 0, -1); - NAUTILUS_CHECK_INTEGER_RESULT (nautilus_directory_get_integer_metadata (directory, "TEST_INTEGER", 0), -1); - nautilus_directory_set_integer_metadata (directory, "TEST_INTEGER", 42, 42); - NAUTILUS_CHECK_INTEGER_RESULT (nautilus_directory_get_integer_metadata (directory, "TEST_INTEGER", 42), 42); - NAUTILUS_CHECK_INTEGER_RESULT (nautilus_directory_get_integer_metadata (NULL, "TEST_INTEGER", 42), 42); - NAUTILUS_CHECK_INTEGER_RESULT (nautilus_directory_get_integer_metadata (directory, "NONEXISTENT_KEY", 42), 42); + nautilus_file_set_integer_metadata (file, "TEST_INTEGER", 0, 17); + NAUTILUS_CHECK_INTEGER_RESULT (nautilus_file_get_integer_metadata (file, "TEST_INTEGER", 0), 17); + nautilus_file_set_integer_metadata (file, "TEST_INTEGER", 0, -1); + NAUTILUS_CHECK_INTEGER_RESULT (nautilus_file_get_integer_metadata (file, "TEST_INTEGER", 0), -1); + nautilus_file_set_integer_metadata (file, "TEST_INTEGER", 42, 42); + NAUTILUS_CHECK_INTEGER_RESULT (nautilus_file_get_integer_metadata (file, "TEST_INTEGER", 42), 42); + NAUTILUS_CHECK_INTEGER_RESULT (nautilus_file_get_integer_metadata (NULL, "TEST_INTEGER", 42), 42); + NAUTILUS_CHECK_INTEGER_RESULT (nautilus_file_get_integer_metadata (file, "NONEXISTENT_KEY", 42), 42); NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_directory_get ("file:///etc") == directory, TRUE); nautilus_directory_unref (directory); @@ -1359,6 +1348,8 @@ nautilus_self_check_directory (void) NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_directory_get ("file:///etc////") == directory, TRUE); nautilus_directory_unref (directory); + nautilus_file_unref (file); + nautilus_directory_file_monitor_remove (directory, &data_dummy); nautilus_directory_unref (directory); @@ -1399,7 +1390,11 @@ nautilus_self_check_directory (void) NAUTILUS_CHECK_INTEGER_RESULT (g_hash_table_size (directories), 1); - NAUTILUS_CHECK_STRING_RESULT (nautilus_directory_get_metadata (directory, "TEST", "default"), "value"); + file = nautilus_file_get ("file:///etc/passwd"); + + NAUTILUS_CHECK_STRING_RESULT (nautilus_file_get_metadata (file, "TEST", "default"), "value"); + + nautilus_file_unref (file); nautilus_directory_unref (directory); diff --git a/libnautilus-extensions/nautilus-directory.h b/libnautilus-extensions/nautilus-directory.h index 671b3a686..8d895d59d 100644 --- a/libnautilus-extensions/nautilus-directory.h +++ b/libnautilus-extensions/nautilus-directory.h @@ -93,12 +93,6 @@ typedef struct void (* files_changed) (NautilusDirectory *directory, GList *changed_files); - /* The metadata_changed signal is emitted when changes to the metadata - * for the directory itself are made. Changes to file metadata just - * result in calls to files_changed. - */ - void (* metadata_changed) (NautilusDirectory *directory); - /* The done_loading signal is emitted when a directory load * request completes. This is needed because, at least in the * case where the directory is empty, the caller will receive @@ -169,37 +163,6 @@ void nautilus_directory_cancel_callback (NautilusDirectory NautilusDirectoryCallback callback, gpointer callback_data); -/* Getting and setting metadata. */ -char * nautilus_directory_get_metadata (NautilusDirectory *directory, - const char *key, - const char *default_metadata); -GList *nautilus_directory_get_metadata_list (NautilusDirectory *directory, - const char *list_key, - const char *list_subkey); -void nautilus_directory_set_metadata (NautilusDirectory *directory, - const char *key, - const char *default_metadata, - const char *metadata); -void nautilus_directory_set_metadata_list (NautilusDirectory *directory, - const char *list_key, - const char *list_subkey, - GList *list); - -/* Covers for common data types. */ -gboolean nautilus_directory_get_boolean_metadata (NautilusDirectory *directory, - const char *key, - gboolean default_metadata); -void nautilus_directory_set_boolean_metadata (NautilusDirectory *directory, - const char *key, - gboolean default_metadata, - gboolean metadata); -int nautilus_directory_get_integer_metadata (NautilusDirectory *directory, - const char *key, - int default_metadata); -void nautilus_directory_set_integer_metadata (NautilusDirectory *directory, - const char *key, - int default_metadata, - int metadata); /* Monitor the files in a directory. */ void nautilus_directory_file_monitor_add (NautilusDirectory *directory, diff --git a/libnautilus-extensions/nautilus-file.c b/libnautilus-extensions/nautilus-file.c index 8aa3b889e..f01b075e4 100644 --- a/libnautilus-extensions/nautilus-file.c +++ b/libnautilus-extensions/nautilus-file.c @@ -1661,6 +1661,87 @@ nautilus_file_set_metadata_list (NautilusFile *file, } } + +gboolean +nautilus_file_get_boolean_metadata (NautilusFile *file, + const char *key, + gboolean default_metadata) +{ + g_return_val_if_fail (key != NULL, default_metadata); + g_return_val_if_fail (key[0] != '\0', default_metadata); + if (file == NULL) { + return default_metadata; + } + g_return_val_if_fail (NAUTILUS_IS_FILE (file), default_metadata); + + return nautilus_directory_get_boolean_file_metadata + (file->details->directory, + file->details->name, + key, + default_metadata); +} + +int +nautilus_file_get_integer_metadata (NautilusFile *file, + const char *key, + int default_metadata) +{ + g_return_val_if_fail (key != NULL, default_metadata); + g_return_val_if_fail (key[0] != '\0', default_metadata); + if (file == NULL) { + return default_metadata; + } + g_return_val_if_fail (NAUTILUS_IS_FILE (file), default_metadata); + + return nautilus_directory_get_integer_file_metadata + (file->details->directory, + file->details->name, + key, + default_metadata); +} + + +void +nautilus_file_set_boolean_metadata (NautilusFile *file, + const char *key, + gboolean default_metadata, + gboolean metadata) +{ + g_return_if_fail (NAUTILUS_IS_FILE (file)); + g_return_if_fail (key != NULL); + g_return_if_fail (key[0] != '\0'); + + if (nautilus_directory_set_boolean_file_metadata (file->details->directory, + file->details->name, + key, + default_metadata, + metadata)) { + nautilus_file_changed (file); + } +} + +void +nautilus_file_set_integer_metadata (NautilusFile *file, + const char *key, + int default_metadata, + int metadata) +{ + g_return_if_fail (NAUTILUS_IS_FILE (file)); + g_return_if_fail (key != NULL); + g_return_if_fail (key[0] != '\0'); + + if (nautilus_directory_set_integer_file_metadata (file->details->directory, + file->details->name, + key, + default_metadata, + metadata)) { + nautilus_file_changed (file); + } +} + + + + char * nautilus_file_get_name (NautilusFile *file) { diff --git a/libnautilus-extensions/nautilus-file.h b/libnautilus-extensions/nautilus-file.h index 70882c926..b8bf1c191 100644 --- a/libnautilus-extensions/nautilus-file.h +++ b/libnautilus-extensions/nautilus-file.h @@ -213,6 +213,23 @@ void nautilus_file_set_metadata_list (NautilusFile const char *list_subkey, GList *list); +/* Covers for common data types. */ +gboolean nautilus_file_get_boolean_metadata (NautilusFile *file, + const char *key, + gboolean default_metadata); +void nautilus_file_set_boolean_metadata (NautilusFile *file, + const char *key, + gboolean default_metadata, + gboolean metadata); +int nautilus_file_get_integer_metadata (NautilusFile *file, + const char *key, + int default_metadata); +void nautilus_file_set_integer_metadata (NautilusFile *file, + const char *key, + int default_metadata, + int metadata); + + /* Attributes for file objects as user-displayable strings. */ char * nautilus_file_get_string_attribute (NautilusFile *file, const char *attribute_name); diff --git a/libnautilus-extensions/nautilus-metadata.h b/libnautilus-extensions/nautilus-metadata.h index c4c1c4500..3de64b564 100644 --- a/libnautilus-extensions/nautilus-metadata.h +++ b/libnautilus-extensions/nautilus-metadata.h @@ -29,7 +29,7 @@ * should define its key here, so we can keep track of the whole set easily. */ -/* Per-directory */ +/* Per-file */ #define NAUTILUS_METADATA_KEY_CONTENT_VIEWS "CONTENT_VIEWS" @@ -45,10 +45,8 @@ #define NAUTILUS_METADATA_KEY_EXPLICIT_COMPONENT "EXPLICIT_CONTENT_VIEW" #define NAUTILUS_METADATA_SUBKEY_COMPONENT_IID "IID" -#define NAUTILUS_METADATA_KEY_WINDOW_GEOMETRY "WINDOW_GEOMETRY" - -#define NAUTILUS_METADATA_KEY_DIRECTORY_BACKGROUND_COLOR "BACKGROUND_COLOR" -#define NAUTILUS_METADATA_KEY_DIRECTORY_BACKGROUND_IMAGE "BACKGROUND_TILE_IMAGE" +#define NAUTILUS_METADATA_KEY_LOCATION_BACKGROUND_COLOR "BACKGROUND_COLOR" +#define NAUTILUS_METADATA_KEY_LOCATION_BACKGROUND_IMAGE "BACKGROUND_TILE_IMAGE" #define NAUTILUS_METADATA_KEY_ICON_VIEW_ZOOM_LEVEL "ICONS_ZOOM_LEVEL" #define NAUTILUS_METADATA_KEY_ICON_VIEW_AUTO_LAYOUT "ICONS_AUTO_LAYOUT" @@ -60,14 +58,14 @@ #define NAUTILUS_METADATA_KEY_LIST_VIEW_SORT_COLUMN "LIST_SORT_COLUMN" #define NAUTILUS_METADATA_KEY_LIST_VIEW_SORT_REVERSED "LIST_SORT_REVERSED" +#define NAUTILUS_METADATA_KEY_WINDOW_GEOMETRY "WINDOW_GEOMETRY" + #define NAUTILUS_METADATA_KEY_SIDEBAR_BACKGROUND_COLOR "SIDEBAR_BACKGROUND_COLOR" #define NAUTILUS_METADATA_KEY_SIDEBAR_BACKGROUND_IMAGE "SIDEBAR_BACKGROUND_TILE_IMAGE" #define NAUTILUS_METADATA_KEY_SIDEBAR_BUTTONS "SIDEBAR_BUTTONS" #define NAUTILUS_METADATA_KEY_SIDEBAR_TAB_COLOR "SIDEBAR_TAB_COLOR" #define NAUTILUS_METADATA_KEY_SIDEBAR_TITLE_TAB_COLOR "SIDEBAR_TITLE_TAB_COLOR" -/* Per-file */ - #define NAUTILUS_METADATA_KEY_NOTES "NOTES" #define NAUTILUS_METADATA_KEY_ANNOTATION "ANNOTATION" #define NAUTILUS_METADATA_KEY_ICON_POSITION "ICON_POSITION" diff --git a/libnautilus-extensions/nautilus-mime-actions.c b/libnautilus-extensions/nautilus-mime-actions.c index 60fe4b3f3..2533a9ac1 100644 --- a/libnautilus-extensions/nautilus-mime-actions.c +++ b/libnautilus-extensions/nautilus-mime-actions.c @@ -53,7 +53,7 @@ static char *extract_prefix_add_suffix (const char const char *suffix); static char *mime_type_get_supertype (const char *mime_type); static char *uri_string_get_scheme (const char *uri_string); -static GList *get_explicit_content_view_iids_from_metafile (NautilusDirectory *directory); +static GList *get_explicit_content_view_iids_from_metafile (NautilusFile *file); static char *make_oaf_query_for_explicit_content_view_iids (GList *view_iids); static char *make_oaf_query_with_known_mime_type (const char *mime_type, const char *uri_scheme, @@ -99,9 +99,8 @@ is_known_mime_type (const char *mime_type) } static void -nautilus_directory_wait_for_metadata (NautilusDirectory *directory) +nautilus_file_wait_for_metadata (NautilusFile *file) { - GList *file_list; GList *attributes; /* When nautilus_directory_wait_until_ready is called this way, it @@ -111,9 +110,8 @@ nautilus_directory_wait_for_metadata (NautilusDirectory *directory) */ attributes = g_list_append (NULL, NAUTILUS_FILE_ATTRIBUTE_METADATA); - file_list = nautilus_directory_wait_until_ready (directory, attributes); + nautilus_file_wait_until_ready (file, attributes); g_list_free (attributes); - nautilus_file_list_free (file_list); } GnomeVFSMimeActionType @@ -124,9 +122,10 @@ nautilus_mime_get_default_action_type_for_uri (NautilusDirectory *directory, char *action_type_string; GnomeVFSMimeActionType action_type; - nautilus_directory_wait_for_metadata (directory); - action_type_string = nautilus_directory_get_metadata - (directory, NAUTILUS_METADATA_KEY_DEFAULT_ACTION_TYPE, NULL); + nautilus_file_wait_for_metadata (file); + + action_type_string = nautilus_file_get_metadata + (file, NAUTILUS_METADATA_KEY_DEFAULT_ACTION_TYPE, NULL); if (action_type_string == NULL) { mime_type = get_mime_type_from_file (file); @@ -194,9 +193,9 @@ nautilus_mime_get_default_application_for_uri_internal (NautilusDirectory *direc used_user_chosen_info = TRUE; - nautilus_directory_wait_for_metadata (directory); - default_application_string = nautilus_directory_get_metadata - (directory, NAUTILUS_METADATA_KEY_DEFAULT_APPLICATION, NULL); + nautilus_file_wait_for_metadata (file); + default_application_string = nautilus_file_get_metadata + (file, NAUTILUS_METADATA_KEY_DEFAULT_APPLICATION, NULL); if (default_application_string == NULL) { mime_type = get_mime_type_from_file (file); @@ -278,17 +277,18 @@ nautilus_mime_get_default_component_for_uri_internal (NautilusDirectory *directo g_free (uri); + nautilus_file_wait_for_metadata (file); + explicit_iids = get_explicit_content_view_iids_from_metafile (file); + /* Arrange for all the file attributes we will need. */ attributes = NULL; attributes = g_list_prepend (attributes, NAUTILUS_FILE_ATTRIBUTE_MIME_TYPE); - attributes = g_list_append (NULL, NAUTILUS_FILE_ATTRIBUTE_METADATA); - files = nautilus_directory_wait_until_ready (directory, attributes); - default_component_string = nautilus_directory_get_metadata - (directory, NAUTILUS_METADATA_KEY_DEFAULT_COMPONENT, NULL); - explicit_iids = get_explicit_content_view_iids_from_metafile (directory); g_list_free (attributes); + default_component_string = nautilus_file_get_metadata + (file, NAUTILUS_METADATA_KEY_DEFAULT_COMPONENT, NULL); + if (default_component_string == NULL && is_known_mime_type (mime_type)) { mime_default = gnome_vfs_mime_get_default_component (mime_type); if (mime_default != NULL) { @@ -438,13 +438,13 @@ nautilus_mime_get_short_list_applications_for_uri (NautilusDirectory *directory, CORBA_exception_init (&ev); - nautilus_directory_wait_for_metadata (directory); - metadata_application_add_ids = nautilus_directory_get_metadata_list - (directory, + nautilus_file_wait_for_metadata (file); + metadata_application_add_ids = nautilus_file_get_metadata_list + (file, NAUTILUS_METADATA_KEY_SHORT_LIST_APPLICATION_ADD, NAUTILUS_METADATA_SUBKEY_APPLICATION_ID); - metadata_application_remove_ids = nautilus_directory_get_metadata_list - (directory, + metadata_application_remove_ids = nautilus_file_get_metadata_list + (file, NAUTILUS_METADATA_KEY_SHORT_LIST_APPLICATION_REMOVE, NAUTILUS_METADATA_SUBKEY_APPLICATION_ID); @@ -507,21 +507,22 @@ nautilus_mime_get_short_list_components_for_uri (NautilusDirectory *directory, g_free (uri); + nautilus_file_wait_for_metadata (file); + explicit_iids = get_explicit_content_view_iids_from_metafile (file); + /* Arrange for all the file attributes we will need. */ attributes = NULL; attributes = g_list_prepend (attributes, NAUTILUS_FILE_ATTRIBUTE_MIME_TYPE); - attributes = g_list_append (NULL, NAUTILUS_FILE_ATTRIBUTE_METADATA); - files = nautilus_directory_wait_until_ready (directory, attributes); - explicit_iids = get_explicit_content_view_iids_from_metafile (directory); g_list_free (attributes); - metadata_component_add_ids = nautilus_directory_get_metadata_list - (directory, + + metadata_component_add_ids = nautilus_file_get_metadata_list + (file, NAUTILUS_METADATA_KEY_SHORT_LIST_COMPONENT_ADD, NAUTILUS_METADATA_SUBKEY_COMPONENT_IID); - metadata_component_remove_ids = nautilus_directory_get_metadata_list - (directory, + metadata_component_remove_ids = nautilus_file_get_metadata_list + (file, NAUTILUS_METADATA_KEY_SHORT_LIST_COMPONENT_REMOVE, NAUTILUS_METADATA_SUBKEY_COMPONENT_IID); @@ -608,9 +609,9 @@ nautilus_mime_get_all_applications_for_uri (NautilusDirectory *directory, GList *p; GnomeVFSMimeApplication *application; - nautilus_directory_wait_for_metadata (directory); - metadata_application_ids = nautilus_directory_get_metadata_list - (directory, + nautilus_file_wait_for_metadata (file); + metadata_application_ids = nautilus_file_get_metadata_list + (file, NAUTILUS_METADATA_KEY_EXPLICIT_APPLICATION, NAUTILUS_METADATA_SUBKEY_APPLICATION_ID); @@ -668,14 +669,15 @@ nautilus_mime_get_all_components_for_uri (NautilusDirectory *directory, uri = nautilus_file_get_uri (file); uri_scheme = uri_string_get_scheme (uri); g_free (uri); + + nautilus_file_wait_for_metadata (file); + explicit_iids = get_explicit_content_view_iids_from_metafile (file); /* Arrange for all the file attributes we will need. */ attributes = NULL; attributes = g_list_prepend (attributes, NAUTILUS_FILE_ATTRIBUTE_MIME_TYPE); - attributes = g_list_append (NULL, NAUTILUS_FILE_ATTRIBUTE_METADATA); files = nautilus_directory_wait_until_ready (directory, attributes); - explicit_iids = get_explicit_content_view_iids_from_metafile (directory); g_list_free (attributes); info_list = nautilus_do_component_query (mime_type, uri_scheme, files, explicit_iids, NULL, NULL, &ev); @@ -721,9 +723,9 @@ nautilus_mime_set_default_action_type_for_uri (NautilusDirectory *directory action_string = "none"; } - nautilus_directory_wait_for_metadata (directory); - nautilus_directory_set_metadata - (directory, NAUTILUS_METADATA_KEY_DEFAULT_ACTION_TYPE, NULL, action_string); + nautilus_file_wait_for_metadata (file); + nautilus_file_set_metadata + (file, NAUTILUS_METADATA_KEY_DEFAULT_ACTION_TYPE, NULL, action_string); return GNOME_VFS_OK; } @@ -733,9 +735,9 @@ nautilus_mime_set_default_application_for_uri (NautilusDirectory *directory, NautilusFile *file, const char *application_id) { - nautilus_directory_wait_for_metadata (directory); - nautilus_directory_set_metadata - (directory, NAUTILUS_METADATA_KEY_DEFAULT_APPLICATION, NULL, application_id); + nautilus_file_wait_for_metadata (file); + nautilus_file_set_metadata + (file, NAUTILUS_METADATA_KEY_DEFAULT_APPLICATION, NULL, application_id); /* If there's no default action type, set it to match this. */ if (application_id != NULL && @@ -751,9 +753,9 @@ nautilus_mime_set_default_component_for_uri (NautilusDirectory *directory, NautilusFile *file, const char *component_iid) { - nautilus_directory_wait_for_metadata (directory); - nautilus_directory_set_metadata - (directory, NAUTILUS_METADATA_KEY_DEFAULT_COMPONENT, NULL, component_iid); + nautilus_file_wait_for_metadata (file); + nautilus_file_set_metadata + (file, NAUTILUS_METADATA_KEY_DEFAULT_COMPONENT, NULL, component_iid); /* If there's no default action type, set it to match this. */ if (component_iid != NULL && @@ -792,14 +794,14 @@ nautilus_mime_set_short_list_applications_for_uri (NautilusDirectory *directory, add_list = str_list_difference (applications, normal_short_list_ids); remove_list = str_list_difference (normal_short_list_ids, applications); - nautilus_directory_wait_for_metadata (directory); - nautilus_directory_set_metadata_list - (directory, + nautilus_file_wait_for_metadata (file); + nautilus_file_set_metadata_list + (file, NAUTILUS_METADATA_KEY_SHORT_LIST_APPLICATION_ADD, NAUTILUS_METADATA_SUBKEY_APPLICATION_ID, add_list); - nautilus_directory_set_metadata_list - (directory, + nautilus_file_set_metadata_list + (file, NAUTILUS_METADATA_KEY_SHORT_LIST_APPLICATION_REMOVE, NAUTILUS_METADATA_SUBKEY_APPLICATION_ID, remove_list); @@ -839,14 +841,14 @@ nautilus_mime_set_short_list_components_for_uri (NautilusDirectory *directory, add_list = str_list_difference (components, normal_short_list_ids); remove_list = str_list_difference (normal_short_list_ids, components); - nautilus_directory_wait_for_metadata (directory); - nautilus_directory_set_metadata_list - (directory, + nautilus_file_wait_for_metadata (file); + nautilus_file_set_metadata_list + (file, NAUTILUS_METADATA_KEY_SHORT_LIST_COMPONENT_ADD, NAUTILUS_METADATA_SUBKEY_COMPONENT_IID, add_list); - nautilus_directory_set_metadata_list - (directory, + nautilus_file_set_metadata_list + (file, NAUTILUS_METADATA_KEY_SHORT_LIST_COMPONENT_REMOVE, NAUTILUS_METADATA_SUBKEY_COMPONENT_IID, remove_list); @@ -967,10 +969,10 @@ nautilus_mime_extend_all_applications_for_uri (NautilusDirectory *directory, GList *extras; GList *final_applications; - nautilus_directory_wait_for_metadata (directory); + nautilus_file_wait_for_metadata (file); - metadata_application_ids = nautilus_directory_get_metadata_list - (directory, + metadata_application_ids = nautilus_file_get_metadata_list + (file, NAUTILUS_METADATA_KEY_EXPLICIT_APPLICATION, NAUTILUS_METADATA_SUBKEY_APPLICATION_ID); @@ -978,8 +980,8 @@ nautilus_mime_extend_all_applications_for_uri (NautilusDirectory *directory, final_applications = g_list_concat (g_list_copy (metadata_application_ids), extras); - nautilus_directory_set_metadata_list - (directory, + nautilus_file_set_metadata_list + (file, NAUTILUS_METADATA_KEY_EXPLICIT_APPLICATION, NAUTILUS_METADATA_SUBKEY_APPLICATION_ID, final_applications); @@ -995,21 +997,21 @@ nautilus_mime_remove_from_all_applications_for_uri (NautilusDirectory *directory GList *metadata_application_ids; GList *final_applications; - nautilus_directory_wait_for_metadata (directory); + nautilus_file_wait_for_metadata (file); - metadata_application_ids = nautilus_directory_get_metadata_list - (directory, + metadata_application_ids = nautilus_file_get_metadata_list + (file, NAUTILUS_METADATA_KEY_EXPLICIT_APPLICATION, NAUTILUS_METADATA_SUBKEY_APPLICATION_ID); - + final_applications = str_list_difference (metadata_application_ids, applications); - - nautilus_directory_set_metadata_list - (directory, + + nautilus_file_set_metadata_list + (file, NAUTILUS_METADATA_KEY_EXPLICIT_APPLICATION, NAUTILUS_METADATA_SUBKEY_APPLICATION_ID, final_applications); - + return GNOME_VFS_OK; } @@ -1091,11 +1093,11 @@ uri_string_get_scheme (const char *uri_string) */ static GList * -get_explicit_content_view_iids_from_metafile (NautilusDirectory *directory) +get_explicit_content_view_iids_from_metafile (NautilusFile *file) { - if (directory != NULL) { - return nautilus_directory_get_metadata_list - (directory, + if (file != NULL) { + return nautilus_file_get_metadata_list + (file, NAUTILUS_METADATA_KEY_EXPLICIT_COMPONENT, NAUTILUS_METADATA_SUBKEY_COMPONENT_IID); } else { diff --git a/libnautilus-private/nautilus-directory-background.c b/libnautilus-private/nautilus-directory-background.c index 8c87c8d19..175b9d711 100644 --- a/libnautilus-private/nautilus-directory-background.c +++ b/libnautilus-private/nautilus-directory-background.c @@ -2,7 +2,7 @@ /* nautilus-directory-background.c: Helper for the background of a widget - that is viewing a particular directory. + that is viewing a particular location. Copyright (C) 2000 Eazel, Inc. @@ -42,32 +42,35 @@ #include <libgnome/gnome-util.h> #include <libgnomevfs/gnome-vfs-utils.h> -static void background_changed_callback (NautilusBackground *background, NautilusDirectory *directory); -static void background_reset_callback (NautilusBackground *background, NautilusDirectory *directory); +static void background_changed_callback (NautilusBackground *background, + NautilusFile *file); +static void background_reset_callback (NautilusBackground *background, + NautilusFile *file); -static void saved_settings_changed_callback (NautilusDirectory *directory, NautilusBackground *background); +static void saved_settings_changed_callback (NautilusFile *file, + NautilusBackground *background); -static void nautilus_directory_background_receive_root_window_changes (NautilusBackground *background); +static void nautilus_file_background_receive_root_window_changes (NautilusBackground *background); -static const char *default_theme_source = "directory"; +static const char *default_theme_source = "file"; static const char *desktop_theme_source = "desktop"; void -static nautilus_directory_background_set_desktop (NautilusBackground *background) +static nautilus_file_background_set_desktop (NautilusBackground *background) { gtk_object_set_data (GTK_OBJECT (background), "theme_source", (gpointer) desktop_theme_source); - nautilus_directory_background_receive_root_window_changes (background); + nautilus_file_background_receive_root_window_changes (background); } static gboolean -nautilus_directory_background_is_desktop (NautilusBackground *background) +nautilus_file_background_is_desktop (NautilusBackground *background) { /* == works because we're carful to always use the same string. */ return gtk_object_get_data (GTK_OBJECT (background), "theme_source") == desktop_theme_source; } -static const char *nautilus_directory_background_peek_theme_source (NautilusBackground *background) +static const char *nautilus_file_background_peek_theme_source (NautilusBackground *background) { char *theme_source; @@ -110,20 +113,20 @@ theme_image_path_to_uri (char *image_file) */ static void -nautilus_directory_background_get_default_settings (const char* theme_source, - char **color, - char **image, - NautilusBackgroundImagePlacement *placement, - gboolean *combine) +nautilus_file_background_get_default_settings (const char* theme_source, + char **color, + char **image, + NautilusBackgroundImagePlacement *placement, + gboolean *combine) { char *combine_str; char *image_local_path; *placement = NAUTILUS_BACKGROUND_TILED; - *color = nautilus_theme_get_theme_data (theme_source, NAUTILUS_METADATA_KEY_DIRECTORY_BACKGROUND_COLOR); + *color = nautilus_theme_get_theme_data (theme_source, NAUTILUS_METADATA_KEY_LOCATION_BACKGROUND_COLOR); - image_local_path = nautilus_theme_get_theme_data (theme_source, NAUTILUS_METADATA_KEY_DIRECTORY_BACKGROUND_IMAGE); + image_local_path = nautilus_theme_get_theme_data (theme_source, NAUTILUS_METADATA_KEY_LOCATION_BACKGROUND_IMAGE); *image = theme_image_path_to_uri (image_local_path); g_free (image_local_path); @@ -153,10 +156,10 @@ enum { }; static void -nautilus_directory_background_read_desktop_settings (char **color, - char **image, - NautilusBackgroundImagePlacement *placement, - gboolean *combine) +nautilus_file_background_read_desktop_settings (char **color, + char **image, + NautilusBackgroundImagePlacement *placement, + gboolean *combine) { int image_alignment; char* image_local_path; @@ -172,7 +175,7 @@ nautilus_directory_background_read_desktop_settings (char **color, gboolean no_start_color; gboolean no_end_color; - nautilus_directory_background_get_default_settings (desktop_theme_source, &default_color, &default_image_file, &default_placement, combine); + nautilus_file_background_get_default_settings (desktop_theme_source, &default_color, &default_image_file, &default_placement, combine); /* note - value of combine comes from the theme, not currently setable in gnome_config */ image_local_path = gnome_config_get_string ("/Background/Default/wallpaper=none"); @@ -233,7 +236,7 @@ nautilus_directory_background_read_desktop_settings (char **color, } static void -nautilus_directory_background_write_desktop_settings (char *color, char *image, NautilusBackgroundImagePlacement placement, gboolean combine) +nautilus_file_background_write_desktop_settings (char *color, char *image, NautilusBackgroundImagePlacement placement, gboolean combine) { char *end_color; char *start_color; @@ -315,29 +318,29 @@ nautilus_directory_background_write_desktop_settings (char *color, char *image, } static void -nautilus_directory_background_write_desktop_default_settings () +nautilus_file_background_write_desktop_default_settings () { char *color; char *image; gboolean combine; NautilusBackgroundImagePlacement placement; - nautilus_directory_background_get_default_settings (desktop_theme_source, &color, &image, &placement, &combine); - nautilus_directory_background_write_desktop_settings (color, image, placement, combine); + nautilus_file_background_get_default_settings (desktop_theme_source, &color, &image, &placement, &combine); + nautilus_file_background_write_desktop_settings (color, image, placement, combine); } static int call_settings_changed (NautilusBackground *background) { - NautilusDirectory *directory; - directory = gtk_object_get_data (GTK_OBJECT (background), "nautilus_background_directory"); - if (directory) { - saved_settings_changed_callback (directory, background); + NautilusFile *file; + file = gtk_object_get_data (GTK_OBJECT (background), "nautilus_background_file"); + if (file) { + saved_settings_changed_callback (file, background); } return FALSE; } static GdkFilterReturn -nautilus_directory_background_event_filter (GdkXEvent *gdk_xevent, GdkEvent *event, gpointer data) +nautilus_file_background_event_filter (GdkXEvent *gdk_xevent, GdkEvent *event, gpointer data) { XEvent *xevent; NautilusBackground *background; @@ -366,16 +369,16 @@ nautilus_directory_background_event_filter (GdkXEvent *gdk_xevent, GdkEvent *eve static void desktop_background_destroyed_callback (NautilusBackground *background, void *georgeWBush) { - gdk_window_remove_filter (GDK_ROOT_PARENT(), nautilus_directory_background_event_filter, background); + gdk_window_remove_filter (GDK_ROOT_PARENT(), nautilus_file_background_event_filter, background); } static void -nautilus_directory_background_receive_root_window_changes (NautilusBackground *background) +nautilus_file_background_receive_root_window_changes (NautilusBackground *background) { XWindowAttributes attribs = { 0 }; /* set up a filter on the root window to get notified about property changes */ - gdk_window_add_filter (GDK_ROOT_PARENT(), nautilus_directory_background_event_filter, background); + gdk_window_add_filter (GDK_ROOT_PARENT(), nautilus_file_background_event_filter, background); gdk_error_trap_push (); @@ -514,7 +517,7 @@ image_loading_done_callback (NautilusBackground *background, gboolean successful } static void -nautilus_directory_update_root_window (NautilusBackground *background) +nautilus_file_update_root_window (NautilusBackground *background) { if (nautilus_background_is_loaded (background)) { image_loading_done_callback (background, TRUE, GINT_TO_POINTER (FALSE)); @@ -528,7 +531,7 @@ nautilus_directory_update_root_window (NautilusBackground *background) /* return true if the background is not in the default state */ gboolean -nautilus_directory_background_is_set (NautilusBackground *background) +nautilus_file_background_is_set (NautilusBackground *background) { char *color; char *image; @@ -547,8 +550,8 @@ nautilus_directory_background_is_set (NautilusBackground *background) combine = nautilus_background_get_combine_mode (background); placement = nautilus_background_get_image_placement (background); - nautilus_directory_background_get_default_settings ( - nautilus_directory_background_peek_theme_source (background), + nautilus_file_background_get_default_settings ( + nautilus_file_background_peek_theme_source (background), &default_color, &default_image, &default_placement, &default_combine); is_set = (default_color != NULL && nautilus_strcmp (color, default_color) != 0) || @@ -567,41 +570,41 @@ nautilus_directory_background_is_set (NautilusBackground *background) /* handle the background changed signal */ static void background_changed_callback (NautilusBackground *background, - NautilusDirectory *directory) + NautilusFile *file) { char *color, *image; g_assert (NAUTILUS_IS_BACKGROUND (background)); - g_assert (NAUTILUS_IS_DIRECTORY (directory)); - g_assert (gtk_object_get_data (GTK_OBJECT (background), "nautilus_background_directory") - == directory); + g_assert (NAUTILUS_IS_FILE (file)); + g_assert (gtk_object_get_data (GTK_OBJECT (background), "nautilus_background_file") + == file); color = nautilus_background_get_color (background); image = nautilus_background_get_image_uri (background); - if (nautilus_directory_background_is_desktop (background)) { - nautilus_directory_background_write_desktop_settings (color, image, nautilus_background_get_image_placement (background), nautilus_background_get_combine_mode (background)); + if (nautilus_file_background_is_desktop (background)) { + nautilus_file_background_write_desktop_settings (color, image, nautilus_background_get_image_placement (background), nautilus_background_get_combine_mode (background)); } else { /* Block the other handler while we are writing metadata so it doesn't * try to change the background. */ - gtk_signal_handler_block_by_func (GTK_OBJECT (directory), + gtk_signal_handler_block_by_func (GTK_OBJECT (file), saved_settings_changed_callback, background); - nautilus_directory_set_metadata (directory, - NAUTILUS_METADATA_KEY_DIRECTORY_BACKGROUND_COLOR, - NULL, - color); + nautilus_file_set_metadata (file, + NAUTILUS_METADATA_KEY_LOCATION_BACKGROUND_COLOR, + NULL, + color); - nautilus_directory_set_metadata (directory, - NAUTILUS_METADATA_KEY_DIRECTORY_BACKGROUND_IMAGE, - NULL, - image); + nautilus_file_set_metadata (file, + NAUTILUS_METADATA_KEY_LOCATION_BACKGROUND_IMAGE, + NULL, + image); /* Unblock the handler. */ - gtk_signal_handler_unblock_by_func (GTK_OBJECT (directory), + gtk_signal_handler_unblock_by_func (GTK_OBJECT (file), saved_settings_changed_callback, background); } @@ -609,43 +612,43 @@ background_changed_callback (NautilusBackground *background, g_free (color); g_free (image); - if (nautilus_directory_background_is_desktop (background)) { - nautilus_directory_update_root_window (background); + if (nautilus_file_background_is_desktop (background)) { + nautilus_file_update_root_window (background); } } -/* handle the directory changed signal */ +/* handle the file changed signal */ static void -saved_settings_changed_callback (NautilusDirectory *directory, - NautilusBackground *background) +saved_settings_changed_callback (NautilusFile *file, + NautilusBackground *background) { char *color; char *image; gboolean combine; NautilusBackgroundImagePlacement placement; - g_assert (NAUTILUS_IS_DIRECTORY (directory)); + g_assert (NAUTILUS_IS_FILE (file)); g_assert (NAUTILUS_IS_BACKGROUND (background)); - g_assert (gtk_object_get_data (GTK_OBJECT (background), "nautilus_background_directory") - == directory); + g_assert (gtk_object_get_data (GTK_OBJECT (background), "nautilus_background_file") + == file); - if (nautilus_directory_background_is_desktop (background)) { - nautilus_directory_background_read_desktop_settings (&color, &image, &placement, &combine); + if (nautilus_file_background_is_desktop (background)) { + nautilus_file_background_read_desktop_settings (&color, &image, &placement, &combine); } else { - color = nautilus_directory_get_metadata (directory, - NAUTILUS_METADATA_KEY_DIRECTORY_BACKGROUND_COLOR, - NULL); - image = nautilus_directory_get_metadata (directory, - NAUTILUS_METADATA_KEY_DIRECTORY_BACKGROUND_IMAGE, - NULL); + color = nautilus_file_get_metadata (file, + NAUTILUS_METADATA_KEY_LOCATION_BACKGROUND_COLOR, + NULL); + image = nautilus_file_get_metadata (file, + NAUTILUS_METADATA_KEY_LOCATION_BACKGROUND_IMAGE, + NULL); placement = NAUTILUS_BACKGROUND_TILED; /* non-tiled only avail for desktop, at least for now */ combine = FALSE; /* only from theme, at least for now */ /* if there's none, read the default from the theme */ if (color == NULL && image == NULL) { - nautilus_directory_background_get_default_settings ( - nautilus_directory_background_peek_theme_source (background), - &color, &image, &placement, &combine); + nautilus_file_background_get_default_settings + (nautilus_file_background_peek_theme_source (background), + &color, &image, &placement, &combine); } } @@ -654,7 +657,7 @@ saved_settings_changed_callback (NautilusDirectory *directory, */ gtk_signal_handler_block_by_func (GTK_OBJECT (background), background_changed_callback, - directory); + file); nautilus_background_set_color (background, color); nautilus_background_set_image_uri (background, image); @@ -663,8 +666,8 @@ saved_settings_changed_callback (NautilusDirectory *directory, /* Unblock the handler. */ gtk_signal_handler_unblock_by_func (GTK_OBJECT (background), - background_changed_callback, - directory); + background_changed_callback, + file); g_free (color); g_free (image); @@ -672,190 +675,180 @@ saved_settings_changed_callback (NautilusDirectory *directory, /* handle the theme changing */ static void -nautilus_directory_background_theme_changed (gpointer user_data) +nautilus_file_background_theme_changed (gpointer user_data) { - NautilusDirectory *directory; + NautilusFile *file; NautilusBackground *background; background = NAUTILUS_BACKGROUND (user_data); - directory = gtk_object_get_data (GTK_OBJECT (background), "nautilus_background_directory"); - if (directory) { - saved_settings_changed_callback (directory, background); + file = gtk_object_get_data (GTK_OBJECT (background), "nautilus_background_file"); + if (file) { + saved_settings_changed_callback (file, background); } } /* handle the background reset signal by setting values from the current theme */ static void background_reset_callback (NautilusBackground *background, - NautilusDirectory *directory) + NautilusFile *file) { - if (nautilus_directory_background_is_desktop (background)) { - nautilus_directory_background_write_desktop_default_settings (); + if (nautilus_file_background_is_desktop (background)) { + nautilus_file_background_write_desktop_default_settings (); } else { /* Block the other handler while we are writing metadata so it doesn't * try to change the background. */ - gtk_signal_handler_block_by_func (GTK_OBJECT (directory), + gtk_signal_handler_block_by_func (GTK_OBJECT (file), saved_settings_changed_callback, background); /* reset the metadata */ - nautilus_directory_set_metadata (directory, - NAUTILUS_METADATA_KEY_DIRECTORY_BACKGROUND_COLOR, - NULL, - NULL); - - nautilus_directory_set_metadata (directory, - NAUTILUS_METADATA_KEY_DIRECTORY_BACKGROUND_IMAGE, - NULL, - NULL); + nautilus_file_set_metadata (file, + NAUTILUS_METADATA_KEY_LOCATION_BACKGROUND_COLOR, + NULL, + NULL); + + nautilus_file_set_metadata (file, + NAUTILUS_METADATA_KEY_LOCATION_BACKGROUND_IMAGE, + NULL, + NULL); /* Unblock the handler. */ - gtk_signal_handler_unblock_by_func (GTK_OBJECT (directory), + gtk_signal_handler_unblock_by_func (GTK_OBJECT (file), saved_settings_changed_callback, background); } - saved_settings_changed_callback (directory, background); + saved_settings_changed_callback (file, background); /* We don't want the default reset handler running. * It will set color and image_uri to NULL. */ gtk_signal_emit_stop_by_name (GTK_OBJECT (background), "reset"); - if (nautilus_directory_background_is_desktop (background)) { - nautilus_directory_update_root_window (background); + if (nautilus_file_background_is_desktop (background)) { + nautilus_file_update_root_window (background); } } /* handle the background destroyed signal */ static void background_destroyed_callback (NautilusBackground *background, - NautilusDirectory *directory) + NautilusFile *file) { - gtk_signal_disconnect_by_func (GTK_OBJECT (directory), + gtk_signal_disconnect_by_func (GTK_OBJECT (file), GTK_SIGNAL_FUNC (saved_settings_changed_callback), background); - nautilus_directory_file_monitor_remove (directory, background); + nautilus_file_monitor_remove (file, background); nautilus_preferences_remove_callback (NAUTILUS_PREFERENCES_THEME, - nautilus_directory_background_theme_changed, + nautilus_file_background_theme_changed, background); } -/* key routine that hooks up a background and directory */ +/* key routine that hooks up a background and location */ void -nautilus_connect_background_to_directory_metadata (GtkWidget *widget, - NautilusDirectory *directory) +nautilus_connect_background_to_file_metadata (GtkWidget *widget, + NautilusFile *file) { NautilusBackground *background; - gpointer old_directory; + gpointer old_file; GList *attributes; /* Get at the background object we'll be connecting. */ background = nautilus_get_widget_background (widget); - /* Check if it is already connected. */ - old_directory = gtk_object_get_data (GTK_OBJECT (background), "nautilus_background_directory"); - if (old_directory == directory) { + old_file = gtk_object_get_data (GTK_OBJECT (background), "nautilus_background_file"); + if (old_file == file) { return; } /* Disconnect old signal handlers. */ - if (old_directory != NULL) { - g_assert (NAUTILUS_IS_DIRECTORY (old_directory)); + if (old_file != NULL) { + g_assert (NAUTILUS_IS_FILE (old_file)); gtk_signal_disconnect_by_func (GTK_OBJECT (background), GTK_SIGNAL_FUNC (background_changed_callback), - old_directory); + old_file); gtk_signal_disconnect_by_func (GTK_OBJECT (background), GTK_SIGNAL_FUNC (background_destroyed_callback), - old_directory); + old_file); gtk_signal_disconnect_by_func (GTK_OBJECT (background), GTK_SIGNAL_FUNC (background_reset_callback), - old_directory); - gtk_signal_disconnect_by_func (GTK_OBJECT (old_directory), + old_file); + gtk_signal_disconnect_by_func (GTK_OBJECT (old_file), GTK_SIGNAL_FUNC (saved_settings_changed_callback), background); - nautilus_directory_file_monitor_remove (old_directory, background); + nautilus_file_monitor_remove (old_file, background); nautilus_preferences_remove_callback (NAUTILUS_PREFERENCES_THEME, - nautilus_directory_background_theme_changed, - background); + nautilus_file_background_theme_changed, + background); } /* Attach the new directory. */ - nautilus_directory_ref (directory); + nautilus_file_ref (file); gtk_object_set_data_full (GTK_OBJECT (background), - "nautilus_background_directory", - directory, - (GtkDestroyNotify) nautilus_directory_unref); + "nautilus_background_file", + file, + (GtkDestroyNotify) nautilus_file_unref); /* Connect new signal handlers. */ - if (directory != NULL) { + if (file != NULL) { gtk_signal_connect (GTK_OBJECT (background), "settings_changed", GTK_SIGNAL_FUNC (background_changed_callback), - directory); + file); gtk_signal_connect (GTK_OBJECT (background), "destroy", GTK_SIGNAL_FUNC (background_destroyed_callback), - directory); + file); gtk_signal_connect (GTK_OBJECT (background), "reset", GTK_SIGNAL_FUNC (background_reset_callback), - directory); - gtk_signal_connect (GTK_OBJECT (directory), - "metadata_changed", + file); + gtk_signal_connect (GTK_OBJECT (file), + "changed", GTK_SIGNAL_FUNC (saved_settings_changed_callback), background); - /* arrange to receive directory metadata */ - /* FIXME bugzilla.eazel.com 2551: - * This says we want to monitor the file - * metadata, and it has the side effect of monitoring - * the file list. We want to monitor the directory - * metadata, which would not mean monitoring the file - * list. This may require a change to the - * NautilusDirectory API. - */ - + /* arrange to receive file metadata */ attributes = g_list_append (NULL, NAUTILUS_FILE_ATTRIBUTE_METADATA); - nautilus_directory_file_monitor_add (directory, - background, - attributes, FALSE); + nautilus_file_monitor_add (file, + background, + attributes); g_list_free (attributes); /* arrange for notification when the theme changes */ nautilus_preferences_add_callback (NAUTILUS_PREFERENCES_THEME, - nautilus_directory_background_theme_changed, background); + nautilus_file_background_theme_changed, background); } - /* Update the background based on the directory metadata. */ - saved_settings_changed_callback (directory, background); + /* Update the background based on the file metadata. */ + saved_settings_changed_callback (file, background); } void -nautilus_connect_desktop_background_to_directory_metadata (GtkWidget *widget, - NautilusDirectory *directory) +nautilus_connect_desktop_background_to_file_metadata (GtkWidget *widget, + NautilusFile *file) { - nautilus_directory_background_set_desktop (nautilus_get_widget_background (widget)); + nautilus_file_background_set_desktop (nautilus_get_widget_background (widget)); /* Strictly speaking, we don't need to know about metadata changes, since * the desktop setting aren't stored there. But, hooking up to metadata * changes is actually a small part of what this fn does, and we do need * the other stuff (hooked up to background & theme changes). Being notified - * of metadata changes on the directory is a waste, but won't hurt, so I don't + * of metadata changes on the file is a waste, but won't hurt, so I don't * think it's worth refactoring the fn at this point. */ - nautilus_connect_background_to_directory_metadata (widget, directory); + nautilus_connect_background_to_file_metadata (widget, file); } void -nautilus_connect_background_to_directory_metadata_by_uri (GtkWidget *widget, - const char *uri) +nautilus_connect_background_to_file_metadata_by_uri (GtkWidget *widget, + const char *uri) { - NautilusDirectory *directory; - directory = nautilus_directory_get (uri); - nautilus_connect_background_to_directory_metadata (widget, directory); - nautilus_directory_unref (directory); + NautilusFile *file; + file = nautilus_file_get (uri); + nautilus_connect_background_to_file_metadata (widget, file); + nautilus_file_unref (file); } diff --git a/libnautilus-private/nautilus-directory-background.h b/libnautilus-private/nautilus-directory-background.h index 46d2032d6..9adf6ea4d 100644 --- a/libnautilus-private/nautilus-directory-background.h +++ b/libnautilus-private/nautilus-directory-background.h @@ -25,14 +25,14 @@ */ #include <gtk/gtkwidget.h> -#include "nautilus-directory.h" +#include "nautilus-file.h" #include "nautilus-background.h" -void nautilus_connect_background_to_directory_metadata (GtkWidget *widget, - NautilusDirectory *directory); -void nautilus_connect_desktop_background_to_directory_metadata (GtkWidget *widget, - NautilusDirectory *directory); -void nautilus_connect_background_to_directory_metadata_by_uri (GtkWidget *widget, - const char *uri); -gboolean nautilus_directory_background_is_set (NautilusBackground *background); +void nautilus_connect_background_to_file_metadata (GtkWidget *widget, + NautilusFile *file); +void nautilus_connect_desktop_background_to_file_metadata (GtkWidget *widget, + NautilusFile *file); +void nautilus_connect_background_to_file_metadata_by_uri (GtkWidget *widget, + const char *uri); +gboolean nautilus_file_background_is_set (NautilusBackground *background); diff --git a/libnautilus-private/nautilus-directory-metafile.c b/libnautilus-private/nautilus-directory-metafile.c index 1e205e6cd..83d164961 100644 --- a/libnautilus-private/nautilus-directory-metafile.c +++ b/libnautilus-private/nautilus-directory-metafile.c @@ -172,13 +172,9 @@ set_metadata_string_in_metafile (NautilusDirectory *directory, xmlAttr *property_node; /* If the data in the metafile is already correct, do nothing. */ - if (file_name == NULL) { - old_metadata = nautilus_directory_get_metadata - (directory, key, default_metadata); - } else { - old_metadata = nautilus_directory_get_file_metadata - (directory, file_name, key, default_metadata); - } + old_metadata = nautilus_directory_get_file_metadata + (directory, file_name, key, default_metadata); + old_metadata_matches = nautilus_strcmp (old_metadata, metadata) == 0; g_free (old_metadata); if (old_metadata_matches) { @@ -536,29 +532,6 @@ nautilus_directory_metafile_destroy (NautilusDirectory *directory) destroy_metadata_changes_hash_table (directory->details->metadata_changes); } -char * -nautilus_directory_get_metadata (NautilusDirectory *directory, - const char *key, - const char *default_metadata) -{ - g_return_val_if_fail (key != NULL, g_strdup (default_metadata)); - g_return_val_if_fail (key[0] != '\0', g_strdup (default_metadata)); - - /* It's legal to call this on a NULL directory. */ - if (directory == NULL) { - return g_strdup (default_metadata); - } - - g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), g_strdup (default_metadata)); - - if (directory->details->metafile_read) { - return get_metadata_string_from_metafile - (directory, NULL, key, default_metadata); - } else { - return get_metadata_string_from_table - (directory, NULL, key, default_metadata); - } -} char * nautilus_directory_get_file_metadata (NautilusDirectory *directory, @@ -582,31 +555,6 @@ nautilus_directory_get_file_metadata (NautilusDirectory *directory, } -GList * -nautilus_directory_get_metadata_list (NautilusDirectory *directory, - const char *list_key, - const char *list_subkey) -{ - g_return_val_if_fail (list_key != NULL, NULL); - g_return_val_if_fail (list_key[0] != '\0', NULL); - g_return_val_if_fail (list_subkey != NULL, NULL); - g_return_val_if_fail (list_subkey[0] != '\0', NULL); - - /* It's legal to call this on a NULL directory. */ - if (directory == NULL) { - return NULL; - } - - g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), NULL); - - if (directory->details->metafile_read) { - return get_metadata_list_from_metafile - (directory, NULL, list_key, list_subkey); - } else { - return get_metadata_list_from_table - (directory, NULL, list_key, list_subkey); - } -} GList * nautilus_directory_get_file_metadata_list (NautilusDirectory *directory, @@ -631,58 +579,6 @@ nautilus_directory_get_file_metadata_list (NautilusDirectory *directory, } } -void -nautilus_directory_set_metadata (NautilusDirectory *directory, - const char *key, - const char *default_metadata, - const char *metadata) -{ - MetadataValue *value; - - g_return_if_fail (NAUTILUS_IS_DIRECTORY (directory)); - g_return_if_fail (key != NULL); - g_return_if_fail (key[0] != '\0'); - - if (directory->details->metafile_read) { - if (set_metadata_string_in_metafile (directory, NULL, key, - default_metadata, metadata)) { - nautilus_directory_emit_metadata_changed (directory); - } - } else { - value = metadata_value_new (default_metadata, metadata); - if (set_metadata_eat_value (directory, NULL, key, NULL, value)) { - nautilus_directory_emit_metadata_changed (directory); - } - } -} - -void -nautilus_directory_set_metadata_list (NautilusDirectory *directory, - const char *list_key, - const char *list_subkey, - GList *list) -{ - MetadataValue *value; - - g_return_if_fail (NAUTILUS_IS_DIRECTORY (directory)); - g_return_if_fail (list_key != NULL); - g_return_if_fail (list_key[0] != '\0'); - g_return_if_fail (list_subkey != NULL); - g_return_if_fail (list_subkey[0] != '\0'); - - if (directory->details->metafile_read) { - if (set_metadata_list_in_metafile (directory, NULL, - list_key, list_subkey, list)) { - nautilus_directory_emit_metadata_changed (directory); - } - } else { - value = metadata_value_new_list (list); - if (set_metadata_eat_value (directory, NULL, - list_key, list_subkey, value)) { - nautilus_directory_emit_metadata_changed (directory); - } - } -} gboolean nautilus_directory_set_file_metadata (NautilusDirectory *directory, @@ -831,16 +727,19 @@ nautilus_directory_metafile_apply_pending_changes (NautilusDirectory *directory) directory->details->metadata_changes = NULL; } + + gboolean -nautilus_directory_get_boolean_metadata (NautilusDirectory *directory, - const char *key, - gboolean default_metadata) +nautilus_directory_get_boolean_file_metadata (NautilusDirectory *directory, + const char *file_name, + const char *key, + gboolean default_metadata) { char *result_as_string; gboolean result; - result_as_string = nautilus_directory_get_metadata - (directory, key, + result_as_string = nautilus_directory_get_file_metadata + (directory, file_name, key, default_metadata ? "true" : "false"); g_strdown (result_as_string); @@ -859,30 +758,32 @@ nautilus_directory_get_boolean_metadata (NautilusDirectory *directory, return result; } -void -nautilus_directory_set_boolean_metadata (NautilusDirectory *directory, - const char *key, - gboolean default_metadata, - gboolean metadata) -{ - nautilus_directory_set_metadata - (directory, key, +gboolean +nautilus_directory_set_boolean_file_metadata (NautilusDirectory *directory, + const char *file_name, + const char *key, + gboolean default_metadata, + gboolean metadata) +{ + return nautilus_directory_set_file_metadata + (directory, file_name, key, default_metadata ? "true" : "false", metadata ? "true" : "false"); } int -nautilus_directory_get_integer_metadata (NautilusDirectory *directory, - const char *key, - int default_metadata) +nautilus_directory_get_integer_file_metadata (NautilusDirectory *directory, + const char *file_name, + const char *key, + int default_metadata) { char *result_as_string; char *default_as_string; int result; default_as_string = g_strdup_printf ("%d", default_metadata); - result_as_string = nautilus_directory_get_metadata - (directory, key, default_as_string); + result_as_string = nautilus_directory_get_file_metadata + (directory, file_name, key, default_as_string); /* Handle oddball case of non-existent directory */ if (result_as_string == NULL) { @@ -897,11 +798,12 @@ nautilus_directory_get_integer_metadata (NautilusDirectory *directory, } -void -nautilus_directory_set_integer_metadata (NautilusDirectory *directory, - const char *key, - int default_metadata, - int metadata) +gboolean +nautilus_directory_set_integer_file_metadata (NautilusDirectory *directory, + const char *file_name, + const char *key, + int default_metadata, + int metadata) { char *value_as_string; char *default_as_string; @@ -909,14 +811,16 @@ nautilus_directory_set_integer_metadata (NautilusDirectory *directory, value_as_string = g_strdup_printf ("%d", metadata); default_as_string = g_strdup_printf ("%d", default_metadata); - nautilus_directory_set_metadata - (directory, key, + return nautilus_directory_set_file_metadata + (directory, file_name, key, default_as_string, value_as_string); g_free (value_as_string); g_free (default_as_string); } + + static void copy_file_metadata_for_key (NautilusDirectory *source_directory, const char *source_file_name, diff --git a/libnautilus-private/nautilus-directory-metafile.h b/libnautilus-private/nautilus-directory-metafile.h index 330ac9aa1..3aa6f254c 100644 --- a/libnautilus-private/nautilus-directory-metafile.h +++ b/libnautilus-private/nautilus-directory-metafile.h @@ -34,6 +34,15 @@ GList * nautilus_directory_get_file_metadata_list (NautilusDirectory *d const char *file_name, const char *list_key, const char *list_subkey); +gboolean nautilus_directory_get_boolean_file_metadata (NautilusDirectory *directory, + const char *file_name, + const char *key, + gboolean default_metadata); +int nautilus_directory_get_integer_file_metadata (NautilusDirectory *directory, + const char *file_name, + const char *key, + int default_metadata); + gboolean nautilus_directory_set_file_metadata (NautilusDirectory *directory, const char *file_name, const char *key, @@ -44,6 +53,17 @@ gboolean nautilus_directory_set_file_metadata_list (NautilusDirectory *d const char *list_key, const char *list_subkey, GList *list); +gboolean nautilus_directory_set_boolean_file_metadata (NautilusDirectory *directory, + const char *file_name, + const char *key, + gboolean default_metadata, + gboolean metadata); +gboolean nautilus_directory_set_integer_file_metadata (NautilusDirectory *directory, + const char *file_name, + const char *key, + int default_metadata, + int metadata); + void nautilus_directory_copy_file_metadata (NautilusDirectory *source_directory, const char *source_file_name, NautilusDirectory *destination_directory, diff --git a/libnautilus-private/nautilus-directory.c b/libnautilus-private/nautilus-directory.c index 7ecbcf8af..5ab99d517 100644 --- a/libnautilus-private/nautilus-directory.c +++ b/libnautilus-private/nautilus-directory.c @@ -46,7 +46,6 @@ enum { FILES_ADDED, FILES_CHANGED, - METADATA_CHANGED, DONE_LOADING, LAST_SIGNAL }; @@ -99,13 +98,6 @@ nautilus_directory_initialize_class (NautilusDirectoryClass *klass) GTK_SIGNAL_OFFSET (NautilusDirectoryClass, files_changed), gtk_marshal_NONE__POINTER, GTK_TYPE_NONE, 1, GTK_TYPE_POINTER); - signals[METADATA_CHANGED] = - gtk_signal_new ("metadata_changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (NautilusDirectoryClass, metadata_changed), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); signals[DONE_LOADING] = gtk_signal_new ("done_loading", GTK_RUN_LAST, @@ -659,10 +651,6 @@ nautilus_directory_emit_change_signals_deep (NautilusDirectory *directory, void nautilus_directory_emit_metadata_changed (NautilusDirectory *directory) { - /* Tell that the directory metadata has changed. */ - gtk_signal_emit (GTK_OBJECT (directory), - signals[METADATA_CHANGED]); - /* Say that all the files have changed. * We could optimize this to only mention files that * have metadata, but this is a fine rough cut for now. @@ -1284,7 +1272,6 @@ static void got_metadata_callback (NautilusDirectory *directory, GList *files, gpointer callback_data) { g_assert (NAUTILUS_IS_DIRECTORY (directory)); - g_assert (files == NULL); g_assert (callback_data == &data_dummy); got_metadata_flag = TRUE; @@ -1311,9 +1298,11 @@ void nautilus_self_check_directory (void) { NautilusDirectory *directory; + NautilusFile *file; GList *attributes; directory = nautilus_directory_get ("file:///etc"); + file = nautilus_file_get ("file:///etc/passwd"); NAUTILUS_CHECK_INTEGER_RESULT (g_hash_table_size (directories), 1); @@ -1332,23 +1321,23 @@ nautilus_self_check_directory (void) gtk_main_iteration (); } - nautilus_directory_set_metadata (directory, "TEST", "default", "value"); - NAUTILUS_CHECK_STRING_RESULT (nautilus_directory_get_metadata (directory, "TEST", "default"), "value"); + nautilus_file_set_metadata (file, "TEST", "default", "value"); + NAUTILUS_CHECK_STRING_RESULT (nautilus_file_get_metadata (file, "TEST", "default"), "value"); - nautilus_directory_set_boolean_metadata (directory, "TEST_BOOLEAN", TRUE, TRUE); - NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_directory_get_boolean_metadata (directory, "TEST_BOOLEAN", TRUE), TRUE); - nautilus_directory_set_boolean_metadata (directory, "TEST_BOOLEAN", TRUE, FALSE); - NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_directory_get_boolean_metadata (directory, "TEST_BOOLEAN", TRUE), FALSE); - NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_directory_get_boolean_metadata (NULL, "TEST_BOOLEAN", TRUE), TRUE); + nautilus_file_set_boolean_metadata (file, "TEST_BOOLEAN", TRUE, TRUE); + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_file_get_boolean_metadata (file, "TEST_BOOLEAN", TRUE), TRUE); + nautilus_file_set_boolean_metadata (file, "TEST_BOOLEAN", TRUE, FALSE); + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_file_get_boolean_metadata (file, "TEST_BOOLEAN", TRUE), FALSE); + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_file_get_boolean_metadata (NULL, "TEST_BOOLEAN", TRUE), TRUE); - nautilus_directory_set_integer_metadata (directory, "TEST_INTEGER", 0, 17); - NAUTILUS_CHECK_INTEGER_RESULT (nautilus_directory_get_integer_metadata (directory, "TEST_INTEGER", 0), 17); - nautilus_directory_set_integer_metadata (directory, "TEST_INTEGER", 0, -1); - NAUTILUS_CHECK_INTEGER_RESULT (nautilus_directory_get_integer_metadata (directory, "TEST_INTEGER", 0), -1); - nautilus_directory_set_integer_metadata (directory, "TEST_INTEGER", 42, 42); - NAUTILUS_CHECK_INTEGER_RESULT (nautilus_directory_get_integer_metadata (directory, "TEST_INTEGER", 42), 42); - NAUTILUS_CHECK_INTEGER_RESULT (nautilus_directory_get_integer_metadata (NULL, "TEST_INTEGER", 42), 42); - NAUTILUS_CHECK_INTEGER_RESULT (nautilus_directory_get_integer_metadata (directory, "NONEXISTENT_KEY", 42), 42); + nautilus_file_set_integer_metadata (file, "TEST_INTEGER", 0, 17); + NAUTILUS_CHECK_INTEGER_RESULT (nautilus_file_get_integer_metadata (file, "TEST_INTEGER", 0), 17); + nautilus_file_set_integer_metadata (file, "TEST_INTEGER", 0, -1); + NAUTILUS_CHECK_INTEGER_RESULT (nautilus_file_get_integer_metadata (file, "TEST_INTEGER", 0), -1); + nautilus_file_set_integer_metadata (file, "TEST_INTEGER", 42, 42); + NAUTILUS_CHECK_INTEGER_RESULT (nautilus_file_get_integer_metadata (file, "TEST_INTEGER", 42), 42); + NAUTILUS_CHECK_INTEGER_RESULT (nautilus_file_get_integer_metadata (NULL, "TEST_INTEGER", 42), 42); + NAUTILUS_CHECK_INTEGER_RESULT (nautilus_file_get_integer_metadata (file, "NONEXISTENT_KEY", 42), 42); NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_directory_get ("file:///etc") == directory, TRUE); nautilus_directory_unref (directory); @@ -1359,6 +1348,8 @@ nautilus_self_check_directory (void) NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_directory_get ("file:///etc////") == directory, TRUE); nautilus_directory_unref (directory); + nautilus_file_unref (file); + nautilus_directory_file_monitor_remove (directory, &data_dummy); nautilus_directory_unref (directory); @@ -1399,7 +1390,11 @@ nautilus_self_check_directory (void) NAUTILUS_CHECK_INTEGER_RESULT (g_hash_table_size (directories), 1); - NAUTILUS_CHECK_STRING_RESULT (nautilus_directory_get_metadata (directory, "TEST", "default"), "value"); + file = nautilus_file_get ("file:///etc/passwd"); + + NAUTILUS_CHECK_STRING_RESULT (nautilus_file_get_metadata (file, "TEST", "default"), "value"); + + nautilus_file_unref (file); nautilus_directory_unref (directory); diff --git a/libnautilus-private/nautilus-directory.h b/libnautilus-private/nautilus-directory.h index 671b3a686..8d895d59d 100644 --- a/libnautilus-private/nautilus-directory.h +++ b/libnautilus-private/nautilus-directory.h @@ -93,12 +93,6 @@ typedef struct void (* files_changed) (NautilusDirectory *directory, GList *changed_files); - /* The metadata_changed signal is emitted when changes to the metadata - * for the directory itself are made. Changes to file metadata just - * result in calls to files_changed. - */ - void (* metadata_changed) (NautilusDirectory *directory); - /* The done_loading signal is emitted when a directory load * request completes. This is needed because, at least in the * case where the directory is empty, the caller will receive @@ -169,37 +163,6 @@ void nautilus_directory_cancel_callback (NautilusDirectory NautilusDirectoryCallback callback, gpointer callback_data); -/* Getting and setting metadata. */ -char * nautilus_directory_get_metadata (NautilusDirectory *directory, - const char *key, - const char *default_metadata); -GList *nautilus_directory_get_metadata_list (NautilusDirectory *directory, - const char *list_key, - const char *list_subkey); -void nautilus_directory_set_metadata (NautilusDirectory *directory, - const char *key, - const char *default_metadata, - const char *metadata); -void nautilus_directory_set_metadata_list (NautilusDirectory *directory, - const char *list_key, - const char *list_subkey, - GList *list); - -/* Covers for common data types. */ -gboolean nautilus_directory_get_boolean_metadata (NautilusDirectory *directory, - const char *key, - gboolean default_metadata); -void nautilus_directory_set_boolean_metadata (NautilusDirectory *directory, - const char *key, - gboolean default_metadata, - gboolean metadata); -int nautilus_directory_get_integer_metadata (NautilusDirectory *directory, - const char *key, - int default_metadata); -void nautilus_directory_set_integer_metadata (NautilusDirectory *directory, - const char *key, - int default_metadata, - int metadata); /* Monitor the files in a directory. */ void nautilus_directory_file_monitor_add (NautilusDirectory *directory, diff --git a/libnautilus-private/nautilus-file.c b/libnautilus-private/nautilus-file.c index 8aa3b889e..f01b075e4 100644 --- a/libnautilus-private/nautilus-file.c +++ b/libnautilus-private/nautilus-file.c @@ -1661,6 +1661,87 @@ nautilus_file_set_metadata_list (NautilusFile *file, } } + +gboolean +nautilus_file_get_boolean_metadata (NautilusFile *file, + const char *key, + gboolean default_metadata) +{ + g_return_val_if_fail (key != NULL, default_metadata); + g_return_val_if_fail (key[0] != '\0', default_metadata); + if (file == NULL) { + return default_metadata; + } + g_return_val_if_fail (NAUTILUS_IS_FILE (file), default_metadata); + + return nautilus_directory_get_boolean_file_metadata + (file->details->directory, + file->details->name, + key, + default_metadata); +} + +int +nautilus_file_get_integer_metadata (NautilusFile *file, + const char *key, + int default_metadata) +{ + g_return_val_if_fail (key != NULL, default_metadata); + g_return_val_if_fail (key[0] != '\0', default_metadata); + if (file == NULL) { + return default_metadata; + } + g_return_val_if_fail (NAUTILUS_IS_FILE (file), default_metadata); + + return nautilus_directory_get_integer_file_metadata + (file->details->directory, + file->details->name, + key, + default_metadata); +} + + +void +nautilus_file_set_boolean_metadata (NautilusFile *file, + const char *key, + gboolean default_metadata, + gboolean metadata) +{ + g_return_if_fail (NAUTILUS_IS_FILE (file)); + g_return_if_fail (key != NULL); + g_return_if_fail (key[0] != '\0'); + + if (nautilus_directory_set_boolean_file_metadata (file->details->directory, + file->details->name, + key, + default_metadata, + metadata)) { + nautilus_file_changed (file); + } +} + +void +nautilus_file_set_integer_metadata (NautilusFile *file, + const char *key, + int default_metadata, + int metadata) +{ + g_return_if_fail (NAUTILUS_IS_FILE (file)); + g_return_if_fail (key != NULL); + g_return_if_fail (key[0] != '\0'); + + if (nautilus_directory_set_integer_file_metadata (file->details->directory, + file->details->name, + key, + default_metadata, + metadata)) { + nautilus_file_changed (file); + } +} + + + + char * nautilus_file_get_name (NautilusFile *file) { diff --git a/libnautilus-private/nautilus-file.h b/libnautilus-private/nautilus-file.h index 70882c926..b8bf1c191 100644 --- a/libnautilus-private/nautilus-file.h +++ b/libnautilus-private/nautilus-file.h @@ -213,6 +213,23 @@ void nautilus_file_set_metadata_list (NautilusFile const char *list_subkey, GList *list); +/* Covers for common data types. */ +gboolean nautilus_file_get_boolean_metadata (NautilusFile *file, + const char *key, + gboolean default_metadata); +void nautilus_file_set_boolean_metadata (NautilusFile *file, + const char *key, + gboolean default_metadata, + gboolean metadata); +int nautilus_file_get_integer_metadata (NautilusFile *file, + const char *key, + int default_metadata); +void nautilus_file_set_integer_metadata (NautilusFile *file, + const char *key, + int default_metadata, + int metadata); + + /* Attributes for file objects as user-displayable strings. */ char * nautilus_file_get_string_attribute (NautilusFile *file, const char *attribute_name); diff --git a/libnautilus-private/nautilus-metadata.h b/libnautilus-private/nautilus-metadata.h index c4c1c4500..3de64b564 100644 --- a/libnautilus-private/nautilus-metadata.h +++ b/libnautilus-private/nautilus-metadata.h @@ -29,7 +29,7 @@ * should define its key here, so we can keep track of the whole set easily. */ -/* Per-directory */ +/* Per-file */ #define NAUTILUS_METADATA_KEY_CONTENT_VIEWS "CONTENT_VIEWS" @@ -45,10 +45,8 @@ #define NAUTILUS_METADATA_KEY_EXPLICIT_COMPONENT "EXPLICIT_CONTENT_VIEW" #define NAUTILUS_METADATA_SUBKEY_COMPONENT_IID "IID" -#define NAUTILUS_METADATA_KEY_WINDOW_GEOMETRY "WINDOW_GEOMETRY" - -#define NAUTILUS_METADATA_KEY_DIRECTORY_BACKGROUND_COLOR "BACKGROUND_COLOR" -#define NAUTILUS_METADATA_KEY_DIRECTORY_BACKGROUND_IMAGE "BACKGROUND_TILE_IMAGE" +#define NAUTILUS_METADATA_KEY_LOCATION_BACKGROUND_COLOR "BACKGROUND_COLOR" +#define NAUTILUS_METADATA_KEY_LOCATION_BACKGROUND_IMAGE "BACKGROUND_TILE_IMAGE" #define NAUTILUS_METADATA_KEY_ICON_VIEW_ZOOM_LEVEL "ICONS_ZOOM_LEVEL" #define NAUTILUS_METADATA_KEY_ICON_VIEW_AUTO_LAYOUT "ICONS_AUTO_LAYOUT" @@ -60,14 +58,14 @@ #define NAUTILUS_METADATA_KEY_LIST_VIEW_SORT_COLUMN "LIST_SORT_COLUMN" #define NAUTILUS_METADATA_KEY_LIST_VIEW_SORT_REVERSED "LIST_SORT_REVERSED" +#define NAUTILUS_METADATA_KEY_WINDOW_GEOMETRY "WINDOW_GEOMETRY" + #define NAUTILUS_METADATA_KEY_SIDEBAR_BACKGROUND_COLOR "SIDEBAR_BACKGROUND_COLOR" #define NAUTILUS_METADATA_KEY_SIDEBAR_BACKGROUND_IMAGE "SIDEBAR_BACKGROUND_TILE_IMAGE" #define NAUTILUS_METADATA_KEY_SIDEBAR_BUTTONS "SIDEBAR_BUTTONS" #define NAUTILUS_METADATA_KEY_SIDEBAR_TAB_COLOR "SIDEBAR_TAB_COLOR" #define NAUTILUS_METADATA_KEY_SIDEBAR_TITLE_TAB_COLOR "SIDEBAR_TITLE_TAB_COLOR" -/* Per-file */ - #define NAUTILUS_METADATA_KEY_NOTES "NOTES" #define NAUTILUS_METADATA_KEY_ANNOTATION "ANNOTATION" #define NAUTILUS_METADATA_KEY_ICON_POSITION "ICON_POSITION" diff --git a/libnautilus-private/nautilus-mime-actions.c b/libnautilus-private/nautilus-mime-actions.c index 60fe4b3f3..2533a9ac1 100644 --- a/libnautilus-private/nautilus-mime-actions.c +++ b/libnautilus-private/nautilus-mime-actions.c @@ -53,7 +53,7 @@ static char *extract_prefix_add_suffix (const char const char *suffix); static char *mime_type_get_supertype (const char *mime_type); static char *uri_string_get_scheme (const char *uri_string); -static GList *get_explicit_content_view_iids_from_metafile (NautilusDirectory *directory); +static GList *get_explicit_content_view_iids_from_metafile (NautilusFile *file); static char *make_oaf_query_for_explicit_content_view_iids (GList *view_iids); static char *make_oaf_query_with_known_mime_type (const char *mime_type, const char *uri_scheme, @@ -99,9 +99,8 @@ is_known_mime_type (const char *mime_type) } static void -nautilus_directory_wait_for_metadata (NautilusDirectory *directory) +nautilus_file_wait_for_metadata (NautilusFile *file) { - GList *file_list; GList *attributes; /* When nautilus_directory_wait_until_ready is called this way, it @@ -111,9 +110,8 @@ nautilus_directory_wait_for_metadata (NautilusDirectory *directory) */ attributes = g_list_append (NULL, NAUTILUS_FILE_ATTRIBUTE_METADATA); - file_list = nautilus_directory_wait_until_ready (directory, attributes); + nautilus_file_wait_until_ready (file, attributes); g_list_free (attributes); - nautilus_file_list_free (file_list); } GnomeVFSMimeActionType @@ -124,9 +122,10 @@ nautilus_mime_get_default_action_type_for_uri (NautilusDirectory *directory, char *action_type_string; GnomeVFSMimeActionType action_type; - nautilus_directory_wait_for_metadata (directory); - action_type_string = nautilus_directory_get_metadata - (directory, NAUTILUS_METADATA_KEY_DEFAULT_ACTION_TYPE, NULL); + nautilus_file_wait_for_metadata (file); + + action_type_string = nautilus_file_get_metadata + (file, NAUTILUS_METADATA_KEY_DEFAULT_ACTION_TYPE, NULL); if (action_type_string == NULL) { mime_type = get_mime_type_from_file (file); @@ -194,9 +193,9 @@ nautilus_mime_get_default_application_for_uri_internal (NautilusDirectory *direc used_user_chosen_info = TRUE; - nautilus_directory_wait_for_metadata (directory); - default_application_string = nautilus_directory_get_metadata - (directory, NAUTILUS_METADATA_KEY_DEFAULT_APPLICATION, NULL); + nautilus_file_wait_for_metadata (file); + default_application_string = nautilus_file_get_metadata + (file, NAUTILUS_METADATA_KEY_DEFAULT_APPLICATION, NULL); if (default_application_string == NULL) { mime_type = get_mime_type_from_file (file); @@ -278,17 +277,18 @@ nautilus_mime_get_default_component_for_uri_internal (NautilusDirectory *directo g_free (uri); + nautilus_file_wait_for_metadata (file); + explicit_iids = get_explicit_content_view_iids_from_metafile (file); + /* Arrange for all the file attributes we will need. */ attributes = NULL; attributes = g_list_prepend (attributes, NAUTILUS_FILE_ATTRIBUTE_MIME_TYPE); - attributes = g_list_append (NULL, NAUTILUS_FILE_ATTRIBUTE_METADATA); - files = nautilus_directory_wait_until_ready (directory, attributes); - default_component_string = nautilus_directory_get_metadata - (directory, NAUTILUS_METADATA_KEY_DEFAULT_COMPONENT, NULL); - explicit_iids = get_explicit_content_view_iids_from_metafile (directory); g_list_free (attributes); + default_component_string = nautilus_file_get_metadata + (file, NAUTILUS_METADATA_KEY_DEFAULT_COMPONENT, NULL); + if (default_component_string == NULL && is_known_mime_type (mime_type)) { mime_default = gnome_vfs_mime_get_default_component (mime_type); if (mime_default != NULL) { @@ -438,13 +438,13 @@ nautilus_mime_get_short_list_applications_for_uri (NautilusDirectory *directory, CORBA_exception_init (&ev); - nautilus_directory_wait_for_metadata (directory); - metadata_application_add_ids = nautilus_directory_get_metadata_list - (directory, + nautilus_file_wait_for_metadata (file); + metadata_application_add_ids = nautilus_file_get_metadata_list + (file, NAUTILUS_METADATA_KEY_SHORT_LIST_APPLICATION_ADD, NAUTILUS_METADATA_SUBKEY_APPLICATION_ID); - metadata_application_remove_ids = nautilus_directory_get_metadata_list - (directory, + metadata_application_remove_ids = nautilus_file_get_metadata_list + (file, NAUTILUS_METADATA_KEY_SHORT_LIST_APPLICATION_REMOVE, NAUTILUS_METADATA_SUBKEY_APPLICATION_ID); @@ -507,21 +507,22 @@ nautilus_mime_get_short_list_components_for_uri (NautilusDirectory *directory, g_free (uri); + nautilus_file_wait_for_metadata (file); + explicit_iids = get_explicit_content_view_iids_from_metafile (file); + /* Arrange for all the file attributes we will need. */ attributes = NULL; attributes = g_list_prepend (attributes, NAUTILUS_FILE_ATTRIBUTE_MIME_TYPE); - attributes = g_list_append (NULL, NAUTILUS_FILE_ATTRIBUTE_METADATA); - files = nautilus_directory_wait_until_ready (directory, attributes); - explicit_iids = get_explicit_content_view_iids_from_metafile (directory); g_list_free (attributes); - metadata_component_add_ids = nautilus_directory_get_metadata_list - (directory, + + metadata_component_add_ids = nautilus_file_get_metadata_list + (file, NAUTILUS_METADATA_KEY_SHORT_LIST_COMPONENT_ADD, NAUTILUS_METADATA_SUBKEY_COMPONENT_IID); - metadata_component_remove_ids = nautilus_directory_get_metadata_list - (directory, + metadata_component_remove_ids = nautilus_file_get_metadata_list + (file, NAUTILUS_METADATA_KEY_SHORT_LIST_COMPONENT_REMOVE, NAUTILUS_METADATA_SUBKEY_COMPONENT_IID); @@ -608,9 +609,9 @@ nautilus_mime_get_all_applications_for_uri (NautilusDirectory *directory, GList *p; GnomeVFSMimeApplication *application; - nautilus_directory_wait_for_metadata (directory); - metadata_application_ids = nautilus_directory_get_metadata_list - (directory, + nautilus_file_wait_for_metadata (file); + metadata_application_ids = nautilus_file_get_metadata_list + (file, NAUTILUS_METADATA_KEY_EXPLICIT_APPLICATION, NAUTILUS_METADATA_SUBKEY_APPLICATION_ID); @@ -668,14 +669,15 @@ nautilus_mime_get_all_components_for_uri (NautilusDirectory *directory, uri = nautilus_file_get_uri (file); uri_scheme = uri_string_get_scheme (uri); g_free (uri); + + nautilus_file_wait_for_metadata (file); + explicit_iids = get_explicit_content_view_iids_from_metafile (file); /* Arrange for all the file attributes we will need. */ attributes = NULL; attributes = g_list_prepend (attributes, NAUTILUS_FILE_ATTRIBUTE_MIME_TYPE); - attributes = g_list_append (NULL, NAUTILUS_FILE_ATTRIBUTE_METADATA); files = nautilus_directory_wait_until_ready (directory, attributes); - explicit_iids = get_explicit_content_view_iids_from_metafile (directory); g_list_free (attributes); info_list = nautilus_do_component_query (mime_type, uri_scheme, files, explicit_iids, NULL, NULL, &ev); @@ -721,9 +723,9 @@ nautilus_mime_set_default_action_type_for_uri (NautilusDirectory *directory action_string = "none"; } - nautilus_directory_wait_for_metadata (directory); - nautilus_directory_set_metadata - (directory, NAUTILUS_METADATA_KEY_DEFAULT_ACTION_TYPE, NULL, action_string); + nautilus_file_wait_for_metadata (file); + nautilus_file_set_metadata + (file, NAUTILUS_METADATA_KEY_DEFAULT_ACTION_TYPE, NULL, action_string); return GNOME_VFS_OK; } @@ -733,9 +735,9 @@ nautilus_mime_set_default_application_for_uri (NautilusDirectory *directory, NautilusFile *file, const char *application_id) { - nautilus_directory_wait_for_metadata (directory); - nautilus_directory_set_metadata - (directory, NAUTILUS_METADATA_KEY_DEFAULT_APPLICATION, NULL, application_id); + nautilus_file_wait_for_metadata (file); + nautilus_file_set_metadata + (file, NAUTILUS_METADATA_KEY_DEFAULT_APPLICATION, NULL, application_id); /* If there's no default action type, set it to match this. */ if (application_id != NULL && @@ -751,9 +753,9 @@ nautilus_mime_set_default_component_for_uri (NautilusDirectory *directory, NautilusFile *file, const char *component_iid) { - nautilus_directory_wait_for_metadata (directory); - nautilus_directory_set_metadata - (directory, NAUTILUS_METADATA_KEY_DEFAULT_COMPONENT, NULL, component_iid); + nautilus_file_wait_for_metadata (file); + nautilus_file_set_metadata + (file, NAUTILUS_METADATA_KEY_DEFAULT_COMPONENT, NULL, component_iid); /* If there's no default action type, set it to match this. */ if (component_iid != NULL && @@ -792,14 +794,14 @@ nautilus_mime_set_short_list_applications_for_uri (NautilusDirectory *directory, add_list = str_list_difference (applications, normal_short_list_ids); remove_list = str_list_difference (normal_short_list_ids, applications); - nautilus_directory_wait_for_metadata (directory); - nautilus_directory_set_metadata_list - (directory, + nautilus_file_wait_for_metadata (file); + nautilus_file_set_metadata_list + (file, NAUTILUS_METADATA_KEY_SHORT_LIST_APPLICATION_ADD, NAUTILUS_METADATA_SUBKEY_APPLICATION_ID, add_list); - nautilus_directory_set_metadata_list - (directory, + nautilus_file_set_metadata_list + (file, NAUTILUS_METADATA_KEY_SHORT_LIST_APPLICATION_REMOVE, NAUTILUS_METADATA_SUBKEY_APPLICATION_ID, remove_list); @@ -839,14 +841,14 @@ nautilus_mime_set_short_list_components_for_uri (NautilusDirectory *directory, add_list = str_list_difference (components, normal_short_list_ids); remove_list = str_list_difference (normal_short_list_ids, components); - nautilus_directory_wait_for_metadata (directory); - nautilus_directory_set_metadata_list - (directory, + nautilus_file_wait_for_metadata (file); + nautilus_file_set_metadata_list + (file, NAUTILUS_METADATA_KEY_SHORT_LIST_COMPONENT_ADD, NAUTILUS_METADATA_SUBKEY_COMPONENT_IID, add_list); - nautilus_directory_set_metadata_list - (directory, + nautilus_file_set_metadata_list + (file, NAUTILUS_METADATA_KEY_SHORT_LIST_COMPONENT_REMOVE, NAUTILUS_METADATA_SUBKEY_COMPONENT_IID, remove_list); @@ -967,10 +969,10 @@ nautilus_mime_extend_all_applications_for_uri (NautilusDirectory *directory, GList *extras; GList *final_applications; - nautilus_directory_wait_for_metadata (directory); + nautilus_file_wait_for_metadata (file); - metadata_application_ids = nautilus_directory_get_metadata_list - (directory, + metadata_application_ids = nautilus_file_get_metadata_list + (file, NAUTILUS_METADATA_KEY_EXPLICIT_APPLICATION, NAUTILUS_METADATA_SUBKEY_APPLICATION_ID); @@ -978,8 +980,8 @@ nautilus_mime_extend_all_applications_for_uri (NautilusDirectory *directory, final_applications = g_list_concat (g_list_copy (metadata_application_ids), extras); - nautilus_directory_set_metadata_list - (directory, + nautilus_file_set_metadata_list + (file, NAUTILUS_METADATA_KEY_EXPLICIT_APPLICATION, NAUTILUS_METADATA_SUBKEY_APPLICATION_ID, final_applications); @@ -995,21 +997,21 @@ nautilus_mime_remove_from_all_applications_for_uri (NautilusDirectory *directory GList *metadata_application_ids; GList *final_applications; - nautilus_directory_wait_for_metadata (directory); + nautilus_file_wait_for_metadata (file); - metadata_application_ids = nautilus_directory_get_metadata_list - (directory, + metadata_application_ids = nautilus_file_get_metadata_list + (file, NAUTILUS_METADATA_KEY_EXPLICIT_APPLICATION, NAUTILUS_METADATA_SUBKEY_APPLICATION_ID); - + final_applications = str_list_difference (metadata_application_ids, applications); - - nautilus_directory_set_metadata_list - (directory, + + nautilus_file_set_metadata_list + (file, NAUTILUS_METADATA_KEY_EXPLICIT_APPLICATION, NAUTILUS_METADATA_SUBKEY_APPLICATION_ID, final_applications); - + return GNOME_VFS_OK; } @@ -1091,11 +1093,11 @@ uri_string_get_scheme (const char *uri_string) */ static GList * -get_explicit_content_view_iids_from_metafile (NautilusDirectory *directory) +get_explicit_content_view_iids_from_metafile (NautilusFile *file) { - if (directory != NULL) { - return nautilus_directory_get_metadata_list - (directory, + if (file != NULL) { + return nautilus_file_get_metadata_list + (file, NAUTILUS_METADATA_KEY_EXPLICIT_COMPONENT, NAUTILUS_METADATA_SUBKEY_COMPONENT_IID); } else { diff --git a/src/file-manager/fm-desktop-icon-view.c b/src/file-manager/fm-desktop-icon-view.c index c98171f87..d558e0783 100644 --- a/src/file-manager/fm-desktop-icon-view.c +++ b/src/file-manager/fm-desktop-icon-view.c @@ -521,7 +521,7 @@ fm_desktop_icon_view_create_background_context_menu_items (FMDirectoryView *view NULL, position++, reset_desktop_background_menu_item_callback, - nautilus_directory_background_is_set (fm_directory_view_get_background (view))); + nautilus_file_background_is_set (fm_directory_view_get_background (view))); fm_directory_view_insert_context_menu_item (view, menu, diff --git a/src/file-manager/fm-directory-view.c b/src/file-manager/fm-directory-view.c index 645684096..62007aec0 100644 --- a/src/file-manager/fm-directory-view.c +++ b/src/file-manager/fm-directory-view.c @@ -206,14 +206,10 @@ static void unschedule_timeout_display_of_pending_files static void unschedule_display_of_pending_files (FMDirectoryView *view); static void disconnect_model_handlers (FMDirectoryView *view); static void filtering_changed_callback (gpointer callback_data); -static void get_required_metadata_keys (FMDirectoryView *view, - GList **directory_keys_result, - GList **file_keys_result); static NautilusStringList * real_get_emblem_names_to_exclude (FMDirectoryView *view); static void start_renaming_item (FMDirectoryView *view, const char *uri); -static void metadata_ready_callback (NautilusDirectory *directory, - GList *files, +static void metadata_ready_callback (NautilusFile *file, gpointer callback_data); static void fm_directory_view_trash_state_changed_callback (NautilusTrashMonitor *trash, gboolean state, @@ -304,7 +300,6 @@ fm_directory_view_initialize_class (FMDirectoryViewClass *klass) klass->create_background_context_menu_items = fm_directory_view_real_create_background_context_menu_items; klass->merge_menus = fm_directory_view_real_merge_menus; klass->update_menus = fm_directory_view_real_update_menus; - klass->get_required_metadata_keys = get_required_metadata_keys; klass->get_emblem_names_to_exclude = real_get_emblem_names_to_exclude; klass->start_renaming_item = start_renaming_item; klass->is_read_only = fm_directory_view_real_is_read_only; @@ -2485,13 +2480,12 @@ remove_custom_icon (gpointer file, gpointer callback_data) NULL, NULL); } -static NautilusFile * -get_directory_as_file (FMDirectoryView *view) +NautilusFile * +fm_directory_view_get_directory_as_file (FMDirectoryView *view) { g_assert (FM_IS_DIRECTORY_VIEW (view)); - return nautilus_directory_get_corresponding_file - (fm_directory_view_get_model (view)); + return view->details->directory_as_file; } static gboolean @@ -2502,8 +2496,8 @@ files_have_any_custom_images (GList *files) for (p = files; p != NULL; p = p->next) { uri = nautilus_file_get_metadata (NAUTILUS_FILE (p->data), - NAUTILUS_METADATA_KEY_CUSTOM_ICON, - NULL); + NAUTILUS_METADATA_KEY_CUSTOM_ICON, + NULL); if (uri != NULL) { g_free (uri); return TRUE; @@ -2635,7 +2629,7 @@ compute_menu_item_info (FMDirectoryView *directory_view, *return_sensitivity = files_have_any_custom_images (selection); } else if (strcmp (path, FM_DIRECTORY_VIEW_MENU_PATH_RESET_BACKGROUND) == 0) { name = g_strdup (_("Reset _Background")); - *return_sensitivity = nautilus_directory_background_is_set + *return_sensitivity = nautilus_file_background_is_set (fm_directory_view_get_background (directory_view)); } else { name = ""; @@ -3645,6 +3639,7 @@ fm_directory_view_activate_file (FMDirectoryView *view, parameters->view = view; parameters->file = file; parameters->use_new_window = use_new_window; + nautilus_file_call_when_ready (file, attributes, activate_callback, parameters); @@ -3706,6 +3701,7 @@ fm_directory_view_load_uri (FMDirectoryView *view, const char *uri) { NautilusDirectory *old_model; + NautilusFile *old_file; GList *attributes; g_return_if_fail (FM_IS_DIRECTORY_VIEW (view)); @@ -3726,10 +3722,18 @@ fm_directory_view_load_uri (FMDirectoryView *view, view->details->model = nautilus_directory_get (uri); nautilus_directory_unref (old_model); + old_file = view->details->directory_as_file; + view->details->directory_as_file = nautilus_directory_get_corresponding_file + (fm_directory_view_get_model (view)); + nautilus_file_unref (old_file); + attributes = g_list_append (NULL, NAUTILUS_FILE_ATTRIBUTE_METADATA); - nautilus_directory_call_when_ready - (view->details->model, + /* FIXME: we also need to monitor here, in case external + forces change the directory's file metadata */ + + nautilus_file_call_when_ready + (view->details->directory_as_file, attributes, metadata_ready_callback, view); @@ -3752,10 +3756,19 @@ finish_loading_uri (FMDirectoryView *view) view->details->loading = TRUE; /* Start loading. */ - attributes = g_list_prepend (NULL, - NAUTILUS_FILE_ATTRIBUTE_DIRECTORY_ITEM_COUNT); + + /* Monitor the things needed to get the right + * icon. Also monitor a directory's item count because + * the "size" attribute is based on that, and the file's metadata. + */ + attributes = nautilus_icon_factory_get_required_file_attributes (); attributes = g_list_prepend (attributes, - NAUTILUS_FILE_ATTRIBUTE_TOP_LEFT_TEXT); + NAUTILUS_FILE_ATTRIBUTE_DIRECTORY_ITEM_COUNT); + attributes = g_list_prepend (attributes, + NAUTILUS_FILE_ATTRIBUTE_METADATA); + attributes = g_list_prepend (attributes, + NAUTILUS_FILE_ATTRIBUTE_MIME_TYPE); + nautilus_directory_file_monitor_add (view->details->model, view, attributes, TRUE); g_list_free (attributes); @@ -3778,8 +3791,7 @@ finish_loading_uri (FMDirectoryView *view) } static void -metadata_ready_callback (NautilusDirectory *directory, - GList *files, +metadata_ready_callback (NautilusFile *file, gpointer callback_data) { FMDirectoryView *view; @@ -3787,37 +3799,11 @@ metadata_ready_callback (NautilusDirectory *directory, view = callback_data; g_assert (FM_IS_DIRECTORY_VIEW (view)); - g_assert (view->details->model == directory); + g_assert (view->details->directory_as_file == file); finish_loading_uri (view); } -static void -get_required_metadata_keys (FMDirectoryView *view, - GList **directory_keys_result, - GList **file_keys_result) -{ - GList *directory_keys; - - g_assert (FM_IS_DIRECTORY_VIEW (view)); - g_assert (directory_keys_result != NULL); - g_assert (file_keys_result != NULL); - - directory_keys = NULL; - - /* This needs to be a list of all the metadata needed. - * For now, it's kinda hard-coded. Later we might want - * to gather this info from various sources. - */ - directory_keys = g_list_prepend (directory_keys, - NAUTILUS_METADATA_KEY_DIRECTORY_BACKGROUND_COLOR); - directory_keys = g_list_prepend (directory_keys, - NAUTILUS_METADATA_KEY_DIRECTORY_BACKGROUND_IMAGE); - - *directory_keys_result = directory_keys; - *file_keys_result = NULL; -} - NautilusStringList * fm_directory_view_get_emblem_names_to_exclude (FMDirectoryView *view) { @@ -3873,9 +3859,9 @@ disconnect_model_handlers (FMDirectoryView *view) disconnect_handler (view, &view->details->files_changed_handler_id); if (view->details->model != NULL) { nautilus_directory_file_monitor_remove (view->details->model, view); - nautilus_directory_cancel_callback (view->details->model, - metadata_ready_callback, - view); + nautilus_file_cancel_call_when_ready (view->details->directory_as_file, + metadata_ready_callback, + view); } } @@ -3970,16 +3956,7 @@ fm_directory_view_is_empty (FMDirectoryView *view) static gboolean fm_directory_view_real_is_read_only (FMDirectoryView *view) { - NautilusFile *directory_as_file; - gboolean result; - - directory_as_file = get_directory_as_file (view); - - result = !nautilus_file_can_write (directory_as_file); - - nautilus_file_unref (directory_as_file); - - return result; + return !nautilus_file_can_write (fm_directory_view_get_directory_as_file (view)); } gboolean @@ -4005,16 +3982,7 @@ fm_directory_view_accepts_dragged_files (FMDirectoryView *view) static gboolean showing_trash_directory (FMDirectoryView *view) { - NautilusFile *directory_as_file; - gboolean result; - - directory_as_file = get_directory_as_file (view); - - result = nautilus_file_is_in_trash (directory_as_file); - - nautilus_file_unref (directory_as_file); - - return result; + return nautilus_file_is_in_trash (fm_directory_view_get_directory_as_file (view)); } static gboolean diff --git a/src/file-manager/fm-directory-view.h b/src/file-manager/fm-directory-view.h index 43760d2d1..e64d7ce5f 100644 --- a/src/file-manager/fm-directory-view.h +++ b/src/file-manager/fm-directory-view.h @@ -204,15 +204,6 @@ struct FMDirectoryViewClass { */ void (* update_menus) (FMDirectoryView *view); - /* get_required_metadata_keys is a function pointer that subclasses - * may override to request additional metadata to be read before showing - * the directory view. If overridden, subclasses must all parent class's - * function. - */ - void (* get_required_metadata_keys) (FMDirectoryView *view, - GList **directory_metadata_keys, - GList **file_metadata_keys); - /* get_emblem_names_to_exclude is a function pointer that subclasses * may override to specify a set of emblem names that should not * be displayed with each file. By default, all emblems returned by @@ -344,6 +335,7 @@ void fm_directory_view_notify_selection_changed (FMDirectory Bonobo_UIContainer fm_directory_view_get_bonobo_ui_container (FMDirectoryView *view); NautilusStringList *fm_directory_view_get_emblem_names_to_exclude (FMDirectoryView *view); NautilusDirectory *fm_directory_view_get_model (FMDirectoryView *view); +NautilusFile *fm_directory_view_get_directory_as_file (FMDirectoryView *view); NautilusBackground *fm_directory_view_get_background (FMDirectoryView *view); void fm_directory_view_pop_up_background_context_menu (FMDirectoryView *view); void fm_directory_view_pop_up_selection_context_menu (FMDirectoryView *view); diff --git a/src/file-manager/fm-icon-view.c b/src/file-manager/fm-icon-view.c index 67a72f180..59ac520b0 100644 --- a/src/file-manager/fm-icon-view.c +++ b/src/file-manager/fm-icon-view.c @@ -93,7 +93,7 @@ static void create_icon_container (FMIconView *ic static void fm_icon_view_initialize (FMIconView *icon_view); static void fm_icon_view_initialize_class (FMIconViewClass *klass); static void fm_icon_view_set_directory_sort_by (FMIconView *icon_view, - NautilusDirectory *directory, + NautilusFile *file, const char *sort_by); static void fm_icon_view_set_zoom_level (FMIconView *view, NautilusZoomLevel new_level, @@ -103,9 +103,9 @@ static void fm_icon_view_update_icon_container_fonts (FMIconView *ic static void fm_icon_view_update_click_mode (FMIconView *icon_view); static void fm_icon_view_update_smooth_graphics_mode (FMIconView *icon_view); static gboolean fm_icon_view_get_directory_tighter_layout (FMIconView *icon_view, - NautilusDirectory *directory); + NautilusFile *file); static void fm_icon_view_set_directory_tighter_layout (FMIconView *icon_view, - NautilusDirectory *directory, + NautilusFile *file, gboolean tighter_layout); static gboolean real_supports_auto_layout (FMIconView *view); static void set_sort_criterion_by_id (FMIconView *icon_view, @@ -304,7 +304,7 @@ set_sort_criterion (FMIconView *icon_view, const SortCriterion *sort) /* Store the new sort setting. */ fm_icon_view_set_directory_sort_by (icon_view, - fm_directory_view_get_model (FM_DIRECTORY_VIEW (icon_view)), + fm_directory_view_get_directory_as_file (FM_DIRECTORY_VIEW (icon_view)), sort->metadata_text); /* Update the layout menus to match the new sort setting. */ @@ -386,7 +386,7 @@ static void tighter_layout_callback (gpointer ignored, gpointer view) { NautilusIconContainer *icon_container; - NautilusDirectory *directory; + NautilusFile *file; gboolean is_tighter_layout; /* FIXME bugzilla.eazel.com 916: Workaround for Bonobo/GTK menu bug. */ @@ -394,10 +394,10 @@ tighter_layout_callback (gpointer ignored, gpointer view) return; icon_container = get_icon_container (FM_ICON_VIEW (view)); - directory = fm_directory_view_get_model (FM_DIRECTORY_VIEW (view)); - is_tighter_layout = fm_icon_view_get_directory_tighter_layout (FM_ICON_VIEW (view), directory); + file = fm_directory_view_get_directory_as_file (FM_DIRECTORY_VIEW (view)); + is_tighter_layout = fm_icon_view_get_directory_tighter_layout (FM_ICON_VIEW (view), file); - fm_icon_view_set_directory_tighter_layout (FM_ICON_VIEW (view), directory, !is_tighter_layout); + fm_icon_view_set_directory_tighter_layout (FM_ICON_VIEW (view), file, !is_tighter_layout); nautilus_icon_container_set_tighter_layout (icon_container, !is_tighter_layout); } @@ -901,70 +901,72 @@ update_layout_menus (FMIconView *view) static char * fm_icon_view_get_directory_sort_by (FMIconView *icon_view, - NautilusDirectory *directory) + NautilusFile *file) { if (!fm_icon_view_supports_auto_layout (icon_view)) { return g_strdup ("name"); } return NAUTILUS_CALL_VIRTUAL (FM_ICON_VIEW_CLASS, icon_view, - get_directory_sort_by, (icon_view, directory)); + get_directory_sort_by, (icon_view, file)); } static char * fm_icon_view_real_get_directory_sort_by (FMIconView *icon_view, - NautilusDirectory *directory) + NautilusFile *file) { - return nautilus_directory_get_metadata - (directory, NAUTILUS_METADATA_KEY_ICON_VIEW_SORT_BY, + return nautilus_file_get_metadata + (file, NAUTILUS_METADATA_KEY_ICON_VIEW_SORT_BY, sort_criteria[0].metadata_text); } static void -fm_icon_view_set_directory_sort_by (FMIconView *icon_view, NautilusDirectory *directory, const char *sort_by) +fm_icon_view_set_directory_sort_by (FMIconView *icon_view, + NautilusFile *file, + const char *sort_by) { if (!fm_icon_view_supports_auto_layout (icon_view)) { return; } NAUTILUS_CALL_VIRTUAL (FM_ICON_VIEW_CLASS, icon_view, - set_directory_sort_by, (icon_view, directory, sort_by)); + set_directory_sort_by, (icon_view, file, sort_by)); } static void fm_icon_view_real_set_directory_sort_by (FMIconView *icon_view, - NautilusDirectory *directory, + NautilusFile *file, const char *sort_by) { - nautilus_directory_set_metadata - (directory, NAUTILUS_METADATA_KEY_ICON_VIEW_SORT_BY, + nautilus_file_set_metadata + (file, NAUTILUS_METADATA_KEY_ICON_VIEW_SORT_BY, sort_criteria[0].metadata_text, sort_by); } static gboolean fm_icon_view_get_directory_sort_reversed (FMIconView *icon_view, - NautilusDirectory *directory) + NautilusFile *file) { if (!fm_icon_view_supports_auto_layout (icon_view)) { return FALSE; } return NAUTILUS_CALL_VIRTUAL (FM_ICON_VIEW_CLASS, icon_view, - get_directory_sort_reversed, (icon_view, directory)); + get_directory_sort_reversed, (icon_view, file)); } static gboolean fm_icon_view_real_get_directory_sort_reversed (FMIconView *icon_view, - NautilusDirectory *directory) + NautilusFile *file) { - return nautilus_directory_get_boolean_metadata - (directory, NAUTILUS_METADATA_KEY_ICON_VIEW_SORT_REVERSED, FALSE); + return nautilus_file_get_boolean_metadata + (file, NAUTILUS_METADATA_KEY_ICON_VIEW_SORT_REVERSED, FALSE); } static void fm_icon_view_set_directory_sort_reversed (FMIconView *icon_view, - NautilusDirectory *directory, + NautilusFile *file, gboolean sort_reversed) { if (!fm_icon_view_supports_auto_layout (icon_view)) { @@ -973,16 +975,16 @@ fm_icon_view_set_directory_sort_reversed (FMIconView *icon_view, NAUTILUS_CALL_VIRTUAL (FM_ICON_VIEW_CLASS, icon_view, set_directory_sort_reversed, - (icon_view, directory, sort_reversed)); + (icon_view, file, sort_reversed)); } static void fm_icon_view_real_set_directory_sort_reversed (FMIconView *icon_view, - NautilusDirectory *directory, + NautilusFile *file, gboolean sort_reversed) { - nautilus_directory_set_boolean_metadata - (directory, NAUTILUS_METADATA_KEY_ICON_VIEW_SORT_REVERSED, FALSE, + nautilus_file_set_boolean_metadata + (file, NAUTILUS_METADATA_KEY_ICON_VIEW_SORT_REVERSED, FALSE, sort_reversed); } @@ -990,27 +992,27 @@ fm_icon_view_real_set_directory_sort_reversed (FMIconView *icon_view, static gboolean fm_icon_view_get_directory_auto_layout (FMIconView *icon_view, - NautilusDirectory *directory) + NautilusFile *file) { if (!fm_icon_view_supports_auto_layout (icon_view)) { return FALSE; } return NAUTILUS_CALL_VIRTUAL (FM_ICON_VIEW_CLASS, icon_view, - get_directory_auto_layout, (icon_view, directory)); + get_directory_auto_layout, (icon_view, file)); } static gboolean fm_icon_view_real_get_directory_auto_layout (FMIconView *icon_view, - NautilusDirectory *directory) + NautilusFile *file) { - return nautilus_directory_get_boolean_metadata - (directory, NAUTILUS_METADATA_KEY_ICON_VIEW_AUTO_LAYOUT, TRUE); + return nautilus_file_get_boolean_metadata + (file, NAUTILUS_METADATA_KEY_ICON_VIEW_AUTO_LAYOUT, TRUE); } static void fm_icon_view_set_directory_auto_layout (FMIconView *icon_view, - NautilusDirectory *directory, + NautilusFile *file, gboolean auto_layout) { if (!fm_icon_view_supports_auto_layout (icon_view)) { @@ -1018,52 +1020,52 @@ fm_icon_view_set_directory_auto_layout (FMIconView *icon_view, } NAUTILUS_CALL_VIRTUAL (FM_ICON_VIEW_CLASS, icon_view, - set_directory_auto_layout, (icon_view, directory, auto_layout)); + set_directory_auto_layout, (icon_view, file, auto_layout)); } static void fm_icon_view_real_set_directory_auto_layout (FMIconView *icon_view, - NautilusDirectory *directory, + NautilusFile *file, gboolean auto_layout) { - nautilus_directory_set_boolean_metadata - (directory, NAUTILUS_METADATA_KEY_ICON_VIEW_AUTO_LAYOUT, TRUE, + nautilus_file_set_boolean_metadata + (file, NAUTILUS_METADATA_KEY_ICON_VIEW_AUTO_LAYOUT, TRUE, auto_layout); } /* maintainence of tighter layout boolean */ static gboolean fm_icon_view_get_directory_tighter_layout (FMIconView *icon_view, - NautilusDirectory *directory) + NautilusFile *file) { return NAUTILUS_CALL_VIRTUAL (FM_ICON_VIEW_CLASS, icon_view, - get_directory_tighter_layout, (icon_view, directory)); + get_directory_tighter_layout, (icon_view, file)); } static gboolean fm_icon_view_real_get_directory_tighter_layout (FMIconView *icon_view, - NautilusDirectory *directory) + NautilusFile *file) { - return nautilus_directory_get_boolean_metadata - (directory, NAUTILUS_METADATA_KEY_ICON_VIEW_TIGHTER_LAYOUT, FALSE); + return nautilus_file_get_boolean_metadata + (file, NAUTILUS_METADATA_KEY_ICON_VIEW_TIGHTER_LAYOUT, FALSE); } static void fm_icon_view_set_directory_tighter_layout (FMIconView *icon_view, - NautilusDirectory *directory, - gboolean tighter_layout) + NautilusFile *file, + gboolean tighter_layout) { NAUTILUS_CALL_VIRTUAL (FM_ICON_VIEW_CLASS, icon_view, - set_directory_tighter_layout, (icon_view, directory, tighter_layout)); + set_directory_tighter_layout, (icon_view, file, tighter_layout)); } static void fm_icon_view_real_set_directory_tighter_layout (FMIconView *icon_view, - NautilusDirectory *directory, - gboolean tighter_layout) + NautilusFile *file, + gboolean tighter_layout) { - nautilus_directory_set_boolean_metadata - (directory, NAUTILUS_METADATA_KEY_ICON_VIEW_TIGHTER_LAYOUT, FALSE, + nautilus_file_set_boolean_metadata + (file, NAUTILUS_METADATA_KEY_ICON_VIEW_TIGHTER_LAYOUT, FALSE, tighter_layout); } @@ -1094,7 +1096,7 @@ set_sort_reversed (FMIconView *icon_view, gboolean new_value) icon_view->details->sort_reversed = new_value; /* Store the new sort setting. */ - fm_icon_view_set_directory_sort_reversed (icon_view, fm_directory_view_get_model (FM_DIRECTORY_VIEW (icon_view)), new_value); + fm_icon_view_set_directory_sort_reversed (icon_view, fm_directory_view_get_directory_as_file (FM_DIRECTORY_VIEW (icon_view)), new_value); /* Update the layout menus to match the new sort-order setting. */ update_layout_menus (icon_view); @@ -1135,28 +1137,31 @@ fm_icon_view_begin_loading (FMDirectoryView *view) { FMIconView *icon_view; GtkWidget *icon_container; - NautilusDirectory *directory; + NautilusFile *file; int level; char *sort_name; g_return_if_fail (FM_IS_ICON_VIEW (view)); icon_view = FM_ICON_VIEW (view); - directory = fm_directory_view_get_model (view); + file = fm_directory_view_get_directory_as_file (view); icon_container = GTK_WIDGET (get_icon_container (icon_view)); /* kill any sound preview process that is ongoing */ preview_sound (NULL, FALSE); + /* FIXME: this should be done with a virtual function, not + hardcoding knowledge about a subclass into the parent class. */ + if (FM_IS_DESKTOP_ICON_VIEW (view)) { - nautilus_connect_desktop_background_to_directory_metadata (icon_container, directory); + nautilus_connect_desktop_background_to_file_metadata (icon_container, file); } else { - nautilus_connect_background_to_directory_metadata (icon_container, directory); + nautilus_connect_background_to_file_metadata (icon_container, file); } /* Set up the zoom level from the metadata. */ - level = nautilus_directory_get_integer_metadata - (directory, + level = nautilus_file_get_integer_metadata + (file, NAUTILUS_METADATA_KEY_ICON_VIEW_ZOOM_LEVEL, icon_view->details->default_zoom_level); fm_icon_view_set_zoom_level (icon_view, level, TRUE); @@ -1165,12 +1170,12 @@ fm_icon_view_begin_loading (FMDirectoryView *view) * It's OK not to resort the icons because the * container doesn't have any icons at this point. */ - sort_name = fm_icon_view_get_directory_sort_by (icon_view, directory); + sort_name = fm_icon_view_get_directory_sort_by (icon_view, file); set_sort_criterion (icon_view, get_sort_criterion_by_metadata_text (sort_name)); g_free (sort_name); /* Set the sort direction from the metadata. */ - set_sort_reversed (icon_view, fm_icon_view_get_directory_sort_reversed (icon_view, directory)); + set_sort_reversed (icon_view, fm_icon_view_get_directory_sort_reversed (icon_view, file)); /* Set the layout modes. * We must do this after getting the sort mode, @@ -1179,10 +1184,10 @@ fm_icon_view_begin_loading (FMDirectoryView *view) */ nautilus_icon_container_set_auto_layout (get_icon_container (icon_view), - fm_icon_view_get_directory_auto_layout (icon_view, directory)); + fm_icon_view_get_directory_auto_layout (icon_view, file)); nautilus_icon_container_set_tighter_layout (get_icon_container (icon_view), - fm_icon_view_get_directory_tighter_layout (icon_view, directory)); + fm_icon_view_get_directory_tighter_layout (icon_view, file)); } @@ -1212,8 +1217,8 @@ fm_icon_view_set_zoom_level (FMIconView *view, return; } - nautilus_directory_set_integer_metadata - (fm_directory_view_get_model (FM_DIRECTORY_VIEW (view)), + nautilus_file_set_integer_metadata + (fm_directory_view_get_directory_as_file (FM_DIRECTORY_VIEW (view)), NAUTILUS_METADATA_KEY_ICON_VIEW_ZOOM_LEVEL, view->details->default_zoom_level, new_level); @@ -1388,7 +1393,7 @@ sort_direction_callback (gpointer ignored, gpointer user_data) set_sort_reversed (icon_view, !fm_icon_view_get_directory_sort_reversed (icon_view, - fm_directory_view_get_model (FM_DIRECTORY_VIEW (icon_view)))); + fm_directory_view_get_directory_as_file (FM_DIRECTORY_VIEW (icon_view)))); nautilus_icon_container_sort (get_icon_container (icon_view)); } @@ -1404,21 +1409,21 @@ static void layout_changed_callback (NautilusIconContainer *container, FMIconView *icon_view) { - NautilusDirectory *directory; + NautilusFile *file; g_assert (FM_IS_ICON_VIEW (icon_view)); g_assert (container == get_icon_container (icon_view)); - directory = fm_directory_view_get_model (FM_DIRECTORY_VIEW (icon_view)); + file = fm_directory_view_get_directory_as_file (FM_DIRECTORY_VIEW (icon_view)); - if (directory != NULL) { + if (file != NULL) { fm_icon_view_set_directory_auto_layout (icon_view, - directory, + file, fm_icon_view_using_auto_layout (icon_view)); fm_icon_view_set_directory_tighter_layout (icon_view, - directory, + file, fm_icon_view_using_tighter_layout (icon_view)); } @@ -1677,7 +1682,7 @@ icon_container_preview_callback (NautilusIconContainer *container, /* preview files based on the mime_type. */ /* at first, we just handle sounds */ - mime_type = nautilus_file_get_mime_type(file); + mime_type = nautilus_file_get_mime_type (file); if (nautilus_istr_has_prefix (mime_type, "audio/")) { if (nautilus_sound_can_play_sound ()) { result = 1; @@ -1782,7 +1787,6 @@ icon_position_changed_callback (NautilusIconContainer *container, const NautilusIconPosition *position, FMIconView *icon_view) { - NautilusDirectory *directory; char *position_string; char *scale_string, *scale_string_x, *scale_string_y; char *locale; @@ -1813,7 +1817,6 @@ icon_position_changed_callback (NautilusIconContainer *container, } /* Store the new position of the icon in the metadata. */ - directory = fm_directory_view_get_model (FM_DIRECTORY_VIEW (icon_view)); if (!fm_icon_view_using_auto_layout (icon_view)) { position_string = g_strdup_printf ("%d,%d", position->x, position->y); diff --git a/src/file-manager/fm-icon-view.h b/src/file-manager/fm-icon-view.h index 0c6a0b544..fa93a8f0b 100644 --- a/src/file-manager/fm-icon-view.h +++ b/src/file-manager/fm-icon-view.h @@ -51,17 +51,29 @@ struct FMIconViewClass { /* Note: get_directory_sort_by must return a string that can/will be g_freed. */ - char * (* get_directory_sort_by) (FMIconView *icon_view, NautilusDirectory *directory); - void (* set_directory_sort_by) (FMIconView *icon_view, NautilusDirectory *directory, const char* sort_by); - - gboolean (* get_directory_sort_reversed) (FMIconView *icon_view, NautilusDirectory *directory); - void (* set_directory_sort_reversed) (FMIconView *icon_view, NautilusDirectory *directory, gboolean sort_reversed); - - gboolean (* get_directory_auto_layout) (FMIconView *icon_view, NautilusDirectory *directory); - void (* set_directory_auto_layout) (FMIconView *icon_view, NautilusDirectory *directory, gboolean auto_layout); + char * (* get_directory_sort_by) (FMIconView *icon_view, + NautilusFile *file); + void (* set_directory_sort_by) (FMIconView *icon_view, + NautilusFile *file, + const char* sort_by); + + gboolean (* get_directory_sort_reversed) (FMIconView *icon_view, + NautilusFile *file); + void (* set_directory_sort_reversed) (FMIconView *icon_view, + NautilusFile *file, + gboolean sort_reversed); + + gboolean (* get_directory_auto_layout) (FMIconView *icon_view, + NautilusFile *file); + void (* set_directory_auto_layout) (FMIconView *icon_view, + NautilusFile *file, + gboolean auto_layout); - gboolean (* get_directory_tighter_layout) (FMIconView *icon_view, NautilusDirectory *directory); - void (* set_directory_tighter_layout) (FMIconView *icon_view, NautilusDirectory *directory, gboolean tighter_layout); + gboolean (* get_directory_tighter_layout) (FMIconView *icon_view, + NautilusFile *file); + void (* set_directory_tighter_layout) (FMIconView *icon_view, + NautilusFile *file, + gboolean tighter_layout); /* Override "clean_up" if your subclass has its own notion of where icons should be positioned */ void (* clean_up) (FMIconView *icon_view); diff --git a/src/file-manager/fm-list-view.c b/src/file-manager/fm-list-view.c index d65213a57..5eefccf5e 100644 --- a/src/file-manager/fm-list-view.c +++ b/src/file-manager/fm-list-view.c @@ -1095,23 +1095,23 @@ fm_list_view_begin_adding_files (FMDirectoryView *view) static void fm_list_view_begin_loading (FMDirectoryView *view) { - NautilusDirectory *directory; + NautilusFile *file; FMListView *list_view; char *default_sort_attribute; g_return_if_fail (FM_IS_LIST_VIEW (view)); - directory = fm_directory_view_get_model (view); + file = fm_directory_view_get_directory_as_file (view); list_view = FM_LIST_VIEW (view); /* Set up the background color from the metadata. */ - nautilus_connect_background_to_directory_metadata (GTK_WIDGET (get_list (list_view)), - directory); + nautilus_connect_background_to_file_metadata (GTK_WIDGET (get_list (list_view)), + file); fm_list_view_set_zoom_level ( list_view, - nautilus_directory_get_integer_metadata ( - directory, + nautilus_file_get_integer_metadata ( + file, NAUTILUS_METADATA_KEY_LIST_VIEW_ZOOM_LEVEL, list_view->details->default_zoom_level), TRUE); @@ -1120,13 +1120,12 @@ fm_list_view_begin_loading (FMDirectoryView *view) fm_list_view_sort_items ( list_view, get_sort_column_from_attribute (list_view, - nautilus_directory_get_metadata (directory, - NAUTILUS_METADATA_KEY_LIST_VIEW_SORT_COLUMN, - default_sort_attribute)), - nautilus_directory_get_boolean_metadata ( - directory, - NAUTILUS_METADATA_KEY_LIST_VIEW_SORT_REVERSED, - FALSE)); + nautilus_file_get_metadata (file, + NAUTILUS_METADATA_KEY_LIST_VIEW_SORT_COLUMN, + default_sort_attribute)), + nautilus_file_get_boolean_metadata (file, + NAUTILUS_METADATA_KEY_LIST_VIEW_SORT_REVERSED, + FALSE)); g_free (default_sort_attribute); } @@ -1324,8 +1323,8 @@ fm_list_view_set_zoom_level (FMListView *list_view, } list_view->details->zoom_level = new_level; - nautilus_directory_set_integer_metadata - (fm_directory_view_get_model (FM_DIRECTORY_VIEW (list_view)), + nautilus_file_set_integer_metadata + (fm_directory_view_get_directory_as_file (FM_DIRECTORY_VIEW (list_view)), NAUTILUS_METADATA_KEY_LIST_VIEW_ZOOM_LEVEL, list_view->details->default_zoom_level, new_level); @@ -1426,7 +1425,7 @@ fm_list_view_sort_items (FMListView *list_view, { NautilusList *list; NautilusCList *clist; - NautilusDirectory *directory; + NautilusFile *file; g_return_if_fail (FM_IS_LIST_VIEW (list_view)); g_return_if_fail (column >= 0); @@ -1438,14 +1437,14 @@ fm_list_view_sort_items (FMListView *list_view, return; } - directory = fm_directory_view_get_model (FM_DIRECTORY_VIEW (list_view)); - nautilus_directory_set_metadata - (directory, + file = fm_directory_view_get_directory_as_file (FM_DIRECTORY_VIEW (list_view)); + nautilus_file_set_metadata + (file, NAUTILUS_METADATA_KEY_LIST_VIEW_SORT_COLUMN, LIST_VIEW_DEFAULT_SORTING_ATTRIBUTE, get_column_attribute (list_view, column)); - nautilus_directory_set_boolean_metadata - (directory, + nautilus_file_set_boolean_metadata + (file, NAUTILUS_METADATA_KEY_LIST_VIEW_SORT_REVERSED, FALSE, reversed); diff --git a/src/file-manager/fm-search-list-view.c b/src/file-manager/fm-search-list-view.c index 4968829c9..20efd5af0 100644 --- a/src/file-manager/fm-search-list-view.c +++ b/src/file-manager/fm-search-list-view.c @@ -421,19 +421,25 @@ real_adding_file (FMListView *view, NautilusFile *file) NAUTILUS_CALL_PARENT_CLASS (FM_LIST_VIEW_CLASS, adding_file, (view, file)); + /* FIXME: this implies that positioning, custom icon, icon + * stretching, etc, will be based on the real directory the file is in, + * and won't be specific to the search directory. Is that OK? + */ + gtk_signal_connect_object (GTK_OBJECT (file), "changed", fm_directory_view_queue_file_change, GTK_OBJECT (view)); /* Monitor the things needed to get the right * icon. Also monitor a directory's item count because - * the "size" attribute is based on that. - */ + * the "size" attribute is based on that, and the file's metadata. */ attributes = nautilus_icon_factory_get_required_file_attributes (); attributes = g_list_prepend (attributes, NAUTILUS_FILE_ATTRIBUTE_DIRECTORY_ITEM_COUNT); attributes = g_list_prepend (attributes, NAUTILUS_FILE_ATTRIBUTE_METADATA); + attributes = g_list_prepend (attributes, + NAUTILUS_FILE_ATTRIBUTE_MIME_TYPE); nautilus_file_monitor_add (file, view, attributes); g_list_free (attributes); } |