From c35aabd2c40cd65c01f2443927b04722aed93f85 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Tue, 19 Feb 2019 13:34:04 +0100 Subject: [PATCH 1/3] Add message to indicate that Cura was unable to connect with account server This happens when you were logged previously, but currently don't have internet acces. CURA-6231 --- cura/API/Account.py | 3 +++ cura/OAuth2/AuthorizationService.py | 29 ++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/cura/API/Account.py b/cura/API/Account.py index 8a8b708cfa..30401454b3 100644 --- a/cura/API/Account.py +++ b/cura/API/Account.py @@ -76,6 +76,9 @@ class Account(QObject): self._error_message.hide() self._error_message = Message(error_message, title = i18n_catalog.i18nc("@info:title", "Login failed")) self._error_message.show() + self._logged_in = False + self.loginStateChanged.emit(False) + return if self._logged_in != logged_in: self._logged_in = logged_in diff --git a/cura/OAuth2/AuthorizationService.py b/cura/OAuth2/AuthorizationService.py index a76e8cf304..355db1f1a0 100644 --- a/cura/OAuth2/AuthorizationService.py +++ b/cura/OAuth2/AuthorizationService.py @@ -9,12 +9,16 @@ import requests.exceptions from UM.Logger import Logger +from UM.Message import Message from UM.Signal import Signal from cura.OAuth2.LocalAuthorizationServer import LocalAuthorizationServer from cura.OAuth2.AuthorizationHelpers import AuthorizationHelpers, TOKEN_TIMESTAMP_FORMAT from cura.OAuth2.Models import AuthenticationResponse +from UM.i18n import i18nCatalog +i18n_catalog = i18nCatalog("cura") + if TYPE_CHECKING: from cura.OAuth2.Models import UserProfile, OAuth2Settings from UM.Preferences import Preferences @@ -41,6 +45,14 @@ class AuthorizationService: self._preferences = preferences self._server = LocalAuthorizationServer(self._auth_helpers, self._onAuthStateChanged, daemon=True) + self._unable_to_get_data_message = None + + self.onAuthStateChanged.connect(self._authChanged) + + def _authChanged(self, logged_in): + if logged_in and self._unable_to_get_data_message is not None: + self._unable_to_get_data_message.hide() + def initialize(self, preferences: Optional["Preferences"] = None) -> None: if preferences is not None: self._preferences = preferences @@ -162,7 +174,18 @@ class AuthorizationService: preferences_data = json.loads(self._preferences.getValue(self._settings.AUTH_DATA_PREFERENCE_KEY)) if preferences_data: self._auth_data = AuthenticationResponse(**preferences_data) - self.onAuthStateChanged.emit(logged_in=True) + # Also check if we can actually get the user profile information. + user_profile = self.getUserProfile() + if user_profile is not None: + self.onAuthStateChanged.emit(logged_in=True) + else: + if self._unable_to_get_data_message is not None: + self._unable_to_get_data_message.hide() + + self._unable_to_get_data_message = Message(i18n_catalog.i18nc("@info", "Unable to reach the Ultimaker account server."), title = i18n_catalog.i18nc("@info:title", "Warning")) + self._unable_to_get_data_message.addAction("retry", i18n_catalog.i18nc("@action:button", "Retry"), "[no_icon]", "[no_description]") + self._unable_to_get_data_message.actionTriggered.connect(self._onMessageActionTriggered) + self._unable_to_get_data_message.show() except ValueError: Logger.logException("w", "Could not load auth data from preferences") @@ -179,3 +202,7 @@ class AuthorizationService: else: self._user_profile = None self._preferences.resetPreference(self._settings.AUTH_DATA_PREFERENCE_KEY) + + def _onMessageActionTriggered(self, _, action): + if action == "retry": + self.loadAuthDataFromPreferences() From d53bac6eb80f0642028760569cfbb23c0fee2b88 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Tue, 19 Feb 2019 15:42:51 +0100 Subject: [PATCH 2/3] Simplify the expensive call to the validation state Since the support angle needs to be between 0 and 90, we don't have to rely on the (expensive) validator. We can just check that ourselves. --- plugins/SolidView/SolidView.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/SolidView/SolidView.py b/plugins/SolidView/SolidView.py index 797d6dabec..ec00329f86 100644 --- a/plugins/SolidView/SolidView.py +++ b/plugins/SolidView/SolidView.py @@ -69,8 +69,7 @@ class SolidView(View): if support_angle_stack is not None and Application.getInstance().getPreferences().getValue("view/show_overhang"): angle = support_angle_stack.getProperty("support_angle", "value") # Make sure the overhang angle is valid before passing it to the shader - # Note: if the overhang angle is set to its default value, it does not need to get validated (validationState = None) - if angle is not None and global_container_stack.getProperty("support_angle", "validationState") in [None, ValidatorState.Valid]: + if angle is not None and angle >= 0 and angle <= 90: self._enabled_shader.setUniformValue("u_overhangAngle", math.cos(math.radians(90 - angle))) else: self._enabled_shader.setUniformValue("u_overhangAngle", math.cos(math.radians(0))) #Overhang angle of 0 causes no area at all to be marked as overhang. From 6143906fa403b1d94876b9d651154047912ec33b Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Tue, 19 Feb 2019 15:44:31 +0100 Subject: [PATCH 3/3] Add type for message saying it's unable to connect Contributes to issue CURA-6231. --- cura/OAuth2/AuthorizationService.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cura/OAuth2/AuthorizationService.py b/cura/OAuth2/AuthorizationService.py index 355db1f1a0..3c2f66d037 100644 --- a/cura/OAuth2/AuthorizationService.py +++ b/cura/OAuth2/AuthorizationService.py @@ -1,5 +1,6 @@ -# Copyright (c) 2018 Ultimaker B.V. +# Copyright (c) 2019 Ultimaker B.V. # Cura is released under the terms of the LGPLv3 or higher. + import json import webbrowser from datetime import datetime, timedelta @@ -45,7 +46,7 @@ class AuthorizationService: self._preferences = preferences self._server = LocalAuthorizationServer(self._auth_helpers, self._onAuthStateChanged, daemon=True) - self._unable_to_get_data_message = None + self._unable_to_get_data_message = None # type: Optional[Message] self.onAuthStateChanged.connect(self._authChanged)