From: <si...@us...> - 2013-06-14 07:32:51
|
Revision: 1327 http://sourceforge.net/p/qterm/code/1327 Author: sidos Date: 2013-06-14 07:32:48 +0000 (Fri, 14 Jun 2013) Log Message: ----------- get filename using QNetworkReply::rawHeader Modified Paths: -------------- trunk/qterm/src/qtermhttp.cpp Modified: trunk/qterm/src/qtermhttp.cpp =================================================================== --- trunk/qterm/src/qtermhttp.cpp 2013-06-14 06:50:45 UTC (rev 1326) +++ trunk/qterm/src/qtermhttp.cpp 2013-06-14 07:32:48 UTC (rev 1327) @@ -83,12 +83,18 @@ if (m_httpReply->error() != QNetworkReply::NoError) return; - QVariant value; - int FileLength = m_httpReply->header(QNetworkRequest::ContentLengthHeader).toInt(); + // extract filename if exists + // m_httpReply->header(QNetworkRequest::ContentDispositionHeader) returns QVariant(null) as of Qt5.1 beta + QString ValueString = m_codec->toUnicode(m_httpReply->rawHeader("Content-Disposition")); + if (ValueString.right(1) != ";") + ValueString += ";"; + QRegExp re("filename=(.*);", Qt::CaseInsensitive); + re.setMinimal(true); //Dont FIXME:this will also split filenames with ';' inside, does anyone really do this? + int pos = re.indexIn(ValueString); + if (pos != -1) + m_strHttpFile = re.cap(1); - m_strHttpFile = m_httpReply->header(QNetworkRequest::ContentDispositionHeader).toString(); - if (m_bPreview) { QString strPool = Global::instance()->m_pref.strPoolPath; @@ -145,6 +151,8 @@ void Http::httpRead(qint64 done, qint64 total) { + if(!m_httpReply->attribute(QNetworkRequest::RedirectionTargetAttribute).isNull()) + return; QByteArray ba = m_httpReply->readAll(); QFile file(m_strHttpFile); if (file.open(QIODevice::ReadWrite | QIODevice::Append)) { @@ -179,10 +187,12 @@ QVariant redirectionTarget = m_httpReply->attribute(QNetworkRequest::RedirectionTargetAttribute); if (!redirectionTarget.isNull()) { m_url = m_url.resolved(redirectionTarget.toUrl()); + m_httpReply->abort(); m_httpReply->deleteLater(); getLink(m_url.toString(), m_bPreview); return; } + if (m_bPreview) { QString strPool = Global::instance()->m_pref.strPoolPath; previewImage(m_strHttpFile); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |