Reset button if user declines license

Contributes to: CURA-8587
This commit is contained in:
Jelle Spijker 2021-12-07 15:06:46 +01:00
parent 5b3e9079ed
commit bb9696c39f
No known key found for this signature in database
GPG key ID: 6662DC033BE6B99A
4 changed files with 73 additions and 40 deletions

View file

@ -18,7 +18,7 @@ from cura.CuraApplication import CuraApplication
from cura.CuraPackageManager import CuraPackageManager 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, ManageState
from .Constants import USER_PACKAGES_URL from .Constants import USER_PACKAGES_URL
if TYPE_CHECKING: if TYPE_CHECKING:
@ -161,7 +161,7 @@ class PackageList(ListModel):
dialog.deleteLater() dialog.deleteLater()
# reset package card # reset package card
package = self.getPackageModel(package_id) package = self.getPackageModel(package_id)
package.is_installing = False package.is_installing = ManageState.FAILED
def _requestInstall(self, package_id: str, update: bool = False) -> None: def _requestInstall(self, package_id: str, update: bool = False) -> None:
Logger.debug(f"Request installing {package_id}") Logger.debug(f"Request installing {package_id}")
@ -185,9 +185,9 @@ class PackageList(ListModel):
if package.can_update and to_be_installed: if package.can_update and to_be_installed:
package.can_update = False package.can_update = False
if update: if update:
package.is_updating = False package.is_updating = ManageState.HALTED
else: else:
package.is_installing = False package.is_installing = ManageState.HALTED
self.subscribeUserToPackage(package_id, str(package.sdk_version)) self.subscribeUserToPackage(package_id, str(package.sdk_version))
def download(self, package_id: str, url: str, update: bool = False) -> None: def download(self, package_id: str, url: str, update: bool = False) -> None:
@ -232,9 +232,9 @@ class PackageList(ListModel):
Logger.error(f"Failed to download package: {package_id} due to {reply_string}") Logger.error(f"Failed to download package: {package_id} due to {reply_string}")
package = self.getPackageModel(package_id) package = self.getPackageModel(package_id)
if update: if update:
package.is_updating = False package.is_updating = ManageState.FAILED
else: else:
package.is_installing = False package.is_installing = ManageState.FAILED
def subscribeUserToPackage(self, package_id: str, sdk_version: str) -> None: def subscribeUserToPackage(self, package_id: str, sdk_version: str) -> None:
"""Subscribe the user (if logged in) to the package for a given SDK """Subscribe the user (if logged in) to the package for a given SDK
@ -275,7 +275,7 @@ class PackageList(ListModel):
:param package_id: the package identification string :param package_id: the package identification string
""" """
package = self.getPackageModel(package_id) package = self.getPackageModel(package_id)
package.is_installing = True package.is_installing = ManageState.PROCESSING
url = package.download_url url = package.download_url
Logger.debug(f"Trying to download and install {package_id} from {url}") Logger.debug(f"Trying to download and install {package_id} from {url}")
self.download(package_id, url, False) self.download(package_id, url, False)
@ -288,10 +288,10 @@ class PackageList(ListModel):
""" """
Logger.debug(f"Uninstalling {package_id}") Logger.debug(f"Uninstalling {package_id}")
package = self.getPackageModel(package_id) package = self.getPackageModel(package_id)
package.is_installing = True package.is_installing = ManageState.PROCESSING
self._manager.removePackage(package_id) self._manager.removePackage(package_id)
self.unsunscribeUserFromPackage(package_id) self.unsunscribeUserFromPackage(package_id)
package.is_installing = False package.is_installing = ManageState.HALTED
@pyqtSlot(str) @pyqtSlot(str)
def updatePackage(self, package_id: str) -> None: def updatePackage(self, package_id: str) -> None:
@ -300,7 +300,7 @@ class PackageList(ListModel):
:param package_id: the package identification string :param package_id: the package identification string
""" """
package = self.getPackageModel(package_id) package = self.getPackageModel(package_id)
package.is_updating = True package.is_updating = ManageState.PROCESSING
self._manager.removePackage(package_id, force_add = True) self._manager.removePackage(package_id, force_add = True)
url = package.download_url url = package.download_url
Logger.debug(f"Trying to download and update {package_id} from {url}") Logger.debug(f"Trying to download and update {package_id} from {url}")
@ -313,11 +313,11 @@ class PackageList(ListModel):
:param package_id: the package identification string :param package_id: the package identification string
""" """
package = self.getPackageModel(package_id) package = self.getPackageModel(package_id)
package.is_enabling = True package.is_enabling = ManageState.PROCESSING
Logger.debug(f"Enabling {package_id}") Logger.debug(f"Enabling {package_id}")
self._plugin_registry.enablePlugin(package_id) self._plugin_registry.enablePlugin(package_id)
package.is_active = True package.is_active = True
package.is_enabling = False package.is_enabling = ManageState.HALTED
@pyqtSlot(str) @pyqtSlot(str)
def disablePackage(self, package_id: str) -> None: def disablePackage(self, package_id: str) -> None:
@ -326,8 +326,8 @@ class PackageList(ListModel):
:param package_id: the package identification string :param package_id: the package identification string
""" """
package = self.getPackageModel(package_id) package = self.getPackageModel(package_id)
package.is_enabling = True package.is_enabling = ManageState.PROCESSING
Logger.debug(f"Disabling {package_id}") Logger.debug(f"Disabling {package_id}")
self._plugin_registry.disablePlugin(package_id) self._plugin_registry.disablePlugin(package_id)
package.is_active = False package.is_active = False
package.is_enabling = False package.is_enabling = ManageState.HALTED

