[gnome-software/wip/ubuntu-3-26: 14/14] snap: Make snaps purchasable
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/ubuntu-3-26: 14/14] snap: Make snaps purchasable
- Date: Wed, 24 Jan 2018 03:57:14 +0000 (UTC)
commit 23a35cd3121b6239acbf8a7cf63534ff72e14a7d
Author: Robert Ancell <robert ancell canonical com>
Date: Wed Jan 24 15:53:56 2018 +1300
snap: Make snaps purchasable
plugins/snap/gs-plugin-snap.c | 46 ++++++++++++++++++++++++++++++++++++++--
1 files changed, 43 insertions(+), 3 deletions(-)
---
diff --git a/plugins/snap/gs-plugin-snap.c b/plugins/snap/gs-plugin-snap.c
index faeec24..919b4ba 100644
--- a/plugins/snap/gs-plugin-snap.c
+++ b/plugins/snap/gs-plugin-snap.c
@@ -708,6 +708,8 @@ gs_plugin_refine_app (GsPlugin *plugin,
const gchar *name;
if (gs_app_get_state (app) == AS_APP_STATE_UNKNOWN)
gs_app_set_state (app, AS_APP_STATE_INSTALLED);
+
+ gs_app_set_metadata (app, "snap::id", snapd_snap_get_id (local_snap));
name = snapd_snap_get_title (local_snap);
if (name == NULL || g_strcmp0 (name, "") == 0)
name = snapd_snap_get_name (local_snap);
@@ -728,12 +730,23 @@ gs_plugin_refine_app (GsPlugin *plugin,
/* get information from snap store */
store_snap = get_store_snap (plugin, id, cancellable, NULL);
if (store_snap != NULL) {
- GPtrArray *screenshots;
+ GPtrArray *prices, *screenshots;
const gchar *name;
- if (gs_app_get_state (app) == AS_APP_STATE_UNKNOWN)
- gs_app_set_state (app, AS_APP_STATE_AVAILABLE);
+ prices = snapd_snap_get_prices (store_snap);
+ if (prices->len > 0) {
+ SnapdPrice *price = prices->pdata[0];
+ gs_app_set_price (app, snapd_price_get_amount (price), snapd_price_get_currency
(price));
+ }
+ if (gs_app_get_state (app) == AS_APP_STATE_UNKNOWN) {
+ if (gs_app_get_price (app) != NULL)
+ gs_app_set_state (app, AS_APP_STATE_PURCHASABLE);
+ else
+ gs_app_set_state (app, AS_APP_STATE_AVAILABLE);
+ }
+
+ gs_app_set_metadata (app, "snap::id", snapd_snap_get_id (store_snap));
name = snapd_snap_get_title (store_snap);
if (name == NULL || g_strcmp0 (name, "") == 0)
name = snapd_snap_get_name (store_snap);
@@ -792,6 +805,33 @@ gs_plugin_refine_app (GsPlugin *plugin,
return TRUE;
}
+gboolean
+gs_plugin_app_purchase (GsPlugin *plugin,
+ GsApp *app,
+ GsPrice *price,
+ GCancellable *cancellable,
+ GError **error)
+{
+ g_autoptr(SnapdClient) client = NULL;
+ const gchar *id;
+
+ /* We can only purchase apps we know of */
+ if (g_strcmp0 (gs_app_get_management_plugin (app), "snap") != 0)
+ return TRUE;
+
+ client = get_client (plugin, error);
+ if (client == NULL)
+ return FALSE;
+
+ id = gs_app_get_metadata_item (app, "snap::id");
+ if (!snapd_client_buy_sync (client, id, gs_price_get_amount (price), gs_price_get_currency (price),
cancellable, error)) {
+ snapd_error_convert (error);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
static void
progress_cb (SnapdClient *client, SnapdChange *change, gpointer deprecated, gpointer user_data)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]