/** * as_content_rating_node_insert: (skip) * @content_rating: a #AsContentRating instance. * @parent: the parent #GNode to use.. * @ctx: the #AsNodeContext * * Inserts the content_rating into the DOM tree. * * Returns: (transfer none): A populated #GNode, or %NULL * * Since: 0.5.12 **/ GNode * as_content_rating_node_insert (AsContentRating *content_rating, GNode *parent, AsNodeContext *ctx) { AsContentRatingKey *key; AsContentRatingPrivate *priv = GET_PRIVATE (content_rating); GNode *n; guint i; n = as_node_insert (parent, "content_rating", NULL, AS_NODE_INSERT_FLAG_NONE, NULL); if (priv->kind != NULL) as_node_add_attribute (n, "type", priv->kind); for (i = 0; i < priv->keys->len; i++) { const gchar *tmp; key = g_ptr_array_index (priv->keys, i); tmp = as_content_rating_value_to_string (key->value); as_node_insert (n, "content_attribute", tmp, AS_NODE_INSERT_FLAG_NONE, "id", key->id, NULL); } return n; }
/** * as_image_node_insert: (skip) * @image: a #AsImage instance. * @parent: the parent #GNode to use.. * @ctx: the #AsNodeContext * * Inserts the image into the DOM tree. * * Returns: (transfer none): A populated #GNode * * Since: 0.1.0 **/ GNode * as_image_node_insert (AsImage *image, GNode *parent, AsNodeContext *ctx) { AsImagePrivate *priv = GET_PRIVATE (image); GNode *n; gchar tmp_height[6]; gchar tmp_width[6]; if (priv->width > 0 && priv->height > 0) { g_snprintf (tmp_width, sizeof (tmp_width), "%u", priv->width); g_snprintf (tmp_height, sizeof (tmp_height), "%u", priv->height); n = as_node_insert (parent, "image", priv->url, AS_NODE_INSERT_FLAG_NONE, "width", tmp_width, "height", tmp_height, "type", as_image_kind_to_string (priv->kind), NULL); } else { n = as_node_insert (parent, "image", priv->url, AS_NODE_INSERT_FLAG_NONE, "type", as_image_kind_to_string (priv->kind), NULL); } return n; }
/** * as_screenshot_node_insert: (skip) * @screenshot: a #AsScreenshot instance. * @parent: the parent #GNode to use.. * @ctx: the #AsNodeContext * * Inserts the screenshot into the DOM tree. * * Returns: (transfer none): A populated #GNode, or %NULL * * Since: 0.1.1 **/ GNode * as_screenshot_node_insert (AsScreenshot *screenshot, GNode *parent, AsNodeContext *ctx) { AsImage *image; AsScreenshotPrivate *priv = GET_PRIVATE (screenshot); GNode *n; guint i; /* nothing to add */ if (priv->images->len == 0) return NULL; n = as_node_insert (parent, "screenshot", NULL, AS_NODE_INSERT_FLAG_NONE, NULL); if (priv->kind != AS_SCREENSHOT_KIND_NORMAL) { as_node_add_attribute (n, "type", as_screenshot_kind_to_string (priv->kind)); } if (as_node_context_get_version (ctx) >= 0.41) { as_node_insert_localized (n, "caption", priv->captions, AS_NODE_INSERT_FLAG_DEDUPE_LANG); } if (as_node_context_get_version (ctx) >= 0.8 && priv->priority != 0) as_node_add_attribute_as_int (n, "priority", priv->priority); for (i = 0; i < priv->images->len; i++) { image = g_ptr_array_index (priv->images, i); as_image_node_insert (image, n, ctx); } return n; }
/** * as_provide_node_insert: (skip) * @provide: a #AsProvide instance. * @parent: the parent #GNode to use.. * @ctx: the #AsNodeContext * * Inserts the provide into the DOM tree. * * Returns: (transfer none): A populated #GNode * * Since: 0.1.6 **/ GNode * as_provide_node_insert (AsProvide *provide, GNode *parent, AsNodeContext *ctx) { AsProvidePrivate *priv = GET_PRIVATE (provide); GNode *n = NULL; switch (priv->kind) { case AS_PROVIDE_KIND_UNKNOWN: break; case AS_PROVIDE_KIND_DBUS_SESSION: n = as_node_insert (parent, "dbus", priv->value, AS_NODE_INSERT_FLAG_NONE, "type", "session", NULL); break; case AS_PROVIDE_KIND_DBUS_SYSTEM: n = as_node_insert (parent, "dbus", priv->value, AS_NODE_INSERT_FLAG_NONE, "type", "system", NULL); break; case AS_PROVIDE_KIND_FIRMWARE_FLASHED: n = as_node_insert (parent, "firmware", priv->value, AS_NODE_INSERT_FLAG_NONE, "type", "flashed", NULL); break; case AS_PROVIDE_KIND_FIRMWARE_RUNTIME: n = as_node_insert (parent, "firmware", priv->value, AS_NODE_INSERT_FLAG_NONE, "type", "runtime", NULL); break; default: n = as_node_insert (parent, as_provide_kind_to_string (priv->kind), priv->value, AS_NODE_INSERT_FLAG_NONE, NULL); break; } return n; }
/** * as_icon_node_insert: (skip) * @icon: a #AsIcon instance. * @parent: the parent #GNode to use.. * @ctx: the #AsNodeContext * * Inserts the icon into the DOM tree. * * Returns: (transfer none): A populated #GNode * * Since: 0.3.1 **/ GNode * as_icon_node_insert (AsIcon *icon, GNode *parent, AsNodeContext *ctx) { AsIconPrivate *priv = GET_PRIVATE (icon); GNode *n; /* embedded icon */ if (priv->kind == AS_ICON_KIND_EMBEDDED) return as_icon_node_insert_embedded (icon, parent, ctx); /* other icons */ switch (priv->kind) { case AS_ICON_KIND_REMOTE: n = as_node_insert (parent, "icon", priv->url, 0, "type", as_icon_kind_to_string (priv->kind), NULL); break; case AS_ICON_KIND_LOCAL: if (priv->filename != NULL) { n = as_node_insert (parent, "icon", priv->filename, 0, "type", as_icon_kind_to_string (priv->kind), NULL); } else { n = as_node_insert (parent, "icon", priv->name, 0, "type", as_icon_kind_to_string (priv->kind), NULL); } break; default: n = as_node_insert (parent, "icon", priv->name, 0, "type", as_icon_kind_to_string (priv->kind), NULL); break; } if (priv->kind == AS_ICON_KIND_CACHED && as_node_context_get_version (ctx) >= 0.8) { if (priv->width > 0) as_node_add_attribute_as_uint (n, "width", priv->width); if (priv->height > 0) as_node_add_attribute_as_uint (n, "height", priv->height); } return n; }
static GNode * as_icon_node_insert_embedded (AsIcon *icon, GNode *parent, AsNodeContext *ctx) { AsIconPrivate *priv = GET_PRIVATE (icon); GNode *n; g_autofree gchar *data = NULL; /* embedded icon */ n = as_node_insert (parent, "icon", NULL, 0, "type", as_icon_kind_to_string (priv->kind), NULL); if (as_node_context_get_version (ctx) >= 0.8) { as_node_add_attribute_as_uint (n, "width", priv->width); as_node_add_attribute_as_uint (n, "height", priv->height); } as_node_insert (n, "name", priv->name, 0, NULL); data = g_base64_encode (g_bytes_get_data (priv->data, NULL), g_bytes_get_size (priv->data)); as_node_insert (n, "filecontent", data, AS_NODE_INSERT_FLAG_BASE64_ENCODED, NULL); return n; }
/** * as_icon_node_insert: (skip) * @icon: a #AsIcon instance. * @parent: the parent #GNode to use.. * @api_version: the AppStream API version * * Inserts the icon into the DOM tree. * * Returns: (transfer none): A populated #GNode * * Since: 0.3.1 **/ GNode * as_icon_node_insert (AsIcon *icon, GNode *parent, gdouble api_version) { AsIconPrivate *priv = GET_PRIVATE (icon); GNode *n; _cleanup_free_ gchar *data = NULL; /* normal icon */ if (priv->kind != AS_ICON_KIND_EMBEDDED) { n = as_node_insert (parent, "icon", priv->name, 0, "type", as_icon_kind_to_string (priv->kind), NULL); if (priv->kind == AS_ICON_KIND_CACHED && api_version >= 0.8) { if (priv->width > 0) as_node_add_attribute_as_int (n, "width", priv->width); if (priv->height > 0) as_node_add_attribute_as_int (n, "height", priv->height); } return n; } /* embedded icon */ n = as_node_insert (parent, "icon", NULL, 0, "type", as_icon_kind_to_string (priv->kind), NULL); if (api_version >= 0.8) { as_node_add_attribute_as_int (n, "width", priv->width); as_node_add_attribute_as_int (n, "height", priv->height); } as_node_insert (n, "name", priv->name, 0, NULL); data = g_base64_encode (g_bytes_get_data (priv->data, NULL), g_bytes_get_size (priv->data)); as_node_insert (n, "filecontent", data, AS_NODE_INSERT_FLAG_BASE64_ENCODED, NULL); return n; }
/** * as_image_node_insert: (skip) * @image: a #AsImage instance. * @parent: the parent #GNode to use.. * @ctx: the #AsNodeContext * * Inserts the image into the DOM tree. * * Returns: (transfer none): A populated #GNode * * Since: 0.1.0 **/ GNode * as_image_node_insert (AsImage *image, GNode *parent, AsNodeContext *ctx) { AsImagePrivate *priv = GET_PRIVATE (image); GNode *n; n = as_node_insert (parent, "image", priv->url, AS_NODE_INSERT_FLAG_NONE, NULL); if (priv->width > 0) as_node_add_attribute_as_uint (n, "width", priv->width); if (priv->height > 0) as_node_add_attribute_as_uint (n, "height", priv->height); if (priv->kind > AS_IMAGE_KIND_UNKNOWN) as_node_add_attribute (n, "type", as_image_kind_to_string (priv->kind)); if (priv->locale != NULL) as_node_add_attribute (n, "xml:lang", priv->locale); return n; }
/** * as_require_node_insert: (skip) * @require: a #AsRequire instance. * @parent: the parent #GNode to use.. * @ctx: the #AsNodeContext * * Inserts the require into the DOM tree. * * Returns: (transfer none): A populated #GNode * * Since: 0.6.7 **/ GNode * as_require_node_insert (AsRequire *require, GNode *parent, AsNodeContext *ctx) { AsRequirePrivate *priv = GET_PRIVATE (require); GNode *n; /* don't know what to do here */ if (priv->kind == AS_REQUIRE_KIND_UNKNOWN) return NULL; n = as_node_insert (parent, as_require_kind_to_string (priv->kind), NULL, AS_NODE_INSERT_FLAG_NONE, NULL); if (priv->compare != AS_REQUIRE_COMPARE_UNKNOWN) { as_node_add_attribute (n, "compare", as_require_compare_to_string (priv->compare)); } if (priv->version != NULL) as_node_add_attribute (n, "version", priv->version); if (priv->value != NULL) as_node_set_data (n, priv->value, AS_NODE_INSERT_FLAG_NONE); return n; }
/** * as_review_node_insert: (skip) * @review: a #AsReview instance. * @parent: the parent #GNode to use.. * @ctx: the #AsNodeContext * * Inserts the review into the DOM tree. * * Returns: (transfer none): A populated #GNode * * Since: 0.6.1 **/ GNode * as_review_node_insert (AsReview *review, GNode *parent, AsNodeContext *ctx) { AsReviewPrivate *priv = GET_PRIVATE (review); GNode *n; n = as_node_insert (parent, "review", NULL, AS_NODE_INSERT_FLAG_NONE, NULL); if (priv->id != NULL) as_node_add_attribute (n, "id", priv->id); if (priv->priority != 0) { g_autofree gchar *str = g_strdup_printf ("%i", priv->priority); as_node_insert (n, "priority", str, AS_NODE_INSERT_FLAG_NONE, NULL); } if (priv->rating != 0) { g_autofree gchar *str = g_strdup_printf ("%i", priv->rating); as_node_add_attribute (n, "rating", str); } if (priv->date != NULL) { g_autofree gchar *str = g_date_time_format (priv->date, "%F"); as_node_add_attribute (n, "date", str); } if (priv->summary != NULL) { as_node_insert (n, "summary", priv->summary, AS_NODE_INSERT_FLAG_NONE, NULL); } if (priv->description != NULL) { as_node_insert (n, "description", priv->description, AS_NODE_INSERT_FLAG_PRE_ESCAPED, NULL); } if (priv->version != NULL) { as_node_insert (n, "version", priv->version, AS_NODE_INSERT_FLAG_NONE, NULL); } if (priv->reviewer_id != NULL) { as_node_insert (n, "reviewer_id", priv->reviewer_id, AS_NODE_INSERT_FLAG_NONE, NULL); } if (priv->reviewer_name != NULL) { as_node_insert (n, "reviewer_name", priv->reviewer_name, AS_NODE_INSERT_FLAG_NONE, NULL); } if (priv->locale != NULL) { as_node_insert (n, "lang", priv->locale, AS_NODE_INSERT_FLAG_NONE, NULL); } /* <metadata> */ if (g_hash_table_size (priv->metadata) > 0) { AsNode *node_tmp; node_tmp = as_node_insert (n, "metadata", NULL, 0, NULL); as_node_insert_hash (node_tmp, "value", "key", priv->metadata, FALSE); } return n; }