From 511b10c084ad7d4daa4ee1dc9d56e873a1de702f Mon Sep 17 00:00:00 2001 From: "j.delarago" Date: Thu, 2 Jun 2022 16:54:08 +0200 Subject: [PATCH] Display package cards in the package list for packages that can't be found on the marketplace api. When the final page of results is fetched, the list of all package_ids retrieved from the api will be compared with the ones we were searching for. Any that are missing have cards displayed with only basic information (name and version). CURA-6990 --- plugins/Marketplace/MissingPackageList.py | 28 ++++++++++++++--- plugins/Marketplace/PackageModel.py | 22 ++++++++++++++ .../resources/qml/PackageCardHeader.qml | 30 +++++++++++++++++-- .../Marketplace/resources/qml/Packages.qml | 7 +++-- 4 files changed, 78 insertions(+), 9 deletions(-) diff --git a/plugins/Marketplace/MissingPackageList.py b/plugins/Marketplace/MissingPackageList.py index 818b54eb37..c979f8796c 100644 --- a/plugins/Marketplace/MissingPackageList.py +++ b/plugins/Marketplace/MissingPackageList.py @@ -17,10 +17,30 @@ if TYPE_CHECKING: catalog = i18nCatalog("cura") class MissingPackageList(RemotePackageList): - def __init__(self, packages: List[Dict[str, str]], parent: Optional["QObject"] = None) -> None: + def __init__(self, packages_metadata: List[Dict[str, str]], parent: Optional["QObject"] = None) -> None: super().__init__(parent) - self._package_metadata: List[Dict[str, str]] = [] - # self.packageTypeFilter = None # This will be our new filter + self._packages_metadata: List[Dict[str, str]] = packages_metadata self._package_type_filter = "material" self._search_type = "package_ids" - self._requested_search_string = ",".join(map(lambda package: package["id"], packages)) + self._requested_search_string = ",".join(map(lambda package: package["id"], packages_metadata)) + + def _parseResponse(self, reply: "QNetworkReply") -> None: + super()._parseResponse(reply) + + # At the end of the list we want to show some information about packages the user is missing that can't be found + # This will add cards with some information about the missing packages + if not self.hasMore: + self._addPackagesMissingFromRequest() + + def _addPackagesMissingFromRequest(self): + """Create cards for packages the user needs to install that could not be found""" + returned_packages_ids = [item["package"].packageId for item in self._items] + + for package_metadata in self._packages_metadata: + if package_metadata["id"] not in returned_packages_ids: + package = PackageModel.fromIncompletePackageInformation(package_metadata["display_name"], package_metadata["package_version"], self._package_type_filter) + self.appendItem({"package": package}) + + self.itemsChanged.emit() + + diff --git a/plugins/Marketplace/PackageModel.py b/plugins/Marketplace/PackageModel.py index bd1b0681fc..cf641e3270 100644 --- a/plugins/Marketplace/PackageModel.py +++ b/plugins/Marketplace/PackageModel.py @@ -84,6 +84,20 @@ class PackageModel(QObject): self._is_busy = False + self._is_missing_package_information = False + + @classmethod + def fromIncompletePackageInformation(cls, display_name: str, package_version: str, package_type: str): + package_data = { + "display_name": display_name, + "package_version": package_version, + "package_type": package_type, + "description": "The material package associated with the Cura project could not be found on the Ultimaker marketplace. Use the partial material profile definition stored in the Cura project file at your own risk." + } + package_model = cls(package_data) + package_model.setIsMissingPackageInformation(True) + return package_model + @pyqtSlot() def _processUpdatedPackages(self): self.setCanUpdate(self._package_manager.checkIfPackageCanUpdate(self._package_id)) @@ -385,3 +399,11 @@ class PackageModel(QObject): def canUpdate(self) -> bool: """Flag indicating if the package can be updated""" return self._can_update + + def setIsMissingPackageInformation(self, isMissingPackageInformation: bool): + self._is_missing_package_information = isMissingPackageInformation + + @pyqtProperty(bool) + def isMissingPackageInformation(self) -> bool: + """Flag indicating if the package can be updated""" + return self._is_missing_package_information diff --git a/plugins/Marketplace/resources/qml/PackageCardHeader.qml b/plugins/Marketplace/resources/qml/PackageCardHeader.qml index 00d107f4fc..3e8e0fc26f 100644 --- a/plugins/Marketplace/resources/qml/PackageCardHeader.qml +++ b/plugins/Marketplace/resources/qml/PackageCardHeader.qml @@ -19,6 +19,8 @@ Item property bool showInstallButton: false property bool showUpdateButton: false + property string missingPackageReadMoreUrl: "https://support.ultimaker.com" + width: parent.width height: UM.Theme.getSize("card").height @@ -109,6 +111,7 @@ Item Button { id: externalLinkButton + visible: !packageData.isMissingPackageInformation // For some reason if i set padding, they don't match up. If i set all of them explicitly, it does work? leftPadding: UM.Theme.getSize("narrow_margin").width @@ -155,6 +158,7 @@ Item UM.Label { id: authorBy + visible: !packageData.isMissingPackageInformation Layout.alignment: Qt.AlignCenter text: catalog.i18nc("@label Is followed by the name of an author", "By") @@ -165,6 +169,7 @@ Item // clickable author name Item { + visible: !packageData.isMissingPackageInformation Layout.fillWidth: true implicitHeight: authorBy.height Layout.alignment: Qt.AlignTop @@ -182,10 +187,29 @@ Item } } + Item + { + visible: packageData.isMissingPackageInformation + Layout.fillWidth: true + implicitHeight: readMoreButton.height + Layout.alignment: Qt.AlignTop + Cura.TertiaryButton + { + id: readMoreButton + text: catalog.i18nc("@button:label", "Learn More") + leftPadding: 0 + rightPadding: 0 + iconSource: UM.Theme.getIcon("LinkExternal") + isIconOnRightSide: true + + onClicked: Qt.openUrlExternally(missingPackageReadMoreUrl) + } + } + ManageButton { id: enableManageButton - visible: showDisableButton && packageData.isInstalled && !packageData.isToBeInstalled && packageData.packageType != "material" + visible: showDisableButton && packageData.isInstalled && !packageData.isToBeInstalled && packageData.packageType != "material" && !packageData.isMissingPackageInformation enabled: !packageData.busy button_style: !packageData.isActive @@ -199,7 +223,7 @@ Item ManageButton { id: installManageButton - visible: showInstallButton && (packageData.canDowngrade || !packageData.isBundled) + visible: showInstallButton && (packageData.canDowngrade || !packageData.isBundled) && !packageData.isMissingPackageInformation enabled: !packageData.busy busy: packageData.busy button_style: !(packageData.isInstalled || packageData.isToBeInstalled) @@ -229,7 +253,7 @@ Item ManageButton { id: updateManageButton - visible: showUpdateButton && packageData.canUpdate + visible: showUpdateButton && packageData.canUpdate && !packageData.isMissingPackageInformation enabled: !packageData.busy busy: packageData.busy Layout.alignment: Qt.AlignTop diff --git a/plugins/Marketplace/resources/qml/Packages.qml b/plugins/Marketplace/resources/qml/Packages.qml index 70ff7de195..6e83f1e33b 100644 --- a/plugins/Marketplace/resources/qml/Packages.qml +++ b/plugins/Marketplace/resources/qml/Packages.qml @@ -62,8 +62,11 @@ ListView hoverEnabled: true onClicked: { - packages.selectedPackage = model.package; - contextStack.push(packageDetailsComponent); + if (!model.package.isMissingPackageInformation) + { + packages.selectedPackage = model.package; + contextStack.push(packageDetailsComponent); + } } PackageCard