Add getter to GdkFileList
authorEmmanuele Bassi <ebassi@gnome.org>
Fri, 8 Oct 2021 10:41:56 +0000 (11:41 +0100)
committerEmmanuele Bassi <ebassi@gnome.org>
Mon, 11 Oct 2021 20:40:29 +0000 (21:40 +0100)
Language bindings don't really have any mean of accessing the list of
files for GdkFileList.

gdk/gdkcontentformats.c
gdk/gdkcontentformats.h

index 662ff1b825fdd8b5711a96863f58b128c81ea133..0cdc51fa529d3b49fc009762cbeb9179fba458ea 100644 (file)
@@ -808,8 +808,13 @@ gdk_content_formats_builder_add_mime_type (GdkContentFormatsBuilder *builder,
   builder->n_mime_types++;
 }
 
-/* G_DEFINE_BOXED wants this */
-typedef gpointer GdkFileList;
+/* {{{ GdkFileList */
+
+/* We're using GdkFileList* and GSList* interchangeably, counting on the
+ * fact that we're just passing around gpointers; the only reason why we
+ * have a GdkFileList opaque type is for language bindings, because they
+ * can have no idea what a GSList of GFiles is.
+ */
 
 static gpointer
 gdk_file_list_copy (gpointer list)
@@ -824,3 +829,23 @@ gdk_file_list_free (gpointer list)
 }
 
 G_DEFINE_BOXED_TYPE (GdkFileList, gdk_file_list, gdk_file_list_copy, gdk_file_list_free)
+
+/**
+ * gdk_file_list_get_files:
+ * @file_list: the file list
+ *
+ * Retrieves the list of files inside a `GdkFileList`.
+ *
+ * This function is meant for language bindings.
+ *
+ * Returns: (transfer container) (element-type GFile): the files inside the list
+ *
+ * Since: 4.6
+ */
+GSList *
+gdk_file_list_get_files (GdkFileList *file_list)
+{
+  return g_slist_copy ((GSList *) file_list);
+}
+
+/* }}} */
index 143a66934014791c27ad53e35ad4de2202ad34cd..df536ccef227628e03a2a362321e8a105419b2e5 100644 (file)
@@ -109,8 +109,19 @@ void                    gdk_content_formats_builder_add_gtype   (GdkContentForma
 /* dunno where else to put this */
 #define GDK_TYPE_FILE_LIST (gdk_file_list_get_type ())
 GDK_AVAILABLE_IN_ALL
-GType     gdk_file_list_get_type  (void) G_GNUC_CONST;
+GType gdk_file_list_get_type (void) G_GNUC_CONST;
 
+/**
+ * GdkFileList:
+ *
+ * An opaque type representing a list of files.
+ *
+ * Since: 4.6
+ */
+typedef struct _GdkFileList GdkFileList;
+
+GDK_AVAILABLE_IN_4_6
+GSList *        gdk_file_list_get_files (GdkFileList *file_list);
 
 G_END_DECLS