diff --git a/plugins/Marketplace/PackageModel.py b/plugins/Marketplace/PackageModel.py index 93d73bbc83..24f9671b34 100644 --- a/plugins/Marketplace/PackageModel.py +++ b/plugins/Marketplace/PackageModel.py @@ -1,11 +1,10 @@ # Copyright (c) 2021 Ultimaker B.V. # Cura is released under the terms of the LGPLv3 or higher. -from PyQt5.QtCore import pyqtProperty, QObject +from PyQt5.QtCore import pyqtProperty, pyqtSignal, QObject from typing import Any, Dict, Optional -from UM.Util import parseBool - +from UM.Logger import Logger from UM.i18n import i18nCatalog # To translate placeholder names if data is not present. catalog = i18nCatalog("cura") @@ -28,6 +27,9 @@ class PackageModel(QObject): super().__init__(parent) self._package_id = package_data.get("package_id", "UnknownPackageId") self._package_type = package_data.get("package_type", "") + self._is_installed = package_data.get("is_installed", False) + self._is_active = package_data.get("is_active", False) + self._is_bundled = package_data.get("is_bundled", False) self._icon_url = package_data.get("icon_url", "") self._display_name = package_data.get("display_name", catalog.i18nc("@label:property", "Unknown Package")) tags = package_data.get("tags", []) @@ -96,3 +98,35 @@ class PackageModel(QObject): @pyqtProperty(str, constant = True) def sectionTitle(self) -> Optional[str]: return self._section_title + + enableManageButtonChanged = pyqtSignal() + + @pyqtProperty(str, notify = enableManageButtonChanged) + def enableManageButtonText(self): + if self._is_active: + return catalog.i18nc("@button", "Disable") + else: + return catalog.i18nc("@button", "Enable") + + @pyqtProperty(bool, notify = enableManageButtonChanged) + def enableManageButtonVisible(self): + return self._is_installed + + installManageButtonChanged = pyqtSignal() + + @pyqtProperty(str, notify = installManageButtonChanged) + def installManageButtonText(self): + if self._is_installed: + return catalog.i18nc("@button", "Uninstall") + else: + return catalog.i18nc("@button", "Install") + + @pyqtProperty(bool, notify = installManageButtonChanged) + def installManageButtonVisible(self): + return not self._is_bundled + + updateManageButtonChanged = pyqtSignal() + + @pyqtProperty(bool, notify = updateManageButtonChanged) + def updateManageButtonVisible(self): + return False # Todo: implement diff --git a/plugins/Marketplace/resources/qml/PackageCard.qml b/plugins/Marketplace/resources/qml/PackageCard.qml index 433b77a54d..d4f9d74246 100644 --- a/plugins/Marketplace/resources/qml/PackageCard.qml +++ b/plugins/Marketplace/resources/qml/PackageCard.qml @@ -302,26 +302,26 @@ Rectangle Cura.SecondaryButton { - id: disableButton + id: enableManageButton Layout.alignment: Qt.AlignTop - text: catalog.i18nc("@button", "Disable") - visible: false // not functional right now, also only when unfolding and required + text: packageData.enableManageButtonText + visible: packageData.enableManageButtonVisible } Cura.SecondaryButton { - id: uninstallButton + id: installManageButton Layout.alignment: Qt.AlignTop - text: catalog.i18nc("@button", "Uninstall") - visible: false // not functional right now, also only when unfolding and required + text: packageData.installManageButtonText + visible: packageData.installManageButtonVisible } Cura.PrimaryButton { - id: installButton + id: updateManageButton Layout.alignment: Qt.AlignTop text: catalog.i18nc("@button", "Update") // OR Download, if new! - visible: false // not functional right now, also only when unfolding and required + visible: packageData.updateManageButtonVisible } }