/** * gs_appstream_refine_add_screenshots: */ static void gs_appstream_refine_add_screenshots (GsApp *app, AsApp *item) { AsScreenshot *ss; GPtrArray *images_as; GPtrArray *screenshots_as; guint i; /* do we have any to add */ screenshots_as = as_app_get_screenshots (item); if (screenshots_as->len == 0) return; /* does the app already have some */ gs_app_add_kudo (app, GS_APP_KUDO_HAS_SCREENSHOTS); if (gs_app_get_screenshots(app)->len > 0) return; /* add any we know */ for (i = 0; i < screenshots_as->len && i < GS_APPSTREAM_MAX_SCREENSHOTS; i++) { ss = g_ptr_array_index (screenshots_as, i); images_as = as_screenshot_get_images (ss); if (images_as->len == 0) continue; if (as_screenshot_get_kind (ss) == AS_SCREENSHOT_KIND_UNKNOWN) continue; gs_app_add_screenshot (app, ss); } }
/** * as_app_validate_screenshot: **/ static void as_app_validate_screenshot (AsScreenshot *ss, AsAppValidateHelper *helper) { AsImage *im; GPtrArray *images; guint i; if (as_screenshot_get_kind (ss) == AS_SCREENSHOT_KIND_UNKNOWN) { ai_app_validate_add (helper->probs, AS_PROBLEM_KIND_ATTRIBUTE_INVALID, "<screenshot> has unknown type"); } images = as_screenshot_get_images (ss); for (i = 0; i < images->len; i++) { im = g_ptr_array_index (images, i); as_app_validate_image (im, helper); } }
static void as_app_validate_screenshot (AsScreenshot *ss, AsAppValidateHelper *helper) { AsImage *im; GPtrArray *images; const gchar *tmp; gboolean require_sentence_case = TRUE; guint i; guint length_caption_max = 50; guint length_caption_min = 10; guint str_len; /* relax the requirements a bit */ if ((helper->flags & AS_APP_VALIDATE_FLAG_RELAX) > 0) { length_caption_max = 100; length_caption_min = 5; require_sentence_case = FALSE; } if (as_screenshot_get_kind (ss) == AS_SCREENSHOT_KIND_UNKNOWN) { ai_app_validate_add (helper, AS_PROBLEM_KIND_ATTRIBUTE_INVALID, "<screenshot> has unknown type"); } images = as_screenshot_get_images (ss); for (i = 0; i < images->len; i++) { im = g_ptr_array_index (images, i); as_app_validate_image (im, helper); } tmp = as_screenshot_get_caption (ss, NULL); if (tmp != NULL) { str_len = (guint) strlen (tmp); if (str_len < length_caption_min) { ai_app_validate_add (helper, AS_PROBLEM_KIND_STYLE_INCORRECT, "<caption> is too short [%s];" "shortest allowed is %u chars", tmp, length_caption_min); } if (str_len > length_caption_max) { ai_app_validate_add (helper, AS_PROBLEM_KIND_STYLE_INCORRECT, "<caption> is too long [%s];" "longest allowed is %u chars", tmp, length_caption_max); } if (ai_app_validate_fullstop_ending (tmp)) { ai_app_validate_add (helper, AS_PROBLEM_KIND_STYLE_INCORRECT, "<caption> cannot end in '.' [%s]", tmp); } if (as_app_validate_has_hyperlink (tmp)) { ai_app_validate_add (helper, AS_PROBLEM_KIND_STYLE_INCORRECT, "<caption> cannot contain a hyperlink [%s]", tmp); } if (require_sentence_case && !as_app_validate_has_first_word_capital (helper, tmp)) { ai_app_validate_add (helper, AS_PROBLEM_KIND_STYLE_INCORRECT, "<caption> requires sentence case [%s]", tmp); } } }
static gboolean gs_screenshot_image_save_downloaded_img (GsScreenshotImage *ssimg, GdkPixbuf *pixbuf, GError **error) { g_autoptr(AsImage) im = NULL; gboolean ret; const GPtrArray *images; g_autoptr(GError) error_local = NULL; g_autofree char *filename = NULL; g_autofree char *size_dir = NULL; g_autofree char *cache_kind = NULL; g_autofree char *basename = NULL; guint width = ssimg->width; guint height = ssimg->height; /* save to file, using the same code as the AppStream builder * so the preview looks the same */ im = as_image_new (); as_image_set_pixbuf (im, pixbuf); ret = as_image_save_filename (im, ssimg->filename, ssimg->width * ssimg->scale, ssimg->height * ssimg->scale, AS_IMAGE_SAVE_FLAG_PAD_16_9, error); if (!ret) return FALSE; if (ssimg->screenshot == NULL) return TRUE; images = as_screenshot_get_images (ssimg->screenshot); if (images->len > 1) return TRUE; if (width == AS_IMAGE_THUMBNAIL_WIDTH && height == AS_IMAGE_THUMBNAIL_HEIGHT) { width = AS_IMAGE_NORMAL_WIDTH; height = AS_IMAGE_NORMAL_HEIGHT; } else { width = AS_IMAGE_THUMBNAIL_WIDTH; height = AS_IMAGE_THUMBNAIL_HEIGHT; } width *= ssimg->scale; height *= ssimg->scale; basename = g_path_get_basename (ssimg->filename); size_dir = g_strdup_printf ("%ux%u", width, height); cache_kind = g_build_filename ("screenshots", size_dir, NULL); filename = gs_utils_get_cache_filename (cache_kind, basename, GS_UTILS_CACHE_FLAG_WRITEABLE, &error_local); if (filename == NULL) { /* if we cannot get a cache filename, warn about that but do not * set a user's visible error because this is a complementary * operation */ g_warning ("Failed to get cache filename for counterpart " "screenshot '%s' in folder '%s': %s", basename, cache_kind, error_local->message); return TRUE; } ret = as_image_save_filename (im, filename, width, height, AS_IMAGE_SAVE_FLAG_PAD_16_9, &error_local); if (!ret) { /* if we cannot save this screenshot, warn about that but do not * set a user's visible error because this is a complementary * operation */ g_warning ("Failed to save screenshot '%s': %s", filename, error_local->message); } return TRUE; }