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

	size = as_node_get_attribute_as_uint (node, "width");
	if (size != G_MAXUINT)
		as_image_set_width (image, size);
	size = as_node_get_attribute_as_uint (node, "height");
	if (size != G_MAXUINT)
		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));
	as_ref_string_assign (&priv->url, as_node_get_data (node));
	as_ref_string_assign (&priv->locale, as_node_get_attribute (node, "xml:lang"));
	return TRUE;
}
示例#5
0
static void
refine_screenshots (GsApp *app, SnapdSnap *snap)
{
	GPtrArray *media, *screenshots;
	guint i;

	media = snapd_snap_get_media (snap);
	for (i = 0; i < media->len; i++) {
		SnapdMedia *m = media->pdata[i];
		const gchar *url;
		g_autofree gchar *filename = NULL;
		g_autoptr(AsScreenshot) ss = NULL;
		g_autoptr(AsImage) image = NULL;

		if (g_strcmp0 (snapd_media_get_media_type (m), "screenshot") != 0)
			continue;

		/* skip screenshots used for banner when app is featured */
		url = snapd_media_get_url (m);
		filename = g_path_get_basename (url);
		if (is_banner_image (filename) || is_banner_icon_image (filename))
			continue;

		ss = as_screenshot_new ();
		as_screenshot_set_kind (ss, AS_SCREENSHOT_KIND_NORMAL);
		image = as_image_new ();
		as_image_set_url (image, snapd_media_get_url (m));
		as_image_set_kind (image, AS_IMAGE_KIND_SOURCE);
		as_image_set_width (image, snapd_media_get_width (m));
		as_image_set_height (image, snapd_media_get_height (m));
		as_screenshot_add_image (ss, image);
		gs_app_add_screenshot (app, ss);
	}

	if (gs_app_get_screenshots (app)->len > 0)
		return;

	/* fallback to old screenshots data */
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
	screenshots = snapd_snap_get_screenshots (snap);
G_GNUC_END_IGNORE_DEPRECATIONS
	for (i = 0; i < screenshots->len; i++) {
		SnapdScreenshot *screenshot = screenshots->pdata[i];
		const gchar *url;
		g_autofree gchar *filename = NULL;
		g_autoptr(AsScreenshot) ss = NULL;
		g_autoptr(AsImage) image = NULL;

		/* skip screenshots used for banner when app is featured */
		url = snapd_screenshot_get_url (screenshot);
		filename = g_path_get_basename (url);
		if (is_banner_image (filename) || is_banner_icon_image (filename))
			continue;

		ss = as_screenshot_new ();
		as_screenshot_set_kind (ss, AS_SCREENSHOT_KIND_NORMAL);
		image = as_image_new ();
		as_image_set_url (image, snapd_screenshot_get_url (screenshot));
		as_image_set_kind (image, AS_IMAGE_KIND_SOURCE);
		as_image_set_width (image, snapd_screenshot_get_width (screenshot));
		as_image_set_height (image, snapd_screenshot_get_height (screenshot));
		as_screenshot_add_image (ss, image);
		gs_app_add_screenshot (app, ss);
	}
}
/**
 * as_screenshot_node_parse:
 * @screenshot: a #AsScreenshot 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_screenshot_node_parse (AsScreenshot *screenshot, GNode *node,
			  AsNodeContext *ctx, GError **error)
{
	AsScreenshotPrivate *priv = GET_PRIVATE (screenshot);
	GList *l;
	GNode *c;
	const gchar *tmp;
	guint size;
	gint priority;
	g_autoptr(GHashTable) captions = NULL;

	tmp = as_node_get_attribute (node, "type");
	if (tmp != NULL) {
		as_screenshot_set_kind (screenshot,
					as_screenshot_kind_from_string (tmp));
	}
	priority = as_node_get_attribute_as_int (node, "priority");
	if (priority != G_MAXINT)
		as_screenshot_set_priority (screenshot, priority);

	/* add captions */
	captions = as_node_get_localized (node, "caption");
	if (captions != NULL) {
		g_autoptr(GList) keys = NULL;
		keys = g_hash_table_get_keys (captions);
		for (l = keys; l != NULL; l = l->next) {
			tmp = l->data;
			as_screenshot_set_caption (screenshot,
						   tmp,
						   g_hash_table_lookup (captions, tmp));
		}
	}

	/* AppData files does not have <image> tags */
	tmp = as_node_get_data (node);
	if (tmp != NULL) {
		AsImage *image;
		image = as_image_new ();
		as_image_set_kind (image, AS_IMAGE_KIND_SOURCE);
		size = as_node_get_attribute_as_uint (node, "width");
		if (size != G_MAXINT)
			as_image_set_width (image, size);
		size = as_node_get_attribute_as_uint (node, "height");
		if (size != G_MAXINT)
			as_image_set_height (image, size);
		as_image_set_url (image, tmp);
		g_ptr_array_add (priv->images, image);
	}

	/* add images */
	for (c = node->children; c != NULL; c = c->next) {
		g_autoptr(AsImage) image = NULL;
		if (as_node_get_tag (c) != AS_TAG_IMAGE)
			continue;
		image = as_image_new ();
		if (!as_image_node_parse (image, c, ctx, error))
			return FALSE;
		g_ptr_array_add (priv->images, g_object_ref (image));
	}
	return TRUE;
}