From 9f274a18bfb090e6ae93e156352c448f2e5c7005 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Sat, 14 May 2022 12:36:08 -0700 Subject: [PATCH] HumbleButton: move show_stripe_dialog here --- .../AppContainers/AbstractAppContainer.vala | 27 +--------------- src/Widgets/HumbleButton.vala | 32 +++++++++++++++++-- 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/src/Widgets/AppContainers/AbstractAppContainer.vala b/src/Widgets/AppContainers/AbstractAppContainer.vala index 6c94aed61..9b9bd2563 100644 --- a/src/Widgets/AppContainers/AbstractAppContainer.vala +++ b/src/Widgets/AppContainers/AbstractAppContainer.vala @@ -48,7 +48,7 @@ namespace AppCenter { protected bool updates_view = false; construct { - action_button = new Widgets.HumbleButton (); + action_button = new Widgets.HumbleButton (package); action_button_revealer = new Gtk.Revealer (); action_button_revealer.transition_type = Gtk.RevealerTransitionType.SLIDE_LEFT; @@ -58,10 +58,6 @@ namespace AppCenter { action_clicked.begin (); }); - action_button.payment_requested.connect ((amount) => { - show_stripe_dialog (amount); - }); - uninstall_button = new Gtk.Button.with_label (_("Uninstall")) { margin_end = 12 }; @@ -163,27 +159,6 @@ namespace AppCenter { } } - private void show_stripe_dialog (int amount) { - var stripe = new Widgets.StripeDialog ( - amount, - package.get_name (), - package.normalized_component_id, - package.get_payments_key () - ); - - stripe.transient_for = (Gtk.Window) get_toplevel (); - - stripe.download_requested.connect (() => { - action_clicked.begin (); - - if (stripe.amount != 0) { - App.add_paid_app (package.component.get_id ()); - } - }); - - stripe.show (); - } - protected virtual void set_up_package () { package.notify["state"].connect (on_package_state_changed); diff --git a/src/Widgets/HumbleButton.vala b/src/Widgets/HumbleButton.vala index 32589210b..1a37828c1 100644 --- a/src/Widgets/HumbleButton.vala +++ b/src/Widgets/HumbleButton.vala @@ -1,5 +1,5 @@ /* -* Copyright (c) 2016–2018 elementary, Inc. (https://elementary.io) +* Copyright 2016–2022 elementary, Inc. (https://elementary.io) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public @@ -19,7 +19,8 @@ public class AppCenter.Widgets.HumbleButton : Gtk.Button { public signal void download_requested (); - public signal void payment_requested (int amount); + + public AppCenterCore.Package package { get; construct; } private int _amount = 1; public int amount { @@ -68,6 +69,10 @@ public class AppCenter.Widgets.HumbleButton : Gtk.Button { } } + public HumbleButton (AppCenterCore.Package package) { + Object (package: package); + } + construct { hexpand = true; @@ -79,13 +84,34 @@ public class AppCenter.Widgets.HumbleButton : Gtk.Button { clicked.connect (() => { if (amount != 0) { - payment_requested (amount); + show_stripe_dialog (); } else { download_requested (); } }); } + private void show_stripe_dialog () { + var stripe_dialog = new Widgets.StripeDialog ( + amount, + package.get_name (), + package.normalized_component_id, + package.get_payments_key () + ) { + transient_for = (Gtk.Window) get_toplevel () + }; + + stripe_dialog.download_requested.connect (() => { + download_requested (); + + if (stripe_dialog.amount != 0) { + App.add_paid_app (package.component.get_id ()); + } + }); + + stripe_dialog.show (); + } + public static string get_amount_formatted (int _amount, bool with_short_part = true) { if (with_short_part) { /// This amount will be US Dollars. Some languages might need a "$%dUSD"