Merge pull request #7539 from Ultimaker/CURA-7019_Move_sign_in_screen_in_front_of_add_printer_in_first_run_wizard

Cura 7019 move sign in screen in front of add printer in first run wizard
This commit is contained in:
Nino van Hooff 2020-04-23 14:56:31 +02:00 committed by GitHub
commit 3ba284b36c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 76 additions and 35 deletions

View File

@ -29,10 +29,12 @@ class Account(QObject):
# Signal emitted when user logged in or out. # Signal emitted when user logged in or out.
loginStateChanged = pyqtSignal(bool) loginStateChanged = pyqtSignal(bool)
accessTokenChanged = pyqtSignal() accessTokenChanged = pyqtSignal()
cloudPrintersDetectedChanged = pyqtSignal(bool)
def __init__(self, application: "CuraApplication", parent = None) -> None: def __init__(self, application: "CuraApplication", parent = None) -> None:
super().__init__(parent) super().__init__(parent)
self._application = application self._application = application
self._new_cloud_printers_detected = False
self._error_message = None # type: Optional[Message] self._error_message = None # type: Optional[Message]
self._logged_in = False self._logged_in = False
@ -74,6 +76,10 @@ class Account(QObject):
def isLoggedIn(self) -> bool: def isLoggedIn(self) -> bool:
return self._logged_in return self._logged_in
@pyqtProperty(bool, notify=cloudPrintersDetectedChanged)
def newCloudPrintersDetected(self) -> bool:
return self._new_cloud_printers_detected
def _onLoginStateChanged(self, logged_in: bool = False, error_message: Optional[str] = None) -> None: def _onLoginStateChanged(self, logged_in: bool = False, error_message: Optional[str] = None) -> None:
if error_message: if error_message:
if self._error_message: if self._error_message:

View File

@ -243,6 +243,10 @@ class WelcomePagesModel(ListModel):
{"id": "data_collections", {"id": "data_collections",
"page_url": self._getBuiltinWelcomePagePath("DataCollectionsContent.qml"), "page_url": self._getBuiltinWelcomePagePath("DataCollectionsContent.qml"),
}, },
{"id": "cloud",
"page_url": self._getBuiltinWelcomePagePath("CloudContent.qml"),
"should_show_function": self.shouldShowCloudPage,
},
{"id": "add_network_or_local_printer", {"id": "add_network_or_local_printer",
"page_url": self._getBuiltinWelcomePagePath("AddNetworkOrLocalPrinterContent.qml"), "page_url": self._getBuiltinWelcomePagePath("AddNetworkOrLocalPrinterContent.qml"),
"next_page_id": "machine_actions", "next_page_id": "machine_actions",
@ -253,12 +257,8 @@ class WelcomePagesModel(ListModel):
}, },
{"id": "machine_actions", {"id": "machine_actions",
"page_url": self._getBuiltinWelcomePagePath("FirstStartMachineActionsContent.qml"), "page_url": self._getBuiltinWelcomePagePath("FirstStartMachineActionsContent.qml"),
"next_page_id": "cloud",
"should_show_function": self.shouldShowMachineActions, "should_show_function": self.shouldShowMachineActions,
}, },
{"id": "cloud",
"page_url": self._getBuiltinWelcomePagePath("CloudContent.qml"),
},
] ]
pages_to_show = all_pages_list pages_to_show = all_pages_list
@ -287,6 +287,17 @@ class WelcomePagesModel(ListModel):
first_start_actions = self._application.getMachineActionManager().getFirstStartActions(definition_id) first_start_actions = self._application.getMachineActionManager().getFirstStartActions(definition_id)
return len([action for action in first_start_actions if action.needsUserInteraction()]) > 0 return len([action for action in first_start_actions if action.needsUserInteraction()]) > 0
def shouldShowCloudPage(self) -> bool:
"""
The cloud page should be shown only if the user is not logged in
:return: True if the user is not logged in, False if he/she is
"""
# Import CuraApplication locally or else it fails
from cura.CuraApplication import CuraApplication
api = CuraApplication.getInstance().getCuraAPI()
return not api.account.isLoggedIn
def addPage(self) -> None: def addPage(self) -> None:
pass pass

View File

