Merge pull request #6992 from Ultimaker/CURA-6984_decline_sync

CURA-6984_decline_sync
This commit is contained in:
konskarm 2020-01-21 10:47:22 +01:00 committed by GitHub
commit d8abd24bfe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 44 additions and 13 deletions

View file

@ -152,7 +152,7 @@ UM.Dialog{
} // End of ScrollView } // End of ScrollView
Cura.ActionButton Cura.PrimaryButton
{ {
id: nextButton id: nextButton
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
@ -160,6 +160,8 @@ UM.Dialog{
anchors.margins: UM.Theme.getSize("default_margin").height anchors.margins: UM.Theme.getSize("default_margin").height
text: catalog.i18nc("@button", "Next") text: catalog.i18nc("@button", "Next")
onClicked: accept() onClicked: accept()
leftPadding: UM.Theme.getSize("dialog_primary_button_padding").width
rightPadding: UM.Theme.getSize("dialog_primary_button_padding").width
} }
} }
} }

View file

@ -10,6 +10,7 @@ import QtQuick.Controls.Styles 1.4
// TODO: Switch to QtQuick.Controls 2.x and remove QtQuick.Controls.Styles // TODO: Switch to QtQuick.Controls 2.x and remove QtQuick.Controls.Styles
import UM 1.1 as UM import UM 1.1 as UM
import Cura 1.6 as Cura
UM.Dialog UM.Dialog
{ {
@ -51,18 +52,22 @@ UM.Dialog
} }
rightButtons: rightButtons:
[ [
Button Cura.PrimaryButton
{ {
id: acceptButton leftPadding: UM.Theme.getSize("dialog_primary_button_padding").width
anchors.margins: UM.Theme.getSize("default_margin").width rightPadding: UM.Theme.getSize("dialog_primary_button_padding").width
text: catalog.i18nc("@action:button", "Accept")
text: catalog.i18nc("@button", "Agree")
onClicked: { handler.onLicenseAccepted() } onClicked: { handler.onLicenseAccepted() }
}, }
Button ]
leftButtons:
[
Cura.SecondaryButton
{ {
id: declineButton id: declineButton
anchors.margins: UM.Theme.getSize("default_margin").width text: catalog.i18nc("@button", "Decline and remove from account")
text: catalog.i18nc("@action:button", "Decline")
onClicked: { handler.onLicenseDeclined() } onClicked: { handler.onLicenseDeclined() }
} }
] ]

View file

@ -18,3 +18,11 @@ class CloudApiModel:
cloud_api_root=cloud_api_root, cloud_api_root=cloud_api_root,
cloud_api_version=cloud_api_version, cloud_api_version=cloud_api_version,
) )
## https://api.ultimaker.com/cura-packages/v1/user/packages/{package_id}
@classmethod
def userPackageUrl(cls, package_id: str) -> str:
return (CloudApiModel.api_url_user_packages + "/{package_id}").format(
package_id=package_id
)

View file

@ -16,3 +16,8 @@ class CloudPackageManager:
data=data.encode(), data=data.encode(),
scope=self._scope scope=self._scope
) )
def unsubscribe(self, package_id: str) -> None:
url = CloudApiModel.userPackageUrl(package_id)
self._request_manager.delete(url=url, scope=self._scope)

View file

@ -1,8 +1,10 @@
import os import os
from typing import List, Dict, Any, cast from typing import List, Dict, Any, cast
from UM import i18n_catalog
from UM.Extension import Extension from UM.Extension import Extension
from UM.Logger import Logger from UM.Logger import Logger
from UM.Message import Message
from UM.PluginRegistry import PluginRegistry from UM.PluginRegistry import PluginRegistry
from cura.CuraApplication import CuraApplication from cura.CuraApplication import CuraApplication
from .CloudPackageChecker import CloudPackageChecker from .CloudPackageChecker import CloudPackageChecker
@ -64,7 +66,10 @@ class SyncOrchestrator(Extension):
# \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]) -> None: def _onDownloadFinished(self, success_items: Dict[str, str], error_items: List[str]) -> None:
# todo handle error items if error_items:
message = i18n_catalog.i18nc("@info:generic", "{} plugins failed to download".format(len(error_items)))
self._showErrorMessage(message)
plugin_path = cast(str, PluginRegistry.getInstance().getPluginPath(self.getPluginId())) plugin_path = cast(str, PluginRegistry.getInstance().getPluginPath(self.getPluginId()))
self._license_presenter.present(plugin_path, success_items) self._license_presenter.present(plugin_path, success_items)
@ -78,15 +83,20 @@ class SyncOrchestrator(Extension):
if item["accepted"]: if item["accepted"]:
# install and subscribe packages # install and subscribe packages
if not self._package_manager.installPackage(item["package_path"]): if not self._package_manager.installPackage(item["package_path"]):
Logger.error("could not install {}".format(item["package_id"])) message = "Could not install {}".format(item["package_id"])
self._showErrorMessage(message)
continue continue
self._cloud_package_manager.subscribe(item["package_id"]) self._cloud_package_manager.subscribe(item["package_id"])
has_changes = True has_changes = True
else: else:
# todo unsubscribe declined packages self._cloud_package_manager.unsubscribe(item["package_id"])
pass
# delete temp file # delete temp file
os.remove(item["package_path"]) os.remove(item["package_path"])
if has_changes: if has_changes:
self._restart_presenter.present() self._restart_presenter.present()
## Logs an error and shows it to the user
def _showErrorMessage(self, text: str):
Logger.error(text)
Message(text, lifetime=0).show()

View file

@ -520,6 +520,7 @@
"action_button": [15.0, 2.5], "action_button": [15.0, 2.5],
"action_button_icon": [1.0, 1.0], "action_button_icon": [1.0, 1.0],
"action_button_radius": [0.15, 0.15], "action_button_radius": [0.15, 0.15],
"dialog_primary_button_padding": [3.0, 0],
"radio_button": [1.3, 1.3], "radio_button": [1.3, 1.3],