2017-11-17 16:31:59 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
2017-11-18 01:19:53 +00:00
|
|
|
* Copyright (C) 2017 Benjamin Otte
|
2017-11-17 16:31:59 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2017-11-18 01:19:53 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2017-11-17 16:31:59 +00:00
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2017-11-18 01:19:53 +00:00
|
|
|
/**
|
2021-02-21 05:13:57 +00:00
|
|
|
* GdkContentFormats:
|
|
|
|
*
|
|
|
|
* The `GdkContentFormats` structure is used to advertise and negotiate the
|
|
|
|
* format of content.
|
|
|
|
*
|
|
|
|
* You will encounter `GdkContentFormats` when interacting with objects
|
|
|
|
* controlling operations that pass data between different widgets, window
|
|
|
|
* or application, like [class@Gdk.Drag], [class@Gdk.Drop],
|
|
|
|
* [class@Gdk.Clipboard] or [class@Gdk.ContentProvider].
|
|
|
|
*
|
|
|
|
* GDK supports content in 2 forms: `GType` and mime type.
|
|
|
|
* Using `GTypes` is meant only for in-process content transfers. Mime types
|
2017-11-18 01:19:53 +00:00
|
|
|
* are meant to be used for data passing both in-process and out-of-process.
|
|
|
|
* The details of how data is passed is described in the documentation of
|
2021-02-21 05:13:57 +00:00
|
|
|
* the actual implementations. To transform between the two forms,
|
|
|
|
* [class@Gdk.ContentSerializer] and [class@Gdk.ContentDeserializer] are used.
|
2017-11-18 01:19:53 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* A `GdkContentFormats` describes a set of possible formats content can be
|
|
|
|
* exchanged in. It is assumed that this set is ordered. `GTypes` are more
|
|
|
|
* important than mime types. Order between different `GTypes` or mime types
|
2017-11-18 01:19:53 +00:00
|
|
|
* is the order they were added in, most important first. Functions that
|
2021-02-21 05:13:57 +00:00
|
|
|
* care about order, such as [method@Gdk.ContentFormats.union], will describe
|
|
|
|
* in their documentation how they interpret that order, though in general the
|
2017-11-18 01:19:53 +00:00
|
|
|
* order of the first argument is considered the primary order of the result,
|
|
|
|
* followed by the order of further arguments.
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* For debugging purposes, the function [method@Gdk.ContentFormats.to_string]
|
|
|
|
* exists. It will print a comma-separated list of formats from most important
|
|
|
|
* to least important.
|
2017-11-17 16:31:59 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* `GdkContentFormats` is an immutable struct. After creation, you cannot change
|
|
|
|
* the types it represents. Instead, new `GdkContentFormats` have to be created.
|
2021-05-23 01:20:10 +00:00
|
|
|
* The [struct@Gdk.ContentFormatsBuilder] structure is meant to help in this
|
2021-02-21 05:13:57 +00:00
|
|
|
* endeavor.
|
2017-11-17 16:31:59 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gdkcontentformats.h"
|
|
|
|
#include "gdkcontentformatsprivate.h"
|
|
|
|
|
2017-11-25 20:59:39 +00:00
|
|
|
#include <string.h>
|
2017-11-17 16:31:59 +00:00
|
|
|
|
2017-11-18 01:19:53 +00:00
|
|
|
struct _GdkContentFormats
|
2017-11-17 16:31:59 +00:00
|
|
|
{
|
|
|
|
/*< private >*/
|
|
|
|
guint ref_count;
|
2017-11-20 03:42:43 +00:00
|
|
|
|
|
|
|
const char **mime_types; /* interned */
|
|
|
|
gsize n_mime_types;
|
2017-11-20 14:58:17 +00:00
|
|
|
GType *gtypes;
|
|
|
|
gsize n_gtypes;
|
2017-11-17 16:31:59 +00:00
|
|
|
};
|
|
|
|
|
2017-11-18 01:19:53 +00:00
|
|
|
G_DEFINE_BOXED_TYPE (GdkContentFormats, gdk_content_formats,
|
|
|
|
gdk_content_formats_ref,
|
|
|
|
gdk_content_formats_unref)
|
|
|
|
|
|
|
|
|
2017-11-25 20:59:39 +00:00
|
|
|
/**
|
|
|
|
* gdk_intern_mime_type:
|
|
|
|
* @string: (transfer none): string of a potential mime type
|
|
|
|
*
|
|
|
|
* Canonicalizes the given mime type and interns the result.
|
|
|
|
*
|
|
|
|
* If @string is not a valid mime type, %NULL is returned instead.
|
|
|
|
* See RFC 2048 for the syntax if mime types.
|
|
|
|
*
|
2021-05-22 18:43:11 +00:00
|
|
|
* Returns: (nullable): An interned string for the canonicalized
|
|
|
|
* mime type or %NULL if the string wasn't a valid mime type
|
2021-02-21 05:13:57 +00:00
|
|
|
*/
|
2017-11-25 20:59:39 +00:00
|
|
|
const char *
|
|
|
|
gdk_intern_mime_type (const char *string)
|
|
|
|
{
|
|
|
|
char *tmp;
|
|
|
|
|
|
|
|
g_return_val_if_fail (string != NULL, NULL);
|
|
|
|
|
|
|
|
if (!strchr (string, '/'))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
tmp = g_ascii_strdown (string, -1);
|
|
|
|
|
|
|
|
string = g_intern_string (tmp);
|
|
|
|
|
|
|
|
g_free (tmp);
|
|
|
|
|
|
|
|
return string;
|
|
|
|
}
|
|
|
|
|
2017-11-20 03:42:43 +00:00
|
|
|
static GdkContentFormats *
|
2017-11-20 14:58:17 +00:00
|
|
|
gdk_content_formats_new_take (GType * gtypes,
|
|
|
|
gsize n_gtypes,
|
|
|
|
const char **mime_types,
|
|
|
|
gsize n_mime_types)
|
2017-11-18 01:19:53 +00:00
|
|
|
{
|
2017-11-20 03:42:43 +00:00
|
|
|
GdkContentFormats *result = g_slice_new0 (GdkContentFormats);
|
|
|
|
result->ref_count = 1;
|
2017-11-18 01:19:53 +00:00
|
|
|
|
2017-11-20 14:58:17 +00:00
|
|
|
result->gtypes = gtypes;
|
|
|
|
result->n_gtypes = n_gtypes;
|
2017-11-20 03:42:43 +00:00
|
|
|
result->mime_types = mime_types;
|
|
|
|
result->n_mime_types = n_mime_types;
|
|
|
|
|
|
|
|
return result;
|
2017-11-18 01:19:53 +00:00
|
|
|
}
|
2017-11-17 16:31:59 +00:00
|
|
|
|
|
|
|
/**
|
2017-11-18 01:19:53 +00:00
|
|
|
* gdk_content_formats_new:
|
2021-05-19 11:24:34 +00:00
|
|
|
* @mime_types: (array length=n_mime_types) (nullable): Pointer to an
|
2017-11-18 01:19:53 +00:00
|
|
|
* array of mime types
|
2017-11-28 14:20:14 +00:00
|
|
|
* @n_mime_types: number of entries in @mime_types.
|
2021-02-21 05:13:57 +00:00
|
|
|
*
|
|
|
|
* Creates a new `GdkContentFormats` from an array of mime types.
|
2017-11-20 03:42:43 +00:00
|
|
|
*
|
2017-11-28 01:02:06 +00:00
|
|
|
* The mime types must be valid and different from each other or the
|
|
|
|
* behavior of the return value is undefined. If you cannot guarantee
|
2021-05-22 18:43:11 +00:00
|
|
|
* this, use [struct@Gdk.ContentFormatsBuilder] instead.
|
2021-02-21 05:13:57 +00:00
|
|
|
*
|
|
|
|
* Returns: (transfer full): the new `GdkContentFormats`.
|
|
|
|
*/
|
2017-11-18 01:19:53 +00:00
|
|
|
GdkContentFormats *
|
|
|
|
gdk_content_formats_new (const char **mime_types,
|
|
|
|
guint n_mime_types)
|
2017-11-17 16:31:59 +00:00
|
|
|
{
|
2017-11-20 03:42:43 +00:00
|
|
|
guint i;
|
2018-02-24 07:40:41 +00:00
|
|
|
const char **mime_types_copy;
|
2017-11-17 16:31:59 +00:00
|
|
|
|
2017-11-20 03:42:43 +00:00
|
|
|
if (n_mime_types == 0)
|
2017-11-20 14:58:17 +00:00
|
|
|
return gdk_content_formats_new_take (NULL, 0, NULL, 0);
|
2017-11-20 03:42:43 +00:00
|
|
|
|
2018-02-24 07:40:41 +00:00
|
|
|
mime_types_copy = g_new (const char *, n_mime_types + 1);
|
|
|
|
|
2017-11-20 03:42:43 +00:00
|
|
|
for (i = 0; i < n_mime_types; i++)
|
2018-02-24 07:40:41 +00:00
|
|
|
mime_types_copy[i] = g_intern_string (mime_types[i]);
|
|
|
|
|
|
|
|
mime_types_copy[n_mime_types] = NULL;
|
2017-11-20 03:42:43 +00:00
|
|
|
|
2018-02-24 07:40:41 +00:00
|
|
|
return gdk_content_formats_new_take (NULL, 0, mime_types_copy, n_mime_types);
|
2017-11-17 16:31:59 +00:00
|
|
|
}
|
|
|
|
|
2017-11-28 01:02:06 +00:00
|
|
|
/**
|
|
|
|
* gdk_content_formats_new_for_gtype:
|
2021-02-21 05:13:57 +00:00
|
|
|
* @type: a `GType`
|
2017-11-28 01:02:06 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* Creates a new `GdkContentFormats` for a given `GType`.
|
2017-11-28 01:02:06 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* Returns: a new `GdkContentFormats`
|
|
|
|
*/
|
2017-11-28 01:02:06 +00:00
|
|
|
GdkContentFormats *
|
|
|
|
gdk_content_formats_new_for_gtype (GType type)
|
|
|
|
{
|
|
|
|
GType *data;
|
|
|
|
|
|
|
|
g_return_val_if_fail (type != G_TYPE_INVALID, NULL);
|
|
|
|
|
|
|
|
data = g_new (GType, 2);
|
|
|
|
data[0] = type;
|
|
|
|
data[1] = G_TYPE_INVALID;
|
|
|
|
|
|
|
|
return gdk_content_formats_new_take (data, 1, NULL, 0);
|
|
|
|
}
|
|
|
|
|
2021-07-26 00:33:31 +00:00
|
|
|
/**
|
|
|
|
* gdk_content_formats_parse:
|
|
|
|
* @string: the string to parse
|
|
|
|
*
|
|
|
|
* Parses the given @string into `GdkContentFormats` and
|
|
|
|
* returns the formats.
|
|
|
|
*
|
|
|
|
* Strings printed via [method@Gdk.ContentFormats.to_string]
|
|
|
|
* can be read in again successfully using this function.
|
|
|
|
*
|
|
|
|
* If @string does not describe valid content formats, %NULL
|
|
|
|
* is returned.
|
|
|
|
*
|
|
|
|
* Returns: (nullable): the content formats if @string is valid
|
|
|
|
*
|
|
|
|
* Since: 4.4
|
|
|
|
*/
|
|
|
|
GdkContentFormats *
|
|
|
|
gdk_content_formats_parse (const char *string)
|
|
|
|
{
|
|
|
|
GdkContentFormatsBuilder *builder;
|
|
|
|
char **split;
|
|
|
|
gsize i;
|
|
|
|
|
|
|
|
g_return_val_if_fail (string != NULL, NULL);
|
|
|
|
|
|
|
|
split = g_strsplit_set (string, "\t\n\f\r ", -1); /* same as g_ascii_isspace() */
|
|
|
|
builder = gdk_content_formats_builder_new ();
|
|
|
|
|
|
|
|
/* first the GTypes */
|
|
|
|
for (i = 0; split[i] != NULL; i++)
|
|
|
|
{
|
|
|
|
GType type;
|
|
|
|
|
|
|
|
if (split[i][0] == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
type = g_type_from_name (split[i]);
|
|
|
|
if (type != 0)
|
|
|
|
gdk_content_formats_builder_add_gtype (builder, type);
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* then the mime types */
|
|
|
|
for (; split[i] != NULL; i++)
|
|
|
|
{
|
|
|
|
const char *mime_type;
|
|
|
|
|
|
|
|
if (split[i][0] == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
mime_type = gdk_intern_mime_type (split[i]);
|
|
|
|
if (mime_type)
|
|
|
|
gdk_content_formats_builder_add_mime_type (builder, mime_type);
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (split[i] != NULL)
|
|
|
|
{
|
|
|
|
g_strfreev (split);
|
|
|
|
gdk_content_formats_builder_unref (builder);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_strfreev (split);
|
|
|
|
return gdk_content_formats_builder_free_to_formats (builder);
|
|
|
|
}
|
|
|
|
|
2017-11-17 16:31:59 +00:00
|
|
|
/**
|
2017-11-18 01:19:53 +00:00
|
|
|
* gdk_content_formats_ref:
|
2021-02-21 05:13:57 +00:00
|
|
|
* @formats: a `GdkContentFormats`
|
2017-11-17 16:31:59 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* Increases the reference count of a `GdkContentFormats` by one.
|
|
|
|
*
|
|
|
|
* Returns: the passed in `GdkContentFormats`.
|
|
|
|
*/
|
2017-11-18 01:19:53 +00:00
|
|
|
GdkContentFormats *
|
|
|
|
gdk_content_formats_ref (GdkContentFormats *formats)
|
2017-11-17 16:31:59 +00:00
|
|
|
{
|
2017-11-18 01:19:53 +00:00
|
|
|
g_return_val_if_fail (formats != NULL, NULL);
|
2017-11-17 16:31:59 +00:00
|
|
|
|
2017-11-18 01:19:53 +00:00
|
|
|
formats->ref_count++;
|
2017-11-17 16:31:59 +00:00
|
|
|
|
2017-11-18 01:19:53 +00:00
|
|
|
return formats;
|
2017-11-17 16:31:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-11-18 01:19:53 +00:00
|
|
|
* gdk_content_formats_unref:
|
2021-02-21 05:13:57 +00:00
|
|
|
* @formats: a `GdkContentFormats`
|
|
|
|
*
|
|
|
|
* Decreases the reference count of a `GdkContentFormats` by one.
|
|
|
|
*
|
2017-11-18 01:19:53 +00:00
|
|
|
* If the resulting reference count is zero, frees the formats.
|
2021-02-21 05:13:57 +00:00
|
|
|
*/
|
|
|
|
void
|
2017-11-18 01:19:53 +00:00
|
|
|
gdk_content_formats_unref (GdkContentFormats *formats)
|
2017-11-17 16:31:59 +00:00
|
|
|
{
|
2017-11-18 01:19:53 +00:00
|
|
|
g_return_if_fail (formats != NULL);
|
|
|
|
g_return_if_fail (formats->ref_count > 0);
|
2017-11-17 16:31:59 +00:00
|
|
|
|
2017-11-18 01:19:53 +00:00
|
|
|
formats->ref_count--;
|
|
|
|
if (formats->ref_count > 0)
|
2017-11-17 16:31:59 +00:00
|
|
|
return;
|
|
|
|
|
2017-11-20 14:58:17 +00:00
|
|
|
g_free (formats->gtypes);
|
2017-11-20 03:42:43 +00:00
|
|
|
g_free (formats->mime_types);
|
2017-11-18 01:19:53 +00:00
|
|
|
g_slice_free (GdkContentFormats, formats);
|
2017-11-17 16:31:59 +00:00
|
|
|
}
|
|
|
|
|
2017-11-18 04:53:25 +00:00
|
|
|
/**
|
|
|
|
* gdk_content_formats_print:
|
2021-02-21 05:13:57 +00:00
|
|
|
* @formats: a `GdkContentFormats`
|
|
|
|
* @string: a `GString` to print into
|
2017-11-18 04:53:25 +00:00
|
|
|
*
|
|
|
|
* Prints the given @formats into a string for human consumption.
|
2021-02-21 05:13:57 +00:00
|
|
|
*
|
2021-07-26 00:33:31 +00:00
|
|
|
* The result of this function can later be parsed with
|
|
|
|
* [func@Gdk.ContentFormats.parse].
|
2021-02-21 05:13:57 +00:00
|
|
|
*/
|
2017-11-18 04:53:25 +00:00
|
|
|
void
|
|
|
|
gdk_content_formats_print (GdkContentFormats *formats,
|
|
|
|
GString *string)
|
|
|
|
{
|
2017-11-20 03:42:43 +00:00
|
|
|
gsize i;
|
2017-11-18 04:53:25 +00:00
|
|
|
|
|
|
|
g_return_if_fail (formats != NULL);
|
|
|
|
g_return_if_fail (string != NULL);
|
|
|
|
|
2017-11-20 14:58:17 +00:00
|
|
|
for (i = 0; i < formats->n_gtypes; i++)
|
2017-11-18 04:53:25 +00:00
|
|
|
{
|
2017-11-20 03:42:43 +00:00
|
|
|
if (i > 0)
|
2021-07-26 00:28:49 +00:00
|
|
|
g_string_append (string, " ");
|
2017-11-20 14:58:17 +00:00
|
|
|
g_string_append (string, g_type_name (formats->gtypes[i]));
|
|
|
|
}
|
|
|
|
for (i = 0; i < formats->n_mime_types; i++)
|
|
|
|
{
|
|
|
|
if (i > 0 || formats->n_gtypes > 0)
|
2021-07-26 00:28:49 +00:00
|
|
|
g_string_append (string, " ");
|
2017-11-20 03:42:43 +00:00
|
|
|
g_string_append (string, formats->mime_types[i]);
|
2017-11-18 04:53:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gdk_content_formats_to_string:
|
2021-02-21 05:13:57 +00:00
|
|
|
* @formats: a `GdkContentFormats`
|
2017-11-18 04:53:25 +00:00
|
|
|
*
|
|
|
|
* Prints the given @formats into a human-readable string.
|
2021-02-21 05:13:57 +00:00
|
|
|
*
|
2021-07-26 00:33:31 +00:00
|
|
|
* The resulting string can be parsed with [func@Gdk.ContentFormats.parse].
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* This is a small wrapper around [method@Gdk.ContentFormats.print]
|
|
|
|
* to help when debugging.
|
2017-11-18 04:53:25 +00:00
|
|
|
*
|
|
|
|
* Returns: (transfer full): a new string
|
2021-02-21 05:13:57 +00:00
|
|
|
*/
|
2017-11-18 04:53:25 +00:00
|
|
|
char *
|
|
|
|
gdk_content_formats_to_string (GdkContentFormats *formats)
|
|
|
|
{
|
|
|
|
GString *string;
|
|
|
|
|
|
|
|
g_return_val_if_fail (formats != NULL, NULL);
|
|
|
|
|
|
|
|
string = g_string_new (NULL);
|
|
|
|
gdk_content_formats_print (formats, string);
|
|
|
|
|
|
|
|
return g_string_free (string, FALSE);
|
|
|
|
}
|
|
|
|
|
2017-11-17 16:31:59 +00:00
|
|
|
/**
|
2017-11-18 01:19:53 +00:00
|
|
|
* gdk_content_formats_union:
|
2021-02-21 05:13:57 +00:00
|
|
|
* @first: (transfer full): the `GdkContentFormats` to merge into
|
|
|
|
* @second: (transfer none): the `GdkContentFormats` to merge from
|
2017-11-17 16:31:59 +00:00
|
|
|
*
|
2017-11-18 01:19:53 +00:00
|
|
|
* Append all missing types from @second to @first, in the order
|
|
|
|
* they had in @second.
|
2017-11-20 02:54:42 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* Returns: a new `GdkContentFormats`
|
2017-11-17 16:31:59 +00:00
|
|
|
*/
|
2017-11-20 02:54:42 +00:00
|
|
|
GdkContentFormats *
|
2017-11-18 01:19:53 +00:00
|
|
|
gdk_content_formats_union (GdkContentFormats *first,
|
|
|
|
const GdkContentFormats *second)
|
2017-11-17 16:31:59 +00:00
|
|
|
{
|
2017-11-20 02:54:42 +00:00
|
|
|
GdkContentFormatsBuilder *builder;
|
2017-11-17 16:31:59 +00:00
|
|
|
|
2017-11-20 02:54:42 +00:00
|
|
|
g_return_val_if_fail (first != NULL, NULL);
|
|
|
|
g_return_val_if_fail (second != NULL, NULL);
|
2017-11-17 16:31:59 +00:00
|
|
|
|
2017-11-20 02:54:42 +00:00
|
|
|
builder = gdk_content_formats_builder_new ();
|
|
|
|
|
|
|
|
gdk_content_formats_builder_add_formats (builder, first);
|
|
|
|
gdk_content_formats_unref (first);
|
|
|
|
gdk_content_formats_builder_add_formats (builder, second);
|
|
|
|
|
Allow binding GdkContentFormatsBuilder
GdkContentFormatsBuilder is currently not introspectable, as it does not
have a GType. We can turn it into a boxed type, but we need to implement
memory management for it.
The current gdk_content_formats_builder_free() function returns a newly
constructed value, so we cannot use it as a GBoxedFreeFunc; additionally
copying a GdkContentFormatsBuilder contents would make it a bit odd, as
you could get multiple identical GdkContentFormats out of the copies.
A simple approach is to model the GdkContentFormatsBuilder API to follow
the GBytes one: use reference counting for memory management, and have
a function to release a reference, return a GdkContentFormats, and reset
the GdkContentFormatsBuilder state.
For language bindings, we can provide a get_formats() function that
returns the GdkContentFormats instance and resets the builder instance,
leaving the reference count untouched.
For C convenience we can keep gdk_content_formats_builder_free(), and
make it a wrapper around gdk_content_formats_builder_get_formats(), with
the guarantee that it'll free the builder instance regardless of its
current reference count.
https://bugzilla.gnome.org/show_bug.cgi?id=793097
https://blogs.gnome.org/otte/2018/02/03/builders/
2018-02-01 16:43:15 +00:00
|
|
|
return gdk_content_formats_builder_free_to_formats (builder);
|
2017-11-17 16:31:59 +00:00
|
|
|
}
|
|
|
|
|
2017-11-20 03:42:43 +00:00
|
|
|
static gboolean
|
|
|
|
gdk_content_formats_contain_interned_mime_type (const GdkContentFormats *formats,
|
|
|
|
const char *mime_type)
|
|
|
|
{
|
|
|
|
gsize i;
|
|
|
|
|
|
|
|
for (i = 0; i < formats->n_mime_types; i++)
|
|
|
|
{
|
|
|
|
if (mime_type == formats->mime_types[i])
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2017-11-17 16:31:59 +00:00
|
|
|
/**
|
2017-11-20 03:42:43 +00:00
|
|
|
* gdk_content_formats_match:
|
2021-02-21 05:13:57 +00:00
|
|
|
* @first: the primary `GdkContentFormats` to intersect
|
|
|
|
* @second: the `GdkContentFormats` to intersect with
|
2017-11-17 16:31:59 +00:00
|
|
|
*
|
2017-11-24 10:34:19 +00:00
|
|
|
* Checks if @first and @second have any matching formats.
|
2017-11-17 16:31:59 +00:00
|
|
|
*
|
2017-11-20 14:58:17 +00:00
|
|
|
* Returns: %TRUE if a matching format was found.
|
2017-11-17 16:31:59 +00:00
|
|
|
*/
|
2017-11-20 14:58:17 +00:00
|
|
|
gboolean
|
2017-11-20 03:42:43 +00:00
|
|
|
gdk_content_formats_match (const GdkContentFormats *first,
|
2017-11-24 10:34:19 +00:00
|
|
|
const GdkContentFormats *second)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (first != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (second != NULL, FALSE);
|
|
|
|
|
|
|
|
return gdk_content_formats_match_gtype (first, second) != G_TYPE_INVALID
|
|
|
|
|| gdk_content_formats_match_mime_type (first, second) != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gdk_content_formats_match_gtype:
|
2021-02-21 05:13:57 +00:00
|
|
|
* @first: the primary `GdkContentFormats` to intersect
|
|
|
|
* @second: the `GdkContentFormats` to intersect with
|
2017-11-24 10:34:19 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* Finds the first `GType` from @first that is also contained
|
|
|
|
* in @second.
|
2017-11-24 10:34:19 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* If no matching `GType` is found, %G_TYPE_INVALID is returned.
|
|
|
|
*
|
|
|
|
* Returns: The first common `GType` or %G_TYPE_INVALID if none.
|
|
|
|
*/
|
2017-11-24 10:34:19 +00:00
|
|
|
GType
|
|
|
|
gdk_content_formats_match_gtype (const GdkContentFormats *first,
|
|
|
|
const GdkContentFormats *second)
|
2017-11-17 16:31:59 +00:00
|
|
|
{
|
2017-11-20 03:42:43 +00:00
|
|
|
gsize i;
|
2017-11-17 16:31:59 +00:00
|
|
|
|
2017-11-20 14:58:17 +00:00
|
|
|
g_return_val_if_fail (first != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (second != NULL, FALSE);
|
|
|
|
|
|
|
|
for (i = 0; i < first->n_gtypes; i++)
|
|
|
|
{
|
|
|
|
if (gdk_content_formats_contain_gtype (second, first->gtypes[i]))
|
2017-11-24 10:34:19 +00:00
|
|
|
return first->gtypes[i];
|
2017-11-20 14:58:17 +00:00
|
|
|
}
|
2017-11-17 16:31:59 +00:00
|
|
|
|
2017-11-24 10:34:19 +00:00
|
|
|
return G_TYPE_INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gdk_content_formats_match_mime_type:
|
2021-02-21 05:13:57 +00:00
|
|
|
* @first: the primary `GdkContentFormats` to intersect
|
|
|
|
* @second: the `GdkContentFormats` to intersect with
|
2017-11-24 10:34:19 +00:00
|
|
|
*
|
|
|
|
* Finds the first mime type from @first that is also contained
|
2021-02-21 05:13:57 +00:00
|
|
|
* in @second.
|
|
|
|
*
|
|
|
|
* If no matching mime type is found, %NULL is returned.
|
2017-11-24 10:34:19 +00:00
|
|
|
*
|
2021-05-21 00:45:06 +00:00
|
|
|
* Returns: (nullable): The first common mime type or %NULL if none
|
2021-02-21 05:13:57 +00:00
|
|
|
*/
|
2017-11-24 10:34:19 +00:00
|
|
|
const char *
|
|
|
|
gdk_content_formats_match_mime_type (const GdkContentFormats *first,
|
|
|
|
const GdkContentFormats *second)
|
|
|
|
{
|
|
|
|
gsize i;
|
|
|
|
|
|
|
|
g_return_val_if_fail (first != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (second != NULL, FALSE);
|
|
|
|
|
2017-11-20 03:42:43 +00:00
|
|
|
for (i = 0; i < first->n_mime_types; i++)
|
2017-11-17 16:31:59 +00:00
|
|
|
{
|
2017-11-20 03:42:43 +00:00
|
|
|
if (gdk_content_formats_contain_interned_mime_type (second, first->mime_types[i]))
|
2017-11-24 10:34:19 +00:00
|
|
|
return first->mime_types[i];
|
2017-11-20 14:58:17 +00:00
|
|
|
}
|
|
|
|
|
2017-11-24 10:34:19 +00:00
|
|
|
return NULL;
|
2017-11-20 14:58:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gdk_content_formats_contain_gtype:
|
2021-02-21 05:13:57 +00:00
|
|
|
* @formats: a `GdkContentFormats`
|
|
|
|
* @type: the `GType` to search for
|
2017-11-20 14:58:17 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* Checks if a given `GType` is part of the given @formats.
|
2017-11-20 14:58:17 +00:00
|
|
|
*
|
2021-05-20 03:39:18 +00:00
|
|
|
* Returns: %TRUE if the `GType` was found
|
2021-02-21 05:13:57 +00:00
|
|
|
*/
|
2017-11-20 14:58:17 +00:00
|
|
|
gboolean
|
|
|
|
gdk_content_formats_contain_gtype (const GdkContentFormats *formats,
|
|
|
|
GType type)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (formats != NULL, FALSE);
|
|
|
|
|
|
|
|
gsize i;
|
|
|
|
|
|
|
|
for (i = 0; i < formats->n_gtypes; i++)
|
|
|
|
{
|
|
|
|
if (type == formats->gtypes[i])
|
|
|
|
return TRUE;
|
2017-11-17 16:31:59 +00:00
|
|
|
}
|
|
|
|
|
2017-11-20 14:58:17 +00:00
|
|
|
return FALSE;
|
2017-11-17 16:31:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-11-20 03:42:43 +00:00
|
|
|
* gdk_content_formats_contain_mime_type:
|
2021-02-21 05:13:57 +00:00
|
|
|
* @formats: a `GdkContentFormats`
|
2017-11-18 01:19:53 +00:00
|
|
|
* @mime_type: the mime type to search for
|
2017-11-17 16:31:59 +00:00
|
|
|
*
|
2017-11-18 01:19:53 +00:00
|
|
|
* Checks if a given mime type is part of the given @formats.
|
2017-11-17 16:31:59 +00:00
|
|
|
*
|
2017-11-20 14:58:17 +00:00
|
|
|
* Returns: %TRUE if the mime_type was found
|
2021-02-21 05:13:57 +00:00
|
|
|
*/
|
2017-11-17 16:31:59 +00:00
|
|
|
gboolean
|
2017-11-20 03:42:43 +00:00
|
|
|
gdk_content_formats_contain_mime_type (const GdkContentFormats *formats,
|
|
|
|
const char *mime_type)
|
2017-11-17 16:31:59 +00:00
|
|
|
{
|
2017-11-18 01:19:53 +00:00
|
|
|
g_return_val_if_fail (formats != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (mime_type != NULL, FALSE);
|
2017-11-17 16:31:59 +00:00
|
|
|
|
2017-11-20 03:42:43 +00:00
|
|
|
return gdk_content_formats_contain_interned_mime_type (formats,
|
|
|
|
g_intern_string (mime_type));
|
2017-11-17 16:31:59 +00:00
|
|
|
}
|
|
|
|
|
2017-11-20 14:58:17 +00:00
|
|
|
/**
|
|
|
|
* gdk_content_formats_get_gtypes:
|
2021-02-21 05:13:57 +00:00
|
|
|
* @formats: a `GdkContentFormats`
|
2020-03-09 16:34:00 +00:00
|
|
|
* @n_gtypes: (out) (optional): optional pointer to take the
|
2021-05-18 21:05:26 +00:00
|
|
|
* number of `GType`s contained in the return value
|
2017-11-20 14:58:17 +00:00
|
|
|
*
|
2021-05-18 21:05:26 +00:00
|
|
|
* Gets the `GType`s included in @formats.
|
2021-02-21 05:13:57 +00:00
|
|
|
*
|
2021-05-20 03:39:18 +00:00
|
|
|
* Note that @formats may not contain any `GType`s, in particular when
|
2021-02-21 05:13:57 +00:00
|
|
|
* they are empty. In that case %NULL will be returned.
|
2017-11-20 14:58:17 +00:00
|
|
|
*
|
2021-04-30 13:40:27 +00:00
|
|
|
* Returns: (transfer none) (nullable) (array length=n_gtypes zero-terminated=1):
|
2021-05-18 21:05:26 +00:00
|
|
|
* %G_TYPE_INVALID-terminated array of types included in @formats
|
2021-02-21 05:13:57 +00:00
|
|
|
*/
|
2017-11-20 14:58:17 +00:00
|
|
|
const GType *
|
2020-03-02 02:39:14 +00:00
|
|
|
gdk_content_formats_get_gtypes (const GdkContentFormats *formats,
|
|
|
|
gsize *n_gtypes)
|
2017-11-20 14:58:17 +00:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (formats != NULL, NULL);
|
|
|
|
|
|
|
|
if (n_gtypes)
|
|
|
|
*n_gtypes = formats->n_gtypes;
|
|
|
|
|
|
|
|
return formats->gtypes;
|
|
|
|
}
|
|
|
|
|
2017-11-20 03:42:43 +00:00
|
|
|
/**
|
|
|
|
* gdk_content_formats_get_mime_types:
|
2021-02-21 05:13:57 +00:00
|
|
|
* @formats: a `GdkContentFormats`
|
2021-04-30 11:42:02 +00:00
|
|
|
* @n_mime_types: (out) (optional): optional pointer to take the
|
2021-05-18 21:05:26 +00:00
|
|
|
* number of mime types contained in the return value
|
2017-11-20 03:42:43 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* Gets the mime types included in @formats.
|
|
|
|
*
|
|
|
|
* Note that @formats may not contain any mime types, in particular
|
|
|
|
* when they are empty. In that case %NULL will be returned.
|
2017-11-20 03:42:43 +00:00
|
|
|
*
|
2021-05-18 21:05:26 +00:00
|
|
|
* Returns: (transfer none) (nullable) (array length=n_mime_types zero-terminated=1):
|
|
|
|
* %NULL-terminated array of interned strings of mime types included
|
|
|
|
* in @formats
|
2021-02-21 05:13:57 +00:00
|
|
|
*/
|
2017-11-20 03:42:43 +00:00
|
|
|
const char * const *
|
2020-03-02 02:39:14 +00:00
|
|
|
gdk_content_formats_get_mime_types (const GdkContentFormats *formats,
|
|
|
|
gsize *n_mime_types)
|
2017-11-17 16:31:59 +00:00
|
|
|
{
|
2017-11-20 03:42:43 +00:00
|
|
|
g_return_val_if_fail (formats != NULL, NULL);
|
2017-11-17 16:31:59 +00:00
|
|
|
|
2017-11-20 03:42:43 +00:00
|
|
|
if (n_mime_types)
|
|
|
|
*n_mime_types = formats->n_mime_types;
|
|
|
|
|
|
|
|
return formats->mime_types;
|
2017-11-17 16:31:59 +00:00
|
|
|
}
|
|
|
|
|
2017-11-20 01:47:45 +00:00
|
|
|
/**
|
|
|
|
* GdkContentFormatsBuilder:
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* A `GdkContentFormatsBuilder` is an auxiliary struct used to create
|
|
|
|
* new `GdkContentFormats`, and should not be kept around.
|
2017-11-20 01:47:45 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
struct _GdkContentFormatsBuilder
|
|
|
|
{
|
Allow binding GdkContentFormatsBuilder
GdkContentFormatsBuilder is currently not introspectable, as it does not
have a GType. We can turn it into a boxed type, but we need to implement
memory management for it.
The current gdk_content_formats_builder_free() function returns a newly
constructed value, so we cannot use it as a GBoxedFreeFunc; additionally
copying a GdkContentFormatsBuilder contents would make it a bit odd, as
you could get multiple identical GdkContentFormats out of the copies.
A simple approach is to model the GdkContentFormatsBuilder API to follow
the GBytes one: use reference counting for memory management, and have
a function to release a reference, return a GdkContentFormats, and reset
the GdkContentFormatsBuilder state.
For language bindings, we can provide a get_formats() function that
returns the GdkContentFormats instance and resets the builder instance,
leaving the reference count untouched.
For C convenience we can keep gdk_content_formats_builder_free(), and
make it a wrapper around gdk_content_formats_builder_get_formats(), with
the guarantee that it'll free the builder instance regardless of its
current reference count.
https://bugzilla.gnome.org/show_bug.cgi?id=793097
https://blogs.gnome.org/otte/2018/02/03/builders/
2018-02-01 16:43:15 +00:00
|
|
|
int ref_count;
|
|
|
|
|
|
|
|
/* (element-type GType) */
|
2017-11-20 14:58:17 +00:00
|
|
|
GSList *gtypes;
|
|
|
|
gsize n_gtypes;
|
Allow binding GdkContentFormatsBuilder
GdkContentFormatsBuilder is currently not introspectable, as it does not
have a GType. We can turn it into a boxed type, but we need to implement
memory management for it.
The current gdk_content_formats_builder_free() function returns a newly
constructed value, so we cannot use it as a GBoxedFreeFunc; additionally
copying a GdkContentFormatsBuilder contents would make it a bit odd, as
you could get multiple identical GdkContentFormats out of the copies.
A simple approach is to model the GdkContentFormatsBuilder API to follow
the GBytes one: use reference counting for memory management, and have
a function to release a reference, return a GdkContentFormats, and reset
the GdkContentFormatsBuilder state.
For language bindings, we can provide a get_formats() function that
returns the GdkContentFormats instance and resets the builder instance,
leaving the reference count untouched.
For C convenience we can keep gdk_content_formats_builder_free(), and
make it a wrapper around gdk_content_formats_builder_get_formats(), with
the guarantee that it'll free the builder instance regardless of its
current reference count.
https://bugzilla.gnome.org/show_bug.cgi?id=793097
https://blogs.gnome.org/otte/2018/02/03/builders/
2018-02-01 16:43:15 +00:00
|
|
|
|
|
|
|
/* (element-type utf8) (interned) */
|
2017-11-20 01:47:45 +00:00
|
|
|
GSList *mime_types;
|
|
|
|
gsize n_mime_types;
|
|
|
|
};
|
|
|
|
|
Allow binding GdkContentFormatsBuilder
GdkContentFormatsBuilder is currently not introspectable, as it does not
have a GType. We can turn it into a boxed type, but we need to implement
memory management for it.
The current gdk_content_formats_builder_free() function returns a newly
constructed value, so we cannot use it as a GBoxedFreeFunc; additionally
copying a GdkContentFormatsBuilder contents would make it a bit odd, as
you could get multiple identical GdkContentFormats out of the copies.
A simple approach is to model the GdkContentFormatsBuilder API to follow
the GBytes one: use reference counting for memory management, and have
a function to release a reference, return a GdkContentFormats, and reset
the GdkContentFormatsBuilder state.
For language bindings, we can provide a get_formats() function that
returns the GdkContentFormats instance and resets the builder instance,
leaving the reference count untouched.
For C convenience we can keep gdk_content_formats_builder_free(), and
make it a wrapper around gdk_content_formats_builder_get_formats(), with
the guarantee that it'll free the builder instance regardless of its
current reference count.
https://bugzilla.gnome.org/show_bug.cgi?id=793097
https://blogs.gnome.org/otte/2018/02/03/builders/
2018-02-01 16:43:15 +00:00
|
|
|
G_DEFINE_BOXED_TYPE (GdkContentFormatsBuilder,
|
|
|
|
gdk_content_formats_builder,
|
|
|
|
gdk_content_formats_builder_ref,
|
|
|
|
gdk_content_formats_builder_unref)
|
|
|
|
|
2017-11-20 01:47:45 +00:00
|
|
|
/**
|
|
|
|
* gdk_content_formats_builder_new:
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* Create a new `GdkContentFormatsBuilder` object.
|
2017-11-20 01:47:45 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* The resulting builder would create an empty `GdkContentFormats`.
|
|
|
|
* Use addition functions to add types to it.
|
|
|
|
*
|
|
|
|
* Returns: a new `GdkContentFormatsBuilder`
|
|
|
|
*/
|
2017-11-20 01:47:45 +00:00
|
|
|
GdkContentFormatsBuilder *
|
|
|
|
gdk_content_formats_builder_new (void)
|
|
|
|
{
|
Allow binding GdkContentFormatsBuilder
GdkContentFormatsBuilder is currently not introspectable, as it does not
have a GType. We can turn it into a boxed type, but we need to implement
memory management for it.
The current gdk_content_formats_builder_free() function returns a newly
constructed value, so we cannot use it as a GBoxedFreeFunc; additionally
copying a GdkContentFormatsBuilder contents would make it a bit odd, as
you could get multiple identical GdkContentFormats out of the copies.
A simple approach is to model the GdkContentFormatsBuilder API to follow
the GBytes one: use reference counting for memory management, and have
a function to release a reference, return a GdkContentFormats, and reset
the GdkContentFormatsBuilder state.
For language bindings, we can provide a get_formats() function that
returns the GdkContentFormats instance and resets the builder instance,
leaving the reference count untouched.
For C convenience we can keep gdk_content_formats_builder_free(), and
make it a wrapper around gdk_content_formats_builder_get_formats(), with
the guarantee that it'll free the builder instance regardless of its
current reference count.
https://bugzilla.gnome.org/show_bug.cgi?id=793097
https://blogs.gnome.org/otte/2018/02/03/builders/
2018-02-01 16:43:15 +00:00
|
|
|
GdkContentFormatsBuilder *builder;
|
|
|
|
|
|
|
|
builder = g_slice_new0 (GdkContentFormatsBuilder);
|
|
|
|
builder->ref_count = 1;
|
|
|
|
|
|
|
|
return builder;
|
2017-11-20 01:47:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
Allow binding GdkContentFormatsBuilder
GdkContentFormatsBuilder is currently not introspectable, as it does not
have a GType. We can turn it into a boxed type, but we need to implement
memory management for it.
The current gdk_content_formats_builder_free() function returns a newly
constructed value, so we cannot use it as a GBoxedFreeFunc; additionally
copying a GdkContentFormatsBuilder contents would make it a bit odd, as
you could get multiple identical GdkContentFormats out of the copies.
A simple approach is to model the GdkContentFormatsBuilder API to follow
the GBytes one: use reference counting for memory management, and have
a function to release a reference, return a GdkContentFormats, and reset
the GdkContentFormatsBuilder state.
For language bindings, we can provide a get_formats() function that
returns the GdkContentFormats instance and resets the builder instance,
leaving the reference count untouched.
For C convenience we can keep gdk_content_formats_builder_free(), and
make it a wrapper around gdk_content_formats_builder_get_formats(), with
the guarantee that it'll free the builder instance regardless of its
current reference count.
https://bugzilla.gnome.org/show_bug.cgi?id=793097
https://blogs.gnome.org/otte/2018/02/03/builders/
2018-02-01 16:43:15 +00:00
|
|
|
* gdk_content_formats_builder_ref:
|
2021-02-21 05:13:57 +00:00
|
|
|
* @builder: a `GdkContentFormatsBuilder`
|
2017-11-20 01:47:45 +00:00
|
|
|
*
|
Allow binding GdkContentFormatsBuilder
GdkContentFormatsBuilder is currently not introspectable, as it does not
have a GType. We can turn it into a boxed type, but we need to implement
memory management for it.
The current gdk_content_formats_builder_free() function returns a newly
constructed value, so we cannot use it as a GBoxedFreeFunc; additionally
copying a GdkContentFormatsBuilder contents would make it a bit odd, as
you could get multiple identical GdkContentFormats out of the copies.
A simple approach is to model the GdkContentFormatsBuilder API to follow
the GBytes one: use reference counting for memory management, and have
a function to release a reference, return a GdkContentFormats, and reset
the GdkContentFormatsBuilder state.
For language bindings, we can provide a get_formats() function that
returns the GdkContentFormats instance and resets the builder instance,
leaving the reference count untouched.
For C convenience we can keep gdk_content_formats_builder_free(), and
make it a wrapper around gdk_content_formats_builder_get_formats(), with
the guarantee that it'll free the builder instance regardless of its
current reference count.
https://bugzilla.gnome.org/show_bug.cgi?id=793097
https://blogs.gnome.org/otte/2018/02/03/builders/
2018-02-01 16:43:15 +00:00
|
|
|
* Acquires a reference on the given @builder.
|
2017-11-20 01:47:45 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* This function is intended primarily for bindings.
|
|
|
|
* `GdkContentFormatsBuilder` objects should not be kept around.
|
Allow binding GdkContentFormatsBuilder
GdkContentFormatsBuilder is currently not introspectable, as it does not
have a GType. We can turn it into a boxed type, but we need to implement
memory management for it.
The current gdk_content_formats_builder_free() function returns a newly
constructed value, so we cannot use it as a GBoxedFreeFunc; additionally
copying a GdkContentFormatsBuilder contents would make it a bit odd, as
you could get multiple identical GdkContentFormats out of the copies.
A simple approach is to model the GdkContentFormatsBuilder API to follow
the GBytes one: use reference counting for memory management, and have
a function to release a reference, return a GdkContentFormats, and reset
the GdkContentFormatsBuilder state.
For language bindings, we can provide a get_formats() function that
returns the GdkContentFormats instance and resets the builder instance,
leaving the reference count untouched.
For C convenience we can keep gdk_content_formats_builder_free(), and
make it a wrapper around gdk_content_formats_builder_get_formats(), with
the guarantee that it'll free the builder instance regardless of its
current reference count.
https://bugzilla.gnome.org/show_bug.cgi?id=793097
https://blogs.gnome.org/otte/2018/02/03/builders/
2018-02-01 16:43:15 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* Returns: (transfer none): the given `GdkContentFormatsBuilder`
|
|
|
|
* with its reference count increased
|
Allow binding GdkContentFormatsBuilder
GdkContentFormatsBuilder is currently not introspectable, as it does not
have a GType. We can turn it into a boxed type, but we need to implement
memory management for it.
The current gdk_content_formats_builder_free() function returns a newly
constructed value, so we cannot use it as a GBoxedFreeFunc; additionally
copying a GdkContentFormatsBuilder contents would make it a bit odd, as
you could get multiple identical GdkContentFormats out of the copies.
A simple approach is to model the GdkContentFormatsBuilder API to follow
the GBytes one: use reference counting for memory management, and have
a function to release a reference, return a GdkContentFormats, and reset
the GdkContentFormatsBuilder state.
For language bindings, we can provide a get_formats() function that
returns the GdkContentFormats instance and resets the builder instance,
leaving the reference count untouched.
For C convenience we can keep gdk_content_formats_builder_free(), and
make it a wrapper around gdk_content_formats_builder_get_formats(), with
the guarantee that it'll free the builder instance regardless of its
current reference count.
https://bugzilla.gnome.org/show_bug.cgi?id=793097
https://blogs.gnome.org/otte/2018/02/03/builders/
2018-02-01 16:43:15 +00:00
|
|
|
*/
|
|
|
|
GdkContentFormatsBuilder *
|
|
|
|
gdk_content_formats_builder_ref (GdkContentFormatsBuilder *builder)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (builder != NULL, NULL);
|
|
|
|
g_return_val_if_fail (builder->ref_count > 0, NULL);
|
|
|
|
|
|
|
|
builder->ref_count += 1;
|
|
|
|
|
|
|
|
return builder;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gdk_content_formats_builder_clear (GdkContentFormatsBuilder *builder)
|
|
|
|
{
|
|
|
|
g_clear_pointer (&builder->gtypes, g_slist_free);
|
|
|
|
g_clear_pointer (&builder->mime_types, g_slist_free);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gdk_content_formats_builder_unref:
|
2021-02-21 05:13:57 +00:00
|
|
|
* @builder: a `GdkContentFormatsBuilder`
|
Allow binding GdkContentFormatsBuilder
GdkContentFormatsBuilder is currently not introspectable, as it does not
have a GType. We can turn it into a boxed type, but we need to implement
memory management for it.
The current gdk_content_formats_builder_free() function returns a newly
constructed value, so we cannot use it as a GBoxedFreeFunc; additionally
copying a GdkContentFormatsBuilder contents would make it a bit odd, as
you could get multiple identical GdkContentFormats out of the copies.
A simple approach is to model the GdkContentFormatsBuilder API to follow
the GBytes one: use reference counting for memory management, and have
a function to release a reference, return a GdkContentFormats, and reset
the GdkContentFormatsBuilder state.
For language bindings, we can provide a get_formats() function that
returns the GdkContentFormats instance and resets the builder instance,
leaving the reference count untouched.
For C convenience we can keep gdk_content_formats_builder_free(), and
make it a wrapper around gdk_content_formats_builder_get_formats(), with
the guarantee that it'll free the builder instance regardless of its
current reference count.
https://bugzilla.gnome.org/show_bug.cgi?id=793097
https://blogs.gnome.org/otte/2018/02/03/builders/
2018-02-01 16:43:15 +00:00
|
|
|
*
|
|
|
|
* Releases a reference on the given @builder.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gdk_content_formats_builder_unref (GdkContentFormatsBuilder *builder)
|
|
|
|
{
|
|
|
|
g_return_if_fail (builder != NULL);
|
|
|
|
g_return_if_fail (builder->ref_count > 0);
|
|
|
|
|
|
|
|
builder->ref_count -= 1;
|
|
|
|
|
|
|
|
if (builder->ref_count > 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gdk_content_formats_builder_clear (builder);
|
|
|
|
g_slice_free (GdkContentFormatsBuilder, builder);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gdk_content_formats_builder_free_to_formats: (skip)
|
2021-02-21 05:13:57 +00:00
|
|
|
* @builder: a `GdkContentFormatsBuilder`
|
Allow binding GdkContentFormatsBuilder
GdkContentFormatsBuilder is currently not introspectable, as it does not
have a GType. We can turn it into a boxed type, but we need to implement
memory management for it.
The current gdk_content_formats_builder_free() function returns a newly
constructed value, so we cannot use it as a GBoxedFreeFunc; additionally
copying a GdkContentFormatsBuilder contents would make it a bit odd, as
you could get multiple identical GdkContentFormats out of the copies.
A simple approach is to model the GdkContentFormatsBuilder API to follow
the GBytes one: use reference counting for memory management, and have
a function to release a reference, return a GdkContentFormats, and reset
the GdkContentFormatsBuilder state.
For language bindings, we can provide a get_formats() function that
returns the GdkContentFormats instance and resets the builder instance,
leaving the reference count untouched.
For C convenience we can keep gdk_content_formats_builder_free(), and
make it a wrapper around gdk_content_formats_builder_get_formats(), with
the guarantee that it'll free the builder instance regardless of its
current reference count.
https://bugzilla.gnome.org/show_bug.cgi?id=793097
https://blogs.gnome.org/otte/2018/02/03/builders/
2018-02-01 16:43:15 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* Creates a new `GdkContentFormats` from the current state of the
|
Allow binding GdkContentFormatsBuilder
GdkContentFormatsBuilder is currently not introspectable, as it does not
have a GType. We can turn it into a boxed type, but we need to implement
memory management for it.
The current gdk_content_formats_builder_free() function returns a newly
constructed value, so we cannot use it as a GBoxedFreeFunc; additionally
copying a GdkContentFormatsBuilder contents would make it a bit odd, as
you could get multiple identical GdkContentFormats out of the copies.
A simple approach is to model the GdkContentFormatsBuilder API to follow
the GBytes one: use reference counting for memory management, and have
a function to release a reference, return a GdkContentFormats, and reset
the GdkContentFormatsBuilder state.
For language bindings, we can provide a get_formats() function that
returns the GdkContentFormats instance and resets the builder instance,
leaving the reference count untouched.
For C convenience we can keep gdk_content_formats_builder_free(), and
make it a wrapper around gdk_content_formats_builder_get_formats(), with
the guarantee that it'll free the builder instance regardless of its
current reference count.
https://bugzilla.gnome.org/show_bug.cgi?id=793097
https://blogs.gnome.org/otte/2018/02/03/builders/
2018-02-01 16:43:15 +00:00
|
|
|
* given @builder, and frees the @builder instance.
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* Returns: (transfer full): the newly created `GdkContentFormats`
|
Allow binding GdkContentFormatsBuilder
GdkContentFormatsBuilder is currently not introspectable, as it does not
have a GType. We can turn it into a boxed type, but we need to implement
memory management for it.
The current gdk_content_formats_builder_free() function returns a newly
constructed value, so we cannot use it as a GBoxedFreeFunc; additionally
copying a GdkContentFormatsBuilder contents would make it a bit odd, as
you could get multiple identical GdkContentFormats out of the copies.
A simple approach is to model the GdkContentFormatsBuilder API to follow
the GBytes one: use reference counting for memory management, and have
a function to release a reference, return a GdkContentFormats, and reset
the GdkContentFormatsBuilder state.
For language bindings, we can provide a get_formats() function that
returns the GdkContentFormats instance and resets the builder instance,
leaving the reference count untouched.
For C convenience we can keep gdk_content_formats_builder_free(), and
make it a wrapper around gdk_content_formats_builder_get_formats(), with
the guarantee that it'll free the builder instance regardless of its
current reference count.
https://bugzilla.gnome.org/show_bug.cgi?id=793097
https://blogs.gnome.org/otte/2018/02/03/builders/
2018-02-01 16:43:15 +00:00
|
|
|
* with all the formats added to @builder
|
|
|
|
*/
|
2017-11-20 01:47:45 +00:00
|
|
|
GdkContentFormats *
|
Allow binding GdkContentFormatsBuilder
GdkContentFormatsBuilder is currently not introspectable, as it does not
have a GType. We can turn it into a boxed type, but we need to implement
memory management for it.
The current gdk_content_formats_builder_free() function returns a newly
constructed value, so we cannot use it as a GBoxedFreeFunc; additionally
copying a GdkContentFormatsBuilder contents would make it a bit odd, as
you could get multiple identical GdkContentFormats out of the copies.
A simple approach is to model the GdkContentFormatsBuilder API to follow
the GBytes one: use reference counting for memory management, and have
a function to release a reference, return a GdkContentFormats, and reset
the GdkContentFormatsBuilder state.
For language bindings, we can provide a get_formats() function that
returns the GdkContentFormats instance and resets the builder instance,
leaving the reference count untouched.
For C convenience we can keep gdk_content_formats_builder_free(), and
make it a wrapper around gdk_content_formats_builder_get_formats(), with
the guarantee that it'll free the builder instance regardless of its
current reference count.
https://bugzilla.gnome.org/show_bug.cgi?id=793097
https://blogs.gnome.org/otte/2018/02/03/builders/
2018-02-01 16:43:15 +00:00
|
|
|
gdk_content_formats_builder_free_to_formats (GdkContentFormatsBuilder *builder)
|
|
|
|
{
|
|
|
|
GdkContentFormats *res;
|
|
|
|
|
|
|
|
g_return_val_if_fail (builder != NULL, NULL);
|
|
|
|
|
|
|
|
res = gdk_content_formats_builder_to_formats (builder);
|
|
|
|
|
|
|
|
gdk_content_formats_builder_unref (builder);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gdk_content_formats_builder_to_formats:
|
2021-02-21 05:13:57 +00:00
|
|
|
* @builder: a `GdkContentFormats`Builder
|
Allow binding GdkContentFormatsBuilder
GdkContentFormatsBuilder is currently not introspectable, as it does not
have a GType. We can turn it into a boxed type, but we need to implement
memory management for it.
The current gdk_content_formats_builder_free() function returns a newly
constructed value, so we cannot use it as a GBoxedFreeFunc; additionally
copying a GdkContentFormatsBuilder contents would make it a bit odd, as
you could get multiple identical GdkContentFormats out of the copies.
A simple approach is to model the GdkContentFormatsBuilder API to follow
the GBytes one: use reference counting for memory management, and have
a function to release a reference, return a GdkContentFormats, and reset
the GdkContentFormatsBuilder state.
For language bindings, we can provide a get_formats() function that
returns the GdkContentFormats instance and resets the builder instance,
leaving the reference count untouched.
For C convenience we can keep gdk_content_formats_builder_free(), and
make it a wrapper around gdk_content_formats_builder_get_formats(), with
the guarantee that it'll free the builder instance regardless of its
current reference count.
https://bugzilla.gnome.org/show_bug.cgi?id=793097
https://blogs.gnome.org/otte/2018/02/03/builders/
2018-02-01 16:43:15 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* Creates a new `GdkContentFormats` from the given @builder.
|
Allow binding GdkContentFormatsBuilder
GdkContentFormatsBuilder is currently not introspectable, as it does not
have a GType. We can turn it into a boxed type, but we need to implement
memory management for it.
The current gdk_content_formats_builder_free() function returns a newly
constructed value, so we cannot use it as a GBoxedFreeFunc; additionally
copying a GdkContentFormatsBuilder contents would make it a bit odd, as
you could get multiple identical GdkContentFormats out of the copies.
A simple approach is to model the GdkContentFormatsBuilder API to follow
the GBytes one: use reference counting for memory management, and have
a function to release a reference, return a GdkContentFormats, and reset
the GdkContentFormatsBuilder state.
For language bindings, we can provide a get_formats() function that
returns the GdkContentFormats instance and resets the builder instance,
leaving the reference count untouched.
For C convenience we can keep gdk_content_formats_builder_free(), and
make it a wrapper around gdk_content_formats_builder_get_formats(), with
the guarantee that it'll free the builder instance regardless of its
current reference count.
https://bugzilla.gnome.org/show_bug.cgi?id=793097
https://blogs.gnome.org/otte/2018/02/03/builders/
2018-02-01 16:43:15 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* The given `GdkContentFormatsBuilder` is reset once this function returns;
|
Allow binding GdkContentFormatsBuilder
GdkContentFormatsBuilder is currently not introspectable, as it does not
have a GType. We can turn it into a boxed type, but we need to implement
memory management for it.
The current gdk_content_formats_builder_free() function returns a newly
constructed value, so we cannot use it as a GBoxedFreeFunc; additionally
copying a GdkContentFormatsBuilder contents would make it a bit odd, as
you could get multiple identical GdkContentFormats out of the copies.
A simple approach is to model the GdkContentFormatsBuilder API to follow
the GBytes one: use reference counting for memory management, and have
a function to release a reference, return a GdkContentFormats, and reset
the GdkContentFormatsBuilder state.
For language bindings, we can provide a get_formats() function that
returns the GdkContentFormats instance and resets the builder instance,
leaving the reference count untouched.
For C convenience we can keep gdk_content_formats_builder_free(), and
make it a wrapper around gdk_content_formats_builder_get_formats(), with
the guarantee that it'll free the builder instance regardless of its
current reference count.
https://bugzilla.gnome.org/show_bug.cgi?id=793097
https://blogs.gnome.org/otte/2018/02/03/builders/
2018-02-01 16:43:15 +00:00
|
|
|
* you cannot call this function multiple times on the same @builder instance.
|
|
|
|
*
|
|
|
|
* This function is intended primarily for bindings. C code should use
|
2021-02-21 05:13:57 +00:00
|
|
|
* [method@Gdk.ContentFormatsBuilder.free_to_formats].
|
Allow binding GdkContentFormatsBuilder
GdkContentFormatsBuilder is currently not introspectable, as it does not
have a GType. We can turn it into a boxed type, but we need to implement
memory management for it.
The current gdk_content_formats_builder_free() function returns a newly
constructed value, so we cannot use it as a GBoxedFreeFunc; additionally
copying a GdkContentFormatsBuilder contents would make it a bit odd, as
you could get multiple identical GdkContentFormats out of the copies.
A simple approach is to model the GdkContentFormatsBuilder API to follow
the GBytes one: use reference counting for memory management, and have
a function to release a reference, return a GdkContentFormats, and reset
the GdkContentFormatsBuilder state.
For language bindings, we can provide a get_formats() function that
returns the GdkContentFormats instance and resets the builder instance,
leaving the reference count untouched.
For C convenience we can keep gdk_content_formats_builder_free(), and
make it a wrapper around gdk_content_formats_builder_get_formats(), with
the guarantee that it'll free the builder instance regardless of its
current reference count.
https://bugzilla.gnome.org/show_bug.cgi?id=793097
https://blogs.gnome.org/otte/2018/02/03/builders/
2018-02-01 16:43:15 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* Returns: (transfer full): the newly created `GdkContentFormats`
|
Allow binding GdkContentFormatsBuilder
GdkContentFormatsBuilder is currently not introspectable, as it does not
have a GType. We can turn it into a boxed type, but we need to implement
memory management for it.
The current gdk_content_formats_builder_free() function returns a newly
constructed value, so we cannot use it as a GBoxedFreeFunc; additionally
copying a GdkContentFormatsBuilder contents would make it a bit odd, as
you could get multiple identical GdkContentFormats out of the copies.
A simple approach is to model the GdkContentFormatsBuilder API to follow
the GBytes one: use reference counting for memory management, and have
a function to release a reference, return a GdkContentFormats, and reset
the GdkContentFormatsBuilder state.
For language bindings, we can provide a get_formats() function that
returns the GdkContentFormats instance and resets the builder instance,
leaving the reference count untouched.
For C convenience we can keep gdk_content_formats_builder_free(), and
make it a wrapper around gdk_content_formats_builder_get_formats(), with
the guarantee that it'll free the builder instance regardless of its
current reference count.
https://bugzilla.gnome.org/show_bug.cgi?id=793097
https://blogs.gnome.org/otte/2018/02/03/builders/
2018-02-01 16:43:15 +00:00
|
|
|
* with all the formats added to @builder
|
|
|
|
*/
|
|
|
|
GdkContentFormats *
|
|
|
|
gdk_content_formats_builder_to_formats (GdkContentFormatsBuilder *builder)
|
2017-11-20 01:47:45 +00:00
|
|
|
{
|
|
|
|
GdkContentFormats *result;
|
2017-11-20 14:58:17 +00:00
|
|
|
GType *gtypes;
|
2017-11-20 01:47:45 +00:00
|
|
|
const char **mime_types;
|
|
|
|
GSList *l;
|
|
|
|
gsize i;
|
|
|
|
|
|
|
|
g_return_val_if_fail (builder != NULL, NULL);
|
|
|
|
|
2017-11-20 14:58:17 +00:00
|
|
|
gtypes = g_new (GType, builder->n_gtypes + 1);
|
|
|
|
i = builder->n_gtypes;
|
|
|
|
gtypes[i--] = G_TYPE_INVALID;
|
|
|
|
/* add backwards because most important type is last in the list */
|
|
|
|
for (l = builder->gtypes; l; l = l->next)
|
|
|
|
gtypes[i--] = GPOINTER_TO_SIZE (l->data);
|
|
|
|
|
2017-11-20 01:47:45 +00:00
|
|
|
mime_types = g_new (const char *, builder->n_mime_types + 1);
|
|
|
|
i = builder->n_mime_types;
|
|
|
|
mime_types[i--] = NULL;
|
|
|
|
/* add backwards because most important type is last in the list */
|
|
|
|
for (l = builder->mime_types; l; l = l->next)
|
|
|
|
mime_types[i--] = l->data;
|
|
|
|
|
2017-11-20 14:58:17 +00:00
|
|
|
result = gdk_content_formats_new_take (gtypes, builder->n_gtypes,
|
|
|
|
mime_types, builder->n_mime_types);
|
2017-11-20 03:42:43 +00:00
|
|
|
|
Allow binding GdkContentFormatsBuilder
GdkContentFormatsBuilder is currently not introspectable, as it does not
have a GType. We can turn it into a boxed type, but we need to implement
memory management for it.
The current gdk_content_formats_builder_free() function returns a newly
constructed value, so we cannot use it as a GBoxedFreeFunc; additionally
copying a GdkContentFormatsBuilder contents would make it a bit odd, as
you could get multiple identical GdkContentFormats out of the copies.
A simple approach is to model the GdkContentFormatsBuilder API to follow
the GBytes one: use reference counting for memory management, and have
a function to release a reference, return a GdkContentFormats, and reset
the GdkContentFormatsBuilder state.
For language bindings, we can provide a get_formats() function that
returns the GdkContentFormats instance and resets the builder instance,
leaving the reference count untouched.
For C convenience we can keep gdk_content_formats_builder_free(), and
make it a wrapper around gdk_content_formats_builder_get_formats(), with
the guarantee that it'll free the builder instance regardless of its
current reference count.
https://bugzilla.gnome.org/show_bug.cgi?id=793097
https://blogs.gnome.org/otte/2018/02/03/builders/
2018-02-01 16:43:15 +00:00
|
|
|
gdk_content_formats_builder_clear (builder);
|
2017-11-20 01:47:45 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gdk_content_formats_builder_add_formats:
|
2021-02-21 05:13:57 +00:00
|
|
|
* @builder: a `GdkContentFormatsBuilder`
|
2017-11-20 01:47:45 +00:00
|
|
|
* @formats: the formats to add
|
|
|
|
*
|
|
|
|
* Appends all formats from @formats to @builder, skipping those that
|
|
|
|
* already exist.
|
2021-02-21 05:13:57 +00:00
|
|
|
*/
|
2017-11-20 01:47:45 +00:00
|
|
|
void
|
|
|
|
gdk_content_formats_builder_add_formats (GdkContentFormatsBuilder *builder,
|
2017-11-20 02:54:42 +00:00
|
|
|
const GdkContentFormats *formats)
|
2017-11-20 01:47:45 +00:00
|
|
|
{
|
2017-11-20 03:42:43 +00:00
|
|
|
gsize i;
|
2017-11-20 01:47:45 +00:00
|
|
|
|
|
|
|
g_return_if_fail (builder != NULL);
|
|
|
|
g_return_if_fail (formats != NULL);
|
|
|
|
|
2017-11-20 14:58:17 +00:00
|
|
|
for (i = 0; i < formats->n_gtypes; i++)
|
|
|
|
gdk_content_formats_builder_add_gtype (builder, formats->gtypes[i]);
|
|
|
|
|
2017-11-20 03:42:43 +00:00
|
|
|
for (i = 0; i < formats->n_mime_types; i++)
|
|
|
|
gdk_content_formats_builder_add_mime_type (builder, formats->mime_types[i]);
|
2017-11-20 01:47:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-11-20 14:58:17 +00:00
|
|
|
* gdk_content_formats_builder_add_gtype:
|
2021-02-21 05:13:57 +00:00
|
|
|
* @builder: a `GdkContentFormats`Builder
|
|
|
|
* @type: a `GType`
|
2017-11-20 14:58:17 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* Appends @type to @builder if it has not already been added.
|
2017-11-20 14:58:17 +00:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
gdk_content_formats_builder_add_gtype (GdkContentFormatsBuilder *builder,
|
|
|
|
GType type)
|
|
|
|
{
|
|
|
|
g_return_if_fail (builder != NULL);
|
2017-11-24 10:34:19 +00:00
|
|
|
g_return_if_fail (type != G_TYPE_INVALID);
|
2017-11-20 14:58:17 +00:00
|
|
|
|
|
|
|
if (g_slist_find (builder->gtypes, GSIZE_TO_POINTER (type)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
builder->gtypes = g_slist_prepend (builder->gtypes, GSIZE_TO_POINTER (type));
|
|
|
|
builder->n_gtypes++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gdk_content_formats_builder_add_mime_type:
|
2021-02-21 05:13:57 +00:00
|
|
|
* @builder: a `GdkContentFormatsBuilder`
|
2017-11-20 01:47:45 +00:00
|
|
|
* @mime_type: a mime type
|
|
|
|
*
|
|
|
|
* Appends @mime_type to @builder if it has not already been added.
|
2021-02-21 05:13:57 +00:00
|
|
|
*/
|
2017-11-20 01:47:45 +00:00
|
|
|
void
|
|
|
|
gdk_content_formats_builder_add_mime_type (GdkContentFormatsBuilder *builder,
|
|
|
|
const char *mime_type)
|
|
|
|
{
|
|
|
|
g_return_if_fail (builder != NULL);
|
|
|
|
g_return_if_fail (mime_type != NULL);
|
|
|
|
|
|
|
|
mime_type = g_intern_string (mime_type);
|
|
|
|
|
|
|
|
if (g_slist_find (builder->mime_types, mime_type))
|
|
|
|
return;
|
|
|
|
|
|
|
|
builder->mime_types = g_slist_prepend (builder->mime_types, (gpointer) mime_type);
|
|
|
|
builder->n_mime_types++;
|
|
|
|
}
|
|
|
|
|
2017-11-29 08:37:50 +00:00
|
|
|
/* G_DEFINE_BOXED wants this */
|
|
|
|
typedef gpointer GdkFileList;
|
|
|
|
|
|
|
|
static gpointer
|
|
|
|
gdk_file_list_copy (gpointer list)
|
|
|
|
{
|
|
|
|
return g_slist_copy_deep (list, (GCopyFunc) g_object_ref, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gdk_file_list_free (gpointer list)
|
|
|
|
{
|
|
|
|
g_slist_free_full (list, g_object_unref);
|
|
|
|
}
|
|
|
|
|
|
|
|
G_DEFINE_BOXED_TYPE (GdkFileList, gdk_file_list, gdk_file_list_copy, gdk_file_list_free)
|