/** * as_image_node_parse: * @image: a #AsImage 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_image_node_parse (AsImage *image, GNode *node, AsNodeContext *ctx, GError **error) { AsImagePrivate *priv = GET_PRIVATE (image); const gchar *tmp; guint size; size = as_node_get_attribute_as_uint (node, "width"); if (size != G_MAXUINT) as_image_set_width (image, size); size = as_node_get_attribute_as_uint (node, "height"); if (size != G_MAXUINT) as_image_set_height (image, size); tmp = as_node_get_attribute (node, "type"); if (tmp == NULL) as_image_set_kind (image, AS_IMAGE_KIND_SOURCE); else as_image_set_kind (image, as_image_kind_from_string (tmp)); as_ref_string_assign (&priv->url, as_node_get_data (node)); as_ref_string_assign (&priv->locale, as_node_get_attribute (node, "xml:lang")); return TRUE; }
/** * 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; }
/** * as_icon_node_parse: * @icon: a #AsIcon 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.3.1 **/ gboolean as_icon_node_parse (AsIcon *icon, GNode *node, AsNodeContext *ctx, GError **error) { AsIconPrivate *priv = GET_PRIVATE (icon); const gchar *tmp; guint size; gboolean prepend_size = TRUE; tmp = as_node_get_attribute (node, "type"); as_icon_set_kind (icon, as_icon_kind_from_string (tmp)); switch (priv->kind) { case AS_ICON_KIND_EMBEDDED: if (!as_icon_node_parse_embedded (icon, node, error)) return FALSE; break; default: /* preserve the URL for remote icons */ tmp = as_node_get_data (node); if (tmp == NULL) { g_set_error (error, AS_ICON_ERROR, AS_ICON_ERROR_FAILED, "no data for icon of type %s", as_icon_kind_to_string (priv->kind)); return FALSE; } if (priv->kind == AS_ICON_KIND_REMOTE) as_icon_set_url (icon, tmp); else if (priv->kind == AS_ICON_KIND_LOCAL) as_icon_set_filename (icon, tmp); /* store the name without any prefix */ if (g_strstr_len (tmp, -1, "/") == NULL) { as_icon_set_name (icon, tmp); } else { g_autofree gchar *basename = NULL; basename = g_path_get_basename (tmp); as_icon_set_name (icon, basename); } /* width is optional, assume 64px if missing */ size = as_node_get_attribute_as_uint (node, "width"); if (size == G_MAXUINT) { size = 64; prepend_size = FALSE; } priv->width = size; /* height is optional, assume 64px if missing */ size = as_node_get_attribute_as_uint (node, "height"); if (size == G_MAXUINT) { size = 64; prepend_size = FALSE; } priv->height = size; /* only use the size if the metadata has width and height */ if (prepend_size) { g_free (priv->prefix_private); priv->prefix_private = g_strdup_printf ("%s/%ux%u", priv->prefix, priv->width, priv->height); } break; } return TRUE; }