From 12ab3c92045e510df789db60c67c5d4df16a9027 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Wed, 10 Aug 2011 15:06:59 +0100 Subject: [PATCH] tag: fix compilation of new licenses code with GLib versions < 2.28 Add local g_variant_lookup_value() fallback for now when compiling against older GLib versions. --- gst-libs/gst/tag/licenses.c | 58 +++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/gst-libs/gst/tag/licenses.c b/gst-libs/gst/tag/licenses.c index 31632b1d1e..4d2c4769d0 100644 --- a/gst-libs/gst/tag/licenses.c +++ b/gst-libs/gst/tag/licenses.c @@ -114,6 +114,64 @@ gst_tag_get_license_translations_dictionary (void) #endif #ifdef ENABLE_NLS + +#if !GLIB_CHECK_VERSION(2,28,0) +static GVariant * +gst_g_variant_lookup_value (GVariant * dictionary, const gchar * key, + const GVariantType * expected_type) +{ + GVariantIter iter; + GVariant *entry; + GVariant *value; + + GST_ERROR ("here, using fallback"); + + g_assert (g_variant_is_of_type (dictionary, G_VARIANT_TYPE ("a{s*}"))); + g_assert (expected_type != NULL); + + g_variant_iter_init (&iter, dictionary); + while ((entry = g_variant_iter_next_value (&iter))) { + GVariant *entry_key; + gboolean matches; + + entry_key = g_variant_get_child_value (entry, 0); + matches = strcmp (g_variant_get_string (entry_key, NULL), key) == 0; + g_variant_unref (entry_key); + + if (matches) + break; + + g_variant_unref (entry); + } + + if (entry == NULL) + return NULL; + + value = g_variant_get_child_value (entry, 1); + g_variant_unref (entry); + + if (g_variant_is_of_type (value, G_VARIANT_TYPE_VARIANT)) { + GVariant *tmp; + + tmp = g_variant_get_variant (value); + g_variant_unref (value); + + if (expected_type && !g_variant_is_of_type (tmp, expected_type)) { + g_variant_unref (tmp); + tmp = NULL; + } + + value = tmp; + } + + g_assert (value == NULL || g_variant_is_of_type (value, expected_type)); + + return value; +} + +#define g_variant_lookup_value gst_g_variant_lookup_value +#endif /* !GLIB_CHECK_VERSION(2,28,0) */ + static gboolean gst_variant_lookup_string_value (GVariant * dict, const gchar * lang, const gchar ** translation)