From d74f7eb0982d65e7b371a923268fbef75f5222b3 Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Tue, 11 Dec 2018 15:41:07 -0800 Subject: [PATCH] Implement MS20187: Add trash can feature to Inventory --- .../hifi/commerce/purchases/PurchasedItem.qml | 38 +++++++++++++++++-- .../qml/hifi/commerce/purchases/Purchases.qml | 25 ++++++++++++ 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/interface/resources/qml/hifi/commerce/purchases/PurchasedItem.qml b/interface/resources/qml/hifi/commerce/purchases/PurchasedItem.qml index c8ec7238d6..12a9912e8e 100644 --- a/interface/resources/qml/hifi/commerce/purchases/PurchasedItem.qml +++ b/interface/resources/qml/hifi/commerce/purchases/PurchasedItem.qml @@ -176,6 +176,7 @@ Item { Item { property alias buttonGlyphText: buttonGlyph.text; property alias buttonText: buttonText.text; + property alias glyphSize: buttonGlyph.size; property string buttonColor: hifi.colors.black; property string buttonColor_hover: hifi.colors.blueHighlight; property alias enabled: buttonMouseArea.enabled; @@ -186,7 +187,8 @@ Item { anchors.top: parent.top; anchors.topMargin: 4; anchors.horizontalCenter: parent.horizontalCenter; - anchors.bottom: parent.verticalCenter; + anchors.bottom: buttonText.visible ? parent.verticalCenter : parent.bottom; + anchors.bottomMargin: buttonText.visible ? 0 : 4; width: parent.width; size: 40; horizontalAlignment: Text.AlignHCenter; @@ -196,6 +198,7 @@ Item { RalewayRegular { id: buttonText; + visible: text !== ""; anchors.top: parent.verticalCenter; anchors.topMargin: 4; anchors.bottom: parent.bottom; @@ -300,7 +303,7 @@ Item { anchors.right: certificateButton.left; anchors.top: parent.top; anchors.bottom: parent.bottom; - width: 78; + width: 72; onLoaded: { item.buttonGlyphText = hifi.glyphs.uninstall; @@ -319,7 +322,7 @@ Item { anchors.right: uninstallButton.visible ? uninstallButton.left : certificateButton.left; anchors.top: parent.top; anchors.bottom: parent.bottom; - width: 84; + width: 78; onLoaded: { item.buttonGlyphText = hifi.glyphs.update; @@ -340,6 +343,35 @@ Item { } } } + + Loader { + id: trashButton; + visible: root.itemEdition > 0; + sourceComponent: contextCardButton; + anchors.right: updateButton.visible ? updateButton.left : (uninstallButton.visible ? uninstallButton.left : certificateButton.left); + anchors.top: parent.top; + anchors.bottom: parent.bottom; + width: (updateButton.visible && uninstallButton.visible) ? 15 : 78; + + onLoaded: { + item.buttonGlyphText = hifi.glyphs.trash; + if (updateButton.visible && uninstallButton.visible) { + item.buttonText = ""; + item.glyphSize = 20; + } else { + item.buttonText = "Send to Trash"; + item.glyphSize = 30; + } + item.buttonClicked = function() { + sendToPurchases({method: 'showTrashLightbox', + isInstalled: root.isInstalled, + itemHref: root.itemHref, + itemName: root.itemName, + certID: root.certificateId + }); + } + } + } } Rectangle { diff --git a/interface/resources/qml/hifi/commerce/purchases/Purchases.qml b/interface/resources/qml/hifi/commerce/purchases/Purchases.qml index 18d6bc9f78..dae93b3315 100644 --- a/interface/resources/qml/hifi/commerce/purchases/Purchases.qml +++ b/interface/resources/qml/hifi/commerce/purchases/Purchases.qml @@ -651,6 +651,31 @@ Rectangle { lightboxPopup.visible = false; }; lightboxPopup.visible = true; + } else if (msg.method === "showTrashLightbox") { + lightboxPopup.titleText = "Send \"" + msg.itemName + "\" to Trash"; + lightboxPopup.bodyText = "Sending this item to the Trash means you will no longer own this item " + + "and it will be inaccessible to you from Purchases.\n\nThis action cannot be undone."; + lightboxPopup.button1text = "CANCEL"; + lightboxPopup.button1method = function() { + lightboxPopup.visible = false; + } + lightboxPopup.button2text = "CONFIRM"; + lightboxPopup.button2method = function() { + if (msg.isInstalled) { + Commerce.uninstallApp(msg.itemHref); + } + Commerce.transferAssetToUsername("TrashCan", msg.certID, 1, "Sent " + msg.itemName + " to trash."); + + lightboxPopup.titleText = '"' + msg.itemName + '" Sent to Trash'; + lightboxPopup.button1text = "OK"; + lightboxPopup.button1method = function() { + lightboxPopup.visible = false; + getPurchases(); + } + lightboxPopup.button2text = ""; + lightboxPopup.bodyText = ""; + }; + lightboxPopup.visible = true; } else if (msg.method === "showChangeAvatarLightbox") { lightboxPopup.titleText = "Change Avatar"; lightboxPopup.bodyText = "This will change your current avatar to " + msg.itemName + " while retaining your wearables.";