Remove unused package_name property and add package_id in license model

The `_to_be_installed_package_id` and `_to_be_installed_package_path`
can now be removed from the class as they can requested from the model
itself. This we make sure that the we alway install the package for
which the license was recently accepted.

cura 8587
This commit is contained in:
casper 2021-12-06 18:07:44 +01:00
parent 49a6a83fe9
commit 28b21628b4
2 changed files with 18 additions and 32 deletions

View file

@ -5,23 +5,21 @@ catalog = i18nCatalog("cura")
# Model for the LicenseDialog
class LicenseModel(QObject):
dialogTitleChanged = pyqtSignal()
packageNameChanged = pyqtSignal()
packageIdChanged = pyqtSignal()
licenseTextChanged = pyqtSignal()
def __init__(self, licence_text: str, package_name: str) -> None:
def __init__(self) -> None:
super().__init__()
self._license_text = ""
self._package_name = ""
self._package_id = ""
@pyqtProperty(str, notify=packageNameChanged)
def packageName(self) -> str:
return self._package_name
@pyqtProperty(str, notify=packageIdChanged)
def packageId(self) -> str:
return self._package_id
def setPackageName(self, name: str) -> None:
self._package_name = name
self.packageNameChanged.emit()
def setPackageId(self, name: str) -> None:
self._package_id = name
self.packageIdChanged.emit()
@pyqtProperty(str, notify=licenseTextChanged)
def licenseText(self) -> str:

View file

@ -139,25 +139,20 @@ class PackageList(ListModel):
def _openLicenseDialog(self, plugin_name: str, license_content: str) -> None:
Logger.debug(f"Prompting license for {plugin_name}")
self._license_model.setPackageName(plugin_name)
self._license_model.setPackageId(plugin_name)
self._license_model.setLicenseText(license_content)
self._license_dialog.show()
@pyqtSlot()
def onLicenseAccepted(self) -> None:
package_id = self._to_be_installed_package_id
package_path = self._to_be_installed_package_path
del self._to_be_installed_package_id
del self._to_be_installed_package_path
package_id = self._license_model.packageId
Logger.debug(f"Accepted license for {package_id}")
self._license_dialog.close()
self._install(package_id, package_path)
self._install(package_id)
@pyqtSlot()
def onLicenseDeclined(self) -> None:
package_id = self._to_be_installed_package_id
del self._to_be_installed_package_id
del self._to_be_installed_package_path
package_id = self._license_model.packageId
Logger.debug(f"Declined license for {package_id}")
self._license_dialog.close()
package = self.getPackageModel(package_id)
@ -166,27 +161,20 @@ class PackageList(ListModel):
def _requestInstall(self, package_id: str, update: bool = False) -> None:
Logger.debug(f"Request installing {package_id}")
package_path = self._to_install.pop(package_id)
package_path = self._to_install[package_id]
license_content = self._manager.getPackageLicense(package_path)
if not update and license_content is not None:
# If installation is not and update, and the packages contains a license then
# open dialog, prompting the using to accept the plugin license
# Store some properties that are needed after the dialog is closed
self._to_be_installed_package_id = package_id
self._to_be_installed_package_path = package_path
# Open actual dialog
package = self.getPackageModel(package_id)
plugin_name = package.displayName
self._openLicenseDialog(plugin_name, license_content)
self._openLicenseDialog(package_id, license_content)
else:
# Otherwise continue the installation
self._install(package_id, package_path, update)
self._install(package_id, update)
def _install(self, package_id: str, package_path: str, update: bool = False) -> None:
def _install(self, package_id: str, update: bool = False) -> None:
Logger.debug(f"Installing {package_id}")
package_path = self._to_install.pop(package_id)
to_be_installed = self._manager.installPackage(package_path) is not None
package = self.getPackageModel(package_id)
if package.can_update and to_be_installed: