forked from AuroraMiddleware/gtk
filesystemmodel: Drop the model types
We are no longer storing extra values, so no need to take their types in the api.
This commit is contained in:
parent
b831d01f0d
commit
e5be9e1035
@ -616,11 +616,7 @@ populate_completion_store (GtkFileChooserEntry *chooser_entry)
|
||||
chooser_entry->model =
|
||||
_gtk_file_system_model_new_for_directory (chooser_entry->current_folder_file,
|
||||
"standard::name,standard::display-name,standard::type,"
|
||||
"standard::content-type",
|
||||
N_COLUMNS,
|
||||
G_TYPE_FILE_INFO,
|
||||
G_TYPE_STRING,
|
||||
G_TYPE_STRING);
|
||||
"standard::content-type");
|
||||
g_signal_connect (chooser_entry->model, "items-changed",
|
||||
G_CALLBACK (model_items_changed_cb), chooser_entry);
|
||||
g_signal_connect (chooser_entry->model, "finished-loading",
|
||||
|
@ -356,28 +356,6 @@ static guint signals[LAST_SIGNAL] = { 0 };
|
||||
"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
|
||||
|
||||
@ -4062,8 +4040,7 @@ set_list_model (GtkFileChooserWidget *impl,
|
||||
|
||||
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);
|
||||
|
||||
@ -5932,7 +5909,7 @@ search_setup_model (GtkFileChooserWidget *impl)
|
||||
{
|
||||
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"));
|
||||
@ -6096,7 +6073,7 @@ recent_start_loading (GtkFileChooserWidget *impl)
|
||||
/* 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);
|
||||
|
||||
|
@ -133,8 +133,6 @@ struct _FileModelNode
|
||||
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
|
||||
@ -148,7 +146,6 @@ 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;
|
||||
@ -156,9 +153,6 @@ struct _GtkFileSystemModel
|
||||
* 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 */
|
||||
@ -214,10 +208,10 @@ static void remove_file (GtkFileSystemModel *model,
|
||||
/*** 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
|
||||
@ -450,15 +444,9 @@ gtk_file_system_model_finalize (GObject *object)
|
||||
|
||||
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);
|
||||
|
||||
@ -469,8 +457,6 @@ gtk_file_system_model_finalize (GObject *object)
|
||||
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);
|
||||
}
|
||||
|
||||
@ -703,39 +689,6 @@ gtk_file_system_model_got_enumerator (GObject *dir, GAsyncResult *res, gpointer
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
@ -756,23 +709,8 @@ gtk_file_system_model_set_directory (GtkFileSystemModel *model,
|
||||
|
||||
}
|
||||
|
||||
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()
|
||||
@ -781,17 +719,16 @@ _gtk_file_system_model_new_valist (guint n_columns,
|
||||
* 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;
|
||||
}
|
||||
@ -800,8 +737,6 @@ _gtk_file_system_model_new (guint n_columns,
|
||||
* _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.
|
||||
*
|
||||
@ -814,21 +749,14 @@ _gtk_file_system_model_new (guint n_columns,
|
||||
* 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;
|
||||
@ -1064,7 +992,7 @@ add_file (GtkFileSystemModel *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)
|
||||
{
|
||||
@ -1074,7 +1002,7 @@ add_file (GtkFileSystemModel *model,
|
||||
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;
|
||||
|
||||
@ -1140,7 +1068,7 @@ _gtk_file_system_model_update_file (GtkFileSystemModel *model,
|
||||
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));
|
||||
@ -1157,12 +1085,6 @@ _gtk_file_system_model_update_file (GtkFileSystemModel *model,
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
|
@ -32,12 +32,9 @@ typedef struct _GtkFileSystemModel GtkFileSystemModel;
|
||||
|
||||
GType _gtk_file_system_model_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GtkFileSystemModel *_gtk_file_system_model_new (guint n_columns,
|
||||
...);
|
||||
GtkFileSystemModel *_gtk_file_system_model_new_for_directory(GFile * dir,
|
||||
const char * attributes,
|
||||
guint n_columns,
|
||||
...);
|
||||
GtkFileSystemModel *_gtk_file_system_model_new (void);
|
||||
GtkFileSystemModel *_gtk_file_system_model_new_for_directory(GFile *dir,
|
||||
const char *attributes);
|
||||
GFile * _gtk_file_system_model_get_directory (GtkFileSystemModel *model);
|
||||
GCancellable * _gtk_file_system_model_get_cancellable (GtkFileSystemModel *model);
|
||||
GFileInfo * _gtk_file_system_model_get_info_for_file(GtkFileSystemModel *model,
|
||||
|
Loading…
Reference in New Issue
Block a user