mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-09 07:56:22 -06:00
Finished LicensePresenter
CURA-6983
This commit is contained in:
parent
dda3d0b4eb
commit
89994b92b5
4 changed files with 57 additions and 25 deletions
|
@ -14,7 +14,7 @@ import UM 1.1 as UM
|
|||
UM.Dialog
|
||||
{
|
||||
id: licenseDialog
|
||||
title: catalog.i18nc("@title:window", "Plugin License Agreement")
|
||||
title: licenseModel.dialogTitle
|
||||
minimumWidth: UM.Theme.getSize("license_window_minimum").width
|
||||
minimumHeight: UM.Theme.getSize("license_window_minimum").height
|
||||
width: minimumWidth
|
||||
|
@ -32,18 +32,18 @@ UM.Dialog
|
|||
|
||||
Label
|
||||
{
|
||||
id: licenseTitle
|
||||
id: licenseHeader
|
||||
anchors.top: parent.top
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
text: licenseModel.title
|
||||
text: licenseModel.headerText
|
||||
wrapMode: Text.Wrap
|
||||
renderType: Text.NativeRendering
|
||||
}
|
||||
TextArea
|
||||
{
|
||||
id: licenseText
|
||||
anchors.top: licenseTitle.bottom
|
||||
anchors.top: licenseHeader.bottom
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
|
@ -59,14 +59,14 @@ UM.Dialog
|
|||
id: acceptButton
|
||||
anchors.margins: UM.Theme.getSize("default_margin").width
|
||||
text: catalog.i18nc("@action:button", "Accept")
|
||||
onClicked: handler.onLicenseAccepted
|
||||
onClicked: { handler.onLicenseAccepted() }
|
||||
},
|
||||
Button
|
||||
{
|
||||
id: declineButton
|
||||
anchors.margins: UM.Theme.getSize("default_margin").width
|
||||
text: catalog.i18nc("@action:button", "Decline")
|
||||
onClicked: handler.onLicenseDeclined
|
||||
onClicked: { handler.onLicenseDeclined() }
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -1,24 +1,35 @@
|
|||
from PyQt5.QtCore import QObject, pyqtProperty, pyqtSignal
|
||||
from UM.i18n import i18nCatalog
|
||||
|
||||
catalog = i18nCatalog("cura")
|
||||
|
||||
# Model for the ToolboxLicenseDialog
|
||||
class LicenseModel(QObject):
|
||||
titleChanged = pyqtSignal()
|
||||
dialogTitleChanged = pyqtSignal()
|
||||
headerChanged = pyqtSignal()
|
||||
licenseTextChanged = pyqtSignal()
|
||||
|
||||
def __init__(self, title: str = "", license_text: str = ""):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self._title = title
|
||||
self._license_text = license_text
|
||||
|
||||
@pyqtProperty(str, notify=titleChanged)
|
||||
def title(self) -> str:
|
||||
return self._title
|
||||
self._current_page_idx = 0
|
||||
self._page_count = 1
|
||||
self._dialogTitle = ""
|
||||
self._header_text = ""
|
||||
self._license_text = ""
|
||||
self._package_name = ""
|
||||
|
||||
def setTitle(self, title: str) -> None:
|
||||
if self._title != title:
|
||||
self._title = title
|
||||
self.titleChanged.emit()
|
||||
@pyqtProperty(str, notify=dialogTitleChanged)
|
||||
def dialogTitle(self) -> str:
|
||||
return self._dialogTitle
|
||||
|
||||
@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)
|
||||
def licenseText(self) -> str:
|
||||
|
@ -28,3 +39,16 @@ class LicenseModel(QObject):
|
|||
if self._license_text != license_text:
|
||||
self._license_text = license_text
|
||||
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()
|
||||
|
|
|
@ -23,6 +23,7 @@ class LicensePresenter(QObject):
|
|||
|
||||
self._current_package_idx = 0
|
||||
self._package_models = None # type: Optional[Dict]
|
||||
self._license_model = LicenseModel() # type: LicenseModel
|
||||
|
||||
self._app = app
|
||||
|
||||
|
@ -39,11 +40,11 @@ class LicensePresenter(QObject):
|
|||
|
||||
context_properties = {
|
||||
"catalog": i18nCatalog("cura"),
|
||||
"licenseModel": LicenseModel("initial title", "initial text"),
|
||||
"licenseModel": self._license_model,
|
||||
"handler": self
|
||||
}
|
||||
self._dialog = self._app.createQmlComponent(path, context_properties)
|
||||
|
||||
self._license_model.setPageCount(len(self._package_models))
|
||||
self._present_current_package()
|
||||
|
||||
@pyqtSlot()
|
||||
|
@ -74,7 +75,10 @@ class LicensePresenter(QObject):
|
|||
self.onLicenseAccepted()
|
||||
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
|
||||
|
||||
def _check_next_page(self):
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from typing import List, Dict
|
||||
|
||||
from UM.Extension import Extension
|
||||
from UM.Logger import Logger
|
||||
from UM.PluginRegistry import PluginRegistry
|
||||
from cura.CuraApplication import CuraApplication
|
||||
from plugins.Toolbox import CloudPackageChecker
|
||||
|
@ -38,19 +39,18 @@ class SyncOrchestrator(Extension):
|
|||
self._downloadPresenter = DownloadPresenter(app) # type: DownloadPresenter
|
||||
|
||||
self._licensePresenter = LicensePresenter(app) # type: LicensePresenter
|
||||
self._licensePresenter.license_answers.connect(self._onLicenseAnswers)
|
||||
|
||||
def _onDiscrepancies(self, model: SubscribedPackagesModel):
|
||||
# todo revert
|
||||
self._onDownloadFinished({"SupportEraser" : "/home/nvanhooff/Downloads/ThingiBrowser-v7.0.0-2019-12-12T18_24_40Z.curapackage"}, [])
|
||||
# plugin_path = PluginRegistry.getInstance().getPluginPath(self.getPluginId())
|
||||
# self._discrepanciesPresenter.present(plugin_path, model)
|
||||
plugin_path = PluginRegistry.getInstance().getPluginPath(self.getPluginId())
|
||||
self._discrepanciesPresenter.present(plugin_path, model)
|
||||
|
||||
def _onPackageMutations(self, mutations: SubscribedPackagesModel):
|
||||
self._downloadPresenter = self._downloadPresenter.resetCopy()
|
||||
self._downloadPresenter.done.connect(self._onDownloadFinished)
|
||||
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 error_items: List[package_id]
|
||||
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())
|
||||
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)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue