/**
 * as_screenshot_equal:
 * @screenshot1: a #AsScreenshot instance.
 * @screenshot2: a #AsScreenshot instance.
 *
 * Checks if two screenshots are the same.
 *
 * Returns: %TRUE for success
 *
 * Since: 0.5.7
 **/
gboolean
as_screenshot_equal (AsScreenshot *screenshot1, AsScreenshot *screenshot2)
{
	AsScreenshotPrivate *priv1 = GET_PRIVATE (screenshot1);
	AsScreenshotPrivate *priv2 = GET_PRIVATE (screenshot2);
	AsImage *im1;
	AsImage *im2;

	/* trivial */
	if (screenshot1 == screenshot2)
		return TRUE;

	/* check for equality */
	if (priv1->priority != priv2->priority)
		return FALSE;
	if (priv1->images->len != priv2->images->len)
		return FALSE;
	if (g_strcmp0 (as_screenshot_get_caption (screenshot1, NULL),
		       as_screenshot_get_caption (screenshot2, NULL)) != 0)
		return FALSE;

	/* check source images */
	im1 = as_screenshot_get_source (screenshot1);
	im2 = as_screenshot_get_source (screenshot2);
	if (im1 != NULL && im2 != NULL) {
		if (!as_image_equal (im1, im2))
			return FALSE;
	}

	/* success */
	return TRUE;
}
Example #2
0
void
gs_page_update_app (GsPage *page, GsApp *app, GCancellable *cancellable)
{
	GsPagePrivate *priv = gs_page_get_instance_private (page);
	GsPageHelper *helper;

	/* non-firmware applications do not have to be prepared */
	helper = g_slice_new0 (GsPageHelper);
	helper->action = GS_PLUGIN_ACTION_UPDATE;
	helper->app = g_object_ref (app);
	helper->page = g_object_ref (page);
	helper->cancellable = g_object_ref (cancellable);

	/* tell the user what they have to do */
	if (gs_app_get_kind (app) == AS_APP_KIND_FIRMWARE &&
	    gs_app_has_quirk (app, AS_APP_QUIRK_NEEDS_USER_ACTION)) {
		GPtrArray *screenshots = gs_app_get_screenshots (app);
		if (screenshots->len > 0) {
			AsScreenshot *ss = g_ptr_array_index (screenshots, 0);
			if (as_screenshot_get_caption (ss, NULL) != NULL) {
				gs_page_needs_user_action (helper, ss);
				return;
			}
		}
	}

	/* generic fallback */
	gs_plugin_loader_app_action_async (priv->plugin_loader,
					   helper->app,
					   helper->action,
					   GS_PLUGIN_FAILURE_FLAGS_FATAL_ANY,
					   helper->cancellable,
					   gs_page_app_installed_cb,
					   helper);
}
Example #3
0
static void
gs_page_needs_user_action (GsPageHelper *helper, AsScreenshot *ss)
{
	GtkWidget *content_area;
	GtkWidget *dialog;
	GtkWidget *ssimg;
	g_autofree gchar *escaped = NULL;
	GsPagePrivate *priv = gs_page_get_instance_private (helper->page);

	dialog = gtk_message_dialog_new (gs_shell_get_window (priv->shell),
					 GTK_DIALOG_MODAL |
					 GTK_DIALOG_USE_HEADER_BAR,
					 GTK_MESSAGE_INFO,
					 GTK_BUTTONS_CANCEL,
					 /* TRANSLATORS: this is a prompt message, and
					  * '%s' is an application summary, e.g. 'GNOME Clocks' */
					 _("Prepare %s"),
					 gs_app_get_name (helper->app));
	escaped = g_markup_escape_text (as_screenshot_get_caption (ss, NULL), -1);
	gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (dialog),
						    "%s", escaped);

	/* this will be enabled when the device is in the right mode */
	helper->button_install = gtk_dialog_add_button (GTK_DIALOG (dialog),
							/* TRANSLATORS: update the fw */
							_("Install"),
							GTK_RESPONSE_OK);
	helper->notify_quirk_id =
		g_signal_connect (helper->app, "notify::quirk",
				  G_CALLBACK (gs_page_notify_quirk_cb),
				  helper);
	gtk_widget_set_sensitive (helper->button_install, FALSE);

	/* load screenshot */
	helper->soup_session = soup_session_new_with_options (SOUP_SESSION_USER_AGENT,
							      gs_user_agent (), NULL);
	ssimg = gs_screenshot_image_new (helper->soup_session);
	gs_screenshot_image_set_screenshot (GS_SCREENSHOT_IMAGE (ssimg), ss);
	gs_screenshot_image_set_size (GS_SCREENSHOT_IMAGE (ssimg), 400, 225);
	gs_screenshot_image_load_async (GS_SCREENSHOT_IMAGE (ssimg),
					helper->cancellable);
	gtk_widget_set_margin_start (ssimg, 24);
	gtk_widget_set_margin_end (ssimg, 24);
	content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
	gtk_container_add (GTK_CONTAINER (content_area), ssimg);
	gtk_container_child_set (GTK_CONTAINER (content_area), ssimg, "pack-type", GTK_PACK_END, NULL);

	/* handle this async */
	g_signal_connect (dialog, "response",
			  G_CALLBACK (gs_page_update_app_response_cb), helper);
	gs_shell_modal_dialog_present (priv->shell, GTK_DIALOG (dialog));
}
Example #4
0
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);
		}
	}
}