Esempio n. 1
0
/**
 * as_image_node_parse_dep11:
 * @image: a #AsImage instance.
 * @node: a #GNode.
 * @ctx: a #AsNodeContext.
 * @error: A #GError or %NULL.
 *
 * Populates the object from a DEP-11 node.
 *
 * Returns: %TRUE for success
 *
 * Since: 0.3.0
 **/
gboolean
as_image_node_parse_dep11 (AsImage *im, GNode *node,
			   AsNodeContext *ctx, GError **error)
{
	GNode *n;
	const gchar *tmp;

	for (n = node->children; n != NULL; n = n->next) {
		tmp = as_yaml_node_get_key (n);
		if (g_strcmp0 (tmp, "height") == 0)
			as_image_set_height (im, as_yaml_node_get_value_as_uint (n));
		else if (g_strcmp0 (tmp, "width") == 0)
			as_image_set_width (im, as_yaml_node_get_value_as_uint (n));
		else if (g_strcmp0 (tmp, "url") == 0) {
			const gchar *media_base_url = as_node_context_get_media_base_url (ctx);
			if (media_base_url != NULL) {
				g_autofree gchar *url = NULL;
				url = g_build_path ("/", media_base_url, as_yaml_node_get_value (n), NULL);
				as_image_set_url (im, url);
			} else {
				as_image_set_url (im, as_yaml_node_get_value (n));
			}
		}
	}
	return TRUE;
}
Esempio n. 2
0
/**
 * as_icon_node_parse_dep11:
 * @icon: a #AsIcon instance.
 * @node: a #GNode.
 * @ctx: a #AsNodeContext.
 * @error: A #GError or %NULL.
 *
 * Populates the object from a DEP-11 node.
 *
 * Returns: %TRUE for success
 *
 * Since: 0.3.1
 **/
gboolean
as_icon_node_parse_dep11 (AsIcon *icon, GNode *node,
			  AsNodeContext *ctx, GError **error)
{
	GNode *n;
	AsIconPrivate *priv = GET_PRIVATE (icon);

	for (n = node->children; n != NULL; n = n->next) {
		const gchar *key;
		guint size;

		key = as_yaml_node_get_key (n);
		if (g_strcmp0 (key, "width") == 0) {
			size = as_yaml_node_get_value_as_uint (n);
			if (size == G_MAXUINT)
				size = 64;
			priv->width = size;
		} else if (g_strcmp0 (key, "height") == 0) {
			size = as_yaml_node_get_value_as_uint (n);
			if (size == G_MAXUINT)
				size = 64;
			priv->height = size;
		} else {
			if (priv->kind == AS_ICON_KIND_REMOTE) {
				if (g_strcmp0 (key, "url") == 0) {
					const gchar *media_baseurl;
					media_baseurl = as_node_context_get_media_base_url (ctx);
					if (media_baseurl == NULL) {
						/* no baseurl, we can just set the value as URL */
						as_icon_set_url (icon, as_yaml_node_get_value (n));
					} else {
						/* handle the media baseurl */
						g_autofree gchar *url = NULL;
						url = g_build_filename (media_baseurl,
									as_yaml_node_get_value (n),
									NULL);
						as_icon_set_url (icon, url);
					}
				}
			} else {
				if (g_strcmp0 (key, "name") == 0) {
					const gchar *icon_name;
					icon_name = as_yaml_node_get_value (n);

					if (g_str_has_prefix (icon_name, "/"))
						as_icon_set_filename (icon, icon_name);
					else
						as_icon_set_name (icon, icon_name);
				}
			}
		}
	}

	return TRUE;
}
Esempio n. 3
0
/**
 * as_icon_node_parse_dep11:
 * @icon: a #AsIcon instance.
 * @node: a #GNode.
 * @error: A #GError or %NULL.
 *
 * Populates the object from a DEP-11 node.
 *
 * Returns: %TRUE for success
 *
 * Since: 0.3.1
 **/
gboolean
as_icon_node_parse_dep11 (AsIcon *im, GNode *node, GError **error)
{
	if (g_strcmp0 (as_yaml_node_get_key (node), "cached") != 0)
		return TRUE;
	as_icon_set_name (im, as_yaml_node_get_value (node), -1);
	as_icon_set_kind (im, AS_ICON_KIND_CACHED);
	return TRUE;
}
Esempio n. 4
0
/**
 * as_screenshot_node_parse_dep11:
 * @screenshot: a #AsScreenshot instance.
 * @node: a #GNode.
 * @ctx: a #AsNodeContext.
 * @error: A #GError or %NULL.
 *
 * Populates the object from a DEP-11 node.
 *
 * Returns: %TRUE for success
 *
 * Since: 0.3.0
 **/
gboolean
as_screenshot_node_parse_dep11 (AsScreenshot *ss, GNode *node,
				AsNodeContext *ctx, GError **error)
{
	GNode *c;
	GNode *n;
	const gchar *tmp;

	for (n = node->children; n != NULL; n = n->next) {
		tmp = as_yaml_node_get_key (n);
		if (g_strcmp0 (tmp, "default") == 0) {
			if (g_strcmp0 (as_yaml_node_get_value (n), "true") == 0)
				as_screenshot_set_kind (ss, AS_SCREENSHOT_KIND_DEFAULT);
			else if (g_strcmp0 (as_yaml_node_get_value (n), "false") == 0)
				as_screenshot_set_kind (ss, AS_SCREENSHOT_KIND_NORMAL);
			continue;
		}
		if (g_strcmp0 (tmp, "source-image") == 0) {
			g_autoptr(AsImage) im = as_image_new ();
			as_image_set_kind (im, AS_IMAGE_KIND_SOURCE);
			if (!as_image_node_parse_dep11 (im, n, ctx, error))
				return FALSE;
			as_screenshot_add_image (ss, im);
			continue;
		}
		if (g_strcmp0 (tmp, "thumbnails") == 0) {
			for (c = n->children; c != NULL; c = c->next) {
				g_autoptr(AsImage) im = as_image_new ();
				as_image_set_kind (im, AS_IMAGE_KIND_THUMBNAIL);
				if (!as_image_node_parse_dep11 (im, c, ctx, error))
					return FALSE;
				as_screenshot_add_image (ss, im);
			}
			continue;
		}
	}
	return TRUE;
}
Esempio n. 5
0
/**
 * as_image_node_parse_dep11:
 * @image: a #AsImage instance.
 * @node: a #GNode.
 * @ctx: a #AsNodeContext.
 * @error: A #GError or %NULL.
 *
 * Populates the object from a DEP-11 node.
 *
 * Returns: %TRUE for success
 *
 * Since: 0.3.0
 **/
gboolean
as_image_node_parse_dep11 (AsImage *im, GNode *node,
			   AsNodeContext *ctx, GError **error)
{
	GNode *n;
	const gchar *tmp;

	for (n = node->children; n != NULL; n = n->next) {
		tmp = as_yaml_node_get_key (n);
		if (g_strcmp0 (tmp, "height") == 0)
			as_image_set_height (im, as_yaml_node_get_value_as_int (n));
		else if (g_strcmp0 (tmp, "width") == 0)
			as_image_set_width (im, as_yaml_node_get_value_as_int (n));
		else if (g_strcmp0 (tmp, "url") == 0)
			as_image_set_url (im, as_yaml_node_get_value (n));
	}
	return TRUE;
}