Add constructors for GdkFileList

C API users can keep dealing with the implicit equivalence of
GdkFileList and GSList, but language bindings have no idea that one type
is another, and none of them exposes GSList as a type anyway, so they
will need a way to construct a GdkFileList.

Instead of making GdkFileList mutable, and re-implement GSList, we only
provide a constructors pair that lets you create a GdkFileList from a
linked list or from an array.
This commit is contained in:
Emmanuele Bassi 2022-07-28 10:13:17 +01:00
parent f480ff2e4d
commit dcd549aebe
2 changed files with 55 additions and 4 deletions

View File

@ -184,7 +184,7 @@ gdk_content_formats_new_for_gtype (GType type)
* @string: the string to parse
*
* Parses the given @string into `GdkContentFormats` and
* returns the formats.
* returns the formats.
*
* Strings printed via [method@Gdk.ContentFormats.to_string]
* can be read in again successfully using this function.
@ -540,7 +540,7 @@ gdk_content_formats_get_gtypes (const GdkContentFormats *formats,
if (n_gtypes)
*n_gtypes = formats->n_gtypes;
return formats->gtypes;
}
@ -567,7 +567,7 @@ gdk_content_formats_get_mime_types (const GdkContentFormats *formats,
if (n_mime_types)
*n_mime_types = formats->n_mime_types;
return formats->mime_types;
}
@ -663,7 +663,7 @@ gdk_content_formats_builder_unref (GdkContentFormatsBuilder *builder)
if (builder->ref_count > 0)
return;
gdk_content_formats_builder_clear (builder);
g_slice_free (GdkContentFormatsBuilder, builder);
}
@ -862,4 +862,50 @@ gdk_file_list_get_files (GdkFileList *file_list)
return g_slist_copy ((GSList *) file_list);
}
/**
* gdk_file_list_new_from_list:
* @files: (element-type GFile): a list of files
*
* Creates a new files list container from a singly linked list of
* `GFile` instances.
*
* This function is meant to be used by language bindings
*
* Returns: (transfer full): the newly created files list
*
* Since: 4.8
*/
GdkFileList *
gdk_file_list_new_from_list (GSList *files)
{
return gdk_file_list_copy (files);
}
/**
* gdk_file_list_new_from_array:
* @files: (array length=n_files): the files to add to the list
* @n_files: the number of files in the array
*
* Creates a new `GdkFileList` for the given array of files.
*
* This function is meant to be used by language bindings.
*
* Returns: (transfer full): the newly create files list
*
* Since: 4.8
*/
GdkFileList *
gdk_file_list_new_from_array (GFile **files,
gsize n_files)
{
if (files == NULL || n_files == 0)
return NULL;
GSList *res = NULL;
for (gssize i = n_files - 1; i >= 0; i--)
res = g_slist_prepend (res, g_object_ref (files[i]));
return (GdkFileList *) res;
}
/* }}} */

View File

@ -122,6 +122,11 @@ typedef struct _GdkFileList GdkFileList;
GDK_AVAILABLE_IN_4_6
GSList * gdk_file_list_get_files (GdkFileList *file_list);
GDK_AVAILABLE_IN_4_8
GdkFileList * gdk_file_list_new_from_list (GSList *files);
GDK_AVAILABLE_IN_4_8
GdkFileList * gdk_file_list_new_from_array (GFile **files,
gsize n_files);
G_END_DECLS