示例#1
0
/**
 * 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;
}
示例#2
0
/**
 * 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;
}
示例#3
0
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;
}