mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-18 20:28:01 -06:00
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:
parent
49a6a83fe9
commit
28b21628b4
2 changed files with 18 additions and 32 deletions
|
@ -5,23 +5,21 @@ catalog = i18nCatalog("cura")
|
||||||
|
|
||||||
# Model for the LicenseDialog
|
# Model for the LicenseDialog
|
||||||
class LicenseModel(QObject):
|
class LicenseModel(QObject):
|
||||||
|
packageIdChanged = pyqtSignal()
|
||||||
dialogTitleChanged = pyqtSignal()
|
|
||||||
packageNameChanged = pyqtSignal()
|
|
||||||
licenseTextChanged = pyqtSignal()
|
licenseTextChanged = pyqtSignal()
|
||||||
|
|
||||||
def __init__(self, licence_text: str, package_name: str) -> None:
|
def __init__(self) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._license_text = ""
|
self._license_text = ""
|
||||||
self._package_name = ""
|
self._package_id = ""
|
||||||
|
|
||||||
@pyqtProperty(str, notify=packageNameChanged)
|
@pyqtProperty(str, notify=packageIdChanged)
|
||||||
def packageName(self) -> str:
|
def packageId(self) -> str:
|
||||||
return self._package_name
|
return self._package_id
|
||||||
|
|
||||||
def setPackageName(self, name: str) -> None:
|
def setPackageId(self, name: str) -> None:
|
||||||
self._package_name = name
|
self._package_id = name
|
||||||
self.packageNameChanged.emit()
|
self.packageIdChanged.emit()
|
||||||
|
|
||||||
@pyqtProperty(str, notify=licenseTextChanged)
|
@pyqtProperty(str, notify=licenseTextChanged)
|
||||||
def licenseText(self) -> str:
|
def licenseText(self) -> str:
|
||||||
|
|
|
@ -139,25 +139,20 @@ class PackageList(ListModel):
|
||||||
|
|
||||||
def _openLicenseDialog(self, plugin_name: str, license_content: str) -> None:
|
def _openLicenseDialog(self, plugin_name: str, license_content: str) -> None:
|
||||||
Logger.debug(f"Prompting license for {plugin_name}")
|
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_model.setLicenseText(license_content)
|
||||||
self._license_dialog.show()
|
self._license_dialog.show()
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def onLicenseAccepted(self) -> None:
|
def onLicenseAccepted(self) -> None:
|
||||||
package_id = self._to_be_installed_package_id
|
package_id = self._license_model.packageId
|
||||||
package_path = self._to_be_installed_package_path
|
|
||||||
del self._to_be_installed_package_id
|
|
||||||
del self._to_be_installed_package_path
|
|
||||||
Logger.debug(f"Accepted license for {package_id}")
|
Logger.debug(f"Accepted license for {package_id}")
|
||||||
self._license_dialog.close()
|
self._license_dialog.close()
|
||||||
self._install(package_id, package_path)
|
self._install(package_id)
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def onLicenseDeclined(self) -> None:
|
def onLicenseDeclined(self) -> None:
|
||||||
package_id = self._to_be_installed_package_id
|
package_id = self._license_model.packageId
|
||||||
del self._to_be_installed_package_id
|
|
||||||
del self._to_be_installed_package_path
|
|
||||||
Logger.debug(f"Declined license for {package_id}")
|
Logger.debug(f"Declined license for {package_id}")
|
||||||
self._license_dialog.close()
|
self._license_dialog.close()
|
||||||
package = self.getPackageModel(package_id)
|
package = self.getPackageModel(package_id)
|
||||||
|
@ -166,27 +161,20 @@ class PackageList(ListModel):
|
||||||
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}")
|
||||||
|
|
||||||
package_path = self._to_install.pop(package_id)
|
package_path = self._to_install[package_id]
|
||||||
license_content = self._manager.getPackageLicense(package_path)
|
license_content = self._manager.getPackageLicense(package_path)
|
||||||
|
|
||||||
if not update and license_content is not None:
|
if not update and license_content is not None:
|
||||||
# If installation is not and update, and the packages contains a license then
|
# If installation is not and update, and the packages contains a license then
|
||||||
# open dialog, prompting the using to accept the plugin license
|
# open dialog, prompting the using to accept the plugin license
|
||||||
|
self._openLicenseDialog(package_id, license_content)
|
||||||
# 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)
|
|
||||||
else:
|
else:
|
||||||
# Otherwise continue the installation
|
# 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}")
|
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
|
to_be_installed = self._manager.installPackage(package_path) is not None
|
||||||
package = self.getPackageModel(package_id)
|
package = self.getPackageModel(package_id)
|
||||||
if package.can_update and to_be_installed:
|
if package.can_update and to_be_installed:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue