Move interface definition into a private header so it can refer to

Fri Apr  4 17:30:27 2003  Owen Taylor  <otaylor@redhat.com>

        * gtkfilechooserprivate.h gtkfilechooser.h: Move
        interface definition into a private header so it
        can refer to GtkFileSystem.

        * *.[ch]: Switch over from using gchar *uri internally
        to using GtkFilePath * internally, and add
        conversion routines to GtkFileSystem.

        * TODO README: Updates.
This commit is contained in:
Owen Taylor 2003-04-04 22:43:12 +00:00 committed by Owen Taylor
parent a013536bef
commit bc3fb55c1b
13 changed files with 951 additions and 570 deletions

View File

@ -19,6 +19,7 @@
*/
#include "gtkfilechooser.h"
#include "gtkfilechooserprivate.h"
#include "gtkfilechooserenums.h"
#include "gtkfilesystem.h"
@ -26,6 +27,8 @@
static void gtk_file_chooser_base_init (gpointer g_class);
static GtkFilePath *gtk_file_chooser_get_path (GtkFileChooser *chooser);
GType
gtk_file_chooser_get_type (void)
{
@ -212,21 +215,21 @@ gtk_file_chooser_get_select_multiple (GtkFileChooser *chooser)
return select_multiple;
}
char *
gchar *
gtk_file_chooser_get_filename (GtkFileChooser *chooser)
{
GSList *list;
GtkFileSystem *file_system;
GtkFilePath *path;
gchar *result = NULL;
g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
list = gtk_file_chooser_get_filenames (chooser);
if (list)
file_system = _gtk_file_chooser_get_file_system (chooser);
path = gtk_file_chooser_get_path (chooser);
if (path)
{
result = list->data;
list = g_slist_delete_link (list, list);
g_slist_foreach (list, (GFunc)g_free, NULL);
g_slist_free (list);
result = gtk_file_system_path_to_filename (file_system, path);
gtk_file_path_free (path);
}
return result;
@ -234,65 +237,132 @@ gtk_file_chooser_get_filename (GtkFileChooser *chooser)
void
gtk_file_chooser_set_filename (GtkFileChooser *chooser,
const char *filename)
const gchar *filename)
{
g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
gtk_file_chooser_unselect_all (chooser);
gtk_file_chooser_select_filename (chooser, filename);
}
void
gtk_file_chooser_select_filename (GtkFileChooser *chooser,
const char *filename)
const gchar *filename)
{
GtkFileSystem *file_system;
GtkFilePath *path;
g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
g_return_if_fail (filename != NULL);
file_system = _gtk_file_chooser_get_file_system (chooser);
path = gtk_file_system_filename_to_path (file_system, filename);
if (path)
{
_gtk_file_chooser_select_path (chooser, path);
gtk_file_path_free (path);
}
}
void
gtk_file_chooser_unselect_filename (GtkFileChooser *chooser,
const char *filename)
{
GtkFileSystem *file_system;
GtkFilePath *path;
g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
g_return_if_fail (filename != NULL);
file_system = _gtk_file_chooser_get_file_system (chooser);
path = gtk_file_system_filename_to_path (file_system, filename);
if (path)
{
_gtk_file_chooser_unselect_path (chooser, path);
gtk_file_path_free (path);
}
}
GSList *
gtk_file_chooser_get_filenames (GtkFileChooser *chooser)
{
GtkFileSystem *file_system;
GSList *paths;
GSList *tmp_list;
GSList *result = NULL;
g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
return 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);
}
gtk_file_paths_free (paths);
return g_slist_reverse (result);
}
void
gtk_file_chooser_set_current_folder (GtkFileChooser *chooser,
const gchar *filename)
{
GtkFileSystem *file_system;
GtkFilePath *path;
g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
g_return_if_fail (filename != NULL);
file_system = _gtk_file_chooser_get_file_system (chooser);
path = gtk_file_system_filename_to_path (file_system, filename);
if (path)
{
_gtk_file_chooser_set_current_folder (chooser, path);
gtk_file_path_free (path);
}
}
gchar *
gtk_file_chooser_get_current_folder (GtkFileChooser *chooser)
{
GtkFileSystem *file_system;
GtkFilePath *path;
gchar *filename;
g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
return NULL;
file_system = _gtk_file_chooser_get_file_system (chooser);
path = _gtk_file_chooser_get_current_folder (chooser);
filename = gtk_file_system_path_to_filename (file_system, path);
gtk_file_path_free (path);
return filename;
}
gchar *
gtk_file_chooser_get_uri (GtkFileChooser *chooser)
{
GSList *list;
GtkFileSystem *file_system;
GtkFilePath *path;
gchar *result = NULL;
g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
list = gtk_file_chooser_get_uris (chooser);
if (list)
file_system = _gtk_file_chooser_get_file_system (chooser);
path = gtk_file_chooser_get_path (chooser);
if (path)
{
result = list->data;
list = g_slist_delete_link (list, list);
g_slist_foreach (list, (GFunc)g_free, NULL);
g_slist_free (list);
result = gtk_file_system_path_to_uri (file_system, path);
gtk_file_path_free (path);
}
return result;
@ -303,24 +373,49 @@ gtk_file_chooser_set_uri (GtkFileChooser *chooser,
const char *uri)
{
g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
gtk_file_chooser_unselect_all (chooser);
gtk_file_chooser_select_uri (chooser, uri);
}
void
gtk_file_chooser_select_uri (GtkFileChooser *chooser,
const char *uri)
{
g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
GtkFileSystem *file_system;
GtkFilePath *path;
GTK_FILE_CHOOSER_GET_IFACE (chooser)->unselect_uri (chooser, uri);
g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
g_return_if_fail (uri != NULL);
file_system = _gtk_file_chooser_get_file_system (chooser);
path = gtk_file_system_uri_to_path (file_system, uri);
if (path)
{
_gtk_file_chooser_select_path (chooser, path);
gtk_file_path_free (path);
}
}
void
gtk_file_chooser_unselect_uri (GtkFileChooser *chooser,
const char *uri)
{
g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
GtkFileSystem *file_system;
GtkFilePath *path;
GTK_FILE_CHOOSER_GET_IFACE (chooser)->unselect_uri (chooser, uri);
g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
g_return_if_fail (uri != NULL);
file_system = _gtk_file_chooser_get_file_system (chooser);
path = gtk_file_system_uri_to_path (file_system, uri);
if (path)
{
_gtk_file_chooser_unselect_path (chooser, path);
gtk_file_path_free (path);
}
}
void
@ -343,30 +438,138 @@ gtk_file_chooser_unselect_all (GtkFileChooser *chooser)
GSList *
gtk_file_chooser_get_uris (GtkFileChooser *chooser)
{
g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
GtkFileSystem *file_system;
GSList *paths;
GSList *tmp_list;
GSList *result = NULL;
return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_uris (chooser);
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);
}
gtk_file_paths_free (paths);
return g_slist_reverse (result);
}
void
gtk_file_chooser_set_current_folder_uri (GtkFileChooser *chooser,
const gchar *uri)
{
GtkFileSystem *file_system;
GtkFilePath *path;
g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
g_return_if_fail (uri != NULL);
return GTK_FILE_CHOOSER_GET_IFACE (chooser)->set_current_folder (chooser, uri);
}
file_system = _gtk_file_chooser_get_file_system (chooser);
path = gtk_file_system_uri_to_path (file_system, uri);
if (path)
{
_gtk_file_chooser_set_current_folder (chooser, path);
gtk_file_path_free (path);
}
}
gchar *
gtk_file_chooser_get_current_folder_uri (GtkFileChooser *chooser)
{
GtkFileSystem *file_system;
GtkFilePath *path;
gchar *uri;
g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
file_system = _gtk_file_chooser_get_file_system (chooser);
path = _gtk_file_chooser_get_current_folder (chooser);
uri = gtk_file_system_path_to_uri (file_system, path);
gtk_file_path_free (path);
return uri;
}
void
_gtk_file_chooser_set_current_folder (GtkFileChooser *chooser,
const GtkFilePath *path)
{
g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
g_return_if_fail (path != NULL);
GTK_FILE_CHOOSER_GET_IFACE (chooser)->set_current_folder (chooser, path);
}
GtkFilePath *
_gtk_file_chooser_get_current_folder (GtkFileChooser *chooser)
{
g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_current_folder (chooser);
}
void
_gtk_file_chooser_select_path (GtkFileChooser *chooser,
const GtkFilePath *path)
{
g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
GTK_FILE_CHOOSER_GET_IFACE (chooser)->select_path (chooser, path);
}
void
_gtk_file_chooser_unselect_path (GtkFileChooser *chooser,
const GtkFilePath *path)
{
g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
GTK_FILE_CHOOSER_GET_IFACE (chooser)->unselect_path (chooser, path);
}
GSList *
_gtk_file_chooser_get_paths (GtkFileChooser *chooser)
{
g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_paths (chooser);
}
static GtkFilePath *
gtk_file_chooser_get_path (GtkFileChooser *chooser)
{
GSList *list;
GtkFilePath *result = NULL;
g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
list = _gtk_file_chooser_get_paths (chooser);
if (list)
{
result = list->data;
list = g_slist_delete_link (list, list);
gtk_file_paths_free (list);
}
return result;
}
GtkFileSystem *
_gtk_file_chooser_get_file_system (GtkFileChooser *chooser)
{
g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_file_system (chooser);
}
/* Preview widget
*/
void

View File

