Improve conditions for starting cloud flow

Contributes to CL-1222
This commit is contained in:
Ian Paschal 2019-02-06 13:58:33 +01:00
parent 3a4fcb354a
commit 162fdad4e4

View File

@ -11,6 +11,7 @@ from PyQt5.QtCore import pyqtSlot, QUrl, pyqtSignal, pyqtProperty, QObject
from PyQt5.QtGui import QDesktopServices
from cura.CuraApplication import CuraApplication
from cura.PrinterOutputDevice import ConnectionType
from UM.OutputDevice.OutputDevicePlugin import OutputDevicePlugin
from UM.Logger import Logger
from UM.Signal import Signal, signalemitter
@ -89,9 +90,15 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
# Check if cloud flow is possible when user logs in
self._account.loginStateChanged.connect(self.checkCloudFlowIsPossible)
# Check if cloud flow is possible when user switches machines
self._application.globalContainerStackChanged.connect(self._onMachineSwitched)
# Listen for when cloud flow is possible
self.cloudFlowIsPossible.connect(self._onCloudFlowPossible)
self._start_cloud_flow_message = None # type: Optional[Message]
self._cloud_flow_complete_message = None # type: Optional[Message]
def getDiscoveredDevices(self):
return self._discovered_devices
@ -156,6 +163,7 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
um_network_key = CuraApplication.getInstance().getGlobalContainerStack().getMetaDataEntry("um_network_key")
if key == um_network_key:
self.getOutputDeviceManager().addOutputDevice(self._discovered_devices[key])
self.checkCloudFlowIsPossible()
else:
self.getOutputDeviceManager().removeOutputDevice(key)
@ -391,42 +399,46 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
## Check if the prerequsites are in place to start the cloud flow
def checkCloudFlowIsPossible(self):
active_machine = self._application.getMachineManager().activeMachine
if active_machine:
# Skip if already complete
if active_machine.getMetaDataEntry("cloud_flow_complete", "value") is not None:
return
# Skip if user said don't remind me
if active_machine.getMetaDataEntry("show_cloud_message", "value") is False:
return
Logger.log("d", "Checking if cloud connection is possible...")
# Check #1: User is logged in with an Ultimaker account
# Pre-Check: Skip if active machine already has been cloud connected or you said don't ask again
active_machine = self._application.getMachineManager().activeMachine
if active_machine:
# Check 1: Printer isn't already configured for cloud
if ConnectionType.CloudConnection.value in active_machine.configuredConnectionTypes:
Logger.log("d", "Active machine was already configured for cloud.")
return
# Check 2: User did not already say "Don't ask me again"
if active_machine.getMetaDataEntry("show_cloud_message", "value") is False:
Logger.log("d", "Active machine shouldn't ask about cloud anymore.")
return
# Check 3: User is logged in with an Ultimaker account
if not self._account.isLoggedIn:
Logger.log("d", "Cloud Flow not possible: User not logged in!")
return
# Check #2: Machine has a network connection
# Check 4: Machine is configured for network connectivity
if not self._application.getMachineManager().activeMachineHasActiveNetworkConnection:
Logger.log("d", "Cloud Flow not possible: Machine is not connected!")
return
# Check #3: Machine has correct firmware version
firmware_version = self._application.getMachineManager().activeMachineFirmwareVersion
if not Version(firmware_version) > self._min_cloud_version:
Logger.log("d", "Cloud Flow not possible: Machine firmware (%s) is too low! (Requires version %s)",
firmware_version,
self._min_cloud_version)
return
# Check 5: Machine has correct firmware version
# firmware_version = self._application.getMachineManager().activeMachineFirmwareVersion
# if not Version(firmware_version) > self._min_cloud_version:
# Logger.log("d", "Cloud Flow not possible: Machine firmware (%s) is too low! (Requires version %s)",
# firmware_version,
# self._min_cloud_version)
# return
Logger.log("d", "Cloud flow is possible!")
self.cloudFlowIsPossible.emit()
def _onCloudFlowPossible(self):
# Cloud flow is possible, so show the message
if not self._start_cloud_flow_message:
self._start_cloud_flow_message = Message(
i18n_catalog.i18nc("@info:status", "Pair your printer to your Ultimaker account and start print jobs from anywhere."),
0, # Lifetime
@ -449,7 +461,10 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
def _onCloudPrintingConfigured(self):
if self._start_cloud_flow_message:
self._start_cloud_flow_message.hide()
self._start_cloud_flow_message = None
# Show the successful pop-up
if not self._start_cloud_flow_message:
self._cloud_flow_complete_message = Message(
i18n_catalog.i18nc("@info:status", "You can now send and monitor print jobs from anywhere using your Ultimaker account."),
30, # Lifetime
@ -462,7 +477,7 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
i18n_catalog.i18nc("@info:status", "Connected!") # image caption
)
self._cloud_flow_complete_message.addAction("", i18n_catalog.i18nc("@action", "Review your connection"), "", "", 1) # TODO: Icon
self._start_cloud_flow_message.actionTriggered.connect(self._onReviewCloudConnection)
self._cloud_flow_complete_message.actionTriggered.connect(self._onReviewCloudConnection)
self._cloud_flow_complete_message.show()
# Set the machine's cloud flow as complete so we don't ask the user again and again for cloud connected printers
@ -484,6 +499,7 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
QDesktopServices.openUrl(QUrl("http://" + address + "/cloud_connect"))
if self._start_cloud_flow_message:
self._start_cloud_flow_message.hide()
self._start_cloud_flow_message = None
return
def _onReviewCloudConnection(self, message, action):
@ -491,3 +507,13 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
if address:
QDesktopServices.openUrl(QUrl("http://" + address + "/settings"))
return
def _onMachineSwitched(self):
if self._start_cloud_flow_message is not None:
self._start_cloud_flow_message.hide()
self._start_cloud_flow_message = None
if self._cloud_flow_complete_message is not None:
self._cloud_flow_complete_message.hide()
self._cloud_flow_complete_message = None
self.checkCloudFlowIsPossible()