Added download progress bar to plugin browser

CURA-3856
This commit is contained in:
Jaime van Kessel 2017-06-23 11:48:13 +02:00
parent e6a3577e9d
commit d815c2afcf
2 changed files with 34 additions and 9 deletions

View file

@ -39,8 +39,10 @@ class PluginBrowser(QObject, Extension):
self._qml_component = None self._qml_component = None
self._qml_context = None self._qml_context = None
self._dialog = None self._dialog = None
self._download_progress = 0
pluginsMetadataChanged = pyqtSignal() pluginsMetadataChanged = pyqtSignal()
onDownloadProgressChanged = pyqtSignal()
def browsePlugins(self): def browsePlugins(self):
self._createNetworkManager() self._createNetworkManager()
@ -72,7 +74,10 @@ class PluginBrowser(QObject, Extension):
def _onDownloadPluginProgress(self, bytes_sent, bytes_total): def _onDownloadPluginProgress(self, bytes_sent, bytes_total):
if bytes_total > 0: if bytes_total > 0:
new_progress = bytes_sent / bytes_total * 100 new_progress = bytes_sent / bytes_total * 100
if new_progress > self._download_progress:
self._download_progress = new_progress
self.onDownloadProgressChanged.emit()
self._download_progress = new_progress
if new_progress == 100.0: if new_progress == 100.0:
self._download_plugin_reply.downloadProgress.disconnect(self._onDownloadPluginProgress) self._download_plugin_reply.downloadProgress.disconnect(self._onDownloadPluginProgress)
self._temp_plugin_file = tempfile.NamedTemporaryFile(suffix = ".curaplugin") self._temp_plugin_file = tempfile.NamedTemporaryFile(suffix = ".curaplugin")
@ -80,12 +85,18 @@ class PluginBrowser(QObject, Extension):
result = PluginRegistry.getInstance().installPlugin("file://" + self._temp_plugin_file.name) result = PluginRegistry.getInstance().installPlugin("file://" + self._temp_plugin_file.name)
self._temp_plugin_file.close() # Plugin was installed, delete temp file self._temp_plugin_file.close() # Plugin was installed, delete temp file
@pyqtProperty(int, notify = onDownloadProgressChanged)
def downloadProgress(self):
return self._download_progress
@pyqtSlot(str) @pyqtSlot(str)
def downloadAndInstallPlugin(self, url): def downloadAndInstallPlugin(self, url):
Logger.log("i", "Attempting to download & install plugin from %s", url) Logger.log("i", "Attempting to download & install plugin from %s", url)
url = QUrl(url) url = QUrl(url)
self._download_plugin_request = QNetworkRequest(url) self._download_plugin_request = QNetworkRequest(url)
self._download_plugin_reply = self._network_manager.get(self._download_plugin_request) self._download_plugin_reply = self._network_manager.get(self._download_plugin_request)
self._download_progress = 0
self.onDownloadProgressChanged.emit()
self._download_plugin_reply.downloadProgress.connect(self._onDownloadPluginProgress) self._download_plugin_reply.downloadProgress.connect(self._onDownloadPluginProgress)
@pyqtProperty(QObject, notify=pluginsMetadataChanged) @pyqtProperty(QObject, notify=pluginsMetadataChanged)

View file

@ -13,7 +13,8 @@ UM.Dialog
height: 150 height: 150
ScrollView ScrollView
{ {
anchors.fill: parent width: parent.width
height: parent.height - progressbar.height - UM.Theme.getSize("default_margin").height
frameVisible: true frameVisible: true
ListView ListView
{ {
@ -24,6 +25,17 @@ UM.Dialog
delegate: pluginDelegate delegate: pluginDelegate
} }
} }
ProgressBar
{
id: progressbar
anchors.bottom: parent.bottom
style: UM.Theme.styles.progressbar
minimumValue: 0;
maximumValue: 100
width: parent.width
height: 20
value: manager.downloadProgress
}
Item Item
{ {
SystemPalette { id: palette } SystemPalette { id: palette }
@ -37,23 +49,25 @@ UM.Dialog
color: index % 2 ? palette.base : palette.alternateBase color: index % 2 ? palette.base : palette.alternateBase
Row Row
{ {
width: parent.width width: childrenRect.width
height: childrenRect.height; height: childrenRect.height;
anchors.left: parent.left anchors.left: parent.left
anchors.leftMargin: UM.Theme.getSize("default_margin").width anchors.leftMargin: UM.Theme.getSize("default_margin").width
Label Label
{ {
text: model.name text: model.name
width: contentWidth width: contentWidth
} }
Button
{ }
text: "Download" Button
onClicked: manager.downloadAndInstallPlugin(model.file_location) {
} text: "Download"
onClicked: manager.downloadAndInstallPlugin(model.file_location)
anchors.right: parent.right
} }
} }
} }
} }
} }