Browse Source

Inform the Cloud page about new cloud printers

Properly close the welcome screen if the user has signed in and has
cloud printers linked to his/her account. If he doesn't have any, move
to the next page of the welcome wizard.

CURA-7019
Kostas Karmas 4 years ago
parent
commit
1602b71841

+ 6 - 0
cura/API/Account.py

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

+ 4 - 7
plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py

@@ -100,13 +100,6 @@ class CloudOutputDeviceManager:
         new_clusters = []
         online_clusters = {c.cluster_id: c for c in clusters if c.is_online}  # type: Dict[str, CloudClusterResponse]
 
-        # If the user signs in from the welcome dialog, then we will search for cloud printers and if any of them are
-        # found, the welcome screen will close. This way we avoid prompting the user to add printers if he/she already
-        # has cloud printers
-        welcome_pages_model = CuraApplication.getInstance().getWelcomePagesModel()
-        cloud_page_idx = welcome_pages_model.getPageIndexById("cloud") + 1
-        if welcome_pages_model.currentPageIndex == cloud_page_idx and len(online_clusters) > 0:
-            welcome_pages_model.atEnd()
         for device_id, cluster_data in online_clusters.items():
             if device_id not in self._remote_clusters:
                 new_clusters.append(cluster_data)
@@ -115,6 +108,10 @@ class CloudOutputDeviceManager:
 
         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())
         for device_id in removed_device_keys:
             self._onDiscoveredDeviceRemoved(device_id)

+ 9 - 5
resources/qml/WelcomePages/CloudContent.qml

@@ -15,14 +15,18 @@ Item
 {
     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()
         }
     }