static gboolean
desktop_are_all_files_seen (NautilusDirectory *directory)
{
	NautilusDesktopDirectory *desktop;

	desktop = NAUTILUS_DESKTOP_DIRECTORY (directory);

	if (!nautilus_directory_are_all_files_seen (desktop->details->real_directory)) {
		return FALSE;
	}

	return TRUE;
}
static gboolean
desktop_is_not_empty (NautilusDirectory *directory)
{
	NautilusDesktopDirectory *desktop;

	desktop = NAUTILUS_DESKTOP_DIRECTORY (directory);

	if (nautilus_directory_is_not_empty (desktop->details->real_directory)) {
		return TRUE;
	}

	return directory->details->file_list != NULL;
}
static gboolean
desktop_contains_file (NautilusDirectory *directory,
		       NautilusFile *file)
{
	NautilusDesktopDirectory *desktop;

	desktop = NAUTILUS_DESKTOP_DIRECTORY (directory);

	if (nautilus_directory_contains_file (desktop->details->real_directory, file)) {
		return TRUE;
	}

	return file->details->directory == directory;
}
static void
desktop_monitor_add (NautilusDirectory *directory,
		    gconstpointer client,
		    gboolean monitor_hidden_files,
		    NautilusFileAttributes file_attributes,
		    NautilusDirectoryCallback callback,
		    gpointer callback_data)
{
	NautilusDesktopDirectory *desktop;
	MergedMonitor *monitor;
	GList *merged_callback_list;

	desktop = NAUTILUS_DESKTOP_DIRECTORY (directory);

	/* Map the client to a unique value so this doesn't interfere
	 * with direct monitoring of the directory by the same client.
	 */
	monitor = g_hash_table_lookup (desktop->details->monitors, client);
	if (monitor != NULL) {
		g_assert (monitor->desktop_dir == desktop);
	} else {
		monitor = g_new0 (MergedMonitor, 1);
		monitor->desktop_dir = desktop;
		g_hash_table_insert (desktop->details->monitors,
				     (gpointer) client, monitor);
	}
	monitor->monitor_hidden_files = monitor_hidden_files;
	monitor->monitor_attributes = file_attributes;
	
	/* Call through to the real directory add calls. */
	merged_callback_list = NULL;

	/* Call up to real dir */
	nautilus_directory_file_monitor_add
		(desktop->details->real_directory, monitor,
		 monitor_hidden_files,
		 file_attributes,
		 build_merged_callback_list, &merged_callback_list);
	
	/* Handle the desktop part */
	merged_callback_list = g_list_concat (merged_callback_list,
					      nautilus_file_list_copy (directory->details->file_list));

	
	if (callback != NULL) {
		(* callback) (directory, merged_callback_list, callback_data);
	}
	nautilus_file_list_free (merged_callback_list);
}
static void
desktop_monitor_remove (NautilusDirectory *directory,
		       gconstpointer client)
{
	NautilusDesktopDirectory *desktop;
	MergedMonitor *monitor;
	
	desktop = NAUTILUS_DESKTOP_DIRECTORY (directory);

	monitor = g_hash_table_lookup (desktop->details->monitors, client);
	if (monitor == NULL) {
		return;
	}
	
	g_hash_table_remove (desktop->details->monitors, client);
}
static void
nautilus_desktop_directory_init (NautilusDesktopDirectory *desktop)
{
	desktop->details = g_new0 (NautilusDesktopDirectoryDetails, 1);

	desktop->details->callbacks = g_hash_table_new_full
		(merged_callback_hash, merged_callback_equal,
		 NULL, (GDestroyNotify)merged_callback_destroy);
	desktop->details->monitors = g_hash_table_new_full (NULL, NULL,
							    NULL, (GDestroyNotify)merged_monitor_destroy);

	update_desktop_directory (NAUTILUS_DESKTOP_DIRECTORY (desktop));

	g_signal_connect_swapped (nautilus_preferences, "changed::" NAUTILUS_PREFERENCES_DESKTOP_IS_HOME_DIR,
				  G_CALLBACK(desktop_directory_changed_callback),
				  desktop);
}
static void
desktop_finalize (GObject *object)
{
	NautilusDesktopDirectory *desktop;

	desktop = NAUTILUS_DESKTOP_DIRECTORY (object);

	nautilus_directory_unref (desktop->details->real_directory);

	g_hash_table_destroy (desktop->details->callbacks);
	g_hash_table_destroy (desktop->details->monitors);
	g_free (desktop->details);

	g_signal_handlers_disconnect_by_func (nautilus_preferences,
					      desktop_directory_changed_callback,
					      desktop);

	G_OBJECT_CLASS (nautilus_desktop_directory_parent_class)->finalize (object);
}
static void
desktop_directory_changed_callback (gpointer data)
{
	update_desktop_directory (NAUTILUS_DESKTOP_DIRECTORY (data));
	nautilus_directory_force_reload (NAUTILUS_DIRECTORY (data));
}