CloudSync: documentation and cleanup

CURA-6983
This commit is contained in:
Nino van Hooff 2020-01-09 18:05:49 +01:00
parent 89994b92b5
commit 6069096141
3 changed files with 15 additions and 8 deletions

View file

@ -8,18 +8,20 @@ from UM.Signal import Signal
from cura.CuraApplication import CuraApplication from cura.CuraApplication import CuraApplication
from UM.i18n import i18nCatalog from UM.i18n import i18nCatalog
from plugins.Toolbox.src.CloudSync.LicenseModel import LicenseModel from plugins.Toolbox.src.CloudSync.LicenseModel import LicenseModel
## Call present() to show a licenseDialog for a set of packages
# licenseAnswers emits a list of Dicts containing answers when the user has made a choice for all provided packages
class LicensePresenter(QObject): class LicensePresenter(QObject):
def __init__(self, app: CuraApplication): def __init__(self, app: CuraApplication):
super().__init__() super().__init__()
self._dialog = None #type: Optional[QObject] self._dialog = None # type: Optional[QObject]
self._package_manager = app.getPackageManager() # type: PackageManager self._package_manager = app.getPackageManager() # type: PackageManager
# Emits # todo # Emits List[Dict[str, str]] containing for example
self.license_answers = Signal() # [{ "package_id": "BarbarianPlugin", "package_path" : "/tmp/dg345as", "accepted" : True }]
self.licenseAnswers = Signal()
self._current_package_idx = 0 self._current_package_idx = 0
self._package_models = None # type: Optional[Dict] self._package_models = None # type: Optional[Dict]
@ -30,6 +32,7 @@ class LicensePresenter(QObject):
self._compatibility_dialog_path = "resources/qml/dialogs/ToolboxLicenseDialog.qml" self._compatibility_dialog_path = "resources/qml/dialogs/ToolboxLicenseDialog.qml"
## Show a license dialog for multiple packages where users can read a license and accept or decline them ## Show a license dialog for multiple packages where users can read a license and accept or decline them
# \param plugin_path: Root directory of the Toolbox plugin
# \param packages: Dict[package id, file path] # \param packages: Dict[package id, file path]
def present(self, plugin_path: str, packages: Dict[str, str]): def present(self, plugin_path: str, packages: Dict[str, str]):
path = os.path.join(plugin_path, self._compatibility_dialog_path) path = os.path.join(plugin_path, self._compatibility_dialog_path)
@ -87,7 +90,7 @@ class LicensePresenter(QObject):
self._present_current_package() self._present_current_package()
else: else:
self._dialog.close() self._dialog.close()
self.license_answers.emit(self._package_models) self.licenseAnswers.emit(self._package_models)

View file

@ -20,7 +20,7 @@ from plugins.Toolbox.src.CloudSync.SubscribedPackagesModel import SubscribedPack
# - The SyncOrchestrator uses PackageManager to remove local packages the users wants to see removed # - The SyncOrchestrator uses PackageManager to remove local packages the users wants to see removed
# - The DownloadPresenter shows a download progress dialog. It emits A tuple of succeeded and failed downloads # - The DownloadPresenter shows a download progress dialog. It emits A tuple of succeeded and failed downloads
# - The LicensePresenter extracts licenses from the downloaded packages and presents a license for each package to # - The LicensePresenter extracts licenses from the downloaded packages and presents a license for each package to
# - be installed. It emits the `licenseAnswers` {'packageId' : bool} for accept or declines # be installed. It emits the `licenseAnswers` {'packageId' : bool} for accept or declines
# - The CloudPackageManager removes the declined packages from the account # - The CloudPackageManager removes the declined packages from the account
# - The SyncOrchestrator uses PackageManager to install the downloaded packages. # - The SyncOrchestrator uses PackageManager to install the downloaded packages.
# - Bliss / profit / done # - Bliss / profit / done
@ -28,7 +28,9 @@ class SyncOrchestrator(Extension):
def __init__(self, app: CuraApplication): def __init__(self, app: CuraApplication):
super().__init__() super().__init__()
self._name = "SyncOrchestrator" # Critical to differentiate This PluginObject from the Toolbox # Differentiate This PluginObject from the Toolbox. self.getId() includes _name.
# getPluginId() will return the same value for The toolbox extension and this one
self._name = "SyncOrchestrator"
self._checker = CloudPackageChecker(app) # type: CloudPackageChecker self._checker = CloudPackageChecker(app) # type: CloudPackageChecker
self._checker.discrepancies.connect(self._onDiscrepancies) self._checker.discrepancies.connect(self._onDiscrepancies)
@ -39,7 +41,7 @@ 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) self._licensePresenter.licenseAnswers.connect(self._onLicenseAnswers)
def _onDiscrepancies(self, model: SubscribedPackagesModel): def _onDiscrepancies(self, model: SubscribedPackagesModel):
plugin_path = PluginRegistry.getInstance().getPluginPath(self.getPluginId()) plugin_path = PluginRegistry.getInstance().getPluginPath(self.getPluginId())

View file

@ -31,6 +31,8 @@ if TYPE_CHECKING:
i18n_catalog = i18nCatalog("cura") i18n_catalog = i18nCatalog("cura")
# todo Remove license and download dialog, use SyncOrchestrator instead
## Provides a marketplace for users to download plugins an materials ## Provides a marketplace for users to download plugins an materials
class Toolbox(QObject, Extension): class Toolbox(QObject, Extension):
def __init__(self, application: CuraApplication) -> None: def __init__(self, application: CuraApplication) -> None: