on xenial help sign in
More cleanup.
0368a49Rodney Dawes
plugins/Ubuntu/Payments/Payments.cpp+8−3
@@ -28,7 +28,7 @@
28
28
29
29
30// The observer callback for the package we are watching.
30// The observer callback for the package we are watching.
31−static void observer(PayPackage* /* package */, const char* /*itemid*/, PayPackageItemStatus status, void* user_data) {
31+static void observer(PayPackage* /* package */, const char* itemid, PayPackageItemStatus status, void* user_data) {
32 // This function is called in libpay's thread, so be careful what you call
32 // This function is called in libpay's thread, so be careful what you call
33 // Emitting signals should be fine as long as they use Queued or Auto
33 // Emitting signals should be fine as long as they use Queued or Auto
34 // connections (the default)
34 // connections (the default)
@@ -36,6 +36,11 @@ static void observer(PayPackage* /* package */, const char* /*itemid*/, PayPacka
36
36
37 Payments *self = static_cast<Payments*>(user_data);
37 Payments *self = static_cast<Payments*>(user_data);
38
38
39+ // If the item ID is different, ignore it.
40+ if (itemid != self->storeItemId()) {
41+ return;
42+ }
43+
39 // FIXME: No error reporting from libpay, but we need to show some
44 // FIXME: No error reporting from libpay, but we need to show some
40 // types of errors to the user. https://launchpad.net/bugs/1333403
45 // types of errors to the user. https://launchpad.net/bugs/1333403
41 switch (status) {
46 switch (status) {
@@ -51,11 +56,13 @@ Payments::Payments(QObject *parent)
51 : QObject(parent)
56 : QObject(parent)
52{
57{
53 m_package = pay_package_new("click-scope");
58 m_package = pay_package_new("click-scope");
59+ pay_package_item_observer_install(m_package, observer, this);
54}
60}
55
61
56Payments::~Payments()
62Payments::~Payments()
57{
63{
58 pay_package_item_observer_uninstall(m_package, observer, this);
64 pay_package_item_observer_uninstall(m_package, observer, this);
65+ pay_package_delete(m_package);
59}
66}
60
67
61QString Payments::currency() const
68QString Payments::currency() const
@@ -108,8 +115,6 @@ void Payments::setStoreItemId(const QString &store_item_id)
108 return;
115 return;
109 }
116 }
110
117
111− pay_package_item_observer_uninstall(m_package, observer, this);
112− pay_package_item_observer_install(m_package, observer, this);
113 pay_package_item_start_verification(m_package,
118 pay_package_item_start_verification(m_package,
114 m_store_item_id.toLocal8Bit().data());
119 m_store_item_id.toLocal8Bit().data());
115}
120}