Commit b49a5ec5 authored by Federico Mena Quintero's avatar Federico Mena Quintero Committed by Federico Mena Quintero

Removed. (gtk_file_system_gnome_vfs_set_bookmarks): Removed.

2003-10-17  Federico Mena Quintero  <federico@ximian.com>

	* gtkfilesystemgnomevfs.c
	(gtk_file_system_gnome_vfs_get_supports_bookmarks): Removed.
	(gtk_file_system_gnome_vfs_set_bookmarks): Removed.
	(gtk_file_system_gnome_vfs_add_bookmark): Implement.
	(gtk_file_system_gnome_vfs_remove_bookmark): Implement.

	* gtkfilechooserprivate.h (struct _GtkFileChooserIface): Replaced
	the ::set_shortcut_folders() method with :;add_shortcut_folder()
	and ::remove_shortcut_folder().

	* gtkfilechooserutils.c (delegate_add_shortcut_folder): New function.
	(delegate_remove_shortcut_folder): New function.
	(delegate_list_shortcut_folders): New function.

	* gtkfilechooserimpldefault.c (create_shortcuts_model): Insert the
	Desktop directory as well.
	(shortcuts_insert_path): Renamed from shortcuts_append_path; now
	takes a position index instead of a parent node iter.  Also takes
	a GError argument.
	(struct _GtkFileChooserImplDefault): Removed the shortcuts_folder
	list.  It is all kept in the model now.
	(shortcuts_append_home): Save whether adding a shortcut for the
	home directory was successful.
	(shortcuts_append_desktop): Likewise for the desktop.
	(shortcuts_append_file_system_roots): Count and save the number of
	roots added.
	(shortcuts_append_shortcut_folders): Removed.
	(gtk_file_chooser_impl_default_add_shortcut_folder): Implement.
	(shortcuts_append_bookmarks): Now that we don't have a bookmarks
	parent node, don't expand the tree.
	(add_bookmark_button_clicked_cb): Use gtk_file_system_add_bookmark().
	(remove_bookmark_button_clicked_cb): Use gtk_file_system_remove_bookmark().
	(gtk_file_chooser_impl_default_list_shortcut_folders): Get the
	folders from the shortcuts model; we no longer keep a separate list.

	* gtkfilesystem.h (struct _GtkFileSystemIface): Oops, there
	shouldn't be shortcuts-related virtual methods here.

	* gtkfilechooser.c (file_paths_to_strings): New helper function.
	(gtk_file_chooser_get_filenames): Use file_paths_to_strings().
	(gtk_file_chooser_get_uris): Likewise.
	(gtk_file_chooser_set_shortcut_folders): Removed.
	(gtk_file_chooser_list_shortcut_folders): Return a list of
	strings, not of GtkFilePath*.
	(gtk_file_chooser_list_shortcut_folder_uris): New function.
	(gtk_file_chooser_add_shortcut_folder): New function.
	(gtk_file_chooser_remove_shortcut_folder): New function.
	(gtk_file_chooser_add_shortcut_folder_uri): New function.
	(gtk_file_chooser_remove_shortcut_folder_uri): New function.
	(_gtk_file_chooser_add_shortcut_folder): New function.
	(_gtk_file_chooser_remove_shortcut_folder): New function.

	* gtkfilechooser.h: New enum.

	* gtkfilechooser.c (gtk_file_chooser_error_quark): New function.

	* gtkfilesystem.c (gtk_file_system_get_supports_bookmarks): Removed.
	(gtk_file_system_set_bookmarks): Removed.
	(gtk_file_system_add_bookmark): New function.
	(gtk_file_system_remove_bookmark): New function.

	* gtkfilesystemunix.c
	(gtk_file_system_unix_get_supports_bookmarks): Removed.
	(gtk_file_system_unix_set_bookmarks): Removed.
	(gtk_file_system_unix_add_bookmark): Just a stub for now.
	(gtk_file_system_unix_remove_bookmark): Likewise.

	* testfilechooser.c (main): Add a shortcut for testing purposes.
