Browse Source

Remove much logging or use debug level, fix cloud icon not appearing right away

ChrisTerBeke 6 years ago
parent
commit
beb68213f4

+ 6 - 4
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

+ 2 - 2
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),

+ 2 - 5
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,

+ 6 - 6
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)