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/>.
21#include <libpay/pay-package.h>
24// The observer callback for the package we are watching.
25static void observer(PayPackage* /* package */, const char* itemid, PayPackageItemStatus status, void* user_data) {
26 // This function is called in libpay's thread, so be careful what you call
27 // Emitting signals should be fine as long as they use Queued or Auto
28 // connections (the default)
29 // http://qt-project.org/doc/qt-5/threads-qobject.html#signals-and-slots-across-threads
31 Payments *self = static_cast<Payments*>(user_data);
33 // If the item ID is different, ignore it.
34 if (itemid != self->storeItemId()) {
38 // FIXME: No error reporting from libpay, but we need to show some
39 // types of errors to the user. https://launchpad.net/bugs/1333403
41 case PAY_PACKAGE_ITEM_STATUS_PURCHASED:
42 Q_EMIT self->purchaseCompleted();
44 case PAY_PACKAGE_ITEM_STATUS_PURCHASING:
45 self->setPurchasing(true);
47 case PAY_PACKAGE_ITEM_STATUS_NOT_PURCHASED:
48 if (self->purchasing()) {
49 self->setPurchasing(false);
50 Q_EMIT self->purchaseCancelled();
58Payments::Payments(QObject *parent)
62 m_package = pay_package_new("click-scope");
63 pay_package_item_observer_install(m_package, observer, this);
68 pay_package_item_observer_uninstall(m_package, observer, this);
69 pay_package_delete(m_package);
72QString Payments::currency() const
77double Payments::price() const
82QString Payments::storeItemId() const
84 return m_store_item_id;
87QString Payments::formattedPrice() const
90 return locale.toCurrencyString(m_price, m_currency);
93bool Payments::purchasing() const
98void Payments::setCurrency(const QString ¤cy)
100 if(m_currency != currency) {
101 m_currency = currency;
102 Q_EMIT currencyChanged(currency);
103 Q_EMIT formattedPriceChanged(formattedPrice());
107void Payments::setPrice(const double price)
109 if(m_price != price) {
111 Q_EMIT priceChanged(price);
112 Q_EMIT formattedPriceChanged(formattedPrice());
116void Payments::setStoreItemId(const QString &store_item_id)
118 if (m_store_item_id != store_item_id) {
119 m_store_item_id = store_item_id;
120 Q_EMIT storeItemIdChanged(m_store_item_id);
123 if (m_store_item_id.isEmpty()) {
128void Payments::setPurchasing(bool is_purchasing)
130 m_purchasing = is_purchasing;
133void Payments::start()
135 pay_package_item_start_purchase(m_package, m_store_item_id.toLocal8Bit().data());
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list