From b7282cc776880a2f0a531795306b705f3a4c0193 Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Tue, 15 Aug 2017 13:46:20 -0700 Subject: [PATCH] Lots of fixes --- .../resources/qml/hifi/commerce/Inventory.qml | 19 +++++++ .../qml/hifi/commerce/SecurityImageModel.qml | 42 ++++++++++++++++ .../hifi/commerce/SecurityImageSelection.qml | 49 +++++++++---------- interface/src/commerce/QmlCommerce.cpp | 11 +++++ interface/src/commerce/QmlCommerce.h | 19 ++----- interface/src/commerce/Wallet.cpp | 10 +++- interface/src/commerce/Wallet.h | 20 ++++++++ scripts/system/marketplaces/marketplaces.js | 3 +- 8 files changed, 129 insertions(+), 44 deletions(-) create mode 100644 interface/resources/qml/hifi/commerce/SecurityImageModel.qml diff --git a/interface/resources/qml/hifi/commerce/Inventory.qml b/interface/resources/qml/hifi/commerce/Inventory.qml index df4907e8b9..a3e11e6426 100644 --- a/interface/resources/qml/hifi/commerce/Inventory.qml +++ b/interface/resources/qml/hifi/commerce/Inventory.qml @@ -78,6 +78,25 @@ Rectangle { verticalAlignment: Text.AlignVCenter; } + // "Change Security Image" button + HifiControlsUit.Button { + id: changeSecurityImageButton; + color: hifi.buttons.black; + colorScheme: hifi.colorSchemes.dark; + anchors.top: parent.top; + anchors.topMargin: 3; + anchors.bottom: parent.bottom; + anchors.bottomMargin: 3; + anchors.right: parent.right; + anchors.rightMargin: 20; + width: 200; + text: "Change Security Image" + onClicked: { + securityImageSelection.isManuallyChangingSecurityImage = true; + securityImageSelection.visible = true; + } + } + // Separator HifiControlsUit.Separator { anchors.left: parent.left; diff --git a/interface/resources/qml/hifi/commerce/SecurityImageModel.qml b/interface/resources/qml/hifi/commerce/SecurityImageModel.qml new file mode 100644 index 0000000000..df4490a5b1 --- /dev/null +++ b/interface/resources/qml/hifi/commerce/SecurityImageModel.qml @@ -0,0 +1,42 @@ +// +// SecurityImageModel.qml +// qml/hifi/commerce +// +// SecurityImageModel +// +// Created by Zach Fox on 2017-08-15 +// Copyright 2017 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +import QtQuick 2.5 + +ListModel { + id: root; + ListElement{ + sourcePath: "images/01cat.jpg" + securityImageEnumIndex: 1; + } + ListElement{ + sourcePath: "images/02car.jpg" + securityImageEnumIndex: 2; + } + ListElement{ + sourcePath: "images/03dog.jpg" + securityImageEnumIndex: 3; + } + ListElement{ + sourcePath: "images/04stars.jpg" + securityImageEnumIndex: 4; + } + ListElement{ + sourcePath: "images/05plane.jpg" + securityImageEnumIndex: 5; + } + ListElement{ + sourcePath: "images/06gingerbread.jpg" + securityImageEnumIndex: 6; + } +} diff --git a/interface/resources/qml/hifi/commerce/SecurityImageSelection.qml b/interface/resources/qml/hifi/commerce/SecurityImageSelection.qml index 33bb9edba2..744234c95a 100644 --- a/interface/resources/qml/hifi/commerce/SecurityImageSelection.qml +++ b/interface/resources/qml/hifi/commerce/SecurityImageSelection.qml @@ -25,19 +25,32 @@ Rectangle { id: securityImageSelectionRoot; property string referrerURL: ""; + property bool isManuallyChangingSecurityImage: false; anchors.fill: parent; // Style color: hifi.colors.baseGray; z:999; // On top of everything else + visible: false; Hifi.QmlCommerce { id: commerce; - onSecurityImageChosen: { - securityImageSelectionRoot.visible = (imageID == 0); + onSecurityImageResult: { + if (!isManuallyChangingSecurityImage) { + securityImageSelectionRoot.visible = (imageID == 0); + } + if (imageID !== 0) { + for (var itr = 0; itr < gridModel.count; itr++) { + if (gridModel.get(itr).securityImageEnumIndex === imageID) { + securityImageGrid.currentIndex = itr; + } + } + } } } - visible: commerce.getSecurityImage() == 0; + Component.onCompleted: { + commerce.getSecurityImage(); + } // // TITLE BAR START @@ -137,26 +150,8 @@ Rectangle { anchors.bottom: actionButtonsContainer.top; anchors.bottomMargin: 8; - ListModel { + SecurityImageModel { id: gridModel; - ListElement{ - sourcePath: "images/01cat.jpg" - } - ListElement{ - sourcePath: "images/02car.jpg" - } - ListElement{ - sourcePath: "images/03dog.jpg" - } - ListElement{ - sourcePath: "images/04stars.jpg" - } - ListElement{ - sourcePath: "images/05plane.jpg" - } - ListElement{ - sourcePath: "images/06gingerbread.jpg" - } } GridView { @@ -199,7 +194,6 @@ Rectangle { width: securityImageGrid.cellWidth; height: securityImageGrid.cellHeight; color: hifi.colors.blueHighlight; - y: securityImageGrid.currentItem.y; } } } @@ -235,7 +229,11 @@ Rectangle { width: parent.width/2 - anchors.leftMargin*2; text: "Cancel" onClicked: { - sendToScript({method: 'securityImageSelection_cancelClicked', referrerURL: referrerURL}); + if (!securityImageSelectionRoot.isManuallyChangingSecurityImage) { + sendToScript({method: 'securityImageSelection_cancelClicked', referrerURL: securityImageSelectionRoot.referrerURL}); + } else { + securityImageSelectionRoot.visible = false; + } } } @@ -253,7 +251,8 @@ Rectangle { width: parent.width/2 - anchors.rightMargin*2; text: "Confirm"; onClicked: { - commerce.chooseSecurityImage(securityImageGrid.currentIndex + 1); + securityImageSelectionRoot.isManuallyChangingSecurityImage = false; + commerce.chooseSecurityImage(gridModel.get(securityImageGrid.currentIndex).securityImageEnumIndex); } } } diff --git a/interface/src/commerce/QmlCommerce.cpp b/interface/src/commerce/QmlCommerce.cpp index d49ee8aaf3..573740727f 100644 --- a/interface/src/commerce/QmlCommerce.cpp +++ b/interface/src/commerce/QmlCommerce.cpp @@ -19,9 +19,11 @@ HIFI_QML_DEF(QmlCommerce) QmlCommerce::QmlCommerce(QQuickItem* parent) : OffscreenQmlDialog(parent) { auto ledger = DependencyManager::get(); + auto wallet = DependencyManager::get(); connect(ledger.data(), &Ledger::buyResult, this, &QmlCommerce::buyResult); connect(ledger.data(), &Ledger::balanceResult, this, &QmlCommerce::balanceResult); connect(ledger.data(), &Ledger::inventoryResult, this, &QmlCommerce::inventoryResult); + connect(wallet.data(), &Wallet::securityImageResult, this, &QmlCommerce::securityImageResult); } void QmlCommerce::buy(const QString& assetId, int cost, const QString& buyerUsername) { @@ -49,3 +51,12 @@ void QmlCommerce::inventory() { auto wallet = DependencyManager::get(); ledger->inventory(wallet->listPublicKeys()); } + +void QmlCommerce::chooseSecurityImage(uint imageID) { + auto wallet = DependencyManager::get(); + wallet->chooseSecurityImage(imageID); +} +void QmlCommerce::getSecurityImage() { + auto wallet = DependencyManager::get(); + wallet->getSecurityImage(); +} \ No newline at end of file diff --git a/interface/src/commerce/QmlCommerce.h b/interface/src/commerce/QmlCommerce.h index 7422277631..5b702bfeff 100644 --- a/interface/src/commerce/QmlCommerce.h +++ b/interface/src/commerce/QmlCommerce.h @@ -30,27 +30,14 @@ signals: // because we can't scalably know of out-of-band changes (e.g., another machine interacting with the block chain). void balanceResult(int balance, const QString& failureMessage); void inventoryResult(QJsonObject inventory, const QString& failureMessage); - void securityImageChosen(uint imageID); + void securityImageResult(uint imageID); protected: Q_INVOKABLE void buy(const QString& assetId, int cost, const QString& buyerUsername = ""); Q_INVOKABLE void balance(); Q_INVOKABLE void inventory(); - - enum SecurityImage { - NONE = 0, - Cat, - Car, - Dog, - Stars, - Plane, - Gingerbread - }; - Q_INVOKABLE void chooseSecurityImage(uint imageID) { QmlCommerce::_chosenSecurityImage = (SecurityImage)imageID; emit securityImageChosen(imageID); } - Q_INVOKABLE uint getSecurityImage() { return (uint)QmlCommerce::_chosenSecurityImage; } - -private: - SecurityImage _chosenSecurityImage = SecurityImage::NONE; + Q_INVOKABLE void chooseSecurityImage(uint imageID); + Q_INVOKABLE void getSecurityImage(); }; #endif // hifi_QmlCommerce_h diff --git a/interface/src/commerce/Wallet.cpp b/interface/src/commerce/Wallet.cpp index 34d89b54b0..9edbeddd6e 100644 --- a/interface/src/commerce/Wallet.cpp +++ b/interface/src/commerce/Wallet.cpp @@ -43,4 +43,12 @@ QStringList Wallet::listPublicKeys() { QString Wallet::signWithKey(const QString& text, const QString& key) { qCInfo(commerce) << "Signing text."; return "fixme signed"; -} \ No newline at end of file +} + +void Wallet::chooseSecurityImage(uint imageID) { + _chosenSecurityImage = (SecurityImage)imageID; + emit securityImageResult(imageID); +} +void Wallet::getSecurityImage() { + emit securityImageResult(_chosenSecurityImage); +} diff --git a/interface/src/commerce/Wallet.h b/interface/src/commerce/Wallet.h index 79de5e81da..86638b5c75 100644 --- a/interface/src/commerce/Wallet.h +++ b/interface/src/commerce/Wallet.h @@ -26,9 +26,29 @@ public: bool generateKeyPair(); QStringList listPublicKeys(); QString signWithKey(const QString& text, const QString& key); + void chooseSecurityImage(uint imageID); + void getSecurityImage(); + +signals: + void securityImageResult(uint imageID); + +protected: + // ALWAYS add SecurityImage enum values to the END of the enum. + // They must be in the same order as the images are listed in + // SecurityImageSelection.qml + enum SecurityImage { + NONE = 0, + Cat, + Car, + Dog, + Stars, + Plane, + Gingerbread + }; private: QStringList _publicKeys{}; + SecurityImage _chosenSecurityImage = SecurityImage::NONE; }; #endif // hifi_Wallet_h diff --git a/scripts/system/marketplaces/marketplaces.js b/scripts/system/marketplaces/marketplaces.js index 3e86063dd6..84d7d44689 100644 --- a/scripts/system/marketplaces/marketplaces.js +++ b/scripts/system/marketplaces/marketplaces.js @@ -88,7 +88,7 @@ function onScreenChanged(type, url) { onMarketplaceScreen = type === "Web" && url === MARKETPLACE_URL_INITIAL; - wireEventBridge(type === "QML" && (url === MARKETPLACE_CHECKOUT_QML_PATH || url === MARKETPLACE_INVENTORY_QML_PATH)); + wireEventBridge(type === "QML" && (url === MARKETPLACE_CHECKOUT_QML_PATH || url === MARKETPLACE_INVENTORY_QML_PATH || url === MARKETPLACE_SECURITY_QML_PATH)); // for toolbar mode: change button to active when window is first openend, false otherwise. marketplaceButton.editProperties({ isActive: onMarketplaceScreen }); if (type === "Web" && url.indexOf(MARKETPLACE_URL) !== -1) { @@ -219,7 +219,6 @@ tablet.gotoWebScreen(message.referrerURL, MARKETPLACES_INJECT_SCRIPT_URL); break; case 'securityImageSelection_cancelClicked': - console.log("ZRF HERE " + message.referrerURL); tablet.gotoWebScreen(message.referrerURL, MARKETPLACES_INJECT_SCRIPT_URL); break; default: