Skip to content

Instantly share code, notes, and snippets.

@jturcotte
Last active August 21, 2019 12:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jturcotte/4986536 to your computer and use it in GitHub Desktop.
Save jturcotte/4986536 to your computer and use it in GitHub Desktop.
WebView download API
/// Current API
WebView {
experimental.onDownloadRequested: {
downloadConnection.target = downloadItem
// expectedLength = downloadItem.expectedContentLength
downloadItem.destinationPath = downloadItem.suggestedFilename
downloadItem.start()
}
}
Item {
id: downloadManager
Connections {
id: downloadConnection
onTotalBytesReceivedChanged: {
print("Downloaded " + target.totalBytesReceived + " bytes of " + target.expectedContentLength)
}
onSucceeded: {
print("Done " + target.totalBytesReceived + " bytes")
}
}
onSomeUserAction: downloadConnection.target.cancel()
}
/// Proposed API
WebView {
// Triggers auto-start of all unsupported mime-types globally instead of allowing to decide this per download
// by requiring an explicit call to start().
// Explicit download policies set for navigations through
// QQuickWebView::navigationRequested will trigger a new
// auto-started download regardless of this property.
downloadUnsupportedContent: true
}
Item {
id: downloadManager
Connections {
// Downloads currently on their way are separated from individual WebViews.
target: QtWebKit
onDownloadStarted: {
currentDownload.targetHandle = downloadHandle
}
}
DownloadTracker {
id: currentDownload
onTotalBytesReceivedChanged: {
print("Downloaded " + currentDownload.totalBytesReceived + " bytes of " + currentDownload.expectedContentLength)
}
onSucceeded: {
print("Done " + currentDownload.totalBytesReceived + " bytes")
}
}
onSomeUserAction: currentDownload.cancel()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment