History

Progress on buy endpoint

Zach Fox committed 9 years ago

Commit 11d00621 parent 1d1b8466 files · +59 −41Browse files

Showing the changes to interface/src/scripting/WalletScriptingInterface.cpp (1 of 6 files). Show all

Unified · Split

interface/src/scripting/WalletScriptingInterface.cpp+23−16
@@ -11,30 +11,37 @@ · 10 unmodified lines
1111
1212 #include "WalletScriptingInterface.h"
1313
14+CheckoutProxy::CheckoutProxy(QObject* qmlObject, QObject* parent) : QmlWrapper(qmlObject, parent) {
15+ Q_ASSERT(QThread::currentThread() == qApp->thread());
16+}
17+
1418 WalletScriptingInterface::WalletScriptingInterface() {
1519 }
1620
1721 static const QString CHECKOUT_QML_PATH = qApp->applicationDirPath() + "../../../qml/hifi/commerce/checkout/Checkout.qml";
18−void WalletScriptingInterface::buy() {
22+void WalletScriptingInterface::buy(const QString& name, const QString& id, const int& price, const QString& href) {
23+ if (QThread::currentThread() != thread()) {
24+ QMetaObject::invokeMethod(this, "buy", Q_ARG(const QString&, name), Q_ARG(const QString&, id), Q_ARG(const int&, price), Q_ARG(const QString&, href));
25+ return;
26+ }
27+
1928 auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
2029 auto tablet = dynamic_cast<TabletProxy*>(tabletScriptingInterface->getTablet("com.highfidelity.interface.tablet.system"));
2130
22− if (!tablet->isPathLoaded(CHECKOUT_QML_PATH)) {
23− tablet->loadQMLSource(CHECKOUT_QML_PATH);
24− }
31+ tablet->loadQMLSource(CHECKOUT_QML_PATH);
2532 DependencyManager::get<HMDScriptingInterface>()->openTablet();
2633
27− QVariant message = {};
28−
34+ QQuickItem* root = nullptr;
35+ if (tablet->getToolbarMode() || (!tablet->getTabletRoot() && !qApp->isHMDMode())) {
36+ root = DependencyManager::get<OffscreenUi>()->getRootItem();
37+ } else {
38+ root = tablet->getTabletRoot();
39+ }
40+ CheckoutProxy* checkout = new CheckoutProxy(root->findChild<QObject*>("checkout"));
2941
30− tablet->sendToQml(message); .sendToQml({
31− method: 'updateCheckoutQML', params : {
32− itemId: '0d90d21c-ce7a-4990-ad18-e9d2cf991027',
33− itemName : 'Test Flaregun',
34− itemAuthor : 'hifiDave',
35− itemPrice : 17,
36− itemHref : 'http://mpassets.highfidelity.com/0d90d21c-ce7a-4990-ad18-e9d2cf991027-v1/flaregun.json',
37− },
38− canRezCertifiedItems: Entities.canRezCertified || Entities.canRezTmpCertified
39− });
42+ // Example: Wallet.buy("Test Flaregun", "0d90d21c-ce7a-4990-ad18-e9d2cf991027", 17, "http://mpassets.highfidelity.com/0d90d21c-ce7a-4990-ad18-e9d2cf991027-v1/flaregun.json");
43+ checkout->writeProperty("itemName", name);
44+ checkout->writeProperty("itemId", id);
45+ checkout->writeProperty("itemPrice", price);
46+ checkout->writeProperty("itemHref", href);
4047 }