@ -28,10 +28,8 @@ G_BEGIN_DECLS
#define GTK_TYPE_FILE_CHOOSER (gtk_file_chooser_get_type ())
#define GTK_FILE_CHOOSER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_FILE_CHOOSER, GtkFileChooser))
#define GTK_IS_FILE_CHOOSER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_FILE_CHOOSER))
#define GTK_FILE_CHOOSER_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), GTK_TYPE_FILE_CHOOSER, GtkFileChooserIface))
typedef struct _GtkFileChooser GtkFileChooser;
typedef struct _GtkFileChooserIface GtkFileChooserIface;
typedef enum
{
@ -39,44 +37,6 @@ typedef enum
GTK_FILE_CHOOSER_ACTION_SAVE
} GtkFileChooserAction;
struct _GtkFileChooserIface
{
GTypeInterface base_iface;
/* GtkFileChooser interface has the following properties:
*
* action: GtkFileChooserAction
* folder_mode: boolean
* select_multiple: boolean
* show_hidden: boolean
* local_only: boolean
*
* preview_widget: GtkWidget
* preview_widget_active: boolean
*/
/* Methods
*/
void (*set_current_folder) (GtkFileChooser *chooser,
const char *uri);
char * (*get_current_folder) (GtkFileChooser *chooser);
void (*select_uri) (GtkFileChooser *chooser,
const char *uri);
void (*unselect_uri) (GtkFileChooser *chooser,
const char *uri);
void (*select_all) (GtkFileChooser *chooser);
void (*unselect_all) (GtkFileChooser *chooser);
GSList *(*get_uris) (GtkFileChooser *chooser);
/* Signals
*/
void (*current_folder_changed) (GtkFileChooser *chooser);
void (*selection_changed) (GtkFileChooser *chooser);
void (*update_preview) (GtkFileChooser *chooser,
const char *uri);
};
GType gtk_file_chooser_get_type (void);
/* Configuration

View File

@ -60,7 +60,7 @@ struct _GtkFileChooserImplDefault
GtkFileChooserAction action;
gchar *current_folder;
GtkFilePath *current_folder;
guint folder_mode : 1;
guint local_only : 1;
@ -93,16 +93,17 @@ static void gtk_file_chooser_impl_default_get_property (GObject
GValue *value,
GParamSpec *pspec);
static void gtk_file_chooser_impl_default_set_current_folder (GtkFileChooser *chooser,
const char *uri);
static char * gtk_file_chooser_impl_default_get_current_folder (GtkFileChooser *chooser);
static void gtk_file_chooser_impl_default_select_uri (GtkFileChooser *chooser,
const char *uri);
static void gtk_file_chooser_impl_default_unselect_uri (GtkFileChooser *chooser,
const char *uri);
static void gtk_file_chooser_impl_default_select_all (GtkFileChooser *chooser);
static void gtk_file_chooser_impl_default_unselect_all (GtkFileChooser *chooser);
static GSList *gtk_file_chooser_impl_default_get_uris (GtkFileChooser *chooser);
static void gtk_file_chooser_impl_default_set_current_folder (GtkFileChooser *chooser,
const GtkFilePath *path);
static GtkFilePath * gtk_file_chooser_impl_default_get_current_folder (GtkFileChooser *chooser);
static void gtk_file_chooser_impl_default_select_path (GtkFileChooser *chooser,
const GtkFilePath *path);
static void gtk_file_chooser_impl_default_unselect_path (GtkFileChooser *chooser,
const GtkFilePath *path);
static void gtk_file_chooser_impl_default_select_all (GtkFileChooser *chooser);
static void gtk_file_chooser_impl_default_unselect_all (GtkFileChooser *chooser);
static GSList * gtk_file_chooser_impl_default_get_paths (GtkFileChooser *chooser);
static GtkFileSystem *gtk_file_chooser_impl_default_get_file_system (GtkFileChooser *chooser);
static void tree_selection_changed (GtkTreeSelection *tree_selection,
GtkFileChooserImplDefault *impl);
@ -182,11 +183,12 @@ gtk_file_chooser_impl_default_class_init (GtkFileChooserImplDefaultClass *class)
static void
gtk_file_chooser_impl_default_iface_init (GtkFileChooserIface *iface)
{
iface->select_uri = gtk_file_chooser_impl_default_select_uri;
iface->unselect_uri = gtk_file_chooser_impl_default_unselect_uri;
iface->select_path = gtk_file_chooser_impl_default_select_path;
iface->unselect_path = gtk_file_chooser_impl_default_unselect_path;
iface->select_all = gtk_file_chooser_impl_default_select_all;
iface->unselect_all = gtk_file_chooser_impl_default_unselect_all;
iface->get_uris = gtk_file_chooser_impl_default_get_uris;
iface->get_paths = gtk_file_chooser_impl_default_get_paths;
iface->get_file_system = gtk_file_chooser_impl_default_get_file_system;
iface->set_current_folder = gtk_file_chooser_impl_default_set_current_folder;
iface->get_current_folder = gtk_file_chooser_impl_default_get_current_folder;
}
@ -504,21 +506,21 @@ expand_and_select_func (GtkFileSystemModel *model,
}
static void
gtk_file_chooser_impl_default_set_current_folder (GtkFileChooser *chooser,
const char *uri)
gtk_file_chooser_impl_default_set_current_folder (GtkFileChooser *chooser,
const GtkFilePath *path)
{
GtkFileChooserImplDefault *impl = GTK_FILE_CHOOSER_IMPL_DEFAULT (chooser);
_gtk_file_system_model_uri_do (impl->tree_model, uri,
expand_and_select_func, impl);
_gtk_file_system_model_path_do (impl->tree_model, path,
expand_and_select_func, impl);
}
static char *
static GtkFilePath *
gtk_file_chooser_impl_default_get_current_folder (GtkFileChooser *chooser)
{
GtkFileChooserImplDefault *impl = GTK_FILE_CHOOSER_IMPL_DEFAULT (chooser);
return g_strdup (impl->current_folder);
return gtk_file_path_copy (impl->current_folder);
}
static void
@ -538,24 +540,24 @@ select_func (GtkFileSystemModel *model,
}
static void
gtk_file_chooser_impl_default_select_uri (GtkFileChooser *chooser,
const char *uri)
gtk_file_chooser_impl_default_select_path (GtkFileChooser *chooser,
const GtkFilePath *path)
{
GtkFileChooserImplDefault *impl = GTK_FILE_CHOOSER_IMPL_DEFAULT (chooser);
gchar *parent_uri;
GtkFilePath *parent_path;
if (!gtk_file_system_get_parent (impl->file_system, uri, &parent_uri, NULL)) /* NULL-GError */
if (!gtk_file_system_get_parent (impl->file_system, path, &parent_path, NULL)) /* NULL-GError */
return;
if (!parent_uri)
if (!parent_path)
{
gtk_file_chooser_set_current_folder_uri (chooser, uri);
_gtk_file_chooser_set_current_folder (chooser, path);
}
else
{
gtk_file_chooser_set_current_folder_uri (chooser, parent_uri);
g_free (parent_uri);
_gtk_file_system_model_uri_do (impl->list_model, uri,
_gtk_file_chooser_set_current_folder (chooser, parent_path);
gtk_file_path_free (parent_path);
_gtk_file_system_model_path_do (impl->list_model, path,
select_func, impl);
}
}
@ -578,12 +580,12 @@ unselect_func (GtkFileSystemModel *model,
}
static void
gtk_file_chooser_impl_default_unselect_uri (GtkFileChooser *chooser,
const char *uri)
gtk_file_chooser_impl_default_unselect_path (GtkFileChooser *chooser,
const GtkFilePath *path)
{
GtkFileChooserImplDefault *impl = GTK_FILE_CHOOSER_IMPL_DEFAULT (chooser);
_gtk_file_system_model_uri_do (impl->list_model, uri,
_gtk_file_system_model_path_do (impl->list_model, path,
unselect_func, impl);
}
@ -608,14 +610,14 @@ gtk_file_chooser_impl_default_unselect_all (GtkFileChooser *chooser)
}
static void
get_uris_foreach (GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
gpointer data)
get_paths_foreach (GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
gpointer data)
{
GtkTreePath *child_path;
GtkTreeIter child_iter;
const gchar *uri;
const GtkFilePath *file_path;
struct {
GSList *result;
@ -626,12 +628,12 @@ get_uris_foreach (GtkTreeModel *model,
gtk_tree_model_get_iter (GTK_TREE_MODEL (info->impl->list_model), &child_iter, child_path);
gtk_tree_path_free (child_path);
uri = _gtk_file_system_model_get_uri (info->impl->tree_model, &child_iter);
info->result = g_slist_prepend (info->result, g_strdup (uri));
file_path = _gtk_file_system_model_get_path (info->impl->tree_model, &child_iter);
info->result = g_slist_prepend (info->result, gtk_file_path_copy (file_path));
}
static GSList *
gtk_file_chooser_impl_default_get_uris (GtkFileChooser *chooser)
gtk_file_chooser_impl_default_get_paths (GtkFileChooser *chooser)
{
GtkFileChooserImplDefault *impl = GTK_FILE_CHOOSER_IMPL_DEFAULT (chooser);
GtkTreeSelection *selection;
@ -648,10 +650,18 @@ gtk_file_chooser_impl_default_get_uris (GtkFileChooser *chooser)
info.impl = impl;
gtk_tree_selection_selected_foreach (selection,
get_uris_foreach, &info);
get_paths_foreach, &info);
return g_slist_reverse (info.result);
}
static GtkFileSystem *
gtk_file_chooser_impl_default_get_file_system (GtkFileChooser *chooser)
{
GtkFileChooserImplDefault *impl = GTK_FILE_CHOOSER_IMPL_DEFAULT (chooser);
return impl->file_system;
}
static gint
name_sort_func (GtkTreeModel *model,
GtkTreeIter *a,
@ -763,20 +773,20 @@ tree_selection_changed (GtkTreeSelection *selection,
GtkFileChooserImplDefault *impl)
{
GtkTreeIter iter;
const gchar *uri;
const GtkFilePath *file_path;
GtkTreePath *path;
if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
return;
uri = _gtk_file_system_model_get_uri (impl->tree_model, &iter);
if (impl->current_folder && strcmp (uri, impl->current_folder) == 0)
file_path = _gtk_file_system_model_get_path (impl->tree_model, &iter);
if (impl->current_folder && gtk_file_path_compare (file_path, impl->current_folder) == 0)
return;
if (impl->current_folder)
g_free (impl->current_folder);
impl->current_folder = g_strdup (uri);
_gtk_file_chooser_entry_set_base_folder (GTK_FILE_CHOOSER_ENTRY (impl->entry), uri);
gtk_file_path_free (impl->current_folder);
impl->current_folder = gtk_file_path_copy (file_path);
_gtk_file_chooser_entry_set_base_folder (GTK_FILE_CHOOSER_ENTRY (impl->entry), file_path);
if (impl->list_model)
{
@ -796,10 +806,10 @@ tree_selection_changed (GtkTreeSelection *selection,
/* Now update the list view to show the new row.
*/
uri = _gtk_file_system_model_get_uri (impl->tree_model, &iter);
file_path = _gtk_file_system_model_get_path (impl->tree_model, &iter);
impl->list_model = _gtk_file_system_model_new (impl->file_system,
uri, 0,
file_path, 0,
GTK_FILE_INFO_DISPLAY_NAME |
GTK_FILE_INFO_SIZE);
_gtk_file_system_model_set_show_folders (impl->list_model, FALSE);
@ -837,46 +847,46 @@ entry_activate (GtkEntry *entry,
GtkFileChooserImplDefault *impl)
{
GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (entry);
const gchar *folder_uri = _gtk_file_chooser_entry_get_current_folder (chooser_entry);
const GtkFilePath *folder_path = _gtk_file_chooser_entry_get_current_folder (chooser_entry);
const gchar *file_part = _gtk_file_chooser_entry_get_file_part (chooser_entry);
gchar *new_folder = NULL;
GtkFilePath *new_folder = NULL;
/* If the file part is non-empty, we need to figure out if it
* refers to a folder within folder. We could optimize the case
* here where the folder is already loaded for one of our tree models.
*/
if (file_part[0] == '\0' && strcmp (impl->current_folder, folder_uri) != 0)
new_folder = g_strdup (folder_uri);
if (file_part[0] == '\0' && gtk_file_path_compare (impl->current_folder, folder_path) != 0)
new_folder = gtk_file_path_copy (folder_path);
else
{
GtkFileFolder *folder = NULL;
gchar *subfolder_uri = NULL;
GtkFilePath *subfolder_path = NULL;
GtkFileInfo *info = NULL;
folder = gtk_file_system_get_folder (impl->file_system,
folder_uri,
folder_path,
GTK_FILE_INFO_IS_FOLDER,
NULL); /* NULL-GError */
if (folder)
subfolder_uri = gtk_file_system_make_uri (impl->file_system,
folder_uri,
subfolder_path = gtk_file_system_make_path (impl->file_system,
folder_path,
file_part,
NULL); /* NULL-GError */
if (subfolder_uri)
if (subfolder_path)
info = gtk_file_folder_get_info (folder,
subfolder_uri,
subfolder_path,
NULL); /* NULL-GError */
if (info && gtk_file_info_get_is_folder (info))
new_folder = g_strdup (subfolder_uri);
new_folder = gtk_file_path_copy (subfolder_path);
if (folder)
g_object_unref (folder);
if (subfolder_uri)
g_free (subfolder_uri);
if (subfolder_path)
gtk_file_path_free (subfolder_path);
if (info)
gtk_file_info_free (info);
@ -886,10 +896,10 @@ entry_activate (GtkEntry *entry,
{
g_signal_stop_emission_by_name (entry, "activate");
gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (impl), new_folder);
_gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (impl), new_folder);
_gtk_file_chooser_entry_set_file_part (chooser_entry, "");
g_free (new_folder);
gtk_file_path_free (new_folder);
}
}

View File

@ -40,8 +40,8 @@ struct _GtkFileChooserEntry
GtkEntry parent_instance;
GtkFileSystem *file_system;
gchar *base_folder;
gchar *current_folder_uri;
GtkFilePath *base_folder;
GtkFilePath *current_folder_path;
gchar *file_part;
GSource *completion_idle;
@ -151,8 +151,8 @@ gtk_file_chooser_entry_finalize (GObject *object)
if (chooser_entry->file_system)
g_object_unref (chooser_entry->file_system);
g_free (chooser_entry->base_folder);
g_free (chooser_entry->current_folder_uri);
gtk_file_path_free (chooser_entry->base_folder);
gtk_file_path_free (chooser_entry->current_folder_path);
g_free (chooser_entry->file_part);
parent_class->finalize (object);
@ -162,26 +162,26 @@ static gboolean
completion_idle_callback (GtkFileChooserEntry *chooser_entry)
{
GtkEditable *editable = GTK_EDITABLE (chooser_entry);
GSList *child_uris = NULL;
GSList *child_paths = NULL;
GSList *tmp_list;
gchar *common_prefix = NULL;
gchar *unique_uri = NULL;
GtkFilePath *unique_path = NULL;
chooser_entry->completion_idle = NULL;
if (!chooser_entry->current_folder &&
chooser_entry->file_system &&
chooser_entry->current_folder_uri)
chooser_entry->current_folder_path)
chooser_entry->current_folder = gtk_file_system_get_folder (chooser_entry->file_system,
chooser_entry->current_folder_uri,
chooser_entry->current_folder_path,
GTK_FILE_INFO_DISPLAY_NAME | GTK_FILE_INFO_IS_FOLDER,
NULL); /* NULL-GError */
if (chooser_entry->current_folder)
gtk_file_folder_list_children (chooser_entry->current_folder,
&child_uris,
&child_paths,
NULL); /* NULL-GError */
for (tmp_list = child_uris; tmp_list; tmp_list = tmp_list->next)
for (tmp_list = child_paths; tmp_list; tmp_list = tmp_list->next)
{
GtkFileInfo *info;
@ -197,7 +197,7 @@ completion_idle_callback (GtkFileChooserEntry *chooser_entry)
if (!common_prefix)
{
common_prefix = g_strdup (display_name);
unique_uri = g_strdup (tmp_list->data);
unique_path = gtk_file_path_copy (tmp_list->data);
}
else
{
@ -212,8 +212,8 @@ completion_idle_callback (GtkFileChooserEntry *chooser_entry)
*p = '\0';
g_free (unique_uri);
unique_uri = NULL;
gtk_file_path_free (unique_path);
unique_path = NULL;
}
}
@ -221,12 +221,12 @@ completion_idle_callback (GtkFileChooserEntry *chooser_entry)
}
}
if (unique_uri)
if (unique_path)
{
GtkFileInfo *info;
info = gtk_file_folder_get_info (chooser_entry->current_folder,
unique_uri,
unique_path,
NULL); /* NULL-GError */
if (info)
@ -241,11 +241,11 @@ completion_idle_callback (GtkFileChooserEntry *chooser_entry)
gtk_file_info_free (info);
}
g_free (unique_uri);
gtk_file_path_free (unique_path);
}
g_slist_foreach (child_uris, (GFunc)g_free, NULL);
g_slist_free (child_uris);
gtk_file_paths_free (child_paths);
g_slist_free (child_paths);
if (common_prefix)
{
@ -328,7 +328,7 @@ gtk_file_chooser_entry_changed (GtkEditable *editable)
{
GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (editable);
const gchar *text;
gchar *folder_uri;
GtkFilePath *folder_path;
gchar *file_part;
text = gtk_entry_get_text (GTK_ENTRY (editable));
@ -337,25 +337,27 @@ gtk_file_chooser_entry_changed (GtkEditable *editable)
!chooser_entry->base_folder ||
!gtk_file_system_parse (chooser_entry->file_system,
chooser_entry->base_folder, text,
&folder_uri, &file_part, NULL)) /* NULL-GError */
&folder_path, &file_part, NULL)) /* NULL-GError */
{
folder_uri = g_strdup (chooser_entry->base_folder);
folder_path = gtk_file_path_copy (chooser_entry->base_folder);
file_part = g_strdup ("");
}
if (chooser_entry->current_folder_uri &&
strcmp (folder_uri, chooser_entry->current_folder_uri) != 0)
if (chooser_entry->current_folder_path)
{
if (chooser_entry->current_folder_uri)
g_free (chooser_entry->current_folder_uri);
if (chooser_entry->current_folder)
if (gtk_file_path_compare (folder_path, chooser_entry->current_folder_path) != 0)
{
g_object_unref (chooser_entry->current_folder);
chooser_entry->current_folder = NULL;
if (chooser_entry->current_folder)
{
g_object_unref (chooser_entry->current_folder);
chooser_entry->current_folder = NULL;
}
}
gtk_file_path_free (chooser_entry->current_folder_path);
}
chooser_entry->current_folder_uri = folder_uri;
chooser_entry->current_folder_path = folder_path;
if (chooser_entry->file_part)
g_free (chooser_entry->file_part);
@ -412,18 +414,18 @@ _gtk_file_chooser_entry_set_file_system (GtkFileChooserEntry *chooser_entry,
/**
* _gtk_file_chooser_entry_set_base_folder:
* @chooser_entry: a #GtkFileChooserEntry
* @uri: URI of a folder in the chooser entries current file system.
* @path: path of a folder in the chooser entries current file system.
*
* Sets the folder with respect to which completions occur.
**/
void
_gtk_file_chooser_entry_set_base_folder (GtkFileChooserEntry *chooser_entry,
const gchar *uri)
const GtkFilePath *path)
{
if (chooser_entry->base_folder)
g_free (chooser_entry->base_folder);
gtk_file_path_free (chooser_entry->base_folder);
chooser_entry->base_folder = g_strdup (uri);
chooser_entry->base_folder = gtk_file_path_copy (path);
}
/**
@ -438,13 +440,13 @@ _gtk_file_chooser_entry_set_base_folder (GtkFileChooserEntry *chooser_entry,
* path that doesn't point to a folder in the file system, it will
* be %NULL.
*
* Return value: the URI of current folder - this value is owned by the
* Return value: the path of current folder - this value is owned by the
* chooser entry and must not be modified or freed.
**/
const gchar *
const GtkFilePath *
_gtk_file_chooser_entry_get_current_folder (GtkFileChooserEntry *chooser_entry)
{
return chooser_entry->current_folder_uri;
return chooser_entry->current_folder_path;
}
/**
@ -453,7 +455,7 @@ _gtk_file_chooser_entry_get_current_folder (GtkFileChooserEntry *chooser_entry)
*
* Gets the non-folder portion of whatever the user has entered
* into the file selector. What is returned is a UTF-8 string,
* and if a filename URI is needed, gtk_file_system_make_uri()
* and if a filename path is needed, gtk_file_system_make_path()
* must be used
*
* Return value: the entered filename - this value is owned by the

View File

@ -32,16 +32,16 @@ G_BEGIN_DECLS
typedef struct _GtkFileChooserEntry GtkFileChooserEntry;
GType _gtk_file_chooser_entry_get_type (void);
GtkWidget * _gtk_file_chooser_entry_new (void);
void _gtk_file_chooser_entry_set_file_system (GtkFileChooserEntry *chooser_entry,
GtkFileSystem *file_system);
void _gtk_file_chooser_entry_set_base_folder (GtkFileChooserEntry *chooser_entry,
const gchar *uri);
void _gtk_file_chooser_entry_set_file_part (GtkFileChooserEntry *chooser_entry,
const gchar *file_part);
const gchar *_gtk_file_chooser_entry_get_current_folder (GtkFileChooserEntry *chooser_entry);
const gchar *_gtk_file_chooser_entry_get_file_part (GtkFileChooserEntry *chooser_entry);
GType _gtk_file_chooser_entry_get_type (void);
GtkWidget * _gtk_file_chooser_entry_new (void);
void _gtk_file_chooser_entry_set_file_system (GtkFileChooserEntry *chooser_entry,
GtkFileSystem *file_system);
void _gtk_file_chooser_entry_set_base_folder (GtkFileChooserEntry *chooser_entry,
const GtkFilePath *path);
void _gtk_file_chooser_entry_set_file_part (GtkFileChooserEntry *chooser_entry,
const gchar *file_part);
const GtkFilePath *_gtk_file_chooser_entry_get_current_folder (GtkFileChooserEntry *chooser_entry);
const gchar * _gtk_file_chooser_entry_get_file_part (GtkFileChooserEntry *chooser_entry);
G_END_DECLS

View File

@ -0,0 +1,83 @@
/* GTK - The GIMP Toolkit
* gtkfilechooserprivate.h: Interface definition for file selector GUIs
* Copyright (C) 2003, Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __GTK_FILE_CHOOSER_PRIVATE_H__
#define __GTK_FILE_CHOOSER_PRIVATE_H__
#include "gtkfilechooser.h"
#include "gtkfilesystem.h"
G_BEGIN_DECLS
#define GTK_FILE_CHOOSER_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), GTK_TYPE_FILE_CHOOSER, GtkFileChooserIface))
typedef struct _GtkFileChooserIface GtkFileChooserIface;
struct _GtkFileChooserIface
{
GTypeInterface base_iface;
/* GtkFileChooser interface has the following properties:
*
* action: GtkFileChooserAction
* folder_mode: boolean
* select_multiple: boolean
* show_hidden: boolean
* local_only: boolean
*
* preview_widget: GtkWidget
* preview_widget_active: boolean
*/
/* Methods
*/
void (*set_current_folder) (GtkFileChooser *chooser,
const GtkFilePath *path);
GtkFilePath * (*get_current_folder) (GtkFileChooser *chooser);
void (*select_path) (GtkFileChooser *chooser,
const GtkFilePath *path);
void (*unselect_path) (GtkFileChooser *chooser,
const GtkFilePath *path);
void (*select_all) (GtkFileChooser *chooser);
void (*unselect_all) (GtkFileChooser *chooser);
GSList * (*get_paths) (GtkFileChooser *chooser);
GtkFileSystem *(*get_file_system) (GtkFileChooser *chooser);
/* Signals
*/
void (*current_folder_changed) (GtkFileChooser *chooser);
void (*selection_changed) (GtkFileChooser *chooser);
void (*update_preview) (GtkFileChooser *chooser,
const gchar *uri);
};
GtkFileSystem *_gtk_file_chooser_get_file_system (GtkFileChooser *chooser);
void _gtk_file_chooser_set_current_folder (GtkFileChooser *chooser,
const GtkFilePath *path);
GtkFilePath * _gtk_file_chooser_get_current_folder (GtkFileChooser *chooser);
void _gtk_file_chooser_select_path (GtkFileChooser *chooser,
const GtkFilePath *path);
void _gtk_file_chooser_unselect_path (GtkFileChooser *chooser,
const GtkFilePath *path);
GSList * _gtk_file_chooser_get_paths (GtkFileChooser *chooser);
G_END_DECLS
#endif /* __GTK_FILE_CHOOSER_PRIVATE_H__ */

View File

@ -24,21 +24,21 @@
#include "gtkfilechooserenums.h"
#include "gtkfilesystem.h"
static void delegate_set_current_folder (GtkFileChooser *chooser,
const char *uri);
static char * delegate_get_current_folder (GtkFileChooser *chooser);
static void delegate_select_uri (GtkFileChooser *chooser,
const char *uri);
static void delegate_unselect_uri (GtkFileChooser *chooser,
const char *uri);
static void delegate_select_all (GtkFileChooser *chooser);
static void delegate_unselect_all (GtkFileChooser *chooser);
static GSList *delegate_get_uris (GtkFileChooser *chooser);
static void delegate_current_folder_changed (GtkFileChooser *chooser,
gpointer data);
static void delegate_selection_changed (GtkFileChooser *chooser,
gpointer data);
static void delegate_set_current_folder (GtkFileChooser *chooser,
const GtkFilePath *path);
static GtkFilePath * delegate_get_current_folder (GtkFileChooser *chooser);
static void delegate_select_path (GtkFileChooser *chooser,
const GtkFilePath *path);
static void delegate_unselect_path (GtkFileChooser *chooser,
const GtkFilePath *path);
static void delegate_select_all (GtkFileChooser *chooser);
static void delegate_unselect_all (GtkFileChooser *chooser);
static GSList * delegate_get_paths (GtkFileChooser *chooser);
static GtkFileSystem *delegate_get_file_system (GtkFileChooser *chooser);
static void delegate_current_folder_changed (GtkFileChooser *chooser,
gpointer data);
static void delegate_selection_changed (GtkFileChooser *chooser,
gpointer data);
/**
* _gtk_file_chooser_install_properties:
@ -112,11 +112,12 @@ _gtk_file_chooser_delegate_iface_init (GtkFileChooserIface *iface)
{
iface->set_current_folder = delegate_set_current_folder;
iface->get_current_folder = delegate_get_current_folder;
iface->select_uri = delegate_select_uri;
iface->unselect_uri = delegate_unselect_uri;
iface->select_path = delegate_select_path;
iface->unselect_path = delegate_unselect_path;
iface->select_all = delegate_select_all;
iface->unselect_all = delegate_unselect_all;
iface->get_uris = delegate_get_uris;
iface->get_paths = delegate_get_paths;
iface->get_file_system = delegate_get_file_system;
}
/**
@ -152,17 +153,17 @@ get_delegate (GtkFileChooser *receiver)
}
static void
delegate_select_uri (GtkFileChooser *chooser,
const char *uri)
delegate_select_path (GtkFileChooser *chooser,
const GtkFilePath *path)
{
gtk_file_chooser_select_uri (get_delegate (chooser), uri);
_gtk_file_chooser_select_path (get_delegate (chooser), path);
}
static void
delegate_unselect_uri (GtkFileChooser *chooser,
const char *uri)
delegate_unselect_path (GtkFileChooser *chooser,
const GtkFilePath *path)
{
gtk_file_chooser_unselect_uri (get_delegate (chooser), uri);
_gtk_file_chooser_unselect_path (get_delegate (chooser), path);
}
static void
@ -178,22 +179,28 @@ delegate_unselect_all (GtkFileChooser *chooser)
}
static GSList *
delegate_get_uris (GtkFileChooser *chooser)
delegate_get_paths (GtkFileChooser *chooser)
{
return gtk_file_chooser_get_uris (get_delegate (chooser));
return _gtk_file_chooser_get_paths (get_delegate (chooser));
}
static GtkFileSystem *
delegate_get_file_system (GtkFileChooser *chooser)
{
return _gtk_file_chooser_get_file_system (get_delegate (chooser));
}
static void
delegate_set_current_folder (GtkFileChooser *chooser,
const char *uri)
delegate_set_current_folder (GtkFileChooser *chooser,
const GtkFilePath *path)
{
gtk_file_chooser_set_current_folder_uri (chooser, uri);
_gtk_file_chooser_set_current_folder (chooser, path);
}
static char *
static GtkFilePath *
delegate_get_current_folder (GtkFileChooser *chooser)
{
return gtk_file_chooser_get_current_folder_uri (get_delegate (chooser));
return _gtk_file_chooser_get_current_folder (get_delegate (chooser));
}
static void

View File

@ -22,7 +22,7 @@
#ifndef __GTK_FILE_CHOOSER_UTILS_H__
#define __GTK_FILE_CHOOSER_UTILS_H__
#include "gtkfilechooser.h"
#include "gtkfilechooserprivate.h"
G_BEGIN_DECLS

View File

@ -20,6 +20,8 @@
#include "gtkfilesystem.h"
#include <string.h>
struct _GtkFileInfo
{
GtkFileTime modification_time;
@ -326,85 +328,85 @@ gtk_file_system_list_roots (GtkFileSystem *file_system)
}
GtkFileInfo *
gtk_file_system_get_root_info (GtkFileSystem *file_system,
const gchar *uri,
GtkFileInfoType types,
GError **error)
gtk_file_system_get_root_info (GtkFileSystem *file_system,
const GtkFilePath *path,
GtkFileInfoType types,
GError **error)
{
g_return_val_if_fail (GTK_IS_FILE_SYSTEM (file_system), NULL);
g_return_val_if_fail (uri != NULL, NULL);
g_return_val_if_fail (path != NULL, NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
return GTK_FILE_SYSTEM_GET_IFACE (file_system)->get_root_info (file_system, uri, types, error);
return GTK_FILE_SYSTEM_GET_IFACE (file_system)->get_root_info (file_system, path, types, error);
}
GtkFileFolder *
gtk_file_system_get_folder (GtkFileSystem *file_system,
const gchar *uri,
GtkFileInfoType types,
GError **error)
gtk_file_system_get_folder (GtkFileSystem *file_system,
const GtkFilePath *path,
GtkFileInfoType types,
GError **error)
{
g_return_val_if_fail (GTK_IS_FILE_SYSTEM (file_system), NULL);
g_return_val_if_fail (uri != NULL, NULL);
g_return_val_if_fail (path != NULL, NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
return GTK_FILE_SYSTEM_GET_IFACE (file_system)->get_folder (file_system, uri, types, error);
return GTK_FILE_SYSTEM_GET_IFACE (file_system)->get_folder (file_system, path, types, error);
}
gboolean
gtk_file_system_create_folder(GtkFileSystem *file_system,
const gchar *uri,
GError **error)
gtk_file_system_create_folder(GtkFileSystem *file_system,
const GtkFilePath *path,
GError **error)
{
g_return_val_if_fail (GTK_IS_FILE_SYSTEM (file_system), FALSE);
g_return_val_if_fail (uri != NULL, FALSE);
g_return_val_if_fail (path != NULL, FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
return GTK_FILE_SYSTEM_GET_IFACE (file_system)->create_folder (file_system, uri, error);
return GTK_FILE_SYSTEM_GET_IFACE (file_system)->create_folder (file_system, path, error);
}
gboolean
gtk_file_system_get_parent (GtkFileSystem *file_system,
const gchar *uri,
gchar **parent,
GError **error)
gtk_file_system_get_parent (GtkFileSystem *file_system,
const GtkFilePath *path,
GtkFilePath **parent,
GError **error)
{
gchar *tmp_parent = NULL;
GtkFilePath *tmp_parent = NULL;
gboolean result;
g_return_val_if_fail (GTK_IS_FILE_SYSTEM (file_system), FALSE);
g_return_val_if_fail (uri != NULL, FALSE);
g_return_val_if_fail (path != NULL, FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
result = GTK_FILE_SYSTEM_GET_IFACE (file_system)->get_parent (file_system, uri, &tmp_parent, error);
result = GTK_FILE_SYSTEM_GET_IFACE (file_system)->get_parent (file_system, path, &tmp_parent, error);
g_assert (result || tmp_parent == NULL);
if (parent)
*parent = tmp_parent;
else
g_free (tmp_parent);
gtk_file_path_free (tmp_parent);
return result;
}
gchar *
gtk_file_system_make_uri (GtkFileSystem *file_system,
const gchar *base_uri,
const gchar *display_name,
GError **error)
GtkFilePath *
gtk_file_system_make_path (GtkFileSystem *file_system,
const GtkFilePath *base_path,
const gchar *display_name,
GError **error)
{
g_return_val_if_fail (GTK_IS_FILE_SYSTEM (file_system), NULL);
g_return_val_if_fail (base_uri != NULL, NULL);
g_return_val_if_fail (base_path != NULL, NULL);
g_return_val_if_fail (display_name != NULL, NULL);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
return GTK_FILE_SYSTEM_GET_IFACE (file_system)->make_uri (file_system, base_uri, display_name, error);
return GTK_FILE_SYSTEM_GET_IFACE (file_system)->make_path (file_system, base_path, display_name, error);
}
/**
* gtk_file_system_parse:
* @file_system: a #GtkFileSystem
* @base_uri: reference folder with respect to which relative
* @base_path: reference folder with respect to which relative
* paths should be interpreted.
* @str: the string to parse
* @folder: location to store folder portion of result, or %NULL
@ -412,8 +414,8 @@ gtk_file_system_make_uri (GtkFileSystem *file_system,
* @error: location to store error, or %NULL
*
* Given a string entered by a user, parse it (possibly using
* heuristics) into a folder URI and a UTF-8 encoded
* filename part. (Suitable for passing to gtk_file_system_make_uri())
* heuristics) into a folder path and a UTF-8 encoded
* filename part. (Suitable for passing to gtk_file_system_make_path())
*
* Note that the returned filename point may point to a subfolder
* of the returned folder. Adding a trailing path separator is needed
@ -433,31 +435,31 @@ gtk_file_system_make_uri (GtkFileSystem *file_system,
* Return value: %TRUE if the parsing succeeds, otherwise, %FALSE.
**/
gboolean
gtk_file_system_parse (GtkFileSystem *file_system,
const gchar *base_uri,
const gchar *str,
gchar **folder,
gchar **file_part,
GError **error)
gtk_file_system_parse (GtkFileSystem *file_system,
const GtkFilePath *base_path,
const gchar *str,
GtkFilePath **folder,
gchar **file_part,
GError **error)
{
gchar *tmp_folder = NULL;
GtkFilePath *tmp_folder = NULL;
gchar *tmp_file_part = NULL;
gboolean result;
g_return_val_if_fail (GTK_IS_FILE_SYSTEM (file_system), FALSE);
g_return_val_if_fail (base_uri != NULL, FALSE);
g_return_val_if_fail (base_path != NULL, FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
result = GTK_FILE_SYSTEM_GET_IFACE (file_system)->parse (file_system, base_uri, str,
&tmp_folder, &tmp_file_part,
error);
result = GTK_FILE_SYSTEM_GET_IFACE (file_system)->parse (file_system, base_path, str,
&tmp_folder, &tmp_file_part,
error);
g_assert (result || (tmp_folder == NULL && tmp_file_part == NULL));
if (folder)
*folder = tmp_folder;
else
g_free (tmp_folder);
gtk_file_path_free (tmp_folder);
if (file_part)
*file_part = tmp_file_part;
@ -467,6 +469,47 @@ gtk_file_system_parse (GtkFileSystem *file_system,
return result;
}
gchar *
gtk_file_system_path_to_uri (GtkFileSystem *file_system,
const GtkFilePath *path)
{
g_return_val_if_fail (GTK_IS_FILE_SYSTEM (file_system), NULL);
g_return_val_if_fail (path != NULL, NULL);
return GTK_FILE_SYSTEM_GET_IFACE (file_system)->path_to_uri (file_system, path);
}
gchar *
gtk_file_system_path_to_filename (GtkFileSystem *file_system,
const GtkFilePath *path)
{
g_return_val_if_fail (GTK_IS_FILE_SYSTEM (file_system), NULL);
g_return_val_if_fail (path != NULL, NULL);
return GTK_FILE_SYSTEM_GET_IFACE (file_system)->path_to_filename (file_system, path);
}
GtkFilePath *
gtk_file_system_uri_to_path (GtkFileSystem *file_system,
const gchar *uri)
{
g_return_val_if_fail (GTK_IS_FILE_SYSTEM (file_system), NULL);
g_return_val_if_fail (uri != NULL, NULL);
return GTK_FILE_SYSTEM_GET_IFACE (file_system)->uri_to_path (file_system, uri);
}
GtkFilePath *
gtk_file_system_filename_to_path (GtkFileSystem *file_system,
const gchar *filename)
{
g_return_val_if_fail (GTK_IS_FILE_SYSTEM (file_system), NULL);
g_return_val_if_fail (filename != NULL, NULL);
return GTK_FILE_SYSTEM_GET_IFACE (file_system)->filename_to_path (file_system, filename);
}
/*****************************************
* GtkFileFolder *
*****************************************/
@ -556,22 +599,36 @@ gtk_file_folder_list_children (GtkFileFolder *folder,
if (children)
*children = tmp_children;
else
{
g_slist_foreach (tmp_children, (GFunc)g_free, NULL);
g_slist_free (tmp_children);
}
gtk_file_paths_free (tmp_children);
return result;
}
GtkFileInfo *
gtk_file_folder_get_info (GtkFileFolder *folder,
const gchar *uri,
GError **error)
gtk_file_folder_get_info (GtkFileFolder *folder,
const GtkFilePath *path,
GError **error)
{
g_return_val_if_fail (GTK_IS_FILE_FOLDER (folder), NULL);
g_return_val_if_fail (uri != NULL, NULL);
g_return_val_if_fail (path != NULL, NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
return GTK_FILE_FOLDER_GET_IFACE (folder)->get_info (folder, uri, error);
return GTK_FILE_FOLDER_GET_IFACE (folder)->get_info (folder, path, error);
}
GSList *
gtk_file_paths_sort (GSList *paths)
{
return g_slist_sort (paths, (GCompareFunc)strcmp);
}
void
gtk_file_paths_free (GSList *paths)
{
GSList *tmp_list;
for (tmp_list = paths; tmp_list; tmp_list = tmp_list->next)
gtk_file_path_free (tmp_list->data);
g_slist_free (paths);
}

View File

@ -34,6 +34,8 @@ typedef struct _GtkFileInfo GtkFileInfo;
typedef struct _GtkFileSystem GtkFileSystem;
typedef struct _GtkFileSystemIface GtkFileSystemIface;
typedef struct _GtkFilePath GtkFilePath;
/* Mask of information about a file, for monitoring and
* gtk_file_system_get_info()
*/
@ -110,37 +112,46 @@ struct _GtkFileSystemIface
/* Methods
*/
GSList * (*list_roots) (GtkFileSystem *file_system);
GSList * (*list_roots) (GtkFileSystem *file_system);
GtkFileInfo * (*get_root_info) (GtkFileSystem *file_system,
const gchar *uri,
GtkFileInfoType types,
GError **error);
GtkFileInfo * (*get_root_info) (GtkFileSystem *file_system,
const GtkFilePath *path,
GtkFileInfoType types,
GError **error);
GtkFileFolder * (*get_folder) (GtkFileSystem *file_system,
const gchar *uri,
GtkFileInfoType types,
GError **error);
gboolean (*create_folder) (GtkFileSystem *file_system,
const gchar *uri,
GError **error);
GtkFileFolder * (*get_folder) (GtkFileSystem *file_system,
const GtkFilePath *path,
GtkFileInfoType types,
GError **error);
gboolean (*create_folder) (GtkFileSystem *file_system,
const GtkFilePath *path,
GError **error);
/* URI Manipulation
/* Path Manipulation
*/
gboolean (*get_parent) (GtkFileSystem *file_system,
const gchar *uri,
gchar **parent,
GError **error);
gchar * (*make_uri) (GtkFileSystem *file_system,
const gchar *base_uri,
const gchar *display_name,
GError **error);
gboolean (*parse) (GtkFileSystem *file_system,
const gchar *base_uri,
const gchar *str,
gchar **folder,
gchar **file_part,
GError **error);
gboolean (*get_parent) (GtkFileSystem *file_system,
const GtkFilePath *path,
GtkFilePath **parent,
GError **error);
GtkFilePath * (*make_path) (GtkFileSystem *file_system,
const GtkFilePath *base_path,
const gchar *display_name,
GError **error);
gboolean (*parse) (GtkFileSystem *file_system,
const GtkFilePath *base_path,
const gchar *str,
GtkFilePath **folder,
gchar **file_part,
GError **error);
gchar * (*path_to_uri) (GtkFileSystem *file_system,
const GtkFilePath *path);
gchar * (*path_to_filename) (GtkFileSystem *file_system,
const GtkFilePath *path);
GtkFilePath *(*uri_to_path) (GtkFileSystem *file_system,
const gchar *uri);
GtkFilePath *(*filename_to_path) (GtkFileSystem *file_system,
const gchar *path);
/* Signals
*/
void (*roots_changed) (GtkFileSystem *file_system);
@ -148,33 +159,43 @@ struct _GtkFileSystemIface
GType gtk_file_system_get_type (void);
GSList * gtk_file_system_list_roots (GtkFileSystem *file_system);
GtkFileInfo * gtk_file_system_get_root_info (GtkFileSystem *file_system,
const gchar *uri,
GtkFileInfoType types,
GError **error);
GSList * gtk_file_system_list_roots (GtkFileSystem *file_system);
GtkFileInfo * gtk_file_system_get_root_info (GtkFileSystem *file_system,
const GtkFilePath *path,
GtkFileInfoType types,
GError **error);
gboolean gtk_file_system_get_parent (GtkFileSystem *file_system,
const gchar *uri,
gchar **parent,
GError **error);
GtkFileFolder *gtk_file_system_get_folder (GtkFileSystem *file_system,
const gchar *uri,
GtkFileInfoType types,
GError **error);
gboolean gtk_file_system_create_folder (GtkFileSystem *file_system,
const gchar *uri,
GError **error);
gchar * gtk_file_system_make_uri (GtkFileSystem *file_system,
const gchar *base_uri,
const gchar *display_name,
GError **error);
gboolean gtk_file_system_parse (GtkFileSystem *file_system,
const gchar *base_uri,
const gchar *str,
gchar **folder,
gchar **file_part,
GError **error);
gboolean gtk_file_system_get_parent (GtkFileSystem *file_system,
const GtkFilePath *path,
GtkFilePath **parent,
GError **error);
GtkFileFolder *gtk_file_system_get_folder (GtkFileSystem *file_system,
const GtkFilePath *path,
GtkFileInfoType types,
GError **error);
gboolean gtk_file_system_create_folder (GtkFileSystem *file_system,
const GtkFilePath *path,
GError **error);
GtkFilePath * gtk_file_system_make_path (GtkFileSystem *file_system,
const GtkFilePath *base_path,
const gchar *display_name,
GError **error);
gboolean gtk_file_system_parse (GtkFileSystem *file_system,
const GtkFilePath *base_path,
const gchar *str,
GtkFilePath **folder,
gchar **file_part,
GError **error);
gchar * gtk_file_system_path_to_uri (GtkFileSystem *file_system,
const GtkFilePath *path);
gchar * gtk_file_system_path_to_filename (GtkFileSystem *file_system,
const GtkFilePath *path);
GtkFilePath *gtk_file_system_uri_to_path (GtkFileSystem *file_system,
const gchar *uri);
GtkFilePath *gtk_file_system_filename_to_path (GtkFileSystem *file_system,
const gchar *filename);
/*
* Detailed information about a particular folder
*/
@ -189,12 +210,12 @@ struct _GtkFileFolderIface
/* Methods
*/
GtkFileInfo * (*get_info) (GtkFileFolder *folder,
const gchar *uri,
GError **error);
gboolean (*list_children) (GtkFileFolder *folder,
GSList **children,
GError **error);
GtkFileInfo * (*get_info) (GtkFileFolder *folder,
const GtkFilePath *path,
GError **error);
gboolean (*list_children) (GtkFileFolder *folder,
GSList **children,
GError **error);
/* ??? refresh() ??? */
@ -202,20 +223,43 @@ struct _GtkFileFolderIface
*/
void (*deleted) (GtkFileFolder *monitor);
void (*files_added) (GtkFileFolder *monitor,
GSList *uris);
GSList *paths);
void (*files_changed) (GtkFileFolder *monitor,
GSList *uris);
GSList *paths);
void (*files_removed) (GtkFileFolder *monitor,
GSList *uris);
GSList *paths);
};
GType gtk_file_folder_get_type (void);
gboolean gtk_file_folder_list_children (GtkFileFolder *folder,
GSList **children,
GError **error);
GtkFileInfo *gtk_file_folder_get_info (GtkFileFolder *folder,
const gchar *uri,
GError **error);
gboolean gtk_file_folder_list_children (GtkFileFolder *folder,
GSList **children,
GError **error);
GtkFileInfo *gtk_file_folder_get_info (GtkFileFolder *folder,
const GtkFilePath *path,
GError **error);
#ifdef __GNUC__
#define gtk_file_path_new_dup(str) \
({ const gchar *__s = (str); (GtkFilePath *)g_strdup(__s); })
#define gtk_file_path_new_steal(str) \
({ gchar *__s = (str); (GtkFilePath *)__s; })
#define gtk_file_path_get_string(path) \
({ const GtkFilePath *__p = (path); (const gchar *)__p; })
#define gtk_file_path_free(path) \
({ GtkFilePath *__p = (path); g_free (__p); })
#else /* __GNUC__ */
#define gtk_file_path_new_dup(str) ((GtkFilePath *)g_strdup(str))
#define gtk_file_path_new_steal(str) ((GtkFilePath *)(str))
#define gtk_file_path_get_string(path) ((const gchar *)(str))
#define gtk_file_path_free(path) g_free (path)
#endif/* __GNUC__ */
#define gtk_file_path_copy(path) gtk_file_path_new_dup (gtk_file_path_get_string(path))
#define gtk_file_path_compare(path1,path2) strcmp (gtk_file_path_get_string (path1), \
gtk_file_path_get_string (path2))
GSList *gtk_file_paths_sort (GSList *paths);
void gtk_file_paths_free (GSList *paths);
G_END_DECLS

