Showing the changes to interface/src/scripting/WalletScriptingInterface.cpp (1 of 6 files). Show all
Unified · Split
| @@ -11,30 +11,37 @@ · 10 unmodified lines | ||
| 11 | 11 | |
| 12 | 12 | #include "WalletScriptingInterface.h" |
| 13 | 13 | |
| 14 | +CheckoutProxy::CheckoutProxy(QObject* qmlObject, QObject* parent) : QmlWrapper(qmlObject, parent) { | |
| 15 | + Q_ASSERT(QThread::currentThread() == qApp->thread()); | |
| 16 | +} | |
| 17 | + | |
| 14 | 18 | WalletScriptingInterface::WalletScriptingInterface() { |
| 15 | 19 | } |
| 16 | 20 | |
| 17 | 21 | 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 | + | |
| 19 | 28 | auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>(); |
| 20 | 29 | auto tablet = dynamic_cast<TabletProxy*>(tabletScriptingInterface->getTablet("com.highfidelity.interface.tablet.system")); |
| 21 | 30 | |
| 22 | − if (!tablet->isPathLoaded(CHECKOUT_QML_PATH)) { | |
| 23 | − tablet->loadQMLSource(CHECKOUT_QML_PATH); | |
| 24 | − } | |
| 31 | + tablet->loadQMLSource(CHECKOUT_QML_PATH); | |
| 25 | 32 | DependencyManager::get<HMDScriptingInterface>()->openTablet(); |
| 26 | 33 | |
| 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")); | |
| 29 | 41 | |
| 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); | |
| 40 | 47 | } |