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

@ -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