2 * Copyright (C) 2014 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 import Ubuntu.Components 1.3
19 import Ubuntu.Payments 0.1
21 /*! \brief Preview widget for a purchase button.
23 * When clicked, this button starts the payments service.
24 * Then it waits until the purchase finishes or fails.
25 * Those events trigger the corresponding actions.
31 implicitHeight: paymentButton.implicitHeight
32 implicitWidth: paymentButton.implicitWidth
36 objectName: "paymentButton"
38 color: UbuntuColors.orange
39 text: paymentClient.formattedPrice
41 paymentClient.start();
42 paymentButton.opacity = 0;
44 anchors.right: parent.right
45 width: (root.width - units.gu(1)) / 2
47 visible: paymentButton.opacity == 0 ? false : true
48 Behavior on opacity { PropertyAnimation { duration: UbuntuAnimation.FastDuration } }
52 objectName: "paymentClient"
54 property var source: widgetData["source"]
56 price: source["price"]
57 currency: source["currency"]
58 storeItemId: source["store_item_id"]
59 onPurchaseCompleted: {
60 root.triggered(widgetId, "purchaseCompleted", source);
63 paymentButton.opacity = 1;
64 root.triggered(widgetId, "purchaseError", source);
66 onPurchaseCancelled: {
67 paymentButton.opacity = 1;
68 // DO NOT emit the signal right now, as it causes a new
69 // preview to be requested, when that is not what we want.
70 //root.triggered(widgetId, "purchaseCancelled", source);
77 objectName: "loadingBar"
79 anchors.fill: paymentButton
80 opacity: 1 - paymentButton.opacity
81 visible: !paymentButton.visible