Merge pull request #11020 from Ultimaker/cura-8587_disable_update_install_and_update/licence_agreement

Cura 8587 disable update install and update/licence agreement
This commit is contained in:
Casper Lamboo 2021-12-06 18:38:48 +01:00 committed by GitHub
commit 20fb08145d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 177 additions and 3 deletions

View File

@ -0,0 +1,31 @@
from PyQt5.QtCore import QObject, pyqtProperty, pyqtSignal
from UM.i18n import i18nCatalog
catalog = i18nCatalog("cura")
# Model for the LicenseDialog
class LicenseModel(QObject):
packageIdChanged = pyqtSignal()
licenseTextChanged = pyqtSignal()
def __init__(self) -> None:
super().__init__()
self._license_text = ""
self._package_id = ""
@pyqtProperty(str, notify=packageIdChanged)
def packageId(self) -> str:
return self._package_id
def setPackageId(self, name: str) -> None:
self._package_id = name
self.packageIdChanged.emit()
@pyqtProperty(str, notify=licenseTextChanged)
def licenseText(self) -> str:
return self._license_text
def setLicenseText(self, license_text: str) -> None:
if self._license_text != license_text:
self._license_text = license_text
self.licenseTextChanged.emit()

View File

@ -2,6 +2,7 @@
# Cura is released under the terms of the LGPLv3 or higher.
import tempfile
import json
import os.path
from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, Qt
from typing import cast, Dict, Optional, Set, TYPE_CHECKING
@ -19,6 +20,7 @@ from cura.UltimakerCloud.UltimakerCloudScope import UltimakerCloudScope # To ma
from .PackageModel import PackageModel
from .Constants import USER_PACKAGES_URL
from .LicenseModel import LicenseModel
if TYPE_CHECKING:
from PyQt5.QtCore import QObject
@ -45,12 +47,25 @@ class PackageList(ListModel):
self._has_more = False
self._has_footer = True
self._to_install: Dict[str, str] = {}
self.canInstallChanged.connect(self._install)
self.canInstallChanged.connect(self._requestInstall)
self._local_packages: Set[str] = {p["package_id"] for p in self._manager.local_packages}
self._ongoing_request: Optional[HttpRequestData] = None
self._scope = JsonDecoratorScope(UltimakerCloudScope(CuraApplication.getInstance()))
self._license_model = LicenseModel()
plugin_path = self._plugin_registry.getPluginPath("Marketplace")
if plugin_path is None:
plugin_path = os.path.dirname(__file__)
# create a QML component for the license dialog
license_dialog_component_path = os.path.join(plugin_path, "resources", "qml", "LicenseDialog.qml")
self._license_dialog = CuraApplication.getInstance().createQmlComponent(license_dialog_component_path, {
"licenseModel": self._license_model,
"handler": self
})
@pyqtSlot()
def updatePackages(self) -> None:
""" A Qt slot which will update the List from a source. Actual implementation should be done in the child class"""
@ -122,9 +137,44 @@ class PackageList(ListModel):
canInstallChanged = pyqtSignal(str, bool)
def _openLicenseDialog(self, plugin_name: str, license_content: str) -> None:
Logger.debug(f"Prompting license for {plugin_name}")
self._license_model.setPackageId(plugin_name)
self._license_model.setLicenseText(license_content)
self._license_dialog.show()
@pyqtSlot()
def onLicenseAccepted(self) -> None:
package_id = self._license_model.packageId
Logger.debug(f"Accepted license for {package_id}")
self._license_dialog.close()
self._install(package_id)
@pyqtSlot()
def onLicenseDeclined(self) -> None:
package_id = self._license_model.packageId
Logger.debug(f"Declined license for {package_id}")
self._license_dialog.close()
package = self.getPackageModel(package_id)
package.is_installing = False
def _requestInstall(self, package_id: str, update: bool = False) -> None:
Logger.debug(f"Request installing {package_id}")
package_path = self._to_install[package_id]
license_content = self._manager.getPackageLicense(package_path)
if not update and license_content is not None:
# If installation is not and update, and the packages contains a license then
# open dialog, prompting the using to accept the plugin license
self._openLicenseDialog(package_id, license_content)
else:
# Otherwise continue the installation
self._install(package_id, update)
def _install(self, package_id: str, update: bool = False) -> None:
package_path = self._to_install.pop(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
package = self.getPackageModel(package_id)
if package.can_update and to_be_installed:

View File

@ -0,0 +1,88 @@
//Copyright (c) 2021 Ultimaker B.V.
//Cura is released under the terms of the LGPLv3 or higher.
import QtQuick 2.10
import QtQuick.Dialogs 1.1
import QtQuick.Window 2.2
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3
import QtQuick.Controls.Styles 1.4
import UM 1.1 as UM
import Cura 1.6 as Cura
UM.Dialog
{
id: licenseDialog
title: catalog.i18nc("@button", "Plugin license agreement")
minimumWidth: UM.Theme.getSize("license_window_minimum").width
minimumHeight: UM.Theme.getSize("license_window_minimum").height
width: minimumWidth
height: minimumHeight
backgroundColor: UM.Theme.getColor("main_background")
ColumnLayout
{
anchors.fill: parent
spacing: UM.Theme.getSize("thick_margin").height
UM.I18nCatalog{id: catalog; name: "cura"}
Row {
Layout.fillWidth: true
height: childrenRect.height
spacing: UM.Theme.getSize("default_margin").width
leftPadding: UM.Theme.getSize("narrow_margin").width
UM.RecolorImage
{
width: UM.Theme.getSize("marketplace_large_icon").width
height: UM.Theme.getSize("marketplace_large_icon").height
color: UM.Theme.getColor("text")
source: UM.Theme.getIcon("Certificate", "high")
}
Label
{
text: catalog.i18nc("@text", "Please read and agree with the plugin licence.")
color: UM.Theme.getColor("text")
font: UM.Theme.getFont("large")
anchors.verticalCenter: icon.verticalCenter
height: UM.Theme.getSize("marketplace_large_icon").height
verticalAlignment: Qt.AlignVCenter
wrapMode: Text.Wrap
renderType: Text.NativeRendering
}
}
Cura.ScrollableTextArea
{
Layout.fillWidth: true
Layout.fillHeight: true
anchors.topMargin: UM.Theme.getSize("default_margin").height
textArea.text: licenseModel.licenseText
textArea.readOnly: true
}
}
rightButtons:
[
Cura.PrimaryButton
{
text: catalog.i18nc("@button", "Accept")
onClicked: { handler.onLicenseAccepted() }
}
]
leftButtons:
[
Cura.SecondaryButton
{
text: catalog.i18nc("@button", "Decline")
onClicked: { handler.onLicenseDeclined() }
}
]
}

View File

@ -0,0 +1,3 @@
<svg width="48" height="48" viewBox="0 0 48 48" xmlns="http://www.w3.org/2000/svg">
<path d="M39.0176 13.0001H9.01764V11.0001H39.0176V13.0001ZM24.0176 16.0001H9.01764V18.0001H24.0176V16.0001ZM20.0176 21.0001H9.01764V23.0001H20.0176V21.0001ZM12.0176 26.0001H9.01764V28.0001H12.0176V26.0001ZM43.9576 5.06006V36.9401H35.6976V43.3901L31.6976 42.0501L27.6976 43.3901V36.9401H4.07764V5.06006H43.9576ZM33.6976 33.1401L31.7276 33.6801L29.6976 33.1501V40.6101L31.6976 39.9501L33.6976 40.6101V33.1401ZM36.2876 28.9501L36.9776 26.3001L36.2576 23.6601L34.3176 21.7301L31.6676 21.0401L29.0276 21.7601L27.0976 23.7001L26.4076 26.3501L27.1276 28.9901L29.0676 30.9201L31.7176 31.6101L34.3576 30.8901L36.2876 28.9501ZM42.0776 6.94006H5.95764V35.0601H27.6976V32.3701L25.3376 30.0301L24.3376 26.3601L25.3076 22.6701L27.9876 19.9701L31.6576 18.9601L35.3476 19.9301L38.0476 22.6201L39.0576 26.2901L38.0876 29.9801L35.6976 32.3801V35.0601H42.0776V6.94006Z" fill="#000E1A"/>
</svg>

After

Width:  |  Height:  |  Size: 959 B

View File

@ -686,6 +686,8 @@
"welcome_wizard_content_image_big": [18, 15],
"welcome_wizard_cloud_content_image": [4, 4],
"banner_icon_size": [2.0, 2.0]
"banner_icon_size": [2.0, 2.0],
"marketplace_large_icon": [4.0, 4.0]
}
}