Finished LicensePresenter

CURA-6983
This commit is contained in:
Nino van Hooff 2020-01-09 17:44:31 +01:00
parent dda3d0b4eb
commit 89994b92b5
4 changed files with 57 additions and 25 deletions

View file

@ -14,7 +14,7 @@ import UM 1.1 as UM
UM.Dialog UM.Dialog
{ {
id: licenseDialog id: licenseDialog
title: catalog.i18nc("@title:window", "Plugin License Agreement") title: licenseModel.dialogTitle
minimumWidth: UM.Theme.getSize("license_window_minimum").width minimumWidth: UM.Theme.getSize("license_window_minimum").width
minimumHeight: UM.Theme.getSize("license_window_minimum").height minimumHeight: UM.Theme.getSize("license_window_minimum").height
width: minimumWidth width: minimumWidth
@ -32,18 +32,18 @@ UM.Dialog
Label Label
{ {
id: licenseTitle id: licenseHeader
anchors.top: parent.top anchors.top: parent.top
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
text: licenseModel.title text: licenseModel.headerText
wrapMode: Text.Wrap wrapMode: Text.Wrap
renderType: Text.NativeRendering renderType: Text.NativeRendering
} }
TextArea TextArea
{ {
id: licenseText id: licenseText
anchors.top: licenseTitle.bottom anchors.top: licenseHeader.bottom
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
@ -59,14 +59,14 @@ UM.Dialog
id: acceptButton id: acceptButton
anchors.margins: UM.Theme.getSize("default_margin").width anchors.margins: UM.Theme.getSize("default_margin").width
text: catalog.i18nc("@action:button", "Accept") text: catalog.i18nc("@action:button", "Accept")
onClicked: handler.onLicenseAccepted onClicked: { handler.onLicenseAccepted() }
}, },
Button Button
{ {
id: declineButton id: declineButton
anchors.margins: UM.Theme.getSize("default_margin").width anchors.margins: UM.Theme.getSize("default_margin").width
text: catalog.i18nc("@action:button", "Decline") text: catalog.i18nc("@action:button", "Decline")
onClicked: handler.onLicenseDeclined onClicked: { handler.onLicenseDeclined() }
} }
] ]
} }

View file

@ -1,24 +1,35 @@
from PyQt5.QtCore import QObject, pyqtProperty, pyqtSignal from PyQt5.QtCore import QObject, pyqtProperty, pyqtSignal
from UM.i18n import i18nCatalog
catalog = i18nCatalog("cura")
# Model for the ToolboxLicenseDialog # Model for the ToolboxLicenseDialog
class LicenseModel(QObject): class LicenseModel(QObject):
titleChanged = pyqtSignal() dialogTitleChanged = pyqtSignal()
headerChanged = pyqtSignal()
licenseTextChanged = pyqtSignal() licenseTextChanged = pyqtSignal()
def __init__(self, title: str = "", license_text: str = ""): def __init__(self):
super().__init__() super().__init__()
self._title = title
self._license_text = license_text
@pyqtProperty(str, notify=titleChanged) self._current_page_idx = 0
def title(self) -> str: self._page_count = 1
return self._title self._dialogTitle = ""
self._header_text = ""
self._license_text = ""
self._package_name = ""
def setTitle(self, title: str) -> None: @pyqtProperty(str, notify=dialogTitleChanged)
if self._title != title: def dialogTitle(self) -> str:
self._title = title return self._dialogTitle
self.titleChanged.emit()
@pyqtProperty(str, notify=headerChanged)
def headerText(self) -> str:
return self._header_text
def setPackageName(self, name: str) -> None:
self._header_text = name + ": " + catalog.i18nc("@label", "This plugin contains a license.\nYou need to accept this license to install this plugin.\nDo you agree with the terms below?")
self.headerChanged.emit()
@pyqtProperty(str, notify=licenseTextChanged) @pyqtProperty(str, notify=licenseTextChanged)
def licenseText(self) -> str: def licenseText(self) -> str:
@ -28,3 +39,16 @@ class LicenseModel(QObject):
if self._license_text != license_text: if self._license_text != license_text:
self._license_text = license_text self._license_text = license_text
self.licenseTextChanged.emit() self.licenseTextChanged.emit()
def setCurrentPageNumber(self, idx: int) -> None:
self._current_page_idx = idx
self._updateDialogTitle()
def setPageCount(self, count: int):
self._page_count = count
self._updateDialogTitle()
def _updateDialogTitle(self):
self._dialogTitle = catalog.i18nc("@title:window", "Plugin License Agreement ({}/{})"
.format(self._current_page_idx + 1, self._page_count))
self.dialogTitleChanged.emit()

