/** * as_review_set_version: * @review: a #AsReview * @version: a version string, e.g. "0.1.2" * * Sets the version string for the application being reviewed. * * Since: 0.6.1 **/ void as_review_set_version (AsReview *review, const gchar *version) { AsReviewPrivate *priv = GET_PRIVATE (review); g_return_if_fail (AS_IS_REVIEW (review)); as_ref_string_assign_safe (&priv->version, version); }
/** * as_review_set_summary: * @review: a #AsReview * @summary: a one-line summary, e.g. "Awesome application" * * Sets the one-line summary that may be displayed in bold. * * Since: 0.6.1 **/ void as_review_set_summary (AsReview *review, const gchar *summary) { AsReviewPrivate *priv = GET_PRIVATE (review); g_return_if_fail (AS_IS_REVIEW (review)); as_ref_string_assign_safe (&priv->summary, summary); }
/** * as_review_set_reviewer_name: * @review: a #AsReview * @reviewer_name: the reviewer name, e.g. "David Smith" * * Sets the name of the reviewer, which can be left unset. * * Since: 0.6.1 **/ void as_review_set_reviewer_name (AsReview *review, const gchar *reviewer_name) { AsReviewPrivate *priv = GET_PRIVATE (review); g_return_if_fail (AS_IS_REVIEW (review)); as_ref_string_assign_safe (&priv->reviewer_name, reviewer_name); }
/** * as_content_rating_set_kind: * @content_rating: a #AsContentRating instance. * @kind: the rating kind, e.g. "oars-1.0" * * Sets the content rating kind. * * Since: 0.5.12 **/ void as_content_rating_set_kind (AsContentRating *content_rating, const gchar *kind) { AsContentRatingPrivate *priv = GET_PRIVATE (content_rating); g_return_if_fail (AS_IS_CONTENT_RATING (content_rating)); as_ref_string_assign_safe (&priv->kind, kind); }
/** * as_review_set_id: * @review: a #AsReview * @id: review identifier, e.g. "deadbeef" * * Sets the review identifier that is unique to each review. * * Since: 0.6.1 **/ void as_review_set_id (AsReview *review, const gchar *id) { AsReviewPrivate *priv = GET_PRIVATE (review); g_return_if_fail (AS_IS_REVIEW (review)); as_ref_string_assign_safe (&priv->id, id); }
/** * as_image_set_pixbuf: * @image: a #AsImage instance. * @pixbuf: the #GdkPixbuf, or %NULL * * Sets the image pixbuf. * * Since: 0.1.6 **/ void as_image_set_pixbuf (AsImage *image, GdkPixbuf *pixbuf) { AsImagePrivate *priv = GET_PRIVATE (image); guchar *data; guint len; g_set_object (&priv->pixbuf, pixbuf); if (pixbuf == NULL) return; if (priv->md5 == NULL) { g_autofree gchar *md5_tmp = NULL; data = gdk_pixbuf_get_pixels_with_length (pixbuf, &len); md5_tmp = g_compute_checksum_for_data (G_CHECKSUM_MD5, data, len); as_ref_string_assign_safe (&priv->md5, md5_tmp); } priv->width = (guint) gdk_pixbuf_get_width (pixbuf); priv->height = (guint) gdk_pixbuf_get_height (pixbuf); }
/** * as_content_rating_set_kind: * @content_rating: a #AsContentRating instance. * @kind: the rating kind, e.g. "oars-1.0" * * Sets the content rating kind. * * Since: 0.5.12 **/ void as_content_rating_set_kind (AsContentRating *content_rating, const gchar *kind) { AsContentRatingPrivate *priv = GET_PRIVATE (content_rating); as_ref_string_assign_safe (&priv->kind, kind); }
/** * as_provide_set_value: * @provide: a #AsProvide instance. * @value: the URL. * * Sets the fully-qualified mirror URL to use for the provide. * * Since: 0.1.6 **/ void as_provide_set_value (AsProvide *provide, const gchar *value) { AsProvidePrivate *priv = GET_PRIVATE (provide); as_ref_string_assign_safe (&priv->value, value); }
/** * as_image_load_filename_full: * @image: a #AsImage instance. * @filename: filename to read from * @dest_size: The size of the constructed pixbuf, or 0 for the native size * @src_size_min: The smallest source size allowed, or 0 for none * @flags: a #AsImageLoadFlags, e.g. %AS_IMAGE_LOAD_FLAG_NONE * @error: A #GError or %NULL. * * Reads an image from a file. * * Returns: %TRUE for success * * Since: 0.5.6 **/ gboolean as_image_load_filename_full (AsImage *image, const gchar *filename, guint dest_size, guint src_size_min, AsImageLoadFlags flags, GError **error) { AsImagePrivate *priv = GET_PRIVATE (image); guint pixbuf_height; guint pixbuf_width; guint tmp_height; guint tmp_width; g_autoptr(GdkPixbuf) pixbuf = NULL; g_autoptr(GdkPixbuf) pixbuf_src = NULL; g_autoptr(GdkPixbuf) pixbuf_tmp = NULL; /* only support non-deprecated types */ if (flags & AS_IMAGE_LOAD_FLAG_ONLY_SUPPORTED) { GdkPixbufFormat *fmt; fmt = gdk_pixbuf_get_file_info (filename, NULL, NULL); if (fmt == NULL) { g_set_error_literal (error, AS_UTILS_ERROR, AS_UTILS_ERROR_FAILED, "image format was not recognized"); return FALSE; } if (g_strcmp0 (gdk_pixbuf_format_get_name (fmt), "png") != 0 && g_strcmp0 (gdk_pixbuf_format_get_name (fmt), "jpeg") != 0 && g_strcmp0 (gdk_pixbuf_format_get_name (fmt), "xpm") != 0 && g_strcmp0 (gdk_pixbuf_format_get_name (fmt), "svg") != 0) { g_set_error (error, AS_UTILS_ERROR, AS_UTILS_ERROR_FAILED, "image format %s is not supported", gdk_pixbuf_format_get_name (fmt)); return FALSE; } } /* update basename */ if (flags & AS_IMAGE_LOAD_FLAG_SET_BASENAME) { g_autofree gchar *basename = NULL; basename = g_path_get_basename (filename); as_image_set_basename (image, basename); } /* update checksum */ if (flags & AS_IMAGE_LOAD_FLAG_SET_CHECKSUM) { gsize len; g_autofree gchar *data = NULL; g_autofree gchar *md5_tmp = NULL; /* get the contents so we can hash the predictable file data, * rather than the unpredicatable (for JPEG) pixel data */ if (!g_file_get_contents (filename, &data, &len, error)) return FALSE; md5_tmp = g_compute_checksum_for_data (G_CHECKSUM_MD5, (guchar * )data, len); as_ref_string_assign_safe (&priv->md5, md5_tmp); } /* load the image of the native size */ if (dest_size == 0) { pixbuf = gdk_pixbuf_new_from_file (filename, error); if (pixbuf == NULL) return FALSE; as_image_set_pixbuf (image, pixbuf); return TRUE; } /* open file in native size */ if (g_str_has_suffix (filename, ".svg")) { pixbuf_src = gdk_pixbuf_new_from_file_at_scale (filename, (gint) dest_size, (gint) dest_size, TRUE, error); } else { pixbuf_src = gdk_pixbuf_new_from_file (filename, error); } if (pixbuf_src == NULL) return FALSE; /* check size */ if (gdk_pixbuf_get_width (pixbuf_src) < (gint) src_size_min && gdk_pixbuf_get_height (pixbuf_src) < (gint) src_size_min) { g_set_error (error, AS_UTILS_ERROR, AS_UTILS_ERROR_FAILED, "icon was too small %ix%i", gdk_pixbuf_get_width (pixbuf_src), gdk_pixbuf_get_height (pixbuf_src)); return FALSE; } /* don't do anything to an icon with the perfect size */ pixbuf_width = (guint) gdk_pixbuf_get_width (pixbuf_src); pixbuf_height = (guint) gdk_pixbuf_get_height (pixbuf_src); if (pixbuf_width == dest_size && pixbuf_height == dest_size) { as_image_set_pixbuf (image, pixbuf_src); return TRUE; } /* never scale up, just pad */ if (pixbuf_width < dest_size && pixbuf_height < dest_size) { g_debug ("icon padded to %ux%u as size %ux%u", dest_size, dest_size, pixbuf_width, pixbuf_height); pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, (gint) dest_size, (gint) dest_size); gdk_pixbuf_fill (pixbuf, 0x00000000); gdk_pixbuf_copy_area (pixbuf_src, 0, 0, /* of src */ (gint) pixbuf_width, (gint) pixbuf_height, pixbuf, (gint) (dest_size - pixbuf_width) / 2, (gint) (dest_size - pixbuf_height) / 2); as_image_set_pixbuf (image, pixbuf); return TRUE; } /* is the aspect ratio perfectly square */ if (pixbuf_width == pixbuf_height) { pixbuf = gdk_pixbuf_scale_simple (pixbuf_src, (gint) dest_size, (gint) dest_size, GDK_INTERP_HYPER); as_image_set_pixbuf (image, pixbuf); return TRUE; } /* create new square pixbuf with alpha padding */ pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, (gint) dest_size, (gint) dest_size); gdk_pixbuf_fill (pixbuf, 0x00000000); if (pixbuf_width > pixbuf_height) { tmp_width = dest_size; tmp_height = dest_size * pixbuf_height / pixbuf_width; } else { tmp_width = dest_size * pixbuf_width / pixbuf_height; tmp_height = dest_size; } pixbuf_tmp = gdk_pixbuf_scale_simple (pixbuf_src, (gint) tmp_width, (gint) tmp_height, GDK_INTERP_HYPER); if (flags & AS_IMAGE_LOAD_FLAG_SHARPEN) as_pixbuf_sharpen (pixbuf_tmp, 1, -0.5); gdk_pixbuf_copy_area (pixbuf_tmp, 0, 0, /* of src */ (gint) tmp_width, (gint) tmp_height, pixbuf, (gint) (dest_size - tmp_width) / 2, (gint) (dest_size - tmp_height) / 2); as_image_set_pixbuf (image, pixbuf); return TRUE; }
/** * as_image_set_locale: * @image: a #AsImage instance. * @locale: the new image locale, e.g. "en_GB" or %NULL. * * Sets the image locale. * * Since: 0.5.14 **/ void as_image_set_locale (AsImage *image, const gchar *locale) { AsImagePrivate *priv = GET_PRIVATE (image); as_ref_string_assign_safe (&priv->locale, locale); }
/** * as_image_set_basename: * @image: a #AsImage instance. * @basename: the new filename basename. * * Sets the image basename filename. * * Since: 0.1.6 **/ void as_image_set_basename (AsImage *image, const gchar *basename) { AsImagePrivate *priv = GET_PRIVATE (image); as_ref_string_assign_safe (&priv->basename, basename); }
/** * as_image_set_url: * @image: a #AsImage instance. * @url: the URL. * * Sets the fully-qualified mirror URL to use for the image. * * Since: 0.1.0 **/ void as_image_set_url (AsImage *image, const gchar *url) { AsImagePrivate *priv = GET_PRIVATE (image); as_ref_string_assign_safe (&priv->url, url); }