[gnome-software/wip/rancell/paid] Show purchase confirmation dialog
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/rancell/paid] Show purchase confirmation dialog
- Date: Fri, 6 May 2016 04:34:53 +0000 (UTC)
commit 2101825b9a9a84fe93b037e9fb8ae86ba25ea4ad
Author: Robert Ancell <robert ancell canonical com>
Date: Fri May 6 16:34:44 2016 +1200
Show purchase confirmation dialog
src/gs-page.c | 77 ++++++++++++++++++++++++++++++++++++++++++++------------
1 files changed, 60 insertions(+), 17 deletions(-)
---
diff --git a/src/gs-page.c b/src/gs-page.c
index 1051051..a6af722 100644
--- a/src/gs-page.c
+++ b/src/gs-page.c
@@ -28,6 +28,7 @@
#include "gs-page.h"
#include "gs-shell.h"
#include "gs-utils.h"
+#include "gs-price.h"
typedef struct
{
@@ -58,9 +59,9 @@ gs_page_helper_free (GsPageHelper *helper)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GsPageHelper, gs_page_helper_free);
static void
-gs_page_app_bought_cb (GObject *source,
- GAsyncResult *res,
- gpointer user_data)
+gs_page_app_purchased_cb (GObject *source,
+ GAsyncResult *res,
+ gpointer user_data)
{
g_autoptr(GsPageHelper) helper = (GsPageHelper *) user_data;
GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source);
@@ -215,29 +216,71 @@ gs_page_set_header_end_widget (GsPage *page, GtkWidget *widget)
g_set_object (&priv->header_end_widget, widget);
}
+static void
+gs_page_purchase_app_response_cb (GtkDialog *dialog,
+ gint response,
+ GsPageHelper *helper)
+{
+ GsPagePrivate *priv = gs_page_get_instance_private (helper->page);
+
+ /* not agreed */
+ if (response != GTK_RESPONSE_OK) {
+ gs_page_helper_free (helper);
+ return;
+ }
+ g_debug ("purchase %s", gs_app_get_id (helper->app));
+ gs_plugin_loader_app_action_async (priv->plugin_loader,
+ helper->app,
+ GS_PLUGIN_LOADER_ACTION_PURCHASE,
+ priv->cancellable,
+ gs_page_app_purchased_cb,
+ helper);
+}
+
void
gs_page_purchase_app (GsPage *page, GsApp *app)
{
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;
- }
+ GtkWidget *dialog;
+ GPtrArray *prices;
+ g_autofree gchar *price_text = NULL, *escaped = NULL;
helper = g_slice_new0 (GsPageHelper);
helper->app = g_object_ref (app);
helper->page = g_object_ref (page);
- gs_plugin_loader_app_action_async (priv->plugin_loader,
- app,
- GS_PLUGIN_LOADER_ACTION_PURCHASE,
- priv->cancellable,
- gs_page_app_bought_cb,
- helper);
+
+ /* ask for confirmation */
+ dialog = gtk_message_dialog_new (gs_shell_get_window (priv->shell),
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_QUESTION,
+ GTK_BUTTONS_CANCEL,
+ /* TRANSLATORS: this is a prompt message, and
+ * '%s' is an application summary, e.g. 'GNOME Clocks' */
+ _("Are you sure you want to purchase %s?"),
+ gs_app_get_name (app));
+ prices = gs_app_get_prices (app);
+ if (prices->len > 0) {
+ GsPrice *price = g_ptr_array_index (prices, 0); // FIXME: Give option of price to choose
+ g_autofree gchar *text = NULL;
+ price_text = gs_price_to_string (price);
+ } else {
+ price_text = g_strdup ("nothing"); // FIXME
+ }
+ escaped = g_markup_escape_text (gs_app_get_name (app), -1);
+ gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (dialog),
+ /* TRANSLATORS: longer dialog text */
+ _("You will be charged %s and %s will be installed."),
+ price_text,
+ escaped);
+
+ /* 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_purchase_app_response_cb), helper);
+ gs_shell_modal_dialog_present (priv->shell, GTK_DIALOG (dialog));
}
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]