[gtk/gbsneto/filechooser-column-view: 20/22] filesystemmodel: Retire GtkFileSystemItem
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/gbsneto/filechooser-column-view: 20/22] filesystemmodel: Retire GtkFileSystemItem
- Date: Mon, 10 Oct 2022 16:36:52 +0000 (UTC)
commit bae611e915cabd324b0feaf991a0c7bf6e40a369
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Sun Oct 9 18:52:12 2022 -0300
filesystemmodel: Retire GtkFileSystemItem
This has to be the shortest-living object in GTK history!
It helped us greatly during the transition to GtkColumnView, but
now we can remove it in favour of GFileInfo directly. Perhaps I
could have never introduced GtkFileSystemItem in the first place,
but we're 30 commits deep and it's too late to just redo the whole
thing that will get us exactly here anyway.
gtk/gtkfilechooserwidget.c | 222 +++++++++++++++++++++--------------------
gtk/gtkfilesystemmodel.c | 148 ++++-----------------------
gtk/gtkfilesystemmodel.h | 19 +---
gtk/gtkfilethumbnail.c | 60 +++++------
gtk/gtkfilethumbnail.h | 6 +-
gtk/gtksearchenginemodel.c | 11 +-
gtk/ui/gtkfilechooserwidget.ui | 46 +++++----
7 files changed, 196 insertions(+), 316 deletions(-)
---
diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c
index 2af179c4e6..43359779e8 100644
--- a/gtk/gtkfilechooserwidget.c
+++ b/gtk/gtkfilechooserwidget.c
@@ -1021,19 +1021,17 @@ selection_check (GtkFileChooserWidget *impl,
gtk_bitset_iter_is_valid (&iter);
gtk_bitset_iter_next (&iter, &i))
{
- GtkFileSystemItem *item;
GFileInfo *info;
gboolean is_folder;
- item = g_list_model_get_item (G_LIST_MODEL (impl->selection_model), i);
- info = _gtk_file_system_item_get_file_info (item);
+ info = g_list_model_get_item (G_LIST_MODEL (impl->selection_model), i);
is_folder = _gtk_file_info_consider_as_directory (info);
all_folders &= is_folder;
all_files &= !is_folder;
n_selected++;
- g_clear_object (&item);
+ g_clear_object (&info);
}
g_assert (n_selected == 0 || !(all_files && all_folders));
@@ -1130,15 +1128,15 @@ add_to_shortcuts_cb (GSimpleAction *action,
gtk_bitset_iter_is_valid (&iter);
gtk_bitset_iter_next (&iter, &i))
{
- GtkFileSystemItem *item;
+ GFileInfo *info;
GFile *file;
- item = g_list_model_get_item (G_LIST_MODEL (impl->selection_model), i);
- file = _gtk_file_system_item_get_file (item);
+ info = g_list_model_get_item (G_LIST_MODEL (impl->selection_model), i);
+ file = _gtk_file_info_get_file (info);
_gtk_bookmarks_manager_insert_bookmark (impl->bookmarks_manager, file, 0, NULL);
- g_clear_object (&item);
+ g_clear_object (&info);
}
}
@@ -1223,17 +1221,15 @@ delete_file_cb (GSimpleAction *action,
gtk_bitset_iter_is_valid (&iter);
gtk_bitset_iter_next (&iter, &i))
{
- GtkFileSystemItem *item;
GFileInfo *info;
GFile *file;
- item = g_list_model_get_item (G_LIST_MODEL (impl->selection_model), i);
- file = _gtk_file_system_item_get_file (item);
- info = _gtk_file_system_item_get_file_info (item);
+ info = g_list_model_get_item (G_LIST_MODEL (impl->selection_model), i);
+ file = _gtk_file_info_get_file (info);
confirm_delete (impl, file, info);
- g_clear_object (&item);
+ g_clear_object (&info);
}
}
@@ -1253,17 +1249,17 @@ trash_file_cb (GSimpleAction *action,
gtk_bitset_iter_is_valid (&iter);
gtk_bitset_iter_next (&iter, &i))
{
- GtkFileSystemItem *item;
+ GFileInfo *info;
GError *error = NULL;
GFile *file;
- item = g_list_model_get_item (G_LIST_MODEL (impl->selection_model), i);
- file = _gtk_file_system_item_get_file (item);
+ info = g_list_model_get_item (G_LIST_MODEL (impl->selection_model), i);
+ file = _gtk_file_info_get_file (info);
if (!g_file_trash (file, NULL, &error))
error_trashing_file (impl, file, error);
- g_clear_object (&item);
+ g_clear_object (&info);
}
}
@@ -1337,10 +1333,10 @@ rename_file_cb (GSimpleAction *action,
gpointer data)
{
GtkFileChooserWidget *impl = data;
- GtkFileSystemItem *item;
GtkBitsetIter iter;
GdkRectangle rect;
GtkBitset *bitset;
+ GFileInfo *info;
GFile *file;
double x, y;
guint position;
@@ -1353,8 +1349,10 @@ rename_file_cb (GSimpleAction *action,
/* insensitive until we change the name */
gtk_widget_set_sensitive (impl->rename_file_rename_button, FALSE);
- item = g_list_model_get_item (G_LIST_MODEL (impl->selection_model), position);
- file = _gtk_file_system_item_get_file (item);
+ info = g_list_model_get_item (G_LIST_MODEL (impl->selection_model), position);
+ file = _gtk_file_info_get_file (info);
+ g_clear_object (&info);
+
impl->rename_file_source_file = g_object_ref (file);
rect = (GdkRectangle) { 0, 0, 1, 1 };
@@ -1871,6 +1869,9 @@ column_view_get_file_date (GtkListItem *item,
GtkFileChooserWidget *impl;
glong time;
+ if (!info)
+ return NULL;
+
impl = GTK_FILE_CHOOSER_WIDGET (gtk_widget_get_ancestor (gtk_list_item_get_child (item),
GTK_TYPE_FILE_CHOOSER_WIDGET));
g_assert (impl != NULL);
@@ -1886,6 +1887,16 @@ column_view_get_file_date (GtkListItem *item,
return my_g_format_date_for_display (impl, time);
}
+static char *
+column_view_get_file_display_name (GtkListItem *item,
+ GFileInfo *info)
+{
+ if (info)
+ return g_strdup (g_file_info_get_display_name (info));
+ else
+ return NULL;
+}
+
static char *
column_view_get_file_time (GtkListItem *item,
GFileInfo *info)
@@ -1893,6 +1904,9 @@ column_view_get_file_time (GtkListItem *item,
GtkFileChooserWidget *impl;
glong time;
+ if (!info)
+ return NULL;
+
impl = GTK_FILE_CHOOSER_WIDGET (gtk_widget_get_ancestor (gtk_list_item_get_child (item),
GTK_TYPE_FILE_CHOOSER_WIDGET));
g_assert (impl != NULL);
@@ -1914,7 +1928,7 @@ column_view_get_file_type (GtkListItem *item,
{
GtkFileChooserWidget *impl;
- if (_gtk_file_info_consider_as_directory (info))
+ if (!info || _gtk_file_info_consider_as_directory (info))
return NULL;
impl = GTK_FILE_CHOOSER_WIDGET (gtk_widget_get_ancestor (gtk_list_item_get_child (item),
@@ -1925,20 +1939,19 @@ column_view_get_file_type (GtkListItem *item,
}
static char *
-column_view_get_location (GtkListItem *list_item)
+column_view_get_location (GtkListItem *list_item,
+ GFileInfo *info)
{
GtkFileChooserWidget *impl;
- GtkFileSystemItem *item;
GFile *home_location;
GFile *dir_location;
GFile *file;
char *location;
- item = gtk_list_item_get_item (list_item);
- if (!item)
+ if (!info)
return NULL;
- file = _gtk_file_system_item_get_file (item);
+ file = _gtk_file_info_get_file (info);
home_location = g_file_new_for_path (g_get_home_dir ());
if (file)
@@ -1949,10 +1962,8 @@ column_view_get_location (GtkListItem *list_item)
if (dir_location && file_is_recent_uri (dir_location))
{
const char *target_uri;
- GFileInfo *info;
GFile *target;
- info = _gtk_file_system_item_get_file_info (item);
target_uri = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI);
target = g_file_new_for_uri (target_uri);
g_object_unref (dir_location);
@@ -1992,7 +2003,7 @@ static char *
column_view_get_size (GtkListItem *item,
GFileInfo *info)
{
- if (!_gtk_file_info_consider_as_directory (info))
+ if (info && !_gtk_file_info_consider_as_directory (info))
return g_format_size (g_file_info_get_size (info));
else
return NULL;
@@ -2011,14 +2022,13 @@ column_view_get_time_visible (GtkListItem *item)
}
static char *
-column_view_get_tooltip_text (GtkListItem *list_item)
+column_view_get_tooltip_text (GtkListItem *list_item,
+ GFileInfo *info)
{
GtkFileChooserWidget *impl;
- GtkFileSystemItem *item;
GFile *file;
- item = gtk_list_item_get_item (list_item);
- if (!item)
+ if (!info)
return NULL;
impl = GTK_FILE_CHOOSER_WIDGET (gtk_widget_get_ancestor (gtk_list_item_get_child (list_item),
@@ -2028,7 +2038,7 @@ column_view_get_tooltip_text (GtkListItem *list_item)
if (impl->operation_mode == OPERATION_MODE_BROWSE)
return NULL;
- file = _gtk_file_system_item_get_file (item);
+ file = _gtk_file_info_get_file (info);
return g_file_get_path (file);
}
@@ -2523,16 +2533,16 @@ static void
put_recent_folder_in_pathbar (GtkFileChooserWidget *impl,
guint position)
{
- GtkFileSystemItem *item;
+ GFileInfo *info;
- item = g_list_model_get_item (G_LIST_MODEL (impl->selection_model), position);
- g_assert (item != NULL);
+ info = g_list_model_get_item (G_LIST_MODEL (impl->selection_model), position);
+ g_assert (info != NULL);
_gtk_path_bar_set_file (GTK_PATH_BAR (impl->browse_path_bar),
- _gtk_file_system_item_get_file (item),
+ _gtk_file_info_get_file (info),
FALSE);
- g_clear_object (&item);
+ g_clear_object (&info);
}
/* Sets the location bar in the appropriate mode according to the
@@ -3498,7 +3508,6 @@ show_and_select_files (GtkFileChooserWidget *impl,
GSList *files)
{
GtkFileSystemModel *fsmodel;
- gboolean enabled_hidden, removed_filters;
gboolean selected_a_file;
GSList *walk;
@@ -3509,22 +3518,29 @@ show_and_select_files (GtkFileChooserWidget *impl,
g_assert (fsmodel == impl->browse_files_model);
- enabled_hidden = impl->show_hidden;
- removed_filters = (impl->current_filter == NULL);
-
selected_a_file = FALSE;
for (walk = files; walk; walk = walk->next)
{
- GtkFileSystemItem *item;
- GFile *file = walk->data;
+ GFileInfo *info;
+ GFile *file;
+ guint i;
+
+ file = walk->data;
/* Is it a hidden file? */
- item = _gtk_file_system_model_get_item_for_file (fsmodel, file);
- if (!item)
+ info = _gtk_file_system_model_get_info_for_file (fsmodel, file);
+ if (!info)
continue;
+ /* TODO: Reimplement showing hidden files and removing filters */
+#if 0
+ gboolean enabled_hidden, removed_filters;
+
+ enabled_hidden = impl->show_hidden;
+ removed_filters = (impl->current_filter == NULL);
+
if (!_gtk_file_system_item_is_visible (item))
{
GFileInfo *info = _gtk_file_system_item_get_file_info (item);
@@ -3554,32 +3570,30 @@ show_and_select_files (GtkFileChooserWidget *impl,
}
/* Okay, can we select the file now? */
- item = _gtk_file_system_model_get_item_for_file (fsmodel, file);
+ item = _gtk_file_system_model_get_info_for_file (fsmodel, file);
if (!item)
continue;
+#endif
- if (_gtk_file_system_item_is_visible (item))
+ /* TODO: "accidentally" quadratic! */
+
+ for (i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (impl->selection_model)); i++)
{
- guint i;
+ GFileInfo *info2;
- /* TODO: "accidentally" quadratic! */
+ info2 = g_list_model_get_item (G_LIST_MODEL (impl->selection_model), i);
- for (i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (impl->selection_model)); i++)
+ if (info2 == info)
{
- GtkFileSystemItem *item2 = g_list_model_get_item (G_LIST_MODEL (impl->selection_model), i);
-
- if (item2 == item)
- {
- gtk_selection_model_select_item (impl->selection_model,
- i,
- FALSE);
- g_clear_object (&item2);
- selected_a_file = TRUE;
- break;
- }
-
- g_clear_object (&item2);
+ gtk_selection_model_select_item (impl->selection_model,
+ i,
+ FALSE);
+ g_clear_object (&info);
+ selected_a_file = TRUE;
+ break;
}
+
+ g_clear_object (&info);
}
}
@@ -4089,13 +4103,10 @@ update_chooser_entry (GtkFileChooserWidget *impl)
{
if (impl->operation_mode == OPERATION_MODE_BROWSE)
{
- GtkFileSystemItem *item;
GFileInfo *info;
gboolean change_entry;
- item = g_list_model_get_item (G_LIST_MODEL (impl->selection_model), first);
- info = _gtk_file_system_item_get_file_info (item);
- g_clear_object (&item);
+ info = g_list_model_get_item (G_LIST_MODEL (impl->selection_model), first);
g_free (impl->browse_files_last_selected_name);
impl->browse_files_last_selected_name =
@@ -4130,19 +4141,21 @@ G_GNUC_END_IGNORE_DEPRECATIONS
_gtk_file_chooser_entry_select_filename (GTK_FILE_CHOOSER_ENTRY (impl->location_entry));
}
+ g_clear_object (&info);
+
return;
}
else if (impl->operation_mode == OPERATION_MODE_RECENT
&& impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
{
- GtkFileSystemItem *item;
+ GFileInfo *info;
GFile *folder;
/* Set the base folder on the name entry, so it will do completion relative to the correct
recent-folder */
- item = g_list_model_get_item (G_LIST_MODEL (impl->selection_model), first);
- folder = _gtk_file_system_item_get_file (item);
- g_clear_object (&item);
+ info = g_list_model_get_item (G_LIST_MODEL (impl->selection_model), first);
+ folder = _gtk_file_info_get_file (info);
+ g_clear_object (&info);
_gtk_file_chooser_entry_set_base_folder (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), folder);
return;
@@ -4570,12 +4583,12 @@ gtk_file_chooser_widget_unselect_file (GtkFileChooser *chooser,
gtk_bitset_iter_is_valid (&iter);
gtk_bitset_iter_next (&iter, &i))
{
- GtkFileSystemItem *item;
+ GFileInfo *info;
GFile *f;
- item = g_list_model_get_item (G_LIST_MODEL (impl->selection_model), i);
- f = _gtk_file_system_item_get_file (item);
- g_clear_object (&item);
+ info = g_list_model_get_item (G_LIST_MODEL (impl->selection_model), i);
+ f = _gtk_file_info_get_file (info);
+ g_clear_object (&info);
if (g_file_equal (f, file))
break;
@@ -4603,14 +4616,10 @@ gtk_file_chooser_widget_select_all (GtkFileChooser *chooser)
for (i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (impl->selection_model)); i++)
{
- GtkFileSystemItem *item;
GFileInfo *info;
gboolean is_folder;
- item = g_list_model_get_item (G_LIST_MODEL (impl->selection_model), i);
- info = _gtk_file_system_item_get_file_info (item);
- g_clear_object (&item);
-
+ info = g_list_model_get_item (G_LIST_MODEL (impl->selection_model), i);
is_folder = _gtk_file_info_consider_as_directory (info);
if ((is_folder && impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER) ||
@@ -4618,6 +4627,8 @@ gtk_file_chooser_widget_select_all (GtkFileChooser *chooser)
gtk_selection_model_select_item (impl->selection_model, i, FALSE);
else
gtk_selection_model_unselect_item (impl->selection_model, i);
+
+ g_clear_object (&info);
}
}
}
@@ -4790,12 +4801,12 @@ gtk_file_chooser_widget_get_files (GtkFileChooser *chooser)
gtk_bitset_iter_is_valid (&iter);
gtk_bitset_iter_next (&iter, &i))
{
- GtkFileSystemItem *item;
+ GFileInfo *info;
GFile *file;
- item = g_list_model_get_item (G_LIST_MODEL (impl->selection_model), i);
- file = _gtk_file_system_item_get_file (item);
- g_clear_object (&item);
+ info = g_list_model_get_item (G_LIST_MODEL (impl->selection_model), i);
+ file = _gtk_file_info_get_file (info);
+ g_clear_object (&info);
if (!file_from_entry || !g_file_equal (file_from_entry, file))
g_list_store_append (result, file);
@@ -4993,16 +5004,16 @@ gtk_file_chooser_widget_get_shortcut_folders (GtkFileChooser *chooser)
static void
switch_to_selected_folder (GtkFileChooserWidget *impl)
{
- GtkFileSystemItem *item;
+ GFileInfo *info;
GFile *file;
g_assert (!impl->select_multiple);
g_assert (GTK_IS_SINGLE_SELECTION (impl->selection_model));
- item = gtk_single_selection_get_selected_item (GTK_SINGLE_SELECTION (impl->selection_model));
- g_assert (item != NULL);
+ info = gtk_single_selection_get_selected_item (GTK_SINGLE_SELECTION (impl->selection_model));
+ g_assert (info != NULL);
- file = _gtk_file_system_item_get_file (item);
+ file = _gtk_file_info_get_file (info);
change_folder_and_display_error (impl, file, FALSE);
}
@@ -5012,16 +5023,13 @@ switch_to_selected_folder (GtkFileChooserWidget *impl)
static const char *
get_display_name_from_file_list (GtkFileChooserWidget *impl)
{
- GtkFileSystemItem *item;
GFileInfo *info;
g_assert (!impl->select_multiple);
g_assert (GTK_IS_SINGLE_SELECTION (impl->selection_model));
- item = gtk_single_selection_get_selected_item (GTK_SINGLE_SELECTION (impl->selection_model));
- g_assert (item != NULL);
-
- info = _gtk_file_system_item_get_file_info (item);
+ info = gtk_single_selection_get_selected_item (GTK_SINGLE_SELECTION (impl->selection_model));
+ g_assert (info != NULL);
return g_file_info_get_display_name (info);
}
@@ -5745,15 +5753,15 @@ get_selected_files (GtkFileChooserWidget *impl)
gtk_bitset_iter_is_valid (&iter);
gtk_bitset_iter_next (&iter, &i))
{
- GtkFileSystemItem *item;
+ GFileInfo *info;
GFile *file;
- item = g_list_model_get_item (G_LIST_MODEL (impl->selection_model), i);
- file = _gtk_file_system_item_get_file (item);
+ info = g_list_model_get_item (G_LIST_MODEL (impl->selection_model), i);
+ file = _gtk_file_info_get_file (info);
result = g_slist_prepend (result, g_object_ref (file));
- g_clear_object (&item);
+ g_clear_object (&info);
}
return result;
@@ -5773,15 +5781,12 @@ get_selected_infos (GtkFileChooserWidget *impl)
gtk_bitset_iter_is_valid (&iter);
gtk_bitset_iter_next (&iter, &i))
{
- GtkFileSystemItem *item;
GFileInfo *info;
- item = g_list_model_get_item (G_LIST_MODEL (impl->selection_model), i);
- info = _gtk_file_system_item_get_file_info (item);
-
+ info = g_list_model_get_item (G_LIST_MODEL (impl->selection_model), i);
result = g_slist_prepend (result, g_object_ref (info));
- g_clear_object (&item);
+ g_clear_object (&info);
}
return result;
@@ -6227,16 +6232,14 @@ column_view_row_activated_cb (GtkColumnView *column_view,
guint position,
GtkFileChooserWidget *self)
{
- GtkFileSystemItem *item;
GFileInfo *info;
- item = g_list_model_get_item (G_LIST_MODEL (self->selection_model),
+ info = g_list_model_get_item (G_LIST_MODEL (self->selection_model),
position);
- info = _gtk_file_system_item_get_file_info (item);
if (_gtk_file_info_consider_as_directory (info))
{
- GFile *file = _gtk_file_system_item_get_file (item);
+ GFile *file = _gtk_file_info_get_file (info);
change_folder_and_display_error (self, file, FALSE);
}
else if (self->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
@@ -6245,7 +6248,7 @@ column_view_row_activated_cb (GtkColumnView *column_view,
gtk_widget_activate_default (GTK_WIDGET (self));
}
- g_clear_object (&item);
+ g_clear_object (&info);
}
static void
@@ -6889,6 +6892,7 @@ gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class)
gtk_widget_class_bind_template_callback (widget_class, click_cb);
gtk_widget_class_bind_template_callback (widget_class, long_press_cb);
gtk_widget_class_bind_template_callback (widget_class, column_view_get_file_date);
+ gtk_widget_class_bind_template_callback (widget_class, column_view_get_file_display_name);
gtk_widget_class_bind_template_callback (widget_class, column_view_get_file_time);
gtk_widget_class_bind_template_callback (widget_class, column_view_get_file_type);
gtk_widget_class_bind_template_callback (widget_class, column_view_get_location);
diff --git a/gtk/gtkfilesystemmodel.c b/gtk/gtkfilesystemmodel.c
index 9989c23534..06da0ba33e 100644
--- a/gtk/gtkfilesystemmodel.c
+++ b/gtk/gtkfilesystemmodel.c
@@ -126,7 +126,6 @@ struct _FileModelNode
{
GFile * file; /* file represented by this node or NULL for editable */
GFileInfo * info; /* info for this file or NULL if unknown */
- GtkFileSystemItem * item; /* item for the GListModel implementation */
guint row; /* if valid (see model->n_valid_indexes), visible nodes before and
including
* this one - see the "Structure" comment above.
@@ -648,89 +647,10 @@ gtk_file_system_model_iface_init (GtkTreeModelIface *iface)
/*** GListModel ***/
-struct _GtkFileSystemItem {
- GObject parent;
-
- FileModelNode *node; /* unonwned */
-};
-
-typedef struct _GtkFileSystemItemClass
-{
- GObjectClass parent_class;
-} GtkFileSystemItemClass;
-
-G_DEFINE_TYPE (GtkFileSystemItem, _gtk_file_system_item, G_TYPE_OBJECT)
-
-enum {
- PROP_0,
- PROP_FILE,
- PROP_FILE_INFO,
- PROP_NAME,
- N_PROPS,
-};
-
-static GParamSpec *item_properties[N_PROPS] = { NULL, };
-
-static void
-_gtk_file_system_item_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GtkFileSystemItem *self = GTK_FILE_SYSTEM_ITEM (object);
-
- switch (prop_id)
- {
- case PROP_FILE:
- g_value_set_object (value, self->node->file);
- break;
-
- case PROP_FILE_INFO:
- g_value_set_object (value, self->node->info);
- break;
-
- case PROP_NAME:
- g_value_set_string (value, g_file_info_get_display_name (self->node->info));
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-_gtk_file_system_item_class_init (GtkFileSystemItemClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->get_property = _gtk_file_system_item_get_property;
-
- item_properties[PROP_FILE] =
- g_param_spec_object ("file", NULL, NULL,
- G_TYPE_FILE,
- G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
-
- item_properties[PROP_FILE_INFO] =
- g_param_spec_object ("file-info", NULL, NULL,
- G_TYPE_FILE_INFO,
- G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
-
- item_properties[PROP_NAME] =
- g_param_spec_string ("name", NULL, NULL, "",
- G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
-
- g_object_class_install_properties (object_class, N_PROPS, item_properties);
-}
-
-static void
-_gtk_file_system_item_init (GtkFileSystemItem *self)
-{
-}
-
static GType
list_model_get_item_type (GListModel *list_model)
{
- return GTK_TYPE_FILE_SYSTEM_ITEM;
+ return G_TYPE_FILE_INFO;
}
static guint
@@ -754,7 +674,7 @@ list_model_get_item (GListModel *list_model,
return NULL;
node = get_node (model, position + 1);
- return g_object_ref (node->item);
+ return g_object_ref (node->info);
}
static void
@@ -813,7 +733,6 @@ gtk_file_system_model_finalize (GObject *object)
int v;
FileModelNode *node = get_node (model, i);
- g_clear_object (&node->item);
g_clear_object (&node->file);
g_clear_object (&node->info);
@@ -1560,6 +1479,26 @@ _gtk_file_system_model_get_iter_for_file (GtkFileSystemModel *model,
return TRUE;
}
+
+GFileInfo *
+_gtk_file_system_model_get_info_for_file (GtkFileSystemModel *model,
+ GFile *file)
+{
+ FileModelNode *node;
+ guint i;
+
+ g_return_val_if_fail (GTK_IS_FILE_SYSTEM_MODEL (model), FALSE);
+ g_return_val_if_fail (G_IS_FILE (file), FALSE);
+
+ i = node_get_for_file (model, file);
+
+ if (i == 0)
+ return NULL;
+
+ node = get_node (model, i);
+ return node->info;
+}
+
/* When an element is added or removed to the model->files array, we need to
* update the model->file_lookup mappings of (node, index), as the indexes
* change. This function adds the specified increment to the index in that pair
@@ -1622,14 +1561,6 @@ add_file (GtkFileSystemModel *model,
position = model->files->len - 1;
- /* 'node' is now invalid, fetch the actual node from the array - this
- * will all go away when we finish the transition to GtkColumnView
- * and drop the GtkTreeModel code.
- */
- node = get_node (model, position);
- node->item = g_object_new (GTK_TYPE_FILE_SYSTEM_ITEM, NULL);
- node->item->node = node;
-
if (!model->frozen)
node_compute_visibility_and_filters (model, model->files->len -1);
@@ -1668,8 +1599,6 @@ remove_file (GtkFileSystemModel *model,
node_invalidate_index (model, id);
- g_clear_object (&node->item);
-
g_hash_table_remove (model->file_lookup, file);
g_object_unref (node->file);
adjust_file_lookup (model, id, -1);
@@ -1901,36 +1830,3 @@ _gtk_file_system_model_get_directory (GtkFileSystemModel *model)
return model->dir;
}
-GFile *
-_gtk_file_system_item_get_file (GtkFileSystemItem *item)
-{
- return item->node->file;
-}
-
-GFileInfo *
-_gtk_file_system_item_get_file_info (GtkFileSystemItem *item)
-{
- return item->node->info;
-}
-
-gboolean
-_gtk_file_system_item_is_visible (GtkFileSystemItem *item)
-{
- return item->node->visible;
-}
-
-GtkFileSystemItem *
-_gtk_file_system_model_get_item_for_file(GtkFileSystemModel *model,
- GFile *file)
-{
- FileModelNode *node;
- guint i;
-
- i = node_get_for_file (model, file);
-
- if (i == 0)
- return NULL;
-
- node = get_node (model, i);
- return node->item;
-}
diff --git a/gtk/gtkfilesystemmodel.h b/gtk/gtkfilesystemmodel.h
index d73e9e811d..d107a659e5 100644
--- a/gtk/gtkfilesystemmodel.h
+++ b/gtk/gtkfilesystemmodel.h
@@ -33,14 +33,6 @@ typedef struct _GtkFileSystemModel GtkFileSystemModel;
GType _gtk_file_system_model_get_type (void) G_GNUC_CONST;
-#define GTK_TYPE_FILE_SYSTEM_ITEM (_gtk_file_system_item_get_type ())
-#define GTK_FILE_SYSTEM_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_FILE_SYSTEM_ITEM,
GtkFileSystemItem))
-#define GTK_IS_FILE_SYSTEM_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_FILE_SYSTEM_ITEM))
-
-typedef struct _GtkFileSystemItem GtkFileSystemItem;
-
-GType _gtk_file_system_item_get_type (void) G_GNUC_CONST;
-
typedef gboolean (*GtkFileSystemModelGetValue) (GtkFileSystemModel *model,
GFile *file,
GFileInfo *info,
@@ -69,6 +61,8 @@ GFileInfo * _gtk_file_system_model_get_info (GtkFileSystemModel
gboolean _gtk_file_system_model_get_iter_for_file(GtkFileSystemModel *model,
GtkTreeIter *iter,
GFile *file);
+GFileInfo * _gtk_file_system_model_get_info_for_file(GtkFileSystemModel *model,
+ GFile *file);
GFile * _gtk_file_system_model_get_file (GtkFileSystemModel *model,
GtkTreeIter *iter);
const GValue * _gtk_file_system_model_get_value (GtkFileSystemModel *model,
@@ -100,15 +94,6 @@ void _gtk_file_system_model_set_filter_folders (GtkFileSystemMode
void _gtk_file_system_model_set_filter (GtkFileSystemModel *model,
GtkFileFilter *filter);
-GFile * _gtk_file_system_item_get_file (GtkFileSystemItem *item);
-
-GFileInfo * _gtk_file_system_item_get_file_info (GtkFileSystemItem *item);
-
-gboolean _gtk_file_system_item_is_visible (GtkFileSystemItem *item);
-
-GtkFileSystemItem * _gtk_file_system_model_get_item_for_file(GtkFileSystemModel *model,
- GFile *file);
-
G_END_DECLS
#endif /* __GTK_FILE_SYSTEM_MODEL_H__ */
diff --git a/gtk/gtkfilethumbnail.c b/gtk/gtkfilethumbnail.c
index 633b6be912..d8a5171119 100644
--- a/gtk/gtkfilethumbnail.c
+++ b/gtk/gtkfilethumbnail.c
@@ -36,8 +36,8 @@ struct _GtkFileThumbnail
GtkWidget *image;
- GtkFileSystemItem *item;
GCancellable *cancellable;
+ GFileInfo *info;
};
typedef struct
@@ -49,7 +49,7 @@ G_DEFINE_FINAL_TYPE (GtkFileThumbnail, _gtk_file_thumbnail, GTK_TYPE_WIDGET)
enum {
PROP_0,
- PROP_ITEM,
+ PROP_INFO,
N_PROPS,
};
@@ -71,18 +71,16 @@ static gboolean
update_image (GtkFileThumbnail *self)
{
GtkIconTheme *icon_theme;
- GFileInfo *info;
GIcon *icon;
int scale;
- info = _gtk_file_system_item_get_file_info (self->item);
- if (!g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_ICON))
+ if (!g_file_info_has_attribute (self->info, G_FILE_ATTRIBUTE_STANDARD_ICON))
return FALSE;
scale = gtk_widget_get_scale_factor (GTK_WIDGET (self));
icon_theme = gtk_icon_theme_get_for_display (gtk_widget_get_display (GTK_WIDGET (self)));
- icon = _gtk_file_info_get_icon (info, ICON_SIZE, scale, icon_theme);
+ icon = _gtk_file_info_get_icon (self->info, ICON_SIZE, scale, icon_theme);
gtk_image_set_from_gicon (GTK_IMAGE (self->image), icon);
@@ -100,16 +98,14 @@ thumbnail_queried_cb (GObject *object,
GtkFileThumbnail *self = user_data; /* might be unreffed if operation was cancelled */
GFile *file = G_FILE (object);
GFileInfo *queried;
- GFileInfo *info;
queried = g_file_query_info_finish (file, result, NULL);
if (queried == NULL)
return;
- info = _gtk_file_system_item_get_file_info (self->item);
- copy_attribute (info, queried, G_FILE_ATTRIBUTE_THUMBNAIL_PATH);
- copy_attribute (info, queried, G_FILE_ATTRIBUTE_THUMBNAILING_FAILED);
- copy_attribute (info, queried, G_FILE_ATTRIBUTE_STANDARD_ICON);
+ copy_attribute (self->info, queried, G_FILE_ATTRIBUTE_THUMBNAIL_PATH);
+ copy_attribute (self->info, queried, G_FILE_ATTRIBUTE_THUMBNAILING_FAILED);
+ copy_attribute (self->info, queried, G_FILE_ATTRIBUTE_STANDARD_ICON);
update_image (self);
@@ -128,23 +124,21 @@ cancel_thumbnail (GtkFileThumbnail *self)
static void
get_thumbnail (GtkFileThumbnail *self)
{
- if (!self->item)
+ if (!self->info)
return;
if (!update_image (self))
{
- GFileInfo *info;
GFile *file;
- info = _gtk_file_system_item_get_file_info (self->item);
- if (g_file_info_has_attribute (info, "filechooser::queried"))
+ if (g_file_info_has_attribute (self->info, "filechooser::queried"))
return;
g_assert (self->cancellable == NULL);
self->cancellable = g_cancellable_new ();
- file = _gtk_file_system_item_get_file (self->item);
- g_file_info_set_attribute_boolean (info, "filechooser::queried", TRUE);
+ file = _gtk_file_info_get_file (self->info);
+ g_file_info_set_attribute_boolean (self->info, "filechooser::queried", TRUE);
g_file_query_info_async (file,
G_FILE_ATTRIBUTE_THUMBNAIL_PATH ","
G_FILE_ATTRIBUTE_THUMBNAILING_FAILED ","
@@ -162,7 +156,7 @@ _gtk_file_thumbnail_dispose (GObject *object)
{
GtkFileThumbnail *self = (GtkFileThumbnail *)object;
- _gtk_file_thumbnail_set_item (self, NULL);
+ _gtk_file_thumbnail_set_info (self, NULL);
g_clear_pointer (&self->image, gtk_widget_unparent);
@@ -179,8 +173,8 @@ _gtk_file_thumbnail_get_property (GObject *object,
switch (prop_id)
{
- case PROP_ITEM:
- g_value_set_object (value, self->item);
+ case PROP_INFO:
+ g_value_set_object (value, self->info);
break;
default:
@@ -198,8 +192,8 @@ _gtk_file_thumbnail_set_property (GObject *object,
switch (prop_id)
{
- case PROP_ITEM:
- _gtk_file_thumbnail_set_item (self, g_value_get_object (value));
+ case PROP_INFO:
+ _gtk_file_thumbnail_set_info (self, g_value_get_object (value));
break;
default:
@@ -217,9 +211,9 @@ _gtk_file_thumbnail_class_init (GtkFileThumbnailClass *klass)
object_class->get_property = _gtk_file_thumbnail_get_property;
object_class->set_property = _gtk_file_thumbnail_set_property;
- properties[PROP_ITEM] =
- g_param_spec_object ("item", NULL, NULL,
- GTK_TYPE_FILE_SYSTEM_ITEM,
+ properties[PROP_INFO] =
+ g_param_spec_object ("file-info", NULL, NULL,
+ G_TYPE_FILE_INFO,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, N_PROPS, properties);
@@ -236,26 +230,26 @@ _gtk_file_thumbnail_init (GtkFileThumbnail *self)
gtk_widget_set_parent (self->image, GTK_WIDGET (self));
}
-GtkFileSystemItem *
-_gtk_file_thumbnail_get_item (GtkFileThumbnail *self)
+GFileInfo *
+_gtk_file_thumbnail_get_info (GtkFileThumbnail *self)
{
g_assert (GTK_IS_FILE_THUMBNAIL (self));
- return self->item;
+ return self->info;
}
void
-_gtk_file_thumbnail_set_item (GtkFileThumbnail *self,
- GtkFileSystemItem *item)
+_gtk_file_thumbnail_set_info (GtkFileThumbnail *self,
+ GFileInfo *info)
{
g_assert (GTK_IS_FILE_THUMBNAIL (self));
- g_assert (item == NULL || GTK_IS_FILE_SYSTEM_ITEM (item));
+ g_assert (info == NULL || G_IS_FILE_INFO (info));
- if (g_set_object (&self->item, item))
+ if (g_set_object (&self->info, info))
{
cancel_thumbnail (self);
get_thumbnail (self);
- g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ITEM]);
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_INFO]);
}
}
diff --git a/gtk/gtkfilethumbnail.h b/gtk/gtkfilethumbnail.h
index 12ffadefb0..c9c5741d3f 100644
--- a/gtk/gtkfilethumbnail.h
+++ b/gtk/gtkfilethumbnail.h
@@ -36,9 +36,9 @@ typedef struct _GtkFileThumbnail GtkFileThumbnail;
GType _gtk_file_thumbnail_get_type (void) G_GNUC_CONST;
-GtkFileSystemItem *_gtk_file_thumbnail_get_item (GtkFileThumbnail *self);
-void _gtk_file_thumbnail_set_item (GtkFileThumbnail *self,
- GtkFileSystemItem *item);
+GFileInfo *_gtk_file_thumbnail_get_info (GtkFileThumbnail *self);
+void _gtk_file_thumbnail_set_info (GtkFileThumbnail *self,
+ GFileInfo *info);
G_END_DECLS
diff --git a/gtk/gtksearchenginemodel.c b/gtk/gtksearchenginemodel.c
index 18fde279bc..6d174b1ed0 100644
--- a/gtk/gtksearchenginemodel.c
+++ b/gtk/gtksearchenginemodel.c
@@ -24,6 +24,7 @@
#include <gdk/gdk.h>
#include "gtksearchenginemodelprivate.h"
+#include "gtkfilechooserutils.h"
#include "gtkprivate.h"
#include <string.h>
@@ -86,25 +87,21 @@ do_search (gpointer data)
for (guint i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (model->model)); i++)
{
- GtkFileSystemItem *item;
- GFileInfo *info;
-
- item = g_list_model_get_item (G_LIST_MODEL (model->model), i);
- info = _gtk_file_system_item_get_file_info (item);
+ GFileInfo *info = g_list_model_get_item (G_LIST_MODEL (model->model), i);
if (info_matches_query (model->query, info))
{
GFile *file;
GtkSearchHit *hit;
- file = _gtk_file_system_item_get_file (item);
+ file = _gtk_file_info_get_file (info);
hit = g_new (GtkSearchHit, 1);
hit->file = g_object_ref (file);
hit->info = g_object_ref (info);
hits = g_list_prepend (hits, hit);
}
- g_clear_object (&item);
+ g_clear_object (&info);
}
if (hits)
diff --git a/gtk/ui/gtkfilechooserwidget.ui b/gtk/ui/gtkfilechooserwidget.ui
index 98cf0c2a49..ab8d446367 100644
--- a/gtk/ui/gtkfilechooserwidget.ui
+++ b/gtk/ui/gtkfilechooserwidget.ui
@@ -170,13 +170,15 @@
<property name="child">
<object class="GtkBox">
<binding name="tooltip-text">
- <closure type="gchararray" function="column_view_get_tooltip_text" />
+ <closure type="gchararray" function="column_view_get_tooltip_text">
+ <lookup name="item">GtkListItem</lookup>
+ </closure>
</binding>
<child>
<object class="GtkFileThumbnail">
<property name="margin-start">6</property>
<property name="margin-end">6</property>
- <binding name="item">
+ <binding name="file-info">
<lookup name="item">GtkListItem</lookup>
</binding>
</object>
@@ -187,9 +189,9 @@
<property name="xalign">0</property>
<property name="min-chars">10</property>
<binding name="text">
- <lookup type="GtkFileSystemItem" name="name">
+ <closure type="gchararray" function="column_view_get_file_display_name">
<lookup name="item">GtkListItem</lookup>
- </lookup>
+ </closure>
</binding>
</object>
</child>
@@ -223,10 +225,14 @@
<property name="margin-start">6</property>
<property name="margin-end">6</property>
<binding name="text">
- <closure type="gchararray" function="column_view_get_location" />
+ <closure type="gchararray" function="column_view_get_location">
+ <lookup name="item">GtkListItem</lookup>
+ </closure>
</binding>
<binding name="tooltip-text">
- <closure type="gchararray" function="column_view_get_tooltip_text" />
+ <closure type="gchararray" function="column_view_get_tooltip_text">
+ <lookup name="item">GtkListItem</lookup>
+ </closure>
</binding>
</object>
</property>
@@ -253,13 +259,13 @@
<property name="xalign">0</property>
<binding name="label">
<closure type="gchararray" function="column_view_get_size">
- <lookup type="GtkFileSystemItem" name="file-info">
- <lookup name="item">GtkListItem</lookup>
- </lookup>
+ <lookup name="item">GtkListItem</lookup>
</closure>
</binding>
<binding name="tooltip-text">
- <closure type="gchararray" function="column_view_get_tooltip_text" />
+ <closure type="gchararray" function="column_view_get_tooltip_text">
+ <lookup name="item">GtkListItem</lookup>
+ </closure>
</binding>
</object>
</property>
@@ -287,13 +293,13 @@
<property name="xalign">0</property>
<binding name="label">
<closure type="gchararray" function="column_view_get_file_type">
- <lookup type="GtkFileSystemItem" name="file-info">
- <lookup name="item">GtkListItem</lookup>
- </lookup>
+ <lookup name="item">GtkListItem</lookup>
</closure>
</binding>
<binding name="tooltip-text">
- <closure type="gchararray" function="column_view_get_tooltip_text" />
+ <closure type="gchararray" function="column_view_get_tooltip_text">
+ <lookup name="item">GtkListItem</lookup>
+ </closure>
</binding>
</object>
</property>
@@ -318,15 +324,15 @@
<object class="GtkBox">
<property name="spacing">6</property>
<binding name="tooltip-text">
- <closure type="gchararray" function="column_view_get_tooltip_text" />
+ <closure type="gchararray" function="column_view_get_tooltip_text">
+ <lookup name="item">GtkListItem</lookup>
+ </closure>
</binding>
<child>
<object class="GtkLabel">
<binding name="label">
<closure type="gchararray" function="column_view_get_file_date">
- <lookup type="GtkFileSystemItem" name="file-info">
- <lookup name="item">GtkListItem</lookup>
- </lookup>
+ <lookup name="item">GtkListItem</lookup>
</closure>
</binding>
</object>
@@ -338,9 +344,7 @@
</binding>
<binding name="label">
<closure type="gchararray" function="column_view_get_file_time">
- <lookup type="GtkFileSystemItem" name="file-info">
- <lookup name="item">GtkListItem</lookup>
- </lookup>
+ <lookup name="item">GtkListItem</lookup>
</closure>
</binding>
</object>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]