Switch between correct states of the un-/installed buttons

Contributes to CURA-8587
This commit is contained in:
Jelle Spijker 2021-12-15 17:51:38 +01:00
parent 0ffaafc8c0
commit 23cc7084c4
No known key found for this signature in database
GPG key ID: 6662DC033BE6B99A
3 changed files with 12 additions and 6 deletions

View file

@ -19,7 +19,7 @@ from cura.CuraPackageManager import CuraPackageManager
from cura.UltimakerCloud.UltimakerCloudScope import UltimakerCloudScope # To make requests to the Ultimaker API with correct authorization. from cura.UltimakerCloud.UltimakerCloudScope import UltimakerCloudScope # To make requests to the Ultimaker API with correct authorization.
from .PackageModel import PackageModel from .PackageModel import PackageModel
from .Constants import USER_PACKAGES_URL from .Constants import USER_PACKAGES_URL, PACKAGES_URL
if TYPE_CHECKING: if TYPE_CHECKING:
from PyQt5.QtCore import QObject from PyQt5.QtCore import QObject
@ -195,6 +195,9 @@ class PackageList(ListModel):
:param update: A flag if this is download request is an update process :param update: A flag if this is download request is an update process
""" """
if url == "":
url = f"{PACKAGES_URL}/{package_id}/download"
def downloadFinished(reply: "QNetworkReply") -> None: def downloadFinished(reply: "QNetworkReply") -> None:
self._downloadFinished(package_id, reply, update) self._downloadFinished(package_id, reply, update)

View file

@ -314,7 +314,6 @@ class PackageModel(QObject):
@pyqtSlot() @pyqtSlot()
def uninstall(self): def uninstall(self):
self.setBusy(True)
self.uninstallPackageTriggered.emit(self.packageId) self.uninstallPackageTriggered.emit(self.packageId)
@pyqtProperty(bool, notify= busyChanged) @pyqtProperty(bool, notify= busyChanged)
@ -351,7 +350,11 @@ class PackageModel(QObject):
@pyqtProperty(bool, notify = stateManageButtonChanged) @pyqtProperty(bool, notify = stateManageButtonChanged)
def isInstalled(self) -> bool: def isInstalled(self) -> bool:
return self._package_id in self._package_manager.local_packages_ids return self._package_id in self._package_manager.getAllInstalledPackageIDs()
@pyqtProperty(bool, notify = stateManageButtonChanged)
def isToBeInstalled(self) -> bool:
return self._package_id in self._package_manager.getPackagesToInstall()
@pyqtProperty(bool, notify = stateManageButtonChanged) @pyqtProperty(bool, notify = stateManageButtonChanged)
def isActive(self) -> bool: def isActive(self) -> bool:

View file

@ -198,7 +198,7 @@ Item
visible: showManageButtons && (packageData.canDowngrade || !packageData.isBundled) visible: showManageButtons && (packageData.canDowngrade || !packageData.isBundled)
enabled: !packageData.busy enabled: !packageData.busy
busy: packageData.busy busy: packageData.busy
button_style: !packageData.isInstalled button_style: packageData.isInstalled || packageData.isToBeInstalled
Layout.alignment: Qt.AlignTop Layout.alignment: Qt.AlignTop
text: text:
@ -208,7 +208,7 @@ Item
if (busy) { return catalog.i18nc("@button", "Downgrading..."); } if (busy) { return catalog.i18nc("@button", "Downgrading..."); }
else { return catalog.i18nc("@button", "Downgrade"); } else { return catalog.i18nc("@button", "Downgrade"); }
} }
if (!packageData.isInstalled) if (!(packageData.isInstalled || packageData.isToBeInstalled))
{ {
if (busy) { return catalog.i18nc("@button", "Installing..."); } if (busy) { return catalog.i18nc("@button", "Installing..."); }
else { return catalog.i18nc("@button", "Install"); } else { return catalog.i18nc("@button", "Install"); }
@ -219,7 +219,7 @@ Item
} }
} }
onClicked: packageData.isInstalled ? packageData.uninstall(): packageData.install() onClicked: packageData.isInstalled || packageData.isToBeInstalled ? packageData.uninstall(): packageData.install()
} }
ManageButton ManageButton