Пример #1
0
void
gs_page_install_app (GsPage *page,
		     GsApp *app,
		     GsShellInteraction interaction,
		     GCancellable *cancellable)
{
	GsPagePrivate *priv = gs_page_get_instance_private (page);
	GsPageHelper *helper;
	GtkResponseType response;

	/* probably non-free */
	if (gs_app_get_state (app) == AS_APP_STATE_UNAVAILABLE) {
		response = gs_app_notify_unavailable (app, gs_shell_get_window (priv->shell));
		if (response != GTK_RESPONSE_OK)
			return;
	}

	helper = g_slice_new0 (GsPageHelper);
	helper->action = GS_PLUGIN_ACTION_INSTALL;
	helper->app = g_object_ref (app);
	helper->page = g_object_ref (page);
	helper->cancellable = g_object_ref (cancellable);
	helper->interaction = interaction;
	gs_plugin_loader_app_action_async (priv->plugin_loader,
	                                   app,
	                                   helper->action,
	                                   GS_PLUGIN_FAILURE_FLAGS_FATAL_ANY,
	                                   helper->cancellable,
	                                   gs_page_app_installed_cb,
	                                   helper);
}
Пример #2
0
void
gs_page_install_app (GsPage *page,
		     GsApp *app,
		     GsShellInteraction interaction,
		     GCancellable *cancellable)
{
	GsPagePrivate *priv = gs_page_get_instance_private (page);
	GsPageHelper *helper;

	/* probably non-free */
	if (gs_app_get_state (app) == AS_APP_STATE_UNAVAILABLE) {
		GtkResponseType response;

		response = gs_app_notify_unavailable (app, gs_shell_get_window (priv->shell));
		if (response != GTK_RESPONSE_OK)
			return;
	}

	helper = g_slice_new0 (GsPageHelper);
	helper->action = GS_PLUGIN_ACTION_INSTALL;
	helper->app = g_object_ref (app);
	helper->page = g_object_ref (page);
	helper->cancellable = g_object_ref (cancellable);
	helper->interaction = interaction;

	/* need to purchase first */
	if (gs_app_get_state (app) == AS_APP_STATE_PURCHASABLE) {
		GtkWidget *dialog;
		g_autofree gchar *title = NULL;
		g_autofree gchar *message = NULL;
		g_autofree gchar *price_text = NULL;

		/* TRANSLATORS: this is a prompt message, and '%s' is an
		 * application summary, e.g. 'GNOME Clocks' */
		title = g_strdup_printf (_("Are you sure you want to purchase %s?"),
					 gs_app_get_name (app));
		price_text = gs_price_to_string (gs_app_get_price (app));
		/* TRANSLATORS: longer dialog text */
		message = g_strdup_printf (_("%s will be installed, and you will "
					     "be charged %s."),
					   gs_app_get_name (app), price_text);

		dialog = gtk_message_dialog_new (gs_shell_get_window (priv->shell),
						 GTK_DIALOG_MODAL,
						 GTK_MESSAGE_QUESTION,
						 GTK_BUTTONS_CANCEL,
						 "%s", title);
		gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
							  "%s", message);

		/* TRANSLATORS: this is button text to purchase the application */
		gtk_dialog_add_button (GTK_DIALOG (dialog), _("Purchase"), GTK_RESPONSE_OK);

		/* handle this async */
		g_signal_connect (dialog, "response",
				  G_CALLBACK (gs_page_install_purchase_response_cb), helper);
		gs_shell_modal_dialog_present (priv->shell, GTK_DIALOG (dialog));
	} else {
		g_autoptr(GsPluginJob) plugin_job = NULL;

		plugin_job = gs_plugin_job_newv (helper->action,
						 "interactive", TRUE,
						 "app", helper->app,
						 NULL);
		gs_plugin_loader_job_process_async (priv->plugin_loader,
						    plugin_job,
						    helper->cancellable,
						    gs_page_app_installed_cb,
						    helper);
	}
}