View file

@ -23,6 +23,7 @@ class LicensePresenter(QObject):
self._current_package_idx = 0 self._current_package_idx = 0
self._package_models = None # type: Optional[Dict] self._package_models = None # type: Optional[Dict]
self._license_model = LicenseModel() # type: LicenseModel
self._app = app self._app = app
@ -39,11 +40,11 @@ class LicensePresenter(QObject):
context_properties = { context_properties = {
"catalog": i18nCatalog("cura"), "catalog": i18nCatalog("cura"),
"licenseModel": LicenseModel("initial title", "initial text"), "licenseModel": self._license_model,
"handler": self "handler": self
} }
self._dialog = self._app.createQmlComponent(path, context_properties) self._dialog = self._app.createQmlComponent(path, context_properties)
self._license_model.setPageCount(len(self._package_models))
self._present_current_package() self._present_current_package()
@pyqtSlot() @pyqtSlot()
@ -74,7 +75,10 @@ class LicensePresenter(QObject):
self.onLicenseAccepted() self.onLicenseAccepted()
return return
self._dialog.setProperty("licenseModel", LicenseModel("testTitle", "hoi")) self._license_model.setCurrentPageNumber(self._current_package_idx)
self._license_model.setPackageName(package_model["package_id"])
self._license_model.setLicenseText(license_content)
self._dialog.open() # does nothing if already open self._dialog.open() # does nothing if already open
def _check_next_page(self): def _check_next_page(self):

View file

@ -1,6 +1,7 @@
from typing import List, Dict from typing import List, Dict
from UM.Extension import Extension from UM.Extension import Extension
from UM.Logger import Logger
from UM.PluginRegistry import PluginRegistry from UM.PluginRegistry import PluginRegistry
from cura.CuraApplication import CuraApplication from cura.CuraApplication import CuraApplication
from plugins.Toolbox import CloudPackageChecker from plugins.Toolbox import CloudPackageChecker
@ -38,19 +39,18 @@ class SyncOrchestrator(Extension):
self._downloadPresenter = DownloadPresenter(app) # type: DownloadPresenter self._downloadPresenter = DownloadPresenter(app) # type: DownloadPresenter
self._licensePresenter = LicensePresenter(app) # type: LicensePresenter self._licensePresenter = LicensePresenter(app) # type: LicensePresenter
self._licensePresenter.license_answers.connect(self._onLicenseAnswers)
def _onDiscrepancies(self, model: SubscribedPackagesModel): def _onDiscrepancies(self, model: SubscribedPackagesModel):
# todo revert plugin_path = PluginRegistry.getInstance().getPluginPath(self.getPluginId())
self._onDownloadFinished({"SupportEraser" : "/home/nvanhooff/Downloads/ThingiBrowser-v7.0.0-2019-12-12T18_24_40Z.curapackage"}, []) self._discrepanciesPresenter.present(plugin_path, model)
# plugin_path = PluginRegistry.getInstance().getPluginPath(self.getPluginId())
# self._discrepanciesPresenter.present(plugin_path, model)
def _onPackageMutations(self, mutations: SubscribedPackagesModel): def _onPackageMutations(self, mutations: SubscribedPackagesModel):
self._downloadPresenter = self._downloadPresenter.resetCopy() self._downloadPresenter = self._downloadPresenter.resetCopy()
self._downloadPresenter.done.connect(self._onDownloadFinished) self._downloadPresenter.done.connect(self._onDownloadFinished)
self._downloadPresenter.download(mutations) self._downloadPresenter.download(mutations)
## When a set of packages have finished downloading ## Called when a set of packages have finished downloading
# \param success_items: Dict[package_id, file_path] # \param success_items: Dict[package_id, file_path]
# \param error_items: List[package_id] # \param error_items: List[package_id]
def _onDownloadFinished(self, success_items: Dict[str, str], error_items: List[str]): def _onDownloadFinished(self, success_items: Dict[str, str], error_items: List[str]):
@ -58,4 +58,8 @@ class SyncOrchestrator(Extension):
plugin_path = PluginRegistry.getInstance().getPluginPath(self.getPluginId()) plugin_path = PluginRegistry.getInstance().getPluginPath(self.getPluginId())
self._licensePresenter.present(plugin_path, success_items) self._licensePresenter.present(plugin_path, success_items)
# Called when user has accepted / declined all licenses for the downloaded packages
def _onLicenseAnswers(self, answers: Dict[str, bool]):
Logger.debug("Got license answers: {}", answers)