This slot is connected to a QNetworkReply, probably started by downloadFile()
| 112 | |
| 113 | // This slot is connected to a QNetworkReply, probably started by downloadFile() |
| 114 | void JavaScriptAPI::downloadFinished() |
| 115 | { |
| 116 | QNetworkReply *reply = (QNetworkReply *)sender(); |
| 117 | QString callbackName = reply->request().attribute(QNetworkRequest::User).toString(); |
| 118 | QString origFilename = reply->request().attribute(QNetworkRequest::UserMax).toString(); |
| 119 | QUrl redirectUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl(); |
| 120 | if (redirectUrl.isEmpty()) |
| 121 | { |
| 122 | QDir downloadDir = QDir::temp(); |
| 123 | downloadDir.mkdir("BumpTop Downloads"); |
| 124 | downloadDir.cd("BumpTop Downloads"); |
| 125 | |
| 126 | // Save the download to a temp file |
| 127 | QFileInfo fileInfo(origFilename); |
| 128 | QString filename = fileInfo.baseName() + "_XXXXXX." + fileInfo.completeSuffix(); |
| 129 | QTemporaryFile destFile(downloadDir.absoluteFilePath(filename)); |
| 130 | destFile.setAutoRemove(false); |
| 131 | if (destFile.open()) |
| 132 | { |
| 133 | destFile.write(reply->readAll()); |
| 134 | destFile.close(); |
| 135 | } |
| 136 | // Try to rename it to the original filename. Might fail, but that's ok. |
| 137 | destFile.rename(downloadDir.absoluteFilePath(origFilename)); |
| 138 | destFile.setPermissions(QFile::ReadUser); // Make the file read-only |
| 139 | fsManager->launchFile(destFile.fileName()); |
| 140 | if (!callbackName.isNull()) |
| 141 | _page->evaluateJavaScript(callbackName + "(true);"); |
| 142 | } |
| 143 | else |
| 144 | { |
| 145 | // Follow the redirect |
| 146 | downloadFile(redirectUrl, callbackName, origFilename); |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | // This slot is connected to a QNetworkReply, probably started by downloadFile() |
| 151 | void JavaScriptAPI::downloadError( QNetworkReply::NetworkError error) |
nothing calls this directly
no test coverage detected