View File

@ -54,7 +54,7 @@ struct _GtkFileSystemModel
struct _FileModelNode
{
gchar *uri;
GtkFilePath *path;
FileModelNode *next;
GtkFileInfo *info;
@ -114,7 +114,7 @@ static void gtk_file_system_model_unref_node (GtkTreeModel *tr
GtkTreeIter *iter);
static FileModelNode *file_model_node_new (GtkFileSystemModel *model,
const gchar *uri);
const GtkFilePath *path);
static void file_model_node_free (FileModelNode *node);
static void file_model_node_ref (FileModelNode *node);
static void file_model_node_unref (GtkFileSystemModel *model,
@ -132,25 +132,25 @@ static FileModelNode * file_model_node_get_children (GtkFileSystemModel *mode
static void deleted_callback (GtkFileFolder *folder,
FileModelNode *node);
static void files_added_callback (GtkFileFolder *folder,
GSList *uris,
GSList *paths,
FileModelNode *node);
static void files_changed_callback (GtkFileFolder *folder,
GSList *uris,
GSList *paths,
FileModelNode *node);
static void files_removed_callback (GtkFileFolder *folder,
GSList *uris,
GSList *paths,
FileModelNode *node);
static void root_deleted_callback (GtkFileFolder *folder,
GtkFileSystemModel *model);
static void root_files_added_callback (GtkFileFolder *folder,
GSList *uris,
GSList *paths,
GtkFileSystemModel *model);
static void root_files_changed_callback (GtkFileFolder *folder,
GSList *uris,
GSList *paths,
GtkFileSystemModel *model);
static void root_files_removed_callback (GtkFileFolder *folder,
GSList *uris,
GSList *paths,
GtkFileSystemModel *model);
GType
@ -271,8 +271,6 @@ gtk_file_system_model_get_column_type (GtkTreeModel *tree_model,
{
switch (index)
{
case GTK_FILE_SYSTEM_MODEL_URI:
return G_TYPE_STRING;
case GTK_FILE_SYSTEM_MODEL_INFO:
return GTK_TYPE_FILE_INFO;
case GTK_FILE_SYSTEM_MODEL_DISPLAY_NAME:
@ -356,10 +354,6 @@ gtk_file_system_model_get_value (GtkTreeModel *tree_model,
switch (column)
{
case GTK_FILE_SYSTEM_MODEL_URI:
g_value_init (value, G_TYPE_STRING);
g_value_set_string (value, node->uri);
break;
case GTK_FILE_SYSTEM_MODEL_INFO:
g_value_init (value, GTK_TYPE_FILE_INFO);
g_value_set_boxed (value, file_model_node_get_info (model, node));
@ -527,13 +521,13 @@ gtk_file_system_model_unref_node (GtkTreeModel *tree_model,
/**
* _gtk_file_system_model_new:
* @file_system: an object implementing #GtkFileSystem
* @root_uri: the URI of root of the file system to display,
* @root_path: the path of root of the file system to display,
* or %NULL to display starting from the
* root or roots of the fielsystem.
* @max_depth: the maximum depth from the children of @root_uri
* @max_depth: the maximum depth from the children of @root_path
* or the roots of the file system to display in
* the file selector). A depth of 0 displays
* only the immediate children of @root_uri,
* only the immediate children of @root_path,
* or the roots of the filesystem. -1 for no
* maximum depth.
* @types: a bitmask indicating the types of information
@ -543,16 +537,16 @@ gtk_file_system_model_unref_node (GtkTreeModel *tree_model,
*
* Creates a new #GtkFileSystemModel object. The #GtkFileSystemModel
* object wraps a #GtkFileSystem interface as a #GtkTreeModel.
* Using the @root_uri and @max_depth parameters, the tree model
* Using the @root_path and @max_depth parameters, the tree model
* can be restricted to a subportion of the entire file system.
*
* Return value: the newly created #GtkFileSystemModel object.
**/
GtkFileSystemModel *
_gtk_file_system_model_new (GtkFileSystem *file_system,
const gchar *root_uri,
gint max_depth,
GtkFileInfoType types)
_gtk_file_system_model_new (GtkFileSystem *file_system,
const GtkFilePath *root_path,
gint max_depth,
GtkFileInfoType types)
{
GtkFileSystemModel *model;
GSList *roots, *tmp_list;
@ -567,20 +561,20 @@ _gtk_file_system_model_new (GtkFileSystem *file_system,
model->max_depth = MIN (max_depth, G_MAXUSHORT);
model->types = types | GTK_FILE_INFO_IS_FOLDER | GTK_FILE_INFO_IS_HIDDEN;
if (root_uri)
if (root_path)
{
GSList *child_uris;
GSList *child_paths;
model->root_folder = gtk_file_system_get_folder (file_system, root_uri,
model->root_folder = gtk_file_system_get_folder (file_system, root_path,
model->types,
NULL); /* NULL-GError */
if (model->root_folder &&
gtk_file_folder_list_children (model->root_folder,
&child_uris,
&child_paths,
NULL)) /* NULL-GError */
{
roots = child_uris;
roots = child_paths;
g_signal_connect (model->root_folder, "deleted",
G_CALLBACK (root_deleted_callback), model);
@ -595,12 +589,12 @@ _gtk_file_system_model_new (GtkFileSystem *file_system,
else
roots = gtk_file_system_list_roots (file_system);
roots = g_slist_sort (roots, (GCompareFunc)strcmp);
roots = gtk_file_paths_sort (roots);
for (tmp_list = roots; tmp_list; tmp_list = tmp_list->next)
{
FileModelNode *node = file_model_node_new (model, tmp_list->data);
g_free (tmp_list->data);
gtk_file_path_free (tmp_list->data);
node->is_visible = file_model_node_is_visible (model, node);
node->next = model->roots;
node->depth = 0;
@ -779,24 +773,24 @@ _gtk_file_system_model_get_info (GtkFileSystemModel *model,
}
/**
* _gtk_file_system_model_get_uri:
* _gtk_file_system_model_get_path:
* @model: a #GtkFileSystemModel
* @iter: a #GtkTreeIter pointing to a row of @model
*
* Gets the URI for a particular row in @model.
* Gets the path for a particular row in @model.
*
* Return value: the URI. This string is owned by @model and
* or freed. If you want to save the URI for later use,
* Return value: the path. This string is owned by @model and
* or freed. If you want to save the path for later use,
* you must make a copy, since the string may be freed
* on later changes to the file system.
**/
const gchar *
_gtk_file_system_model_get_uri (GtkFileSystemModel *model,
GtkTreeIter *iter)
const GtkFilePath *
_gtk_file_system_model_get_path (GtkFileSystemModel *model,
GtkTreeIter *iter)
{
FileModelNode *node = iter->user_data;
return node->uri;
return node->path;
}
static void
@ -811,7 +805,7 @@ unref_node_and_parents (GtkFileSystemModel *model,
static FileModelNode *
find_child_node (GtkFileSystemModel *model,
FileModelNode *parent_node,
const gchar *uri)
const GtkFilePath *path)
{
FileModelNode *children;
@ -823,7 +817,8 @@ find_child_node (GtkFileSystemModel *model,
while (children)
{
if (children->is_visible &&
strcmp (children->uri, uri) == 0)
children->path &&
gtk_file_path_compare (children->path, path) == 0)
return children;
children = children->next;
@ -834,21 +829,21 @@ find_child_node (GtkFileSystemModel *model,
static FileModelNode *
find_and_ref_uri (GtkFileSystemModel *model,
const gchar *uri)
find_and_ref_path (GtkFileSystemModel *model,
const GtkFilePath *path)
{
gchar *parent_uri;
GtkFilePath *parent_path;
FileModelNode *parent_node;
FileModelNode *child_node;
GtkFileFolder *folder;
if (!gtk_file_system_get_parent (model->file_system, uri, &parent_uri, NULL))
if (!gtk_file_system_get_parent (model->file_system, path, &parent_path, NULL))
return NULL;
if (parent_uri)
if (parent_path)
{
parent_node = find_and_ref_uri (model, parent_uri);
g_free (parent_uri);
parent_node = find_and_ref_path (model, parent_path);
gtk_file_path_free (parent_path);
if (!parent_node)
return NULL;
@ -856,7 +851,7 @@ find_and_ref_uri (GtkFileSystemModel *model,
else
parent_node = NULL;
child_node = find_child_node (model, parent_node, uri);
child_node = find_child_node (model, parent_node, path);
if (child_node)
{
file_model_node_ref (child_node);
@ -864,11 +859,11 @@ find_and_ref_uri (GtkFileSystemModel *model,
}
folder = gtk_file_system_get_folder (model->file_system,
uri,
path,
model->types,
NULL); /* NULL-GError */
child_node = find_child_node (model, parent_node, uri);
child_node = find_child_node (model, parent_node, path);
if (child_node)
{
file_model_node_ref (child_node);
@ -882,17 +877,17 @@ find_and_ref_uri (GtkFileSystemModel *model,
}
/**
* _gtk_file_system_model_uri_do:
* _gtk_file_system_model_path_do:
* @model: a #GtkFileSystemModel
* @uri: a URI pointing to a file in the filesystem
* @path: a path pointing to a file in the filesystem
* for @model.
* @func: Function to call with the path and iter corresponding
* to @uri.
* to @path.
* @user_data: data to pass to @func
*
* Locates @uri within @model, referencing
* Locates @path within @model, referencing
* (gtk_tree_model_ref_node ()) all parent nodes,
* calls @func passing in the path and iter for @uri,
* calls @func passing in the path and iter for @path,
* then unrefs all the parent nodes.
*
* The reason for doing this operation as a callback
@ -904,16 +899,16 @@ find_and_ref_uri (GtkFileSystemModel *model,
* This function is particularly useful for expanding
* a #GtkTreeView to a particular point in the file system.
*
* Return value: %TRUE if the URI was successfully
* Return value: %TRUE if the path was successfully
* found in @model and @func was called.
**/
gboolean
_gtk_file_system_model_uri_do (GtkFileSystemModel *model,
const gchar *uri,
GtkFileSystemModelURIFunc func,
gpointer user_data)
_gtk_file_system_model_path_do (GtkFileSystemModel *model,
const GtkFilePath *path,
GtkFileSystemModelPathFunc func,
gpointer user_data)
{
FileModelNode *node = find_and_ref_uri (model, uri);
FileModelNode *node = find_and_ref_path (model, path);
if (node)
{
@ -936,12 +931,12 @@ _gtk_file_system_model_uri_do (GtkFileSystemModel *model,
static FileModelNode *
file_model_node_new (GtkFileSystemModel *model,
const gchar *uri)
const GtkFilePath *path)
{
FileModelNode *node = g_new0 (FileModelNode, 1);
node->model = model;
node->uri = g_strdup (uri);
node->path = path ? gtk_file_path_copy (path) : NULL;
return node;
}
@ -957,8 +952,8 @@ file_model_node_free (FileModelNode *node)
file_model_node_free (children);
}
if (node->uri)
g_free (node->uri);
if (node->path)
gtk_file_path_free (node->path);
if (node->info)
gtk_file_info_free (node->info);
@ -983,13 +978,13 @@ file_model_node_get_info (GtkFileSystemModel *model,
else if (node->parent || model->root_folder)
{
node->info = gtk_file_folder_get_info (node->parent ? node->parent->folder : model->root_folder,
node->uri,
node->path,
NULL); /* NULL-GError */
}
else
{
node->info = gtk_file_system_get_root_info (model->file_system,
node->uri,
node->path,
model->types,
NULL); /* NULL-GError */
}
@ -1079,22 +1074,22 @@ file_model_node_get_children (GtkFileSystemModel *model,
if (is_folder)
node->folder = gtk_file_system_get_folder (model->file_system,
node->uri,
node->path,
model->types,
NULL); /* NULL-GError */
if (node->folder)
{
GSList *child_uris, *tmp_list;
GSList *child_paths, *tmp_list;
if (gtk_file_folder_list_children (node->folder, &child_uris, NULL)) /* NULL-GError */
if (gtk_file_folder_list_children (node->folder, &child_paths, NULL)) /* NULL-GError */
{
child_uris = g_slist_sort (child_uris, (GCompareFunc)strcmp);
child_paths = gtk_file_paths_sort (child_paths);
for (tmp_list = child_uris; tmp_list; tmp_list = tmp_list->next)
for (tmp_list = child_paths; tmp_list; tmp_list = tmp_list->next)
{
FileModelNode *child_node = file_model_node_new (model, tmp_list->data);
g_free (tmp_list->data);
gtk_file_path_free (tmp_list->data);
child_node->next = node->children;
child_node->parent = node;
child_node->depth = node->depth + 1;
@ -1103,7 +1098,7 @@ file_model_node_get_children (GtkFileSystemModel *model,
has_children = TRUE;
node->children = child_node;
}
g_slist_free (child_uris);
g_slist_free (child_paths);
}
node->children = (FileModelNode *)g_slist_reverse ((GSList *)node->children);
@ -1125,7 +1120,7 @@ file_model_node_get_children (GtkFileSystemModel *model,
/* The hard case ... we claimed this folder had children, but actually
* it didn't. We have to add a dummy child, possibly to remove later.
*/
FileModelNode *child_node = file_model_node_new (model, "***dummy***");
FileModelNode *child_node = file_model_node_new (model, NULL);
child_node->is_visible = TRUE;
child_node->parent = node;
child_node->is_dummy = TRUE;
@ -1143,18 +1138,17 @@ file_model_node_get_children (GtkFileSystemModel *model,
static void
do_files_added (GtkFileSystemModel *model,
FileModelNode *parent_node,
GSList *uris)
GSList *paths)
{
GtkTreeModel *tree_model = GTK_TREE_MODEL (model);
FileModelNode *children;
FileModelNode *prev = NULL;
GtkTreeIter iter;
GtkTreePath *path;
GSList *sorted_uris;
GSList *sorted_paths;
GSList *tmp_list;
sorted_uris = g_slist_copy (uris);
sorted_uris = g_slist_sort (sorted_uris, (GCompareFunc)strcmp);
sorted_paths = gtk_file_paths_sort (g_slist_copy (paths));
if (parent_node)
{
@ -1177,11 +1171,12 @@ do_files_added (GtkFileSystemModel *model,
gtk_tree_path_next (path);
}
for (tmp_list = sorted_uris; tmp_list; tmp_list = tmp_list->next)
for (tmp_list = sorted_paths; tmp_list; tmp_list = tmp_list->next)
{
const gchar *uri = tmp_list->data;
const GtkFilePath *file_path = tmp_list->data;
while (children && strcmp (children->uri, uri) < 0)
while (children &&
(!children->path || gtk_file_path_compare (children->path, file_path) < 0))
{
prev = children;
if (children->is_visible)
@ -1190,7 +1185,8 @@ do_files_added (GtkFileSystemModel *model,
children = children->next;
}
if (children && strcmp (children->uri, uri) == 0)
if (children &&
children->path && gtk_file_path_compare (children->path, file_path) == 0)
{
/* Shouldn't happen */
}
@ -1198,7 +1194,7 @@ do_files_added (GtkFileSystemModel *model,
{
FileModelNode *new;
new = file_model_node_new (model, uri);
new = file_model_node_new (model, file_path);
if (children)
new->next = children;
@ -1251,24 +1247,23 @@ do_files_added (GtkFileSystemModel *model,
}
gtk_tree_path_free (path);
g_slist_free (sorted_uris);
g_slist_free (sorted_paths);
}
static void
do_files_changed (GtkFileSystemModel *model,
FileModelNode *parent_node,
GSList *uris)
GSList *paths)
{
GtkTreeModel *tree_model = GTK_TREE_MODEL (model);
FileModelNode *children;
FileModelNode *prev = NULL;
GtkTreeIter iter;
GtkTreePath *path;
GSList *sorted_uris;
GSList *sorted_paths;
GSList *tmp_list;
sorted_uris = g_slist_copy (uris);
sorted_uris = g_slist_sort (sorted_uris, (GCompareFunc)strcmp);
sorted_paths = gtk_file_paths_sort (g_slist_copy (paths));
if (parent_node)
{
@ -1291,11 +1286,12 @@ do_files_changed (GtkFileSystemModel *model,
gtk_tree_path_next (path);
}
for (tmp_list = sorted_uris; tmp_list; tmp_list = tmp_list->next)
for (tmp_list = sorted_paths; tmp_list; tmp_list = tmp_list->next)
{
const gchar *uri = tmp_list->data;
const GtkFilePath *file_path = tmp_list->data;
while (children && strcmp (children->uri, uri) < 0)
while (children &&
(!children->path || gtk_file_path_compare (children->path, file_path) < 0))
{
prev = children;
if (children->is_visible)
@ -1304,7 +1300,8 @@ do_files_changed (GtkFileSystemModel *model,
children = children->next;
}
if (children && strcmp (children->uri, uri) == 0)
if (children &&
children->path && gtk_file_path_compare (children->path, file_path) == 0)
{
gtk_tree_model_row_changed (tree_model, path, &iter);
}
@ -1315,26 +1312,25 @@ do_files_changed (GtkFileSystemModel *model,
}
gtk_tree_path_free (path);
g_slist_free (sorted_uris);
g_slist_free (sorted_paths);
}
static void
do_files_removed (GtkFileSystemModel *model,
FileModelNode *parent_node,
GSList *uris)
GSList *paths)
{
GtkTreeModel *tree_model = GTK_TREE_MODEL (model);
FileModelNode *children;
FileModelNode *prev = NULL;
GtkTreeIter iter;
GtkTreePath *path;
GSList *sorted_uris;
GSList *sorted_paths;
GSList *tmp_list;
FileModelNode *tmp_child;
gint n_visible;
sorted_uris = g_slist_copy (uris);
sorted_uris = g_slist_sort (sorted_uris, (GCompareFunc)strcmp);
sorted_paths = gtk_file_paths_sort (g_slist_copy (paths));
if (parent_node)
{
@ -1367,11 +1363,12 @@ do_files_removed (GtkFileSystemModel *model,
gtk_tree_path_next (path);
}
for (tmp_list = sorted_uris; tmp_list; tmp_list = tmp_list->next)
for (tmp_list = sorted_paths; tmp_list; tmp_list = tmp_list->next)
{
const gchar *uri = tmp_list->data;
const GtkFilePath *file_path = tmp_list->data;
while (children && strcmp (children->uri, uri) < 0)
while (children &&
(!children->path || gtk_file_path_compare (children->path, file_path) < 0))
{
prev = children;
if (children->is_visible)
@ -1380,7 +1377,8 @@ do_files_removed (GtkFileSystemModel *model,
children = children->next;
}
if (children && strcmp (children->uri, uri) == 0)
if (children &&
children->path && gtk_file_path_compare (children->path, file_path) == 0)
{
FileModelNode *next = children->next;
@ -1389,7 +1387,7 @@ do_files_removed (GtkFileSystemModel *model,
if (n_visible == 0)
{
FileModelNode *dummy = file_model_node_new (model, "***dummy***");
FileModelNode *dummy = file_model_node_new (model, NULL);
dummy->is_visible = TRUE;
dummy->parent = parent_node;
dummy->is_dummy = TRUE;
@ -1425,7 +1423,7 @@ do_files_removed (GtkFileSystemModel *model,
}
gtk_tree_path_free (path);
g_slist_free (sorted_uris);
g_slist_free (sorted_paths);
}
static void
@ -1436,26 +1434,26 @@ deleted_callback (GtkFileFolder *folder,
static void
files_added_callback (GtkFileFolder *folder,
GSList *uris,
GSList *paths,
FileModelNode *node)
{
do_files_added (node->model, node, uris);
do_files_added (node->model, node, paths);
}
static void
files_changed_callback (GtkFileFolder *folder,
GSList *uris,
GSList *paths,
FileModelNode *node)
{
do_files_changed (node->model, node, uris);
do_files_changed (node->model, node, paths);
}
static void
files_removed_callback (GtkFileFolder *folder,
GSList *uris,
GSList *paths,
FileModelNode *node)
{
do_files_removed (node->model, node, uris);
do_files_removed (node->model, node, paths);
}
static void
@ -1466,26 +1464,26 @@ root_deleted_callback (GtkFileFolder *folder,
static void
root_files_added_callback (GtkFileFolder *folder,
GSList *uris,
GSList *paths,
GtkFileSystemModel *model)
{
do_files_added (model, NULL, uris);
do_files_added (model, NULL, paths);
}
static void
root_files_changed_callback (GtkFileFolder *folder,
GSList *uris,
GSList *paths,
GtkFileSystemModel *model)
{
do_files_changed (model, NULL, uris);
do_files_changed (model, NULL, paths);
}
static void
root_files_removed_callback (GtkFileFolder *folder,
GSList *uris,
GSList *paths,
GtkFileSystemModel *model)
{
do_files_removed (model, NULL, uris);
do_files_removed (model, NULL, paths);
}

View File

@ -36,19 +36,18 @@ typedef struct _GtkFileSystemModel GtkFileSystemModel;
GType _gtk_file_system_model_get_type (void);
enum {
GTK_FILE_SYSTEM_MODEL_URI,
GTK_FILE_SYSTEM_MODEL_INFO,
GTK_FILE_SYSTEM_MODEL_DISPLAY_NAME,
GTK_FILE_SYSTEM_MODEL_N_COLUMNS
} GtkFileSystemModelColumns;
GtkFileSystemModel *_gtk_file_system_model_new (GtkFileSystem *file_system,
const gchar *root_uri,
const GtkFilePath *root_path,
gint max_depth,
GtkFileInfoType types);
const GtkFileInfo * _gtk_file_system_model_get_info (GtkFileSystemModel *model,
GtkTreeIter *iter);
const gchar * _gtk_file_system_model_get_uri (GtkFileSystemModel *model,
const GtkFilePath * _gtk_file_system_model_get_path (GtkFileSystemModel *model,
GtkTreeIter *iter);
void _gtk_file_system_model_set_show_hidden (GtkFileSystemModel *model,
gboolean show_hidden);
@ -58,15 +57,15 @@ void _gtk_file_system_model_set_show_files (GtkFileSystemModel
gboolean show_files);
typedef void (*GtkFileSystemModelURIFunc) (GtkFileSystemModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
gpointer user_data);
typedef void (*GtkFileSystemModelPathFunc) (GtkFileSystemModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
gpointer user_data);
gboolean _gtk_file_system_model_uri_do (GtkFileSystemModel *model,
const gchar *uri,
GtkFileSystemModelURIFunc func,
gpointer user_data);
gboolean _gtk_file_system_model_path_do (GtkFileSystemModel *model,
const GtkFilePath *path,
GtkFileSystemModelPathFunc func,
gpointer user_data);
G_END_DECLS

View File

@ -74,32 +74,41 @@ static void gtk_file_system_unix_iface_init (GtkFileSystemIface *iface);
static void gtk_file_system_unix_init (GtkFileSystemUnix *impl);
static void gtk_file_system_unix_finalize (GObject *object);
static GSList * gtk_file_system_unix_list_roots (GtkFileSystem *file_system);
static GtkFileInfo * gtk_file_system_unix_get_root_info (GtkFileSystem *file_system,
const gchar *uri,
GtkFileInfoType types,
GError **error);
static GtkFileFolder *gtk_file_system_unix_get_folder (GtkFileSystem *file_system,
const gchar *uri,
GtkFileInfoType types,
GError **error);
static gboolean gtk_file_system_unix_create_folder (GtkFileSystem *file_system,
const gchar *uri,
GError **error);
static gboolean gtk_file_system_unix_get_parent (GtkFileSystem *file_system,
const gchar *uri,
gchar **parent,
GError **error);
static gchar * gtk_file_system_unix_make_uri (GtkFileSystem *file_system,
const gchar *base_uri,
const gchar *display_name,
GError **error);
static gboolean gtk_file_system_unix_parse (GtkFileSystem *file_system,
const gchar *base_uri,
const gchar *str,
gchar **folder,
gchar **file_part,
GError **error);
static GSList * gtk_file_system_unix_list_roots (GtkFileSystem *file_system);
static GtkFileInfo * gtk_file_system_unix_get_root_info (GtkFileSystem *file_system,
const GtkFilePath *path,
GtkFileInfoType types,
GError **error);
static GtkFileFolder *gtk_file_system_unix_get_folder (GtkFileSystem *file_system,
const GtkFilePath *path,
GtkFileInfoType types,
GError **error);
static gboolean gtk_file_system_unix_create_folder (GtkFileSystem *file_system,
const GtkFilePath *path,
GError **error);
static gboolean gtk_file_system_unix_get_parent (GtkFileSystem *file_system,
const GtkFilePath *path,
GtkFilePath **parent,
GError **error);
static GtkFilePath * gtk_file_system_unix_make_path (GtkFileSystem *file_system,
const GtkFilePath *base_path,
const gchar *display_name,
GError **error);
static gboolean gtk_file_system_unix_parse (GtkFileSystem *file_system,
const GtkFilePath *base_path,
const gchar *str,
GtkFilePath **folder,
gchar **file_part,
GError **error);
static gchar * gtk_file_system_unix_path_to_uri (GtkFileSystem *file_system,
const GtkFilePath *path);
static gchar * gtk_file_system_unix_path_to_filename (GtkFileSystem *file_system,
const GtkFilePath *path);
static GtkFilePath *gtk_file_system_unix_uri_to_path (GtkFileSystem *file_system,
const gchar *uri);
static GtkFilePath *gtk_file_system_unix_filename_to_path (GtkFileSystem *file_system,
const gchar *filename);
static GType gtk_file_folder_unix_get_type (void);
static void gtk_file_folder_unix_class_init (GtkFileFolderUnixClass *class);
@ -108,15 +117,15 @@ static void gtk_file_folder_unix_init (GtkFileFolderUnix *impl);
static void gtk_file_folder_unix_finalize (GObject *object);
static GtkFileInfo *gtk_file_folder_unix_get_info (GtkFileFolder *folder,
const gchar *uri,
const GtkFilePath *path,
GError **error);
static gboolean gtk_file_folder_unix_list_children (GtkFileFolder *folder,
GSList **children,
GError **error);
static gchar * filename_from_uri (const gchar *filename,
GError **error);
static gchar * filename_to_uri (const gchar *filename);
static gchar * filename_from_path (const GtkFilePath *path);
static GtkFilePath *filename_to_path (const gchar *filename);
static gboolean filename_is_root (const char *filename);
static GtkFileInfo *filename_get_info (const gchar *filename,
GtkFileInfoType types,
@ -196,8 +205,12 @@ gtk_file_system_unix_iface_init (GtkFileSystemIface *iface)
iface->get_root_info = gtk_file_system_unix_get_root_info;
iface->create_folder = gtk_file_system_unix_create_folder;
iface->get_parent = gtk_file_system_unix_get_parent;
iface->make_uri = gtk_file_system_unix_make_uri;
iface->make_path = gtk_file_system_unix_make_path;
iface->parse = gtk_file_system_unix_parse;
iface->path_to_uri = gtk_file_system_unix_path_to_uri;
iface->path_to_filename = gtk_file_system_unix_path_to_filename;
iface->uri_to_path = gtk_file_system_unix_uri_to_path;
iface->filename_to_path = gtk_file_system_unix_filename_to_path;
}
static void
@ -214,32 +227,33 @@ gtk_file_system_unix_finalize (GObject *object)
static GSList *
gtk_file_system_unix_list_roots (GtkFileSystem *file_system)
{
return g_slist_append (NULL, g_strdup ("file:///"));
return g_slist_append (NULL, gtk_file_path_new_dup ("/"));
}
static GtkFileInfo *
gtk_file_system_unix_get_root_info (GtkFileSystem *file_system,
const gchar *uri,
const GtkFilePath *path,
GtkFileInfoType types,
GError **error)
{
g_return_val_if_fail (strcmp (uri, "file:///") == 0, NULL);
const gchar *filename = gtk_file_path_get_string (path);
g_return_val_if_fail (strcmp (filename, "/") == 0, NULL);
return filename_get_info ("/", types, error);
}
static GtkFileFolder *
gtk_file_system_unix_get_folder (GtkFileSystem *file_system,
const gchar *uri,
GtkFileInfoType types,
GError **error)
gtk_file_system_unix_get_folder (GtkFileSystem *file_system,
const GtkFilePath *path,
GtkFileInfoType types,
GError **error)
{
GtkFileFolderUnix *folder_unix;
gchar *filename;
filename = filename_from_uri (uri, error);
if (!filename)
return NULL;
filename = filename_from_path (path);
g_return_val_if_fail (filename != NULL, NULL);
folder_unix = g_object_new (GTK_TYPE_FILE_FOLDER_UNIX, NULL);
folder_unix->filename = filename;
@ -249,17 +263,16 @@ gtk_file_system_unix_get_folder (GtkFileSystem *file_system,
}
static gboolean
gtk_file_system_unix_create_folder (GtkFileSystem *file_system,
const gchar *uri,
GError **error)
gtk_file_system_unix_create_folder (GtkFileSystem *file_system,
const GtkFilePath *path,
GError **error)
{
gchar *filename;
gboolean result;
filename = filename_from_uri (uri, error);
if (!filename)
return FALSE;
filename = filename_from_path (path);
g_return_val_if_fail (filename != NULL, FALSE);
result = mkdir (filename, 0777) != 0;
if (!result)
@ -280,15 +293,13 @@ gtk_file_system_unix_create_folder (GtkFileSystem *file_system,
}
static gboolean
gtk_file_system_unix_get_parent (GtkFileSystem *file_system,
const gchar *uri,
gchar **parent,
GError **error)
gtk_file_system_unix_get_parent (GtkFileSystem *file_system,
const GtkFilePath *path,
GtkFilePath **parent,
GError **error)
{
gchar *filename = filename_from_uri (uri, error);
if (!filename)
return FALSE;
gchar *filename = filename_from_path (path);
g_return_val_if_fail (filename != NULL, FALSE);
if (filename_is_root (filename))
{
@ -297,7 +308,7 @@ gtk_file_system_unix_get_parent (GtkFileSystem *file_system,
else
{
gchar *parent_filename = g_path_get_dirname (filename);
*parent = filename_to_uri (parent_filename);
*parent = filename_to_path (parent_filename);
g_free (parent_filename);
}
@ -306,21 +317,20 @@ gtk_file_system_unix_get_parent (GtkFileSystem *file_system,
return TRUE;
}
static gchar *
gtk_file_system_unix_make_uri (GtkFileSystem *file_system,
const gchar *base_uri,
const gchar *display_name,
GError **error)
static GtkFilePath *
gtk_file_system_unix_make_path (GtkFileSystem *file_system,
const GtkFilePath *base_path,
const gchar *display_name,
GError **error)
{
gchar *base_filename;
gchar *filename;
gchar *full_filename;
GError *tmp_error = NULL;
gchar *result;
GtkFilePath *result;
base_filename = filename_from_uri (base_uri, error);
if (!base_filename)
return FALSE;
base_filename = filename_from_path (base_path);
g_return_val_if_fail (base_filename != NULL, NULL);
filename = g_filename_from_utf8 (display_name, -1, NULL, NULL, &tmp_error);
if (!filename)
@ -338,7 +348,7 @@ gtk_file_system_unix_make_uri (GtkFileSystem *file_system,
}
full_filename = g_build_filename (base_filename, filename, NULL);
result = filename_to_uri (full_filename);
result = filename_to_path (full_filename);
g_free (base_filename);
g_free (filename);
g_free (full_filename);
@ -420,25 +430,24 @@ canonicalize_filename (gchar *filename)
}
static gboolean
gtk_file_system_unix_parse (GtkFileSystem *file_system,
const gchar *base_uri,
const gchar *str,
gchar **folder,
gchar **file_part,
GError **error)
gtk_file_system_unix_parse (GtkFileSystem *file_system,
const GtkFilePath *base_path,
const gchar *str,
GtkFilePath **folder,
gchar **file_part,
GError **error)
{
char *base_filename;
gchar *last_slash;
gboolean result = FALSE;
base_filename = filename_from_uri (base_uri, error);
if (!base_filename)
return FALSE;
base_filename = filename_from_path (base_path);
g_return_val_if_fail (base_filename != NULL, FALSE);
last_slash = strrchr (str, G_DIR_SEPARATOR);
if (!last_slash)
{
*folder = g_strdup (base_uri);
*folder = gtk_file_path_copy (base_path);
*file_part = g_strdup (str);
result = TRUE;
}
@ -475,7 +484,7 @@ gtk_file_system_unix_parse (GtkFileSystem *file_system,
canonicalize_filename (folder_path);
*folder = filename_to_uri (folder_path);
*folder = filename_to_path (folder_path);
*file_part = g_strdup (last_slash + 1);
g_free (folder_path);
@ -489,6 +498,38 @@ gtk_file_system_unix_parse (GtkFileSystem *file_system,
return result;
}
static gchar *
gtk_file_system_unix_path_to_uri (GtkFileSystem *file_system,
const GtkFilePath *path)
{
return g_filename_to_uri (gtk_file_path_get_string (path), NULL, NULL);
}
static gchar *
gtk_file_system_unix_path_to_filename (GtkFileSystem *file_system,
const GtkFilePath *path)
{
return g_strdup (gtk_file_path_get_string (path));
}
static GtkFilePath *
gtk_file_system_unix_uri_to_path (GtkFileSystem *file_system,
const gchar *uri)
{
gchar *filename = g_filename_from_uri (uri, NULL, NULL);
if (filename)
return gtk_file_path_new_steal (filename);
else
return NULL;
}
static GtkFilePath *
gtk_file_system_unix_filename_to_path (GtkFileSystem *file_system,
const gchar *filename)
{
return gtk_file_path_new_dup (filename);
}
/*
* GtkFileFolderUnix
*/
@ -564,7 +605,7 @@ gtk_file_folder_unix_finalize (GObject *object)
static GtkFileInfo *
gtk_file_folder_unix_get_info (GtkFileFolder *folder,
const gchar *uri,
const GtkFilePath *path,
GError **error)
{
GtkFileFolderUnix *folder_unix = GTK_FILE_FOLDER_UNIX (folder);
@ -572,9 +613,8 @@ gtk_file_folder_unix_get_info (GtkFileFolder *folder,
gchar *dirname;
gchar *filename;
filename = filename_from_uri (uri, error);
if (!filename)
return NULL;
filename = filename_from_path (path);
g_return_val_if_fail (filename != NULL, NULL);
dirname = g_path_get_dirname (filename);
g_return_val_if_fail (strcmp (dirname, folder_unix->filename) == 0, NULL);
@ -621,7 +661,7 @@ gtk_file_folder_unix_list_children (GtkFileFolder *folder,
break;
fullname = g_build_filename (folder_unix->filename, filename, NULL);
*children = g_slist_prepend (*children, filename_to_uri (fullname));
*children = g_slist_prepend (*children, filename_to_path (fullname));
g_free (fullname);
}
@ -719,37 +759,15 @@ filename_get_info (const gchar *filename,
}
static gchar *
filename_from_uri (const char *uri,
GError **error)
filename_from_path (const GtkFilePath *path)
{
GError *tmp_error = NULL;
gchar *result;
result = g_filename_from_uri (uri, NULL, &tmp_error);
if (!result)
{
g_set_error (error,
GTK_FILE_SYSTEM_ERROR,
GTK_FILE_SYSTEM_ERROR_INVALID_URI,
"%s",
tmp_error->message);
g_error_free (tmp_error);
}
return result;
return g_strdup (gtk_file_path_get_string (path));
}
static gchar *
filename_to_uri (const char *filename)
static GtkFilePath *
filename_to_path (const char *filename)
{
gchar *result;
result = g_filename_to_uri (filename, NULL, NULL);
if (!result)
g_warning ("GtkFileSystemUnix: Handling of non-UTF-8-representable-filenames needs to be fixed");
return result;
return gtk_file_path_new_dup (filename);
}
static gboolean