Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HumbleButton: move show_stripe_dialog here #1847

Merged
merged 3 commits into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 1 addition & 26 deletions src/Widgets/AppContainers/AbstractAppContainer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
};
Expand Down Expand Up @@ -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);

Expand Down
32 changes: 29 additions & 3 deletions src/Widgets/HumbleButton.vala
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -68,6 +69,10 @@ public class AppCenter.Widgets.HumbleButton : Gtk.Button {
}
}

public HumbleButton (AppCenterCore.Package package) {
Object (package: package);
}

construct {
hexpand = true;

Expand All @@ -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"
Expand Down