View file

@ -1,16 +1,25 @@
# Copyright (c) 2021 Ultimaker B.V. # Copyright (c) 2021 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher. # Cura is released under the terms of the LGPLv3 or higher.
from PyQt5.QtCore import pyqtProperty, QObject, pyqtSignal
import re import re
from enum import Enum
from typing import Any, Dict, List, Optional from typing import Any, Dict, List, Optional
from PyQt5.QtCore import pyqtProperty, QObject, pyqtSignal
from cura.Settings.CuraContainerRegistry import CuraContainerRegistry # To get names of materials we're compatible with. from cura.Settings.CuraContainerRegistry import CuraContainerRegistry # To get names of materials we're compatible with.
from UM.i18n import i18nCatalog # To translate placeholder names if data is not present. from UM.i18n import i18nCatalog # To translate placeholder names if data is not present.
from UM.Logger import Logger
catalog = i18nCatalog("cura") catalog = i18nCatalog("cura")
class ManageState(Enum):
PROCESSING = 1
HALTED = 0
FAILED = -1
class PackageModel(QObject): class PackageModel(QObject):
""" """
Represents a package, containing all the relevant information to be displayed about a package. Represents a package, containing all the relevant information to be displayed about a package.
@ -60,14 +69,14 @@ class PackageModel(QObject):
if not self._icon_url or self._icon_url == "": if not self._icon_url or self._icon_url == "":
self._icon_url = author_data.get("icon_url", "") self._icon_url = author_data.get("icon_url", "")
self._is_installing = False self._is_installing: ManageState = ManageState.HALTED
self._is_recently_installed = False self._is_recently_installed = False
self._is_recently_updated = False self._is_recently_updated = False
self._is_recently_enabled = False self._is_recently_enabled = False
self._can_update = False self._can_update = False
self._is_updating = False self._is_updating: ManageState = ManageState.HALTED
self._is_enabling = False self._is_enabling: ManageState = ManageState.HALTED
self._can_downgrade = False self._can_downgrade = False
self._section_title = section_title self._section_title = section_title
self.sdk_version = package_data.get("sdk_version_semver", "") self.sdk_version = package_data.get("sdk_version_semver", "")
@ -288,7 +297,7 @@ class PackageModel(QObject):
@pyqtProperty(str, notify = stateManageButtonChanged) @pyqtProperty(str, notify = stateManageButtonChanged)
def stateManageEnableButton(self) -> str: def stateManageEnableButton(self) -> str:
"""The state of the manage Enable Button of this package""" """The state of the manage Enable Button of this package"""
if self._is_enabling: if self._is_enabling == ManageState.PROCESSING:
return "busy" return "busy"
if self._is_recently_enabled: if self._is_recently_enabled:
return "confirmed" return "confirmed"
@ -299,16 +308,16 @@ class PackageModel(QObject):
return "primary" return "primary"
@property @property
def is_enabling(self) -> bool: def is_enabling(self) -> ManageState:
"""Flag if the package is being enabled/disabled""" """Flag if the package is being enabled/disabled"""
return self._is_enabling return self._is_enabling
@is_enabling.setter @is_enabling.setter
def is_enabling(self, value: bool) -> None: def is_enabling(self, value: ManageState) -> None:
if value != self._is_enabling: if value != self._is_enabling:
if not value:
self._is_recently_enabled = True
self._is_enabling = value self._is_enabling = value
if value == ManageState.HALTED:
self._is_recently_enabled = True
self.stateManageButtonChanged.emit() self.stateManageButtonChanged.emit()
@property @property
@ -327,7 +336,7 @@ class PackageModel(QObject):
@pyqtProperty(str, notify = stateManageButtonChanged) @pyqtProperty(str, notify = stateManageButtonChanged)
def stateManageInstallButton(self) -> str: def stateManageInstallButton(self) -> str:
"""The state of the Manage Install package card""" """The state of the Manage Install package card"""
if self._is_installing: if self._is_installing == ManageState.PROCESSING:
return "busy" return "busy"
if self._is_recently_installed: if self._is_recently_installed:
return "confirmed" return "confirmed"
@ -340,16 +349,16 @@ class PackageModel(QObject):
return "primary" return "primary"
@property @property
def is_installing(self) -> bool: def is_installing(self) -> ManageState:
"""Flag is we're currently installing""" """Flag is we're currently installing, when setting this to ``None`` in indicates a failed installation"""
return self._is_installing return self._is_installing
@is_installing.setter @is_installing.setter
def is_installing(self, value: bool) -> None: def is_installing(self, value: ManageState) -> None:
if value != self._is_installing: if value != self._is_installing:
if not value:
self._is_recently_installed = True
self._is_installing = value self._is_installing = value
if value == ManageState.HALTED:
self._is_recently_installed = True
self.stateManageButtonChanged.emit() self.stateManageButtonChanged.emit()
@property @property
@ -368,7 +377,7 @@ class PackageModel(QObject):
@pyqtProperty(str, notify = stateManageButtonChanged) @pyqtProperty(str, notify = stateManageButtonChanged)
def stateManageUpdateButton(self) -> str: def stateManageUpdateButton(self) -> str:
"""The state of the manage Update button for this card """ """The state of the manage Update button for this card """
if self._is_updating: if self._is_updating == ManageState.PROCESSING:
return "busy" return "busy"
if self._is_recently_updated: if self._is_recently_updated:
return "confirmed" return "confirmed"
@ -377,16 +386,16 @@ class PackageModel(QObject):
return "hidden" return "hidden"
@property @property
def is_updating(self) -> bool: def is_updating(self) -> ManageState:
"""Flag indicating if the package is being updated""" """Flag indicating if the package is being updated"""
return self._is_updating return self._is_updating
@is_updating.setter @is_updating.setter
def is_updating(self, value: bool) -> None: def is_updating(self, value: ManageState) -> None:
if value != self._is_updating: if value != self._is_updating:
if not value:
self._is_recently_updated = True
self._is_updating = value self._is_updating = value
if value == ManageState.HALTED:
self._is_recently_updated = True
self.stateManageButtonChanged.emit() self.stateManageButtonChanged.emit()
@property @property

