Browse Source

Download buttons are now disabled when another plugin is being downloaded

CURA-3856
Jaime van Kessel 7 years ago
parent
commit
a4e353c830
2 changed files with 18 additions and 4 deletions
  1. 15 1
      plugins/PluginBrowser/PluginBrowser.py
  2. 3 3
      plugins/PluginBrowser/PluginBrowser.qml

+ 15 - 1
plugins/PluginBrowser/PluginBrowser.py

@@ -41,8 +41,16 @@ class PluginBrowser(QObject, Extension):
         self._dialog = None
         self._download_progress = 0
 
+        self._is_downloading = False
+
+
     pluginsMetadataChanged = pyqtSignal()
     onDownloadProgressChanged = pyqtSignal()
+    onIsDownloadingChanged = pyqtSignal()
+
+    @pyqtProperty(bool, notify = onIsDownloadingChanged)
+    def isDownloading(self):
+        return self._is_downloading
 
     def browsePlugins(self):
         self._createNetworkManager()
@@ -71,6 +79,11 @@ class PluginBrowser(QObject, Extension):
             Logger.log("e", "QQmlComponent status %s", self._qml_component.status())
             Logger.log("e", "QQmlComponent errorString %s", self._qml_component.errorString())
 
+    def setIsDownloading(self, is_downloading):
+        if self._is_downloading != is_downloading:
+            self._is_downloading = is_downloading
+            self.onIsDownloadingChanged.emit()
+
     def _onDownloadPluginProgress(self, bytes_sent, bytes_total):
         if bytes_total > 0:
             new_progress = bytes_sent / bytes_total * 100
@@ -79,6 +92,7 @@ class PluginBrowser(QObject, Extension):
                 self.onDownloadProgressChanged.emit()
             self._download_progress = new_progress
             if new_progress == 100.0:
+                self.setIsDownloading(False)
                 self._download_plugin_reply.downloadProgress.disconnect(self._onDownloadPluginProgress)
                 self._temp_plugin_file = tempfile.NamedTemporaryFile(suffix = ".curaplugin")
                 self._temp_plugin_file.write(self._download_plugin_reply.readAll())
@@ -96,6 +110,7 @@ class PluginBrowser(QObject, Extension):
         self._download_plugin_request = QNetworkRequest(url)
         self._download_plugin_reply = self._network_manager.get(self._download_plugin_request)
         self._download_progress = 0
+        self.setIsDownloading(True)
         self.onDownloadProgressChanged.emit()
         self._download_plugin_reply.downloadProgress.connect(self._onDownloadPluginProgress)
 
@@ -134,7 +149,6 @@ class PluginBrowser(QObject, Extension):
                 return False
         return True
 
-
     def _onRequestFinished(self, reply):
         reply_url = reply.url().toString()
         if reply.operation() == QNetworkAccessManager.GetOperation:

+ 3 - 3
plugins/PluginBrowser/PluginBrowser.qml

@@ -8,7 +8,7 @@ UM.Dialog
 {
     id: base
 
-    title: "YAY"
+    title: "Find & Update plugins"
     width: 450
     height: 150
     ScrollView
@@ -63,10 +63,10 @@ UM.Dialog
                 }
                 Button
                 {
-                    text: enabled ? "Download" : "Already Installed"
+                    text: !model.already_installed ? "Download" : "Already Installed"
                     onClicked: manager.downloadAndInstallPlugin(model.file_location)
                     anchors.right: parent.right
-                    enabled: !model.already_installed
+                    enabled: !model.already_installed && !manager.isDownloading
                 }
             }