@ -99,12 +99,17 @@ class CloudOutputDeviceManager:
new_clusters = [] new_clusters = []
online_clusters = {c.cluster_id: c for c in clusters if c.is_online} # type: Dict[str, CloudClusterResponse] online_clusters = {c.cluster_id: c for c in clusters if c.is_online} # type: Dict[str, CloudClusterResponse]
for device_id, cluster_data in online_clusters.items(): for device_id, cluster_data in online_clusters.items():
if device_id not in self._remote_clusters: if device_id not in self._remote_clusters:
new_clusters.append(cluster_data) new_clusters.append(cluster_data)
self._onDevicesDiscovered(new_clusters) self._onDevicesDiscovered(new_clusters)
# Inform whether new cloud printers have been detected. If they have, the welcome wizard can close.
self._account._new_cloud_printers_detected = len(new_clusters) > 0
self._account.cloudPrintersDetectedChanged.emit(len(new_clusters) > 0)
removed_device_keys = set(self._remote_clusters.keys()) - set(online_clusters.keys()) removed_device_keys = set(self._remote_clusters.keys()) - set(online_clusters.keys())
for device_id in removed_device_keys: for device_id in removed_device_keys:
self._onDiscoveredDeviceRemoved(device_id) self._onDiscoveredDeviceRemoved(device_id)
@ -176,7 +181,10 @@ class CloudOutputDeviceManager:
message.setProgress((idx / len(new_devices)) * 100) message.setProgress((idx / len(new_devices)) * 100)
CuraApplication.getInstance().processEvents() CuraApplication.getInstance().processEvents()
self._remote_clusters[device.getId()] = device self._remote_clusters[device.getId()] = device
self._createMachineFromDiscoveredDevice(device.getId(), activate = False)
# If there is no active machine, activate the first available cloud printer
activate = not CuraApplication.getInstance().getMachineManager().activeMachine
self._createMachineFromDiscoveredDevice(device.getId(), activate = activate)
message.setProgress(None) message.setProgress(None)

View File

@ -15,14 +15,18 @@ Item
{ {
UM.I18nCatalog { id: catalog; name: "cura" } UM.I18nCatalog { id: catalog; name: "cura" }
property bool isLoggedIn: Cura.API.account.isLoggedIn property bool newCloudPrintersDetected: Cura.API.account.newCloudPrintersDetected
onIsLoggedInChanged: onNewCloudPrintersDetectedChanged:
{ {
if(isLoggedIn) // When the user signs in successfully, it will be checked whether he/she has cloud printers connected to
// the account. If he/she does, then the welcome wizard can close. If not, then proceed to the next page (if any)
if(newCloudPrintersDetected)
{
base.endWizard()
}
else
{ {
// If the user created an account or logged in by pressing any button on this page, all the actions that
// need / can be done by this page are completed, so we can just go to the next (if any).
base.showNextPage() base.showNextPage()
} }
} }
@ -46,7 +50,7 @@ Item
anchors anchors
{ {
top: titleLabel.bottom top: titleLabel.bottom
bottom: finishButton.top bottom: skipButton.top
left: parent.left left: parent.left
right: parent.right right: parent.right
topMargin: UM.Theme.getSize("default_margin").height topMargin: UM.Theme.getSize("default_margin").height
@ -107,35 +111,47 @@ Item
color: UM.Theme.getColor("text") color: UM.Theme.getColor("text")
renderType: Text.NativeRendering renderType: Text.NativeRendering
} }
}
}
// Bottom buttons go here // "Sign in" and "Create an account" exist inside the column
Cura.PrimaryButton Cura.PrimaryButton
{ {
id: finishButton id: signInButton
anchors.right: parent.right height: createAccountButton.height
anchors.bottom: parent.bottom width: createAccountButton.width
text: catalog.i18nc("@button", "Finish") anchors.horizontalCenter: parent.horizontalCenter
onClicked: base.showNextPage() text: catalog.i18nc("@button", "Sign in")
onClicked: Cura.API.account.login()
// Content Item is used in order to align the text inside the button. Without it, when resizing the
// button, the text will be aligned on the left
contentItem: Text {
text: signInButton.text
font: UM.Theme.getFont("medium")
color: UM.Theme.getColor("primary_text")
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
} }
Cura.SecondaryButton Cura.SecondaryButton
{ {
id: createAccountButton id: createAccountButton
anchors.left: parent.left anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: finishButton.verticalCenter text: catalog.i18nc("@button","Create account")
text: catalog.i18nc("@button", "Create an account")
onClicked: Qt.openUrlExternally(CuraApplication.ultimakerCloudAccountRootUrl + "/app/create") onClicked: Qt.openUrlExternally(CuraApplication.ultimakerCloudAccountRootUrl + "/app/create")
} }
}
}
// The "Skip" button exists on the bottom right
Label Label
{ {
id: signInButton id: skipButton
anchors.left: createAccountButton.right anchors.right: parent.right
anchors.verticalCenter: finishButton.verticalCenter anchors.bottom: parent.bottom
anchors.leftMargin: UM.Theme.getSize("default_margin").width anchors.leftMargin: UM.Theme.getSize("default_margin").width
text: catalog.i18nc("@button", "Sign in") text: catalog.i18nc("@button", "Skip")
color: UM.Theme.getColor("secondary_button_text") color: UM.Theme.getColor("secondary_button_text")
font: UM.Theme.getFont("medium") font: UM.Theme.getFont("medium")
renderType: Text.NativeRendering renderType: Text.NativeRendering
@ -144,7 +160,7 @@ Item
{ {
anchors.fill: parent anchors.fill: parent
hoverEnabled: true hoverEnabled: true
onClicked: Cura.API.account.login() onClicked: base.showNextPage()
onEntered: parent.font.underline = true onEntered: parent.font.underline = true
onExited: parent.font.underline = false onExited: parent.font.underline = false
} }