- // Check path suffix. If it is .torrent, we should download:
- /// @todo We should actually check for MIME-type application/x-bittorrent in HTTP response,
- /// instead of relying on file suffix.
- /// e.g. link
- ///http://www.bitenova.org/download.php?id=c84375141231eef49fc6c55e6347ba4f4a623a05&name=Nero_Linux_3.5.1.0__(Debian)_deutsch
- /// will not work.
- /// @todo Also, after downloading, the torrent bencoding validity should be checked at plugin host..
- if (fInfo.suffix() == "torrent") {
-#ifdef QTRAPIDS_DEBUG
- qDebug() << "IS TORRENT";
-#endif
- QString filename = fInfo.fileName();
+ qDebug() << "on_networkReplyFinished()";
+ QString contentType = reply->header(QNetworkRequest::ContentTypeHeader).toString();
+ QString filename;
+ QByteArray replyData;
+ QUrl url = reply->url();
+
+ qDebug() << "on_networkReplyFinished():" << url;
+
+ // If content type is torrent data, read reply data:
+ if (contentType == "application/x-bittorrent") {
+
+ // If HTTP-response has Content-Disposition: -header, then we must use that as filename.
+ if (reply->hasRawHeader("Content-Disposition")) { // NOTE this code block taken from kwebpage.cpp
+ const QString value = QLatin1String(reply->rawHeader("Content-Disposition"));
+ const int pos = value.indexOf(QLatin1String("filename="));
+ if (pos != -1) {
+ QString name = value.mid(pos + 9);
+ if (name.startsWith(QLatin1Char('"')) && name.endsWith(QLatin1Char('"')))
+ name = name.mid(1, name.size() - 2);
+ filename = name;
+ }
+ // No content-disposition header, use last part (the filename) of URL as filename:
+ } else {
+ QString path = url.path();
+ QFileInfo fInfo(path);
+ filename = fInfo.fileName();
+ }