contentformats: Add a utility api

It can be handy to quickly check if a GdkContentFormats is empty.
This commit is contained in:
Matthias Clasen 2024-11-20 16:34:27 -05:00
parent 41d82c0271
commit 608ef5ddf0
2 changed files with 25 additions and 0 deletions

View File

@ -572,6 +572,24 @@ gdk_content_formats_get_mime_types (const GdkContentFormats *formats,
}
/**
* gdk_content_formats_is_empty:
* @formats: content formats
*
* Returns whether the content formats contain any formats.
*
* Returns: true if @formats contains no mime types and no GTypes
*
* Since: 4.18
*/
gboolean
gdk_content_formats_is_empty (GdkContentFormats *formats)
{
return formats->n_mime_types == 0 && formats->n_gtypes == 0;
}
/* {{{ GdkContentFormatsBuilder */
/*
* GdkContentFormatsBuilder:
*
* A `GdkContentFormatsBuilder` is an auxiliary struct used to create
@ -825,6 +843,7 @@ gdk_content_formats_builder_add_mime_type (GdkContentFormatsBuilder *builder,
builder->n_mime_types++;
}
/* }}} */
/* {{{ GdkFileList */
/* We're using GdkFileList* and GSList* interchangeably, counting on the
@ -912,3 +931,5 @@ gdk_file_list_new_from_array (GFile **files,
}
/* }}} */
/* vim:set foldmethod=marker: */

View File

@ -76,6 +76,9 @@ GDK_AVAILABLE_IN_ALL
gboolean gdk_content_formats_contain_mime_type (const GdkContentFormats *formats,
const char *mime_type);
GDK_AVAILABLE_IN_4_18
gboolean gdk_content_formats_is_empty (GdkContentFormats *formats);
#define GDK_TYPE_CONTENT_FORMATS_BUILDER (gdk_content_formats_builder_get_type ())
typedef struct _GdkContentFormatsBuilder GdkContentFormatsBuilder;
@ -103,6 +106,7 @@ GDK_AVAILABLE_IN_ALL
void gdk_content_formats_builder_add_gtype (GdkContentFormatsBuilder *builder,
GType type);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GdkContentFormats, gdk_content_formats_unref)
/* dunno where else to put this */