MCPcopy Create free account
hub / github.com/bumptop/BumpTop / downloadFinished

Method downloadFinished

trunk/win/Source/BT_JavaScriptAPI.cpp:114–148  ·  view source on GitHub ↗

This slot is connected to a QNetworkReply, probably started by downloadFile()

Source from the content-addressed store, hash-verified

112
113// This slot is connected to a QNetworkReply, probably started by downloadFile()
114void 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()
151void JavaScriptAPI::downloadError( QNetworkReply::NetworkError error)

Callers

nothing calls this directly

Calls 15

tempFunction · 0.85
attributeMethod · 0.80
launchFileMethod · 0.80
fileNameMethod · 0.80
evaluateJavaScriptMethod · 0.80
senderFunction · 0.50
toStringMethod · 0.45
requestMethod · 0.45
isEmptyMethod · 0.45
openMethod · 0.45
writeMethod · 0.45
readAllMethod · 0.45

Tested by

no test coverage detected