diff --git a/cura/Settings/MachineManager.py b/cura/Settings/MachineManager.py index f47724372f..bdb0f10082 100755 --- a/cura/Settings/MachineManager.py +++ b/cura/Settings/MachineManager.py @@ -178,6 +178,7 @@ class MachineManager(QObject): self._printer_output_devices.append(printer_output_device) self.outputDevicesChanged.emit() + self.printerConnectedStatusChanged.emit() @pyqtProperty(QObject, notify = currentConfigurationChanged) def currentConfiguration(self) -> ConfigurationModel: @@ -520,7 +521,7 @@ class MachineManager(QObject): return "" @pyqtProperty(bool, notify = printerConnectedStatusChanged) - def printerConnected(self): + def printerConnected(self) -> bool: return bool(self._printer_output_devices) @pyqtProperty(bool, notify = printerConnectedStatusChanged) @@ -532,9 +533,10 @@ class MachineManager(QObject): @pyqtProperty(bool, notify = printerConnectedStatusChanged) def activeMachineHasCloudConnection(self) -> bool: - if not self.activeMachineHasRemoteConnection: - return False - output_device = next(iter(self.printerOutputDevices), None) # type: Optional[PrinterOutputDevice] + # A cloud connection is only available if the active output device actually is a cloud connected device. + # We cannot simply use the connection_type metadata entry as that's always set to 'NetworkConnection' + # if there was a network connection during setup, which is always the case. + output_device = next(iter(self._printer_output_devices), None) # type: Optional[PrinterOutputDevice] if not output_device: return False return output_device.connectionType == ConnectionType.CloudConnection diff --git a/plugins/UM3NetworkPrinting/src/Cloud/CloudApiClient.py b/plugins/UM3NetworkPrinting/src/Cloud/CloudApiClient.py index 29a9f48c3f..302ca86d32 100644 --- a/plugins/UM3NetworkPrinting/src/Cloud/CloudApiClient.py +++ b/plugins/UM3NetworkPrinting/src/Cloud/CloudApiClient.py @@ -101,7 +101,7 @@ class CloudApiClient: request.setHeader(QNetworkRequest.ContentTypeHeader, content_type) if self._account.isLoggedIn: request.setRawHeader(b"Authorization", "Bearer {}".format(self._account.accessToken).encode()) - Logger.log("i", "Created request for URL %s. Logged in = %s", path, self._account.isLoggedIn) + # Logger.log("i", "Created request for URL %s. Logged in = %s", path, self._account.isLoggedIn) return request ## Parses the given JSON network reply into a status code and a dictionary, handling unexpected errors as well. @@ -112,7 +112,7 @@ class CloudApiClient: status_code = reply.attribute(QNetworkRequest.HttpStatusCodeAttribute) try: response = bytes(reply.readAll()).decode() - Logger.log("i", "Received a reply %s from %s with %s", status_code, reply.url().toString(), response) + # Logger.log("i", "Received a reply %s from %s with %s", status_code, reply.url().toString(), response) return status_code, json.loads(response) except (UnicodeDecodeError, JSONDecodeError, ValueError) as err: error = CloudErrorObject(code=type(err).__name__, title=str(err), http_code=str(status_code), diff --git a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py index 7e9608dc8b..c436418f5e 100644 --- a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py +++ b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py @@ -65,8 +65,6 @@ class T: # Currently it only supports viewing the printer and print job status and adding a new job to the queue. # As such, those methods have been implemented here. # Note that this device represents a single remote cluster, not a list of multiple clusters. -# -# TODO: figure our how the QML interface for the cluster networking should operate with this limited functionality. class CloudOutputDevice(NetworkedPrinterOutputDevice): # The interval with which the remote clusters are checked @@ -202,10 +200,9 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice): def _update(self) -> None: super()._update() if self._last_request_time and time() - self._last_request_time < self.CHECK_CLUSTER_INTERVAL: - Logger.log("i", "Not updating: %s - %s < %s", time(), self._last_request_time, self.CHECK_CLUSTER_INTERVAL) return # avoid calling the cloud too often - Logger.log("i", "Updating: %s - %s >= %s", time(), self._last_request_time, self.CHECK_CLUSTER_INTERVAL) + Logger.log("d", "Updating: %s - %s >= %s", time(), self._last_request_time, self.CHECK_CLUSTER_INTERVAL) if self._account.isLoggedIn: self.setAuthenticationState(AuthState.Authenticated) self._last_request_time = time() @@ -342,7 +339,7 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice): ## Shows a message when the upload has succeeded # \param response: The response from the cloud API. def _onPrintRequested(self, response: CloudPrintResponse) -> None: - Logger.log("i", "The cluster will be printing this print job with the ID %s", response.cluster_job_id) + Logger.log("d", "The cluster will be printing this print job with the ID %s", response.cluster_job_id) self._progress.hide() Message( text = T.UPLOAD_SUCCESS_TEXT, diff --git a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py index 07051f15fd..af45f06394 100644 --- a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py +++ b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py @@ -50,7 +50,7 @@ class CloudOutputDeviceManager: # Called when the uses logs in or out def _onLoginStateChanged(self, is_logged_in: bool) -> None: - Logger.log("i", "Log in state changed to %s", is_logged_in) + Logger.log("d", "Log in state changed to %s", is_logged_in) if is_logged_in: if not self._update_timer.isActive(): self._update_timer.start() @@ -64,7 +64,7 @@ class CloudOutputDeviceManager: ## Gets all remote clusters from the API. def _getRemoteClusters(self) -> None: - Logger.log("i", "Retrieving remote clusters") + Logger.log("d", "Retrieving remote clusters") self._api.getClusters(self._onGetRemoteClustersFinished) ## Callback for when the request for getting the clusters. is finished. @@ -73,8 +73,8 @@ class CloudOutputDeviceManager: removed_devices, added_clusters, updates = findChanges(self._remote_clusters, online_clusters) - Logger.log("i", "Parsed remote clusters to %s", [cluster.toDict() for cluster in online_clusters.values()]) - Logger.log("i", "Removed: %s, added: %s, updates: %s", len(removed_devices), len(added_clusters), len(updates)) + Logger.log("d", "Parsed remote clusters to %s", [cluster.toDict() for cluster in online_clusters.values()]) + Logger.log("d", "Removed: %s, added: %s, updates: %s", len(removed_devices), len(added_clusters), len(updates)) # Remove output devices that are gone for removed_cluster in removed_devices: @@ -100,7 +100,7 @@ class CloudOutputDeviceManager: def _connectToActiveMachine(self) -> None: active_machine = CuraApplication.getInstance().getGlobalContainerStack() if not active_machine: - Logger.log("i", "no active machine") + Logger.log("d", "no active machine") return # Check if the stored cluster_id for the active machine is in our list of remote clusters. @@ -109,7 +109,7 @@ class CloudOutputDeviceManager: device = self._remote_clusters[stored_cluster_id] if not device.isConnected(): device.connect() - Logger.log("i", "Device connected by metadata %s", stored_cluster_id) + Logger.log("d", "Device connected by metadata %s", stored_cluster_id) else: self._connectByNetworkKey(active_machine)