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.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
if TYPE_CHECKING:
@ -161,7 +161,7 @@ class PackageList(ListModel):
dialog.deleteLater()
# reset package card
package = self.getPackageModel(package_id)
package.is_installing = False
package.is_installing = ManageState.FAILED
def _requestInstall(self, package_id: str, update: bool = False) -> None:
Logger.debug(f"Request installing {package_id}")
@ -185,9 +185,9 @@ class PackageList(ListModel):
if package.can_update and to_be_installed:
package.can_update = False
if update:
package.is_updating = False
package.is_updating = ManageState.HALTED
else:
package.is_installing = False
package.is_installing = ManageState.HALTED
self.subscribeUserToPackage(package_id, str(package.sdk_version))
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}")
package = self.getPackageModel(package_id)
if update:
package.is_updating = False
package.is_updating = ManageState.FAILED
else:
package.is_installing = False
package.is_installing = ManageState.FAILED
def subscribeUserToPackage(self, package_id: str, sdk_version: str) -> None:
"""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
"""
package = self.getPackageModel(package_id)
package.is_installing = True
package.is_installing = ManageState.PROCESSING
url = package.download_url
Logger.debug(f"Trying to download and install {package_id} from {url}")
self.download(package_id, url, False)
@ -288,10 +288,10 @@ class PackageList(ListModel):
"""
Logger.debug(f"Uninstalling {package_id}")
package = self.getPackageModel(package_id)
package.is_installing = True
package.is_installing = ManageState.PROCESSING
self._manager.removePackage(package_id)
self.unsunscribeUserFromPackage(package_id)
package.is_installing = False
package.is_installing = ManageState.HALTED
@pyqtSlot(str)
def updatePackage(self, package_id: str) -> None:
@ -300,7 +300,7 @@ class PackageList(ListModel):
:param package_id: the package identification string
"""
package = self.getPackageModel(package_id)
package.is_updating = True
package.is_updating = ManageState.PROCESSING
self._manager.removePackage(package_id, force_add = True)
url = package.download_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
"""
package = self.getPackageModel(package_id)
package.is_enabling = True
package.is_enabling = ManageState.PROCESSING
Logger.debug(f"Enabling {package_id}")
self._plugin_registry.enablePlugin(package_id)
package.is_active = True
package.is_enabling = False
package.is_enabling = ManageState.HALTED
@pyqtSlot(str)
def disablePackage(self, package_id: str) -> None:
@ -326,8 +326,8 @@ class PackageList(ListModel):
:param package_id: the package identification string
"""
package = self.getPackageModel(package_id)
package.is_enabling = True
package.is_enabling = ManageState.PROCESSING
Logger.debug(f"Disabling {package_id}")
self._plugin_registry.disablePlugin(package_id)
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.
# Cura is released under the terms of the LGPLv3 or higher.
from PyQt5.QtCore import pyqtProperty, QObject, pyqtSignal
import re
from enum import Enum
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 UM.i18n import i18nCatalog # To translate placeholder names if data is not present.
from UM.Logger import Logger
catalog = i18nCatalog("cura")
class ManageState(Enum):
PROCESSING = 1
HALTED = 0
FAILED = -1
class PackageModel(QObject):
"""
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 == "":
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_updated = False
self._is_recently_enabled = False
self._can_update = False
self._is_updating = False
self._is_enabling = False
self._is_updating: ManageState = ManageState.HALTED
self._is_enabling: ManageState = ManageState.HALTED
self._can_downgrade = False
self._section_title = section_title
self.sdk_version = package_data.get("sdk_version_semver", "")
@ -288,7 +297,7 @@ class PackageModel(QObject):
@pyqtProperty(str, notify = stateManageButtonChanged)
def stateManageEnableButton(self) -> str:
"""The state of the manage Enable Button of this package"""
if self._is_enabling:
if self._is_enabling == ManageState.PROCESSING:
return "busy"
if self._is_recently_enabled:
return "confirmed"
@ -299,16 +308,16 @@ class PackageModel(QObject):
return "primary"
@property
def is_enabling(self) -> bool:
def is_enabling(self) -> ManageState:
"""Flag if the package is being enabled/disabled"""
return self._is_enabling
@is_enabling.setter
def is_enabling(self, value: bool) -> None:
def is_enabling(self, value: ManageState) -> None:
if value != self._is_enabling:
if not value:
self._is_recently_enabled = True
self._is_enabling = value
if value == ManageState.HALTED:
self._is_recently_enabled = True
self.stateManageButtonChanged.emit()
@property
@ -327,7 +336,7 @@ class PackageModel(QObject):
@pyqtProperty(str, notify = stateManageButtonChanged)
def stateManageInstallButton(self) -> str:
"""The state of the Manage Install package card"""
if self._is_installing:
if self._is_installing == ManageState.PROCESSING:
return "busy"
if self._is_recently_installed:
return "confirmed"
@ -340,16 +349,16 @@ class PackageModel(QObject):
return "primary"
@property
def is_installing(self) -> bool:
"""Flag is we're currently installing"""
def is_installing(self) -> ManageState:
"""Flag is we're currently installing, when setting this to ``None`` in indicates a failed installation"""
return self._is_installing
@is_installing.setter
def is_installing(self, value: bool) -> None:
def is_installing(self, value: ManageState) -> None:
if value != self._is_installing:
if not value:
self._is_recently_installed = True
self._is_installing = value
if value == ManageState.HALTED:
self._is_recently_installed = True
self.stateManageButtonChanged.emit()
@property
@ -368,7 +377,7 @@ class PackageModel(QObject):
@pyqtProperty(str, notify = stateManageButtonChanged)
def stateManageUpdateButton(self) -> str:
"""The state of the manage Update button for this card """
if self._is_updating:
if self._is_updating == ManageState.PROCESSING:
return "busy"
if self._is_recently_updated:
return "confirmed"
@ -377,16 +386,16 @@ class PackageModel(QObject):
return "hidden"
@property
def is_updating(self) -> bool:
def is_updating(self) -> ManageState:
"""Flag indicating if the package is being updated"""
return self._is_updating
@is_updating.setter
def is_updating(self, value: bool) -> None:
def is_updating(self, value: ManageState) -> None:
if value != self._is_updating:
if not value:
self._is_recently_updated = True
self._is_updating = value
if value == ManageState.HALTED:
self._is_recently_updated = True
self.stateManageButtonChanged.emit()
@property

View file

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

View file

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