/** * 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_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; }
static void as_node_passthrough_cb (GMarkupParseContext *context, const gchar *passthrough_text, gsize passthrough_len, gpointer user_data, GError **error) { AsNodeToXmlHelper *helper = (AsNodeToXmlHelper *) user_data; const gchar *existing; const gchar *tmp; gchar *found; g_autofree gchar *text = NULL; /* only keep comments when told to */ if ((helper->flags & AS_NODE_FROM_XML_FLAG_KEEP_COMMENTS) == 0) return; /* xml header */ if (g_strstr_len (passthrough_text, passthrough_len, "<?xml") != NULL) return; /* get stripped comment without '<!--' and '-->' */ text = g_strndup (passthrough_text, passthrough_len); if (!g_str_has_prefix (text, "<!--")) { g_warning ("Unexpected input: %s", text); return; } found = g_strrstr (text, "-->"); if (found != NULL) *found = '\0'; tmp = text + 4; if ((helper->flags & AS_NODE_FROM_XML_FLAG_LITERAL_TEXT) == 0) tmp = g_strstrip ((gchar *) tmp); if (tmp == NULL || tmp[0] == '\0') return; /* append together comments */ existing = as_node_get_attribute (helper->current, "@comment-tmp"); if (existing == NULL) { as_node_add_attribute (helper->current, "@comment-tmp", tmp); } else { g_autofree gchar *join = NULL; join = g_strdup_printf ("%s<&>%s", existing, tmp); as_node_add_attribute (helper->current, "@comment-tmp", join); } }
/** * 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; }
static void as_node_start_element_cb (GMarkupParseContext *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer user_data, GError **error) { AsNodeToXmlHelper *helper = (AsNodeToXmlHelper *) user_data; AsNodeData *data; AsNode *current; gchar *tmp; guint i; /* create the new node data */ data = g_slice_new0 (AsNodeData); as_node_data_set_name (data, element_name, AS_NODE_INSERT_FLAG_NONE); for (i = 0; attribute_names[i] != NULL; i++) { as_node_attr_insert (data, attribute_names[i], attribute_values[i]); } /* add the node to the DOM */ current = g_node_append_data (helper->current, data); /* transfer the ownership of the comment to the new child */ tmp = as_node_take_attribute (helper->current, "@comment-tmp"); if (tmp != NULL) { as_node_add_attribute (current, "@comment", tmp); g_free (tmp); } /* the child is now the node to be processed */ helper->current = current; }
/** * as_node_set_comment: (skip) * @node: a #AsNode * @comment: new comment * * Sets new comment for the node. * * Since: 0.1.6 **/ void as_node_set_comment (AsNode *node, const gchar *comment) { as_node_add_attribute (node, "@comment", comment); }
/** * as_node_add_attribute_as_int: (skip) * @node: a #AsNode * @key: the attribute key * @value: new data * * Adds a new attribute to a node. * * Since: 0.3.1 **/ void as_node_add_attribute_as_int (AsNode *node, const gchar *key, gint value) { g_autofree gchar *tmp = g_strdup_printf ("%i", value); as_node_add_attribute (node, key, tmp); }
/** * 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; }