Last active
August 21, 2019 12:08
-
-
Save jturcotte/4986536 to your computer and use it in GitHub Desktop.
WebView download API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 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