"standard::content-type,standard::fast-content-type,time::modified,time::access," \
"access::can-rename,access::can-delete,access::can-trash," \
"standard::target-uri"
-enum {
- /* the first 4 must be these due to settings caching sort column */
- MODEL_COL_NAME,
- MODEL_COL_SIZE,
- MODEL_COL_FILE,
- MODEL_COL_NAME_COLLATED,
- MODEL_COL_IS_FOLDER,
- MODEL_COL_IS_SENSITIVE,
- MODEL_COL_ELLIPSIZE,
- MODEL_COL_NUM_COLUMNS
-};
-
-/* This list of types is passed to _gtk_file_system_model_new*() */
-#define MODEL_COLUMN_TYPES \
- MODEL_COL_NUM_COLUMNS, \
- G_TYPE_STRING, /* MODEL_COL_NAME */ \
- G_TYPE_INT64, /* MODEL_COL_SIZE */ \
- G_TYPE_FILE, /* MODEL_COL_FILE */ \
- G_TYPE_STRING, /* MODEL_COL_NAME_COLLATED */ \
- G_TYPE_BOOLEAN, /* MODEL_COL_IS_FOLDER */ \
- G_TYPE_BOOLEAN, /* MODEL_COL_IS_SENSITIVE */ \
- PANGO_TYPE_ELLIPSIZE_MODE /* MODEL_COL_ELLIPSIZE */
#define DEFAULT_RECENT_FILES_LIMIT 50
impl->browse_files_model =
_gtk_file_system_model_new_for_directory (impl->current_folder,
- MODEL_ATTRIBUTES,
- MODEL_COLUMN_TYPES);
+ MODEL_ATTRIBUTES);
_gtk_file_system_model_set_show_hidden (impl->browse_files_model, impl->show_hidden);
{
g_assert (impl->search_model == NULL);
- impl->search_model = _gtk_file_system_model_new (MODEL_COLUMN_TYPES);
+ impl->search_model = _gtk_file_system_model_new ();
set_current_model (impl, G_LIST_MODEL (impl->search_model));
update_columns (impl, TRUE, _("Modified"));
/* Setup recent model */
g_assert (impl->recent_model == NULL);
- impl->recent_model = _gtk_file_system_model_new (MODEL_COLUMN_TYPES);
+ impl->recent_model = _gtk_file_system_model_new ();
_gtk_file_system_model_set_filter (impl->recent_model, impl->current_filter);
guint visible :1; /* if the file is currently visible */
guint filtered_out :1;/* if the file is currently filtered out (i.e. it didn't pass the filters) */
guint frozen_add :1; /* true if the model was frozen and the entry has not been added yet */
-
- GValue values[1]; /* actually n_columns values */
};
struct _GtkFileSystemModel
GCancellable * cancellable; /* cancellable in use for all operations - cancelled on dispose */
GArray * files; /* array of FileModelNode containing all our files */
- gsize node_size; /* Size of a FileModelNode structure once its ->values field has n_columns */
guint n_nodes_valid; /* count of valid nodes (i.e. those whose node->row is accurate) */
GHashTable * file_lookup; /* mapping of GFile => array index in model->files
* This hash table doesn't always have the same number of entries as the files array;
* detected.
*/
- guint n_columns; /* number of columns */
- GType * column_types; /* types of each column */
-
GtkFileFilter * filter; /* filter to use for deciding which nodes are visible */
guint frozen; /* number of times we're frozen */
/*** FileModelNode ***/
/* Get a FileModelNode structure given an index in the model->files array of nodes */
-#define get_node(_model, _index) ((FileModelNode *) ((_model)->files->data + (_index) * (_model)->node_size))
+#define get_node(_model, _index) ((FileModelNode *) ((_model)->files->data + (_index) * sizeof (FileModelNode)))
/* Get an index within the model->files array of nodes, given a FileModelNode* */
-#define node_index(_model, _node) (((char *) (_node) - (_model)->files->data) / (_model)->node_size)
+#define node_index(_model, _node) (((char *) (_node) - (_model)->files->data) / sizeof (FileModelNode))
/* @up_to_index: smallest model->files array index that will be valid after this call
* @up_to_row: smallest node->row that will be valid after this call
for (i = 0; i < model->files->len; i++)
{
- int v;
-
FileModelNode *node = get_node (model, i);
g_clear_object (&node->file);
g_clear_object (&node->info);
-
- for (v = 0; v < model->n_columns; v++)
- if (G_VALUE_TYPE (&node->values[v]) != G_TYPE_INVALID)
- g_value_unset (&node->values[v]);
}
g_array_free (model->files, TRUE);
g_clear_pointer (&model->file_lookup, g_hash_table_destroy);
g_clear_object (&model->filter);
- g_slice_free1 (sizeof (GType) * model->n_columns, model->column_types);
-
G_OBJECT_CLASS (_gtk_file_system_model_parent_class)->finalize (object);
}
}
}
-static void
-gtk_file_system_model_set_n_columns (GtkFileSystemModel *model,
- int n_columns,
- va_list args)
-{
- guint i;
-
- g_assert (model->files == NULL);
- g_assert (n_columns > 0);
-
- model->n_columns = n_columns;
- model->column_types = g_slice_alloc (sizeof (GType) * n_columns);
-
- model->node_size = sizeof (FileModelNode) + sizeof (GValue) * (n_columns - 1); /* minus 1 because FileModelNode.values[] has a default size of 1 */
-
- for (i = 0; i < (guint) n_columns; i++)
- {
- GType type = va_arg (args, GType);
- if (! _gtk_tree_data_list_check_type (type))
- {
- g_error ("%s: type %s cannot be a column type for GtkFileSystemModel\n", G_STRLOC, g_type_name (type));
- return; /* not reached */
- }
-
- model->column_types[i] = type;
- }
-
- model->files = g_array_sized_new (FALSE, FALSE, model->node_size, FILES_PER_QUERY);
- /* add editable node at start */
- g_array_set_size (model->files, 1);
- memset (get_node (model, 0), 0, model->node_size);
-}
-
static void
gtk_file_system_model_set_directory (GtkFileSystemModel *model,
GFile * dir,
}
-static GtkFileSystemModel *
-_gtk_file_system_model_new_valist (guint n_columns,
- va_list args)
-{
- GtkFileSystemModel *model;
-
- model = g_object_new (GTK_TYPE_FILE_SYSTEM_MODEL, NULL);
-
- gtk_file_system_model_set_n_columns (model, n_columns, args);
-
- return model;
-}
-
/**
* _gtk_file_system_model_new:
- * @n_columns: number of columns
- * @...: @n_columns `GType` types for the columns
*
* Creates a new `GtkFileSystemModel` object. You need to add files
* to the list using _gtk_file_system_model_add_and_query_file()
* Returns: the newly created `GtkFileSystemModel`
**/
GtkFileSystemModel *
-_gtk_file_system_model_new (guint n_columns,
- ...)
+_gtk_file_system_model_new (void)
{
GtkFileSystemModel *model;
- va_list args;
- g_return_val_if_fail (n_columns > 0, NULL);
+ model = g_object_new (GTK_TYPE_FILE_SYSTEM_MODEL, NULL);
- va_start (args, n_columns);
- model = _gtk_file_system_model_new_valist (n_columns, args);
- va_end (args);
+ model->files = g_array_sized_new (FALSE, FALSE, sizeof (FileModelNode), FILES_PER_QUERY);
+ /* add editable node at start */
+ g_array_set_size (model->files, 1);
+ memset (get_node (model, 0), 0, sizeof (FileModelNode));
return model;
}
* _gtk_file_system_model_new_for_directory:
* @directory: the directory to show.
* @attributes: (nullable): attributes to immediately load or %NULL for all
- * @n_columns: number of columns
- * @...: @n_columns `GType` types for the columns
*
* Creates a new `GtkFileSystemModel` object.
*
* Returns: the newly created `GtkFileSystemModel`
**/
GtkFileSystemModel *
-_gtk_file_system_model_new_for_directory (GFile * dir,
- const char * attributes,
- guint n_columns,
- ...)
+_gtk_file_system_model_new_for_directory (GFile *dir,
+ const char *attributes)
{
GtkFileSystemModel *model;
- va_list args;
g_return_val_if_fail (G_IS_FILE (dir), NULL);
- g_return_val_if_fail (n_columns > 0, NULL);
-
- va_start (args, n_columns);
- model = _gtk_file_system_model_new_valist (n_columns, args);
- va_end (args);
+ model = _gtk_file_system_model_new ();
gtk_file_system_model_set_directory (model, dir, attributes);
return model;
g_return_if_fail (G_IS_FILE (file));
g_return_if_fail (G_IS_FILE_INFO (info));
- node = g_slice_alloc0 (model->node_size);
+ node = g_slice_alloc0 (sizeof (FileModelNode));
node->file = g_object_ref (file);
if (info)
{
node->frozen_add = model->frozen ? TRUE : FALSE;
g_array_append_vals (model->files, node, 1);
- g_slice_free1 (model->node_size, node);
+ g_slice_free1 (sizeof (FileModelNode), node);
position = model->files->len - 1;
GFileInfo *info)
{
FileModelNode *node;
- guint i, id;
+ guint id;
g_return_if_fail (GTK_IS_FILE_SYSTEM_MODEL (model));
g_return_if_fail (G_IS_FILE (file));
g_set_object (&node->info, info);
- for (i = 0; i < model->n_columns; i++)
- {
- if (G_VALUE_TYPE (&node->values[i]))
- g_value_unset (&node->values[i]);
- }
-
g_file_info_set_attribute_object (info, "standard::file", G_OBJECT (file));
}