/** * as_provide_node_parse: * @provide: a #AsProvide 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.6 **/ gboolean as_provide_node_parse (AsProvide *provide, GNode *node, AsNodeContext *ctx, GError **error) { AsProvidePrivate *priv = GET_PRIVATE (provide); const gchar *tmp; if (g_strcmp0 (as_node_get_name (node), "dbus") == 0) { tmp = as_node_get_attribute (node, "type"); if (g_strcmp0 (tmp, "system") == 0) priv->kind = AS_PROVIDE_KIND_DBUS_SYSTEM; else priv->kind = AS_PROVIDE_KIND_DBUS_SESSION; } else if (g_strcmp0 (as_node_get_name (node), "firmware") == 0) { tmp = as_node_get_attribute (node, "type"); if (g_strcmp0 (tmp, "flashed") == 0) priv->kind = AS_PROVIDE_KIND_FIRMWARE_FLASHED; else priv->kind = AS_PROVIDE_KIND_FIRMWARE_RUNTIME; } else { priv->kind = as_provide_kind_from_string (as_node_get_name (node)); } g_free (priv->value); priv->value = as_node_take_data (node); return TRUE; }
/** * 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; gchar *taken; guint size; size = as_node_get_attribute_as_int (node, "width"); if (size != G_MAXINT) as_image_set_width (image, size); size = as_node_get_attribute_as_int (node, "height"); if (size != G_MAXINT) 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)); taken = as_node_take_data (node); if (taken != NULL) { g_free (priv->url); priv->url = taken; } return TRUE; }
static gboolean as_icon_node_parse_embedded (AsIcon *icon, GNode *n, GError **error) { AsIconPrivate *priv = GET_PRIVATE (icon); GNode *c; gsize size; g_autofree guchar *data = NULL; g_autoptr(GdkPixbuf) pixbuf = NULL; g_autoptr(GInputStream) stream = NULL; /* get the icon name */ c = as_node_find (n, "name"); if (c == NULL) { g_set_error_literal (error, AS_ICON_ERROR, AS_ICON_ERROR_FAILED, "embedded icons needs <name>"); return FALSE; } g_free (priv->name); priv->name = as_node_take_data (c); /* parse the Base64 data */ c = as_node_find (n, "filecontent"); if (c == NULL) { g_set_error_literal (error, AS_ICON_ERROR, AS_ICON_ERROR_FAILED, "embedded icons needs <filecontent>"); return FALSE; } data = g_base64_decode (as_node_get_data (c), &size); stream = g_memory_input_stream_new_from_data (data, (gssize) size, NULL); if (stream == NULL) { g_set_error_literal (error, AS_ICON_ERROR, AS_ICON_ERROR_FAILED, "failed to load embedded data"); return FALSE; } /* load the image */ pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, error); if (pixbuf == NULL) return FALSE; as_icon_set_pixbuf (icon, pixbuf); /* save the raw data */ if (priv->data != NULL) g_bytes_unref (priv->data); priv->data = g_bytes_new (data, size); return TRUE; }