parent a0628bab
......@@ -152,6 +152,22 @@ gtk_file_chooser_class_init (gpointer g_iface)
G_PARAM_READWRITE));
}
/**
* gtk_file_chooser_error_quark:
*
* Registers an error quark for #GtkFileChooser if necessary.
*
* Return value: The error quark used for #GtkFileChooser errors.
**/
GQuark
gtk_file_chooser_error_quark (void)
{
static GQuark quark = 0;
if (quark == 0)
quark = g_quark_from_static_string ("gtk-file-chooser-error-quark");
return quark;
}
/**
* gtk_file_chooser_set_action:
* @chooser: a #GtkFileChooser
......@@ -436,6 +452,31 @@ gtk_file_chooser_unselect_filename (GtkFileChooser *chooser,
}
}
/* Converts a list of GtkFilePath* to a list of strings using the specified function */
static GSList *
file_paths_to_strings (GtkFileSystem *fs,
GSList *paths,
gchar * (*convert_func) (GtkFileSystem *fs, const GtkFilePath *path))
{
GSList *strings;
strings = NULL;
for (; paths; paths = paths->next)
{
GtkFilePath *path;
gchar *string;
path = paths->data;
string = (* convert_func) (fs, path);
if (string)
strings = g_slist_prepend (strings, string);
}
return g_slist_reverse (strings);
}
/**
* gtk_file_chooser_get_filenames:
* @chooser: a #GtkFileChooser
......@@ -454,24 +495,16 @@ gtk_file_chooser_get_filenames (GtkFileChooser *chooser)
{
GtkFileSystem *file_system;
GSList *paths;
GSList *tmp_list;
GSList *result = NULL;
GSList *result;
g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
file_system = _gtk_file_chooser_get_file_system (chooser);
paths = _gtk_file_chooser_get_paths (chooser);
for (tmp_list = paths; tmp_list; tmp_list = tmp_list->next)
{
gchar *filename = gtk_file_system_path_to_filename (file_system, tmp_list->data);
if (filename)
result = g_slist_prepend (result, filename);
}
result = file_paths_to_strings (file_system, paths, gtk_file_system_path_to_filename);
gtk_file_paths_free (paths);
return g_slist_reverse (result);
return result;
}
/**
......@@ -702,24 +735,16 @@ gtk_file_chooser_get_uris (GtkFileChooser *chooser)
{
GtkFileSystem *file_system;
GSList *paths;
GSList *tmp_list;
GSList *result = NULL;
GSList *result;
g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
file_system = _gtk_file_chooser_get_file_system (chooser);
paths = _gtk_file_chooser_get_paths (chooser);
for (tmp_list = paths; tmp_list; tmp_list = tmp_list->next)
{
gchar *uri = gtk_file_system_path_to_uri (file_system, tmp_list->data);
if (uri)
result = g_slist_prepend (result, uri);
}
result = file_paths_to_strings (file_system, paths, gtk_file_system_path_to_uri);
gtk_file_paths_free (paths);
return g_slist_reverse (result);
return result;
}
/**
......@@ -1012,7 +1037,7 @@ gtk_file_chooser_get_preview_widget_active (GtkFileChooser *chooser)
* @chooser: a #GtkFileChooser
*
* Gets the filename that should be previewed in a custom preview
* Internal function, see gtk_file_chooser_get_preview_uri().n
* Internal function, see gtk_file_chooser_get_preview_uri().
*
* Return value: the #GtkFilePath for the file to preview, or %NULL if no file
* is selected. Free with gtk_file_path_free().
......@@ -1025,6 +1050,52 @@ _gtk_file_chooser_get_preview_path (GtkFileChooser *chooser)
return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_preview_path (chooser);
}
/**
* _gtk_file_chooser_add_shortcut_folder:
* @chooser: a #GtkFileChooser
* @path: path of the folder to add
* @error: location to store error, or %NULL
*
* Adds a folder to be displayed with the shortcut folders in a file chooser.
* Internal function, see gtk_file_chooser_add_shortcut_folder().
*
* Return value: TRUE if the folder could be added successfully, FALSE
* otherwise.
**/
gboolean
_gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
const GtkFilePath *path,
GError **error)
{
g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
g_return_val_if_fail (path != NULL, FALSE);
return GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, path, error);
}
/**
* _gtk_file_chooser_remove_shortcut_folder:
* @chooser: a #GtkFileChooser
* @path: path of the folder to remove
* @error: location to store error, or %NULL
*
* Removes a folder from the shortcut folders in a file chooser. Internal
* function, see gtk_file_chooser_remove_shortcut_folder().
*
* Return value: TRUE if the folder could be removed successfully, FALSE
* otherwise.
**/
gboolean
_gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
const GtkFilePath *path,
GError **error)
{
g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
g_return_val_if_fail (path != NULL, FALSE);
return GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, path, error);
}
/**
* gtk_file_chooser_get_preview_filename:
* @chooser: a #GtkFileChooser
......@@ -1232,23 +1303,89 @@ gtk_file_chooser_get_filter (GtkFileChooser *chooser)
return filter;
}
/* gtk_file_chooser_set_shortcut_folders:
/**
* gtk_file_chooser_add_shortcut_folder:
* @chooser: a #GtkFileChooser
* @shortcut_folders: a list of #GtkFilePath, or NULL if you want to clear the
* current list of shortcut folders.
* @folder: filename of the folder to add
* @error: location to store error, or %NULL
*
* Sets the list of shortcut folders to be shown in a file chooser. Note that
* these do not get saved, as they are provided by the application. For
* example, you can use this to add a "/usr/share/myapp/Clipart" folder to the
* volume list.
* Adds a folder to be displayed with the shortcut folders in a file chooser.
* Note that shortcut folders do not get saved, as they are provided by the
* application. For example, you can use this to add a
* "/usr/share/mydrawprogram/Clipart" folder to the volume list.
*
* Return value: TRUE if the folder could be added successfully, FALSE
* otherwise. In the latter case, the @error will be set as appropriate.
**/
void
gtk_file_chooser_set_shortcut_folders (GtkFileChooser *chooser,
GSList *shortcut_folders)
gboolean
gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
const char *folder,
GError **error)
{
g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
GtkFilePath *path;
gboolean result;
g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
g_return_val_if_fail (folder != NULL, FALSE);
path = gtk_file_system_filename_to_path (_gtk_file_chooser_get_file_system (chooser), folder);
if (!path)
{
g_set_error (error,
GTK_FILE_CHOOSER_ERROR,
GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
"Invalid filename: %s",
folder);
return FALSE;
}
result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, path, error);
gtk_file_path_free (path);
return result;
}
/**
* gtk_file_chooser_remove_shortcut_folder:
* @chooser: a #GtkFileChooser
* @folder: filename of the folder to remove
* @error: location to store error, or %NULL
*
* Removes a folder from a file chooser's list of shortcut folders.
*
* Return value: TRUE if the operation succeeds, FALSE otherwise. In the latter
* case, the @error will be set as appropriate.
*
* See also: gtk_file_chooser_add_shortcut_folder()
**/
gboolean
gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
const char *folder,
GError **error)
{
GtkFilePath *path;
gboolean result;
g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
g_return_val_if_fail (folder != NULL, FALSE);
path = gtk_file_system_filename_to_path (_gtk_file_chooser_get_file_system (chooser), folder);
if (!path)
{
g_set_error (error,
GTK_FILE_CHOOSER_ERROR,
GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
"Invalid filename: %s",
folder);
return FALSE;
}
GTK_FILE_CHOOSER_GET_IFACE (chooser)->set_shortcut_folders (chooser, shortcut_folders);
result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, path, error);
gtk_file_path_free (path);
return result;
}
/**
......@@ -1258,13 +1395,136 @@ gtk_file_chooser_set_shortcut_folders (GtkFileChooser *chooser,
* Queries the list of shortcut folders in the file chooser, as set by
* gtk_file_chooser_set_shortcut_folders().
*
* Return value: A list of #GtkFilePath, or NULL if there are no shortcut
* folders. You should use gtk_file_paths_free() to free this list.
* Return value: A list of folder filenames, or NULL if there are no shortcut
* folders. Free the returned list with g_slist_free(), and the filenames with
* g_free().
**/
GSList *
gtk_file_chooser_list_shortcut_folders (GtkFileChooser *chooser)
{
GSList *folders;
GSList *result;
g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
folders = GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_shortcut_folders (chooser);
result = file_paths_to_strings (_gtk_file_chooser_get_file_system (chooser),
folders,
gtk_file_system_path_to_filename);
gtk_file_paths_free (folders);
return result;
}
/**
* gtk_file_chooser_add_shortcut_folder_uri:
* @chooser: a #GtkFileChooser
* @folder: URI of the folder to add
* @error: location to store error, or %NULL
*
* Adds a folder URI to be displayed with the shortcut folders in a file
* chooser. Note that shortcut folders do not get saved, as they are provided
* by the application. For example, you can use this to add a
* "file:///usr/share/mydrawprogram/Clipart" folder to the volume list.
*
* Return value: TRUE if the folder could be added successfully, FALSE
* otherwise. In the latter case, the @error will be set as appropriate.
**/
gboolean
gtk_file_chooser_add_shortcut_folder_uri (GtkFileChooser *chooser,
const char *uri,
GError **error)
{
GtkFilePath *path;
gboolean result;
g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
g_return_val_if_fail (uri != NULL, FALSE);
path = gtk_file_system_uri_to_path (_gtk_file_chooser_get_file_system (chooser), uri);
if (!path)
{
g_set_error (error,
GTK_FILE_CHOOSER_ERROR,
GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
"Invalid filename: %s",
uri);
return FALSE;
}
result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, path, error);
gtk_file_path_free (path);
return result;
}
/**
* gtk_file_chooser_remove_shortcut_folder_uri:
* @chooser: a #GtkFileChooser
* @uri: URI of the folder to remove
* @error: location to store error, or %NULL
*
* Removes a folder URI from a file chooser's list of shortcut folders.
*
* Return value: TRUE if the operation succeeds, FALSE otherwise. In the latter
* case, the @error will be set as appropriate.
*
* See also: gtk_file_chooser_add_shortcut_folder_uri()
**/
gboolean
gtk_file_chooser_remove_shortcut_folder_uri (GtkFileChooser *chooser,
const char *uri,
GError **error)
{
GtkFilePath *path;
gboolean result;
g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
g_return_val_if_fail (uri != NULL, FALSE);
path = gtk_file_system_filename_to_path (_gtk_file_chooser_get_file_system (chooser), uri);
if (!path)
{
g_set_error (error,
GTK_FILE_CHOOSER_ERROR,
GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
"Invalid filename: %s",
uri);
return FALSE;
}
result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, path, error);
gtk_file_path_free (path);
return result;
}
/**
* gtk_file_chooser_list_shortcut_folder_uris:
* @chooser: a #GtkFileChooser
*
* Queries the list of shortcut folders in the file chooser, as set by
* gtk_file_chooser_set_shortcut_folder_uris().
*
* Return value: A list of folder URIs, or NULL if there are no shortcut
* folders. Free the returned list with g_slist_free(), and the URIs with
* g_free().
**/
GSList *
gtk_file_chooser_list_shortcut_folder_uris (GtkFileChooser *chooser)
{
GSList *folders;
GSList *result;
g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
return GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_shortcut_folders (chooser);
folders = GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_shortcut_folders (chooser);
result = file_paths_to_strings (_gtk_file_chooser_get_file_system (chooser),
folders,
gtk_file_system_path_to_uri);
gtk_file_paths_free (folders);
return result;
}
......@@ -40,6 +40,17 @@ typedef enum
GType gtk_file_chooser_get_type (void);
/* GError enumeration for GtkFileChooser */
#define GTK_FILE_CHOOSER_ERROR (gtk_file_chooser_error_quark ())
typedef enum {
GTK_FILE_CHOOSER_ERROR_NONEXISTENT,
GTK_FILE_CHOOSER_ERROR_BAD_FILENAME
} GtkFileChooserError;
GQuark gtk_file_chooser_error_quark (void);
/* Configuration
*/
void gtk_file_chooser_set_action (GtkFileChooser *chooser,
......@@ -123,9 +134,21 @@ GtkFileFilter *gtk_file_chooser_get_filter (GtkFileChooser *chooser);
/* Per-application shortcut folders */
void gtk_file_chooser_set_shortcut_folders (GtkFileChooser *chooser,
GSList *shortcut_directories);
GSList *gtk_file_chooser_list_shortcut_folders (GtkFileChooser *chooser);
gboolean gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
const char *folder,
GError **error);
gboolean gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
const char *folder,
GError **error);
GSList *gtk_file_chooser_list_shortcut_folders (GtkFileChooser *chooser);
gboolean gtk_file_chooser_add_shortcut_folder_uri (GtkFileChooser *chooser,
const char *folder,
GError **error);
gboolean gtk_file_chooser_remove_shortcut_folder_uri (GtkFileChooser *chooser,
const char *folder,
GError **error);
GSList *gtk_file_chooser_list_shortcut_folder_uris (GtkFileChooser *chooser);
G_END_DECLS
......
......@@ -76,7 +76,11 @@ struct _GtkFileChooserImplDefault
GtkFileFilter *current_filter;
GSList *filters;
GSList *shortcut_folders;
gboolean has_home;
gboolean has_desktop;
int num_roots;
int num_shortcuts;
int num_bookmarks;
guint bookmarks_changed_id;
GtkTreeIter bookmarks_iter;
......@@ -166,8 +170,12 @@ static void gtk_file_chooser_impl_default_add_filter (GtkF
static void gtk_file_chooser_impl_default_remove_filter (GtkFileChooser *chooser,
GtkFileFilter *filter);
static GSList * gtk_file_chooser_impl_default_list_filters (GtkFileChooser *chooser);
static void gtk_file_chooser_impl_default_set_shortcut_folders (GtkFileChooser *chooser,
GSList *shortcut_folders);
static gboolean gtk_file_chooser_impl_default_add_shortcut_folder (GtkFileChooser *chooser,
const GtkFilePath *path,
GError **error);
static gboolean gtk_file_chooser_impl_default_remove_shortcut_folder (GtkFileChooser *chooser,
const GtkFilePath *path,
GError **error);
static GSList * gtk_file_chooser_impl_default_list_shortcut_folders (GtkFileChooser *chooser);
static void set_current_filter (GtkFileChooserImplDefault *impl,
......@@ -290,7 +298,8 @@ gtk_file_chooser_impl_default_iface_init (GtkFileChooserIface *iface)
iface->add_filter = gtk_file_chooser_impl_default_add_filter;
iface->remove_filter = gtk_file_chooser_impl_default_remove_filter;
iface->list_filters = gtk_file_chooser_impl_default_list_filters;
iface->set_shortcut_folders = gtk_file_chooser_impl_default_set_shortcut_folders;
iface->add_shortcut_folder = gtk_file_chooser_impl_default_add_shortcut_folder;
iface->remove_shortcut_folder = gtk_file_chooser_impl_default_remove_shortcut_folder;
iface->list_shortcut_folders = gtk_file_chooser_impl_default_list_shortcut_folders;
}
......@@ -386,7 +395,7 @@ shortcuts_select_folder (GtkFileChooserImplDefault *impl)
/* Convenience function to get the display name and icon info for a path */
static GtkFileInfo *
get_file_info (GtkFileSystem *file_system, GtkFilePath *path, GError **error)
get_file_info (GtkFileSystem *file_system, const GtkFilePath *path, GError **error)
{
GtkFilePath *parent_path;
GtkFileFolder *parent_folder;
......@@ -409,16 +418,17 @@ get_file_info (GtkFileSystem *file_system, GtkFilePath *path, GError **error)
return info;
}
/* Appends a path to the shortcuts tree, making a copy of it. If parent is
* NULL, then the item is appened at the end of the tree. If the label is NULL,
* then the display name of a GtkFileInfo is used.
/* Inserts a path in the shortcuts tree, making a copy of it. A position of -1
* indicates the end of the tree. If the label is NULL, then the display name
* of a GtkFileInfo is used.
*/
static void
shortcuts_append_path (GtkFileChooserImplDefault *impl,
GtkTreeIter *parent,
GtkFilePath *path,
static gboolean
shortcuts_insert_path (GtkFileChooserImplDefault *impl,
int pos,
const GtkFilePath *path,
gboolean is_root,
const char *label)
const char *label,
GError **error)
{
GtkFileInfo *info;
GtkFilePath *path_copy;
......@@ -433,16 +443,16 @@ shortcuts_append_path (GtkFileChooserImplDefault *impl,
info = gtk_file_system_get_root_info (impl->file_system,
path,
GTK_FILE_INFO_DISPLAY_NAME | GTK_FILE_INFO_ICON,
NULL); /* FIXME: Use GError? */
error);
else
info = get_file_info (impl->file_system, path, NULL); /* FIXME: use GError? */
info = get_file_info (impl->file_system, path, error);
if (!info)
return;
return FALSE;
pixbuf = gtk_file_info_render_icon (info, impl->shortcuts_tree, ICON_SIZE);
gtk_tree_store_append (impl->shortcuts_model, &iter, parent);
gtk_tree_store_insert (impl->shortcuts_model, &iter, NULL, pos);
path_copy = gtk_file_path_copy (path);
if (!label)
......@@ -456,6 +466,8 @@ shortcuts_append_path (GtkFileChooserImplDefault *impl,
if (pixbuf)
g_object_unref (pixbuf);
return TRUE;
}
/* Appends an item for the user's home directory to the shortcuts model */
......@@ -473,12 +485,29 @@ shortcuts_append_home (GtkFileChooserImplDefault *impl)
home = g_get_home_dir ();
home_path = gtk_file_system_filename_to_path (impl->file_system, home);
shortcuts_append_path (impl, NULL, home_path, FALSE, label);
impl->has_home = shortcuts_insert_path (impl, -1, home_path, FALSE, label, NULL); /* FIXME: use GError? */
g_free (label);
gtk_file_path_free (home_path);
}
/* Appends the ~/Desktop directory to the shortcuts model */
static void
shortcuts_append_desktop (GtkFileChooserImplDefault *impl)
{
char *name;
GtkFilePath *path;
/* FIXME: What is the Right Way of finding the desktop directory? */
name = g_build_filename (g_get_home_dir (), "Desktop", NULL);
path = gtk_file_system_filename_to_path (impl->file_system, name);
g_free (name);
impl->has_desktop = shortcuts_insert_path (impl, -1, path, FALSE, NULL, NULL); /* FIXME: use GError? */
gtk_file_path_free (path);
}
/* Appends all the file system roots to the shortcuts model */
static void
shortcuts_append_file_system_roots (GtkFileChooserImplDefault *impl)
......@@ -486,33 +515,22 @@ shortcuts_append_file_system_roots (GtkFileChooserImplDefault *impl)
GSList *roots, *l;
roots = gtk_file_system_list_roots (impl->file_system);
/* FIXME: handle the roots-changed signal on the file system */
impl->num_roots = 0;
for (l = roots; l; l = l->next)
{
GtkFilePath *path;
path = l->data;
shortcuts_append_path (impl, NULL, path, TRUE, NULL);
if (shortcuts_insert_path (impl, -1, path, TRUE, NULL, NULL)) /* FIXME: use GError? */
impl->num_roots++;
}
gtk_file_paths_free (roots);
}
/* Appends the application-specific shortcut folders to the shortcuts model */
static void
shortcuts_append_shortcut_folders (GtkFileChooserImplDefault *impl)
{
GSList *l;
for (l = impl->shortcut_folders; l; l = l->next)
{
GtkFilePath *path;
path = l->data;
shortcuts_append_path (impl, NULL, path, FALSE, NULL);
}
}
/* Removes the bookmarks separator node and all the bookmarks from the tree
* model.
*/
......@@ -550,6 +568,7 @@ shortcuts_append_bookmarks (GtkFileChooserImplDefault *impl)
SHORTCUTS_COL_PATH, NULL,
-1);
impl->bookmarks_set = TRUE;
impl->num_bookmarks = 0;
bookmarks = gtk_file_system_list_bookmarks (impl->file_system);
......@@ -558,10 +577,9 @@ shortcuts_append_bookmarks (GtkFileChooserImplDefault *impl)
GtkFilePath *path;
path = l->data;
shortcuts_append_path (impl, NULL, path, FALSE, NULL);
if (shortcuts_insert_path (impl, -1, path, FALSE, NULL, NULL)) /* FIXME: use GError? */
impl->num_bookmarks++;
}
gtk_tree_view_expand_all (GTK_TREE_VIEW (impl->shortcuts_tree));
}
/* Creates the GtkTreeStore used as the shortcuts model */
......@@ -580,8 +598,8 @@ create_shortcuts_model (GtkFileChooserImplDefault *impl)
if (impl->file_system)
{
shortcuts_append_home (impl);
shortcuts_append_desktop (impl);
shortcuts_append_file_system_roots (impl);
shortcuts_append_shortcut_folders (impl);
shortcuts_append_bookmarks (impl);
}
......@@ -675,17 +693,7 @@ static void
add_bookmark_button_clicked_cb (GtkButton *button,
GtkFileChooserImplDefault *impl)
{
GSList *bookmarks;
if (!gtk_file_system_get_supports_bookmarks (impl->file_system))
return;
bookmarks = gtk_file_system_list_bookmarks (impl->file_system);
bookmarks = g_slist_append (bookmarks, gtk_file_path_copy (impl->current_folder));
gtk_file_system_set_bookmarks (impl->file_system, bookmarks, NULL); /* FIXME: use GError */
gtk_file_paths_free (bookmarks);
gtk_file_system_add_bookmark (impl->file_system, impl->current_folder, NULL); /* FIXME: use GError */
}
/* Callback used when the "Remove bookmark" button is clicked */
......@@ -696,8 +704,6 @@ remove_bookmark_button_clicked_cb (GtkButton *button,
GtkTreeSelection *selection;
GtkTreeIter iter;
GtkFilePath *path;
GSList *bookmarks, *l;;
gboolean changed;
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->shortcuts_tree));
......@@ -706,27 +712,7 @@ remove_bookmark_button_clicked_cb (GtkButton *button,
gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter, SHORTCUTS_COL_PATH, &path, -1);
bookmarks = gtk_file_system_list_bookmarks (impl->file_system);
changed = FALSE;
for (l = bookmarks; l; l = l->next)
{
GtkFilePath *p;
p = l->data;
if (gtk_file_path_compare (path, p) == 0)
{
gtk_file_path_free (p);
bookmarks = g_slist_delete_link (bookmarks, l);
changed = TRUE;
break;
}
}
if (changed)
gtk_file_system_set_bookmarks (impl->file_system, bookmarks, NULL); /* FIXME: use GError */
gtk_file_paths_free (bookmarks);
gtk_file_system_remove_bookmark (impl->file_system, path, NULL); /* FIXME: use GError */
}
/* Sensitize the "add bookmark" button if the current folder is not in the
......@@ -738,9 +724,6 @@ bookmarks_check_add_sensitivity (GtkFileChooserImplDefault *impl)
GtkTreeIter iter;
gboolean exists;
if (!gtk_file_system_get_supports_bookmarks (impl->file_system))
return;
exists = FALSE;
if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (impl->shortcuts_model), &iter))
......@@ -863,6 +846,7 @@ create_shortcuts_tree (GtkFileChooserImplDefault *impl)
G_CALLBACK (add_bookmark_button_clicked_cb), impl);
gtk_box_pack_start (GTK_BOX (hbox), impl->add_bookmark_button, TRUE, TRUE, 0);
gtk_widget_set_sensitive (impl->add_bookmark_button, FALSE);
gtk_widget_show (impl->add_bookmark_button);
impl->remove_bookmark_button = gtk_button_new ();
g_signal_connect (impl->remove_bookmark_button, "clicked",
......@@ -872,12 +856,7 @@ create_shortcuts_tree (GtkFileChooserImplDefault *impl)
gtk_widget_show (image);
gtk_widget_set_sensitive (impl->remove_bookmark_button, FALSE);
gtk_box_pack_start (GTK_BOX (hbox), impl->remove_bookmark_button, FALSE, FALSE, 0);
if (gtk_file_system_get_supports_bookmarks (impl->file_system))
{
gtk_widget_show (impl->add_bookmark_button);
gtk_widget_show (impl->remove_bookmark_button);
}
gtk_widget_show (impl->remove_bookmark_button);
shortcuts_select_folder (impl);
......@@ -1777,24 +1756,113 @@ gtk_file_chooser_impl_default_list_filters (GtkFileChooser *chooser)
return g_slist_copy (impl->filters);
}
static void
gtk_file_chooser_impl_default_set_shortcut_folders (GtkFileChooser *chooser,