diff -p -up nautilus-2.21.5/src/nautilus-application.c.dynamic nautilus-2.21.5/src/nautilus-application.c --- nautilus-2.21.5/src/nautilus-application.c.dynamic 2008-01-14 15:45:48.000000000 +0000 +++ nautilus-2.21.5/src/nautilus-application.c 2008-01-14 21:05:01.000000000 +0000 @@ -101,6 +101,10 @@ /* Keeps track of all the desktop windows. */ static GList *nautilus_application_desktop_windows; +/* monitor for dynamic desktop */ +#define DYNAMIC_DIR "/var/lib/gnome/desktop/" +static GFileMonitor *dynamic_monitor = NULL; + /* Keeps track of all the nautilus windows. */ static GList *nautilus_application_window_list; @@ -773,6 +777,131 @@ selection_clear_event_cb (GtkWidget } static void +dynamic_desktop_changed_callback (GFileMonitor* monitor, + GFile *child, + GFile *other_file, + GFileMonitorEvent event_type, + gpointer user_data) +{ + char * basename; + char * desktop_dir; + char * path; + GFile *desktop_file; + GFile *target_file; + GFileInfo *file_info; + NautilusDirectory *directory; + const char *attrs = G_FILE_ATTRIBUTE_STANDARD_NAME "," G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK "," G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET; + const char *symlink_target; + + if ((event_type != G_FILE_MONITOR_EVENT_DELETED) && + (event_type != G_FILE_MONITOR_EVENT_CREATED) && + (event_type != G_FILE_MONITOR_EVENT_CHANGED)) + return; + + desktop_dir = nautilus_get_desktop_directory (); + desktop_file = g_file_new_for_path (desktop_dir); + g_free (desktop_dir); + + basename = g_file_get_basename (child); + target_file = g_file_get_child (desktop_file, basename); + g_free (basename); + + switch (event_type) { + case G_FILE_MONITOR_EVENT_DELETED: + file_info = g_file_query_info(target_file, attrs, G_FILE_QUERY_INFO_NONE, NULL, NULL); + if (file_info) { + if (g_file_info_get_is_symlink (file_info) && + (symlink_target = g_file_info_get_symlink_target (file_info)) && + !strncmp (DYNAMIC_DIR, symlink_target,strlen(DYNAMIC_DIR))) { + g_file_delete (target_file, NULL, NULL); + } + g_object_unref (file_info); + } + break; + case G_FILE_MONITOR_EVENT_CREATED: + path = g_file_get_path (child); + g_file_make_symbolic_link (target_file, path, NULL, NULL); + g_free (path); + case G_FILE_MONITOR_EVENT_CHANGED: + directory = nautilus_directory_get (desktop_file); + nautilus_directory_force_reload(directory); + g_object_unref (directory); + break; + default: + break; + } + g_object_unref (target_file); + g_object_unref (desktop_file); +} + + +void dynamic_desktop_start_monitor () +{ + char * desktop_dir; + GFile * desktop_file; + GFile * target; + GFile * source; + GFile * dynamic_file; + GFileEnumerator *enumerator; + const char *attrs = G_FILE_ATTRIBUTE_STANDARD_NAME "," G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK "," G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET; + GFileInfo* file_info; + const char *symlink_target; + char *path; + + desktop_dir = nautilus_get_desktop_directory (); + desktop_file = g_file_new_for_path (desktop_dir); + g_free (desktop_dir); + + enumerator = g_file_enumerate_children (desktop_file,attrs, G_FILE_QUERY_INFO_NONE, NULL, NULL); + + if (!enumerator) { + g_object_unref (desktop_file); + return; + } + + while ((file_info = g_file_enumerator_next_file (enumerator, NULL, NULL)) != NULL) { + if (g_file_info_get_is_symlink (file_info) && + (symlink_target = g_file_info_get_symlink_target (file_info)) && + !strncmp (DYNAMIC_DIR, symlink_target,strlen(DYNAMIC_DIR))) { + target = g_file_get_child (desktop_file, g_file_info_get_name (file_info)); + g_file_delete (target, NULL, NULL); + g_object_unref (target); + } + g_object_unref (file_info); + } + + dynamic_file = g_file_new_for_path (DYNAMIC_DIR); + + enumerator = g_file_enumerate_children (dynamic_file, G_FILE_ATTRIBUTE_STANDARD_NAME,G_FILE_QUERY_INFO_NONE, NULL, NULL); + + if (!enumerator) { + g_object_unref (desktop_file); + g_object_unref (dynamic_file); + return; + } + + while ((file_info = g_file_enumerator_next_file (enumerator, NULL, NULL)) != NULL) { + target = g_file_get_child (desktop_file, g_file_info_get_name (file_info)); + source = g_file_get_child (dynamic_file, g_file_info_get_name (file_info)); + path = g_file_get_path (source); + g_file_make_symbolic_link (target, path , NULL, NULL); + g_free (path); + g_object_unref (target); + g_object_unref (source); + g_object_unref (file_info); + } + + dynamic_monitor = g_file_monitor_directory (dynamic_file, G_FILE_MONITOR_NONE, NULL, NULL); + if (dynamic_monitor) { + g_signal_connect (dynamic_monitor, "changed", (GCallback)dynamic_desktop_changed_callback, NULL); + } + + g_object_unref (desktop_file); + g_object_unref (dynamic_file); + +} + +static void nautilus_application_create_desktop_windows (NautilusApplication *application) { static gboolean create_in_progress = FALSE; @@ -788,6 +917,10 @@ nautilus_application_create_desktop_wind return; } + if (dynamic_monitor == NULL) { + dynamic_desktop_start_monitor(); + } + create_in_progress = TRUE; display = gdk_display_get_default (); @@ -843,6 +976,12 @@ nautilus_application_close_desktop (void /* Make sure we update the session when the desktop goes away */ update_session (gnome_master_client ()); } + if (dynamic_monitor != NULL) { + g_signal_handlers_disconnect_by_func (dynamic_monitor, dynamic_desktop_changed_callback, NULL); + g_file_monitor_cancel (dynamic_monitor); + g_object_unref (dynamic_monitor); + } + } void