View file

@ -18,8 +18,8 @@ RowLayout
property string confirmedPrimaryText: confirmedMessageText.text property string confirmedPrimaryText: confirmedMessageText.text
property string confirmedSecondaryText: confirmedMessageText.text property string confirmedSecondaryText: confirmedMessageText.text
property bool enabled: true property bool enabled: true
property bool busy: state == "busy" property bool busy: false
property bool confirmed: state == "confirmed" property bool confirmed: false
signal clicked(bool primary_action) signal clicked(bool primary_action)
@ -62,7 +62,7 @@ RowLayout
UM.RecolorImage UM.RecolorImage
{ {
id: busyIndicator id: busyIndicator
visible: parent.visible visible: busyMessage.visible
width: height width: height
anchors.left: parent.left anchors.left: parent.left
anchors.top: parent.top anchors.top: parent.top
@ -76,7 +76,7 @@ RowLayout
RotationAnimator RotationAnimator
{ {
target: busyIndicator target: busyIndicator
running: busyIndicator.visible running: busyMessage.visible
from: 0 from: 0
to: 360 to: 360
loops: Animation.Infinite loops: Animation.Infinite
@ -86,7 +86,7 @@ RowLayout
Label Label
{ {
id: busyMessageText id: busyMessageText
visible: parent.visible visible: busyMessage.visible
anchors.left: busyIndicator.right anchors.left: busyIndicator.right
anchors.leftMargin: UM.Theme.getSize("narrow_margin").width anchors.leftMargin: UM.Theme.getSize("narrow_margin").width
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
@ -122,6 +122,12 @@ RowLayout
{ {
name: "primary" name: "primary"
PropertyChanges PropertyChanges
{
target: manageButton
busy: false
confirmed: false
}
PropertyChanges
{ {
target: primaryButton target: primaryButton
visible: true visible: true
@ -146,6 +152,12 @@ RowLayout
{ {
name: "secondary" name: "secondary"
PropertyChanges PropertyChanges
{
target: manageButton
busy: false
confirmed: false
}
PropertyChanges
{ {
target: primaryButton target: primaryButton
visible: false visible: false
@ -179,6 +191,12 @@ RowLayout
{ {
name: "busy" name: "busy"
PropertyChanges PropertyChanges
{
target: manageButton
busy: true
confirmed: false
}
PropertyChanges
{ {
target: primaryButton target: primaryButton
visible: false visible: false
@ -203,6 +221,12 @@ RowLayout
{ {
name: "confirmed" name: "confirmed"
PropertyChanges PropertyChanges
{
target: manageButton
busy: false
confirmed: true
}
PropertyChanges
{ {
target: primaryButton target: primaryButton
visible: false visible: false

View file

@ -358,7 +358,7 @@ Rectangle
busySecondaryText: catalog.i18nc("@button", "Uninstalling...") busySecondaryText: catalog.i18nc("@button", "Uninstalling...")
confirmedSecondaryText: catalog.i18nc("@button", "Uninstalled") confirmedSecondaryText: catalog.i18nc("@button", "Uninstalled")
enabled: !(enableManageButton.busy || updateManageButton.busy) enabled: !(enableManageButton.busy || updateManageButton.busy)
visible: state == "confirmed" || root.manageableInListView || root.expanded visible: installManageButton.confirmed || root.manageableInListView || root.expanded
onClicked: onClicked:
{ {