mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-12 16:23:07 -07:00
Add DownloadRequest::destFileName
This commit is contained in:
parent
615b76f78c
commit
8b5db328ec
3 changed files with 29 additions and 1 deletions
|
@ -42,6 +42,16 @@ namespace
|
||||||
{
|
{
|
||||||
bool saveToFile(const QByteArray &replyData, QString &filePath)
|
bool saveToFile(const QByteArray &replyData, QString &filePath)
|
||||||
{
|
{
|
||||||
|
if (!filePath.isEmpty())
|
||||||
|
{
|
||||||
|
QFile file {filePath};
|
||||||
|
if (!file.open(QIODevice::WriteOnly))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
file.write(replyData);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
QTemporaryFile tmpfile {Utils::Fs::tempPath() + "XXXXXX"};
|
QTemporaryFile tmpfile {Utils::Fs::tempPath() + "XXXXXX"};
|
||||||
tmpfile.setAutoRemove(false);
|
tmpfile.setAutoRemove(false);
|
||||||
|
|
||||||
|
@ -129,7 +139,7 @@ void DownloadHandlerImpl::processFinishedDownload()
|
||||||
|
|
||||||
if (m_downloadRequest.saveToFile())
|
if (m_downloadRequest.saveToFile())
|
||||||
{
|
{
|
||||||
QString filePath;
|
QString filePath {m_downloadRequest.destFileName()};
|
||||||
if (saveToFile(m_result.data, filePath))
|
if (saveToFile(m_result.data, filePath))
|
||||||
m_result.filePath = filePath;
|
m_result.filePath = filePath;
|
||||||
else
|
else
|
||||||
|
|
|
@ -348,6 +348,17 @@ Net::DownloadRequest &Net::DownloadRequest::saveToFile(const bool value)
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString Net::DownloadRequest::destFileName() const
|
||||||
|
{
|
||||||
|
return m_destFileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
Net::DownloadRequest &Net::DownloadRequest::destFileName(const QString &value)
|
||||||
|
{
|
||||||
|
m_destFileName = value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
Net::ServiceID Net::ServiceID::fromURL(const QUrl &url)
|
Net::ServiceID Net::ServiceID::fromURL(const QUrl &url)
|
||||||
{
|
{
|
||||||
return {url.host(), url.port(80)};
|
return {url.host(), url.port(80)};
|
||||||
|
|
|
@ -78,11 +78,18 @@ namespace Net
|
||||||
bool saveToFile() const;
|
bool saveToFile() const;
|
||||||
DownloadRequest &saveToFile(bool value);
|
DownloadRequest &saveToFile(bool value);
|
||||||
|
|
||||||
|
// if saveToFile is set, the file is saved in destFileName
|
||||||
|
// (deprecated) if destFileName is not provided, the file will be saved
|
||||||
|
// in a temporary file, the name of file is set in DownloadResult::filePath
|
||||||
|
QString destFileName() const;
|
||||||
|
DownloadRequest &destFileName(const QString &value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_url;
|
QString m_url;
|
||||||
QString m_userAgent;
|
QString m_userAgent;
|
||||||
qint64 m_limit = 0;
|
qint64 m_limit = 0;
|
||||||
bool m_saveToFile = false;
|
bool m_saveToFile = false;
|
||||||
|
QString m_destFileName;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DownloadResult
|
struct DownloadResult
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue