static void
update_bookmark_from_text (NautilusBookmarksWindow *self)
{
	NautilusBookmark *bookmark, *bookmark_in_list;
	const char *name;
	GIcon *icon;
	guint selected_row;
	GtkTreeIter iter;
	GFile *location;

	if (!self->priv->text_changed ||
	    gtk_entry_get_text_length (GTK_ENTRY (self->priv->uri_field)) == 0) {
		return;
	}

	location = g_file_parse_name 
		(gtk_entry_get_text (GTK_ENTRY (self->priv->uri_field)));

	bookmark = nautilus_bookmark_new (location,
					  self->priv->name_text_changed ?
					  gtk_entry_get_text (GTK_ENTRY (self->priv->name_field)) : NULL,
					  NULL);
	g_object_unref (location);

	selected_row = get_selected_row (self);

	/* turn off list updating 'cuz otherwise the list-reordering code runs
	 * after repopulate(), thus reordering the correctly-ordered list.
	 */
	g_signal_handler_block (self->priv->bookmarks, self->priv->bookmarks_changed_id);
	nautilus_bookmark_list_delete_item_at (self->priv->bookmarks, selected_row);
	nautilus_bookmark_list_insert_item (self->priv->bookmarks, bookmark, selected_row);
	g_signal_handler_unblock (self->priv->bookmarks, self->priv->bookmarks_changed_id);
	g_object_unref (bookmark);

	/* We also have to update the bookmark pointer in the list
	   store. */
	gtk_tree_selection_get_selected (self->priv->selection, NULL, &iter);
	g_signal_handler_block (self->priv->model, self->priv->row_changed_id);

	bookmark_in_list = nautilus_bookmark_list_item_at (self->priv->bookmarks, selected_row);
	name = nautilus_bookmark_get_name (bookmark_in_list);
	icon = nautilus_bookmark_get_icon (bookmark_in_list);

	gtk_list_store_set (self->priv->model, &iter,
			    BOOKMARK_LIST_COLUMN_BOOKMARK, bookmark_in_list,
			    BOOKMARK_LIST_COLUMN_NAME, name,
			    BOOKMARK_LIST_COLUMN_ICON, icon,
			    -1);

	g_signal_handler_unblock (self->priv->model, self->priv->row_changed_id);
	g_object_unref (icon);
}
static NautilusBookmark *
new_bookmark_from_uri (const char *uri, const char *label)
{
	NautilusBookmark *new_bookmark;
	NautilusFile *file;
	char *name;
	GIcon *icon;
	gboolean has_label;
	GFile *location;
	gboolean native;

	location = NULL;
	if (uri) {
		location = g_file_new_for_uri (uri);
	}
	
	has_label = FALSE;
	if (!label) { 
		name = nautilus_compute_title_for_location (location);
	} else {
		name = g_strdup (label);
		has_label = TRUE;
	}

	new_bookmark = NULL;
	
	if (uri) {
		native = g_file_is_native (location);
		file = nautilus_file_get (location);

		icon = NULL;
		if (nautilus_file_check_if_ready (file,
						  NAUTILUS_FILE_ATTRIBUTES_FOR_ICON)) {
			icon = nautilus_file_get_gicon (file, 0);
		}
		nautilus_file_unref (file);
		
		if (icon == NULL) {
			icon = native ? g_themed_icon_new (NAUTILUS_ICON_FOLDER) :
				g_themed_icon_new (NAUTILUS_ICON_FOLDER_REMOTE);
		}

		new_bookmark = nautilus_bookmark_new (location, name, has_label, icon);

		g_object_unref (icon);

	}
	g_free (name);
	g_object_unref (location);
	return new_bookmark;
}
static NautilusBookmark *
new_bookmark_from_uri (const char *uri, const char *label)
{
	NautilusBookmark *new_bookmark;
	GFile *location;

	location = NULL;
	if (uri) {
		location = g_file_new_for_uri (uri);
	}
	
	new_bookmark = NULL;

	if (location) {
		new_bookmark = nautilus_bookmark_new (location, label);
		g_object_unref (location);
	}

	return new_bookmark;
}