LicenseModel.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # Copyright (c) 2022 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from PyQt6.QtCore import QObject, pyqtProperty, pyqtSignal
  4. from UM.i18n import i18nCatalog
  5. catalog = i18nCatalog("cura")
  6. # Model for the ToolboxLicenseDialog
  7. class LicenseModel(QObject):
  8. DEFAULT_DECLINE_BUTTON_TEXT = catalog.i18nc("@button", "Decline")
  9. ACCEPT_BUTTON_TEXT = catalog.i18nc("@button", "Agree")
  10. dialogTitleChanged = pyqtSignal()
  11. packageNameChanged = pyqtSignal()
  12. licenseTextChanged = pyqtSignal()
  13. iconChanged = pyqtSignal()
  14. def __init__(self, decline_button_text: str = DEFAULT_DECLINE_BUTTON_TEXT, parent = None) -> None:
  15. super().__init__(parent)
  16. self._current_page_idx = 0
  17. self._page_count = 1
  18. self._dialogTitle = ""
  19. self._license_text = ""
  20. self._package_name = ""
  21. self._icon_url = ""
  22. self._decline_button_text = decline_button_text
  23. @pyqtProperty(str, constant = True)
  24. def acceptButtonText(self):
  25. return self.ACCEPT_BUTTON_TEXT
  26. @pyqtProperty(str, constant = True)
  27. def declineButtonText(self):
  28. return self._decline_button_text
  29. @pyqtProperty(str, notify=dialogTitleChanged)
  30. def dialogTitle(self) -> str:
  31. return self._dialogTitle
  32. @pyqtProperty(str, notify=packageNameChanged)
  33. def packageName(self) -> str:
  34. return self._package_name
  35. def setPackageName(self, name: str) -> None:
  36. self._package_name = name
  37. self.packageNameChanged.emit()
  38. @pyqtProperty(str, notify=iconChanged)
  39. def iconUrl(self) -> str:
  40. return self._icon_url
  41. def setIconUrl(self, url: str):
  42. self._icon_url = url
  43. self.iconChanged.emit()
  44. @pyqtProperty(str, notify=licenseTextChanged)
  45. def licenseText(self) -> str:
  46. return self._license_text
  47. def setLicenseText(self, license_text: str) -> None:
  48. if self._license_text != license_text:
  49. self._license_text = license_text
  50. self.licenseTextChanged.emit()
  51. def setCurrentPageIdx(self, idx: int) -> None:
  52. self._current_page_idx = idx
  53. self._updateDialogTitle()
  54. def setPageCount(self, count: int) -> None:
  55. self._page_count = count
  56. self._updateDialogTitle()
  57. def _updateDialogTitle(self):
  58. self._dialogTitle = catalog.i18nc("@title:window", "Plugin License Agreement")
  59. if self._page_count > 1:
  60. self._dialogTitle = self._dialogTitle + " ({}/{})".format(self._current_page_idx + 1, self._page_count)
  61. self.dialogTitleChanged.emit()