[gtk+/wip/otte/clipboard: 79/102] gdk: Add gdk_content_formats_new_for_gtype()



commit 67eec08eef518c7c5d7c6093cedde5b9f4340e80
Author: Benjamin Otte <otte redhat com>
Date:   Tue Nov 28 02:02:06 2017 +0100

    gdk: Add gdk_content_formats_new_for_gtype()
    
    Many places create formats for a single tpye, so make it easy for them
    to get this without having to create a builder first.

 docs/reference/gdk/gdk4-sections.txt |    1 +
 gdk/gdkcontentformats.c              |   28 +++++++++++++++++++++++++---
 gdk/gdkcontentformats.h              |    2 ++
 gdk/gdkcontentproviderimpl.c         |    5 +----
 4 files changed, 29 insertions(+), 7 deletions(-)
---
diff --git a/docs/reference/gdk/gdk4-sections.txt b/docs/reference/gdk/gdk4-sections.txt
index 8deed84..ec11594 100644
--- a/docs/reference/gdk/gdk4-sections.txt
+++ b/docs/reference/gdk/gdk4-sections.txt
@@ -372,6 +372,7 @@ gdk_intern_mime_type
 <SUBSECTION>
 GdkContentFormats
 gdk_content_formats_new
+gdk_content_formats_new_for_gtype
 gdk_content_formats_ref
 gdk_content_formats_unref
 gdk_content_formats_print
diff --git a/gdk/gdkcontentformats.c b/gdk/gdkcontentformats.c
index 8369cdd..5e7d5ea 100644
--- a/gdk/gdkcontentformats.c
+++ b/gdk/gdkcontentformats.c
@@ -137,9 +137,9 @@ gdk_content_formats_new_take (GType *      gtypes,
  * 
  * Creates a new #GdkContentFormats from an array of mime types.
  *
- * The mime types must be different or the behavior of the return value
- * is undefined. If you cannot guarantee this, use #GdkContentFormatsBuilder
- * instead.
+ * The mime types must be valid and different from each other or the
+ * behavior of the return value is undefined. If you cannot guarantee
+ * this, use #GdkContentFormatsBuilder instead.
  * 
  * Returns: (transfer full): the new #GdkContentFormats.
  **/
@@ -162,6 +162,28 @@ gdk_content_formats_new (const char **mime_types,
 }
 
 /**
+ * gdk_content_formats_new_for_gtype:
+ * @type: a $GType
+ *
+ * Creates a new #GdkContentFormats for a given #GType.
+ *
+ * Returns: a new #GdkContentFormats
+ **/
+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);
+}
+
+/**
  * gdk_content_formats_ref:
  * @formats:  a #GdkContentFormats
  * 
diff --git a/gdk/gdkcontentformats.h b/gdk/gdkcontentformats.h
index e265b6a..1e5f714 100644
--- a/gdk/gdkcontentformats.h
+++ b/gdk/gdkcontentformats.h
@@ -39,6 +39,8 @@ GDK_AVAILABLE_IN_3_94
 GdkContentFormats *     gdk_content_formats_new                 (const char                    **mime_types,
                                                                  guint                           
n_mime_types);
 GDK_AVAILABLE_IN_3_94
+GdkContentFormats *     gdk_content_formats_new_for_gtype       (GType                           type);
+GDK_AVAILABLE_IN_3_94
 GdkContentFormats *     gdk_content_formats_ref                 (GdkContentFormats              *formats);
 GDK_AVAILABLE_IN_3_94
 void                    gdk_content_formats_unref               (GdkContentFormats              *formats);
diff --git a/gdk/gdkcontentproviderimpl.c b/gdk/gdkcontentproviderimpl.c
index 77e4d8d..adb3cc4 100644
--- a/gdk/gdkcontentproviderimpl.c
+++ b/gdk/gdkcontentproviderimpl.c
@@ -64,11 +64,8 @@ static GdkContentFormats *
 gdk_content_provider_value_ref_formats (GdkContentProvider *provider)
 {
   GdkContentProviderValue *content = GDK_CONTENT_PROVIDER_VALUE (provider);
-  GdkContentFormatsBuilder *builder;
 
-  builder = gdk_content_formats_builder_new ();
-  gdk_content_formats_builder_add_gtype (builder, G_VALUE_TYPE (&content->value));
-  return gdk_content_formats_builder_free (builder);
+  return gdk_content_formats_new_for_gtype (G_VALUE_TYPE (&content->value));
 }
 
 static gboolean


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]