/** * as_node_get_localized_best: * @node: a #AsNode. * @key: the tag name. * * Gets the 'best' locale version of a specific data value. * * Returns: the string value, or %NULL if there was no data * * Since: 0.1.0 **/ const gchar * as_node_get_localized_best (const AsNode *node, const gchar *key) { g_autoptr(GHashTable) hash = NULL; hash = as_node_get_localized (node, key); if (hash == NULL) return NULL; return as_hash_lookup_by_locale (hash, NULL); }
/** * as_screenshot_node_parse: * @screenshot: a #AsScreenshot instance. * @node: a #GNode. * @ctx: a #AsNodeContext. * @error: A #GError or %NULL. * * Populates the object from a DOM node. * * Returns: %TRUE for success * * Since: 0.1.0 **/ gboolean as_screenshot_node_parse (AsScreenshot *screenshot, GNode *node, AsNodeContext *ctx, GError **error) { AsScreenshotPrivate *priv = GET_PRIVATE (screenshot); GList *l; GNode *c; const gchar *tmp; guint size; gint priority; g_autoptr(GHashTable) captions = NULL; tmp = as_node_get_attribute (node, "type"); if (tmp != NULL) { as_screenshot_set_kind (screenshot, as_screenshot_kind_from_string (tmp)); } priority = as_node_get_attribute_as_int (node, "priority"); if (priority != G_MAXINT) as_screenshot_set_priority (screenshot, priority); /* add captions */ captions = as_node_get_localized (node, "caption"); if (captions != NULL) { g_autoptr(GList) keys = NULL; keys = g_hash_table_get_keys (captions); for (l = keys; l != NULL; l = l->next) { tmp = l->data; as_screenshot_set_caption (screenshot, tmp, g_hash_table_lookup (captions, tmp)); } } /* AppData files does not have <image> tags */ tmp = as_node_get_data (node); if (tmp != NULL) { AsImage *image; image = as_image_new (); as_image_set_kind (image, AS_IMAGE_KIND_SOURCE); size = as_node_get_attribute_as_uint (node, "width"); if (size != G_MAXINT) as_image_set_width (image, size); size = as_node_get_attribute_as_uint (node, "height"); if (size != G_MAXINT) as_image_set_height (image, size); as_image_set_url (image, tmp); g_ptr_array_add (priv->images, image); } /* add images */ for (c = node->children; c != NULL; c = c->next) { g_autoptr(AsImage) image = NULL; if (as_node_get_tag (c) != AS_TAG_IMAGE) continue; image = as_image_new (); if (!as_image_node_parse (image, c, ctx, error)) return FALSE; g_ptr_array_add (priv->images, g_object_ref (image)); } return TRUE; }