32 #include <QTemporaryFile>
48 if (!
file.open() || (
file.write(data) != data.length()) || !
file.flush())
49 return nonstd::make_unexpected(
file.errorString());
51 file.setAutoRemove(
false);
52 return file.fileName();
57 : DownloadHandler {manager}
59 , m_downloadRequest {downloadRequest}
103 qDebug(
"Download finished: %s", qUtf8Printable(
url()));
106 if (
m_reply->error() != QNetworkReply::NoError)
116 const QVariant redirection =
m_reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
117 if (redirection.isValid())
131 if (destinationPath.isEmpty())
137 setError(tr(
"I/O Error: %1").arg(result.error()));
145 setError(tr(
"I/O Error: %1").arg(result.error()));
164 setError(tr(
"The file size (%1) exceeds the download limit (%2)")
181 const QUrl resolvedUrl = newUrl.isRelative() ?
m_reply->url().resolved(newUrl) : newUrl;
182 const QString newUrlString = resolvedUrl.toString();
183 qDebug(
"Redirecting from %s to %s...", qUtf8Printable(
m_reply->url().toString()), qUtf8Printable(newUrlString));
186 if (newUrlString.startsWith(
"magnet:", Qt::CaseInsensitive))
188 qDebug(
"Magnet redirect detected.");
223 case QNetworkReply::HostNotFoundError:
224 return tr(
"The remote host name was not found (invalid hostname)");
225 case QNetworkReply::OperationCanceledError:
226 return tr(
"The operation was canceled");
227 case QNetworkReply::RemoteHostClosedError:
228 return tr(
"The remote server closed the connection prematurely, before the entire reply was received and processed");
229 case QNetworkReply::TimeoutError:
230 return tr(
"The connection to the remote server timed out");
231 case QNetworkReply::SslHandshakeFailedError:
232 return tr(
"SSL/TLS handshake failed");
233 case QNetworkReply::ConnectionRefusedError:
234 return tr(
"The remote server refused the connection");
235 case QNetworkReply::ProxyConnectionRefusedError:
236 return tr(
"The connection to the proxy server was refused");
237 case QNetworkReply::ProxyConnectionClosedError:
238 return tr(
"The proxy server closed the connection prematurely");
239 case QNetworkReply::ProxyNotFoundError:
240 return tr(
"The proxy host name was not found");
241 case QNetworkReply::ProxyTimeoutError:
242 return tr(
"The connection to the proxy timed out or the proxy did not reply in time to the request sent");
243 case QNetworkReply::ProxyAuthenticationRequiredError:
244 return tr(
"The proxy requires authentication in order to honor the request but did not accept any credentials offered");
245 case QNetworkReply::ContentAccessDenied:
246 return tr(
"The access to the remote content was denied (401)");
247 case QNetworkReply::ContentOperationNotPermittedError:
248 return tr(
"The operation requested on the remote content is not permitted");
249 case QNetworkReply::ContentNotFoundError:
250 return tr(
"The remote content was not found at the server (404)");
251 case QNetworkReply::AuthenticationRequiredError:
252 return tr(
"The remote server requires authentication to serve the content but the credentials provided were not accepted");
253 case QNetworkReply::ProtocolUnknownError:
254 return tr(
"The Network Access API cannot honor the request because the protocol is not known");
255 case QNetworkReply::ProtocolInvalidOperationError:
256 return tr(
"The requested operation is invalid for this protocol");
257 case QNetworkReply::UnknownNetworkError:
258 return tr(
"An unknown network-related error was detected");
259 case QNetworkReply::UnknownProxyError:
260 return tr(
"An unknown proxy-related error was detected");
261 case QNetworkReply::UnknownContentError:
262 return tr(
"An unknown error related to the remote content was detected");
263 case QNetworkReply::ProtocolFailure:
264 return tr(
"A breakdown in protocol was detected");
266 return tr(
"Unknown error");
void assignNetworkReply(QNetworkReply *reply)
Net::DownloadResult m_result
static QString errorCodeToString(QNetworkReply::NetworkError status)
void handleRedirection(const QUrl &newUrl)
void checkDownloadSize(qint64 bytesReceived, qint64 bytesTotal)
DownloadHandlerImpl(Net::DownloadManager *manager, const Net::DownloadRequest &downloadRequest)
const Net::DownloadRequest downloadRequest() const
const Net::DownloadRequest m_downloadRequest
Net::DownloadManager * m_manager
void setError(const QString &error)
void processFinishedDownload()
void finished(const DownloadResult &result)
DownloadHandler * download(const DownloadRequest &downloadRequest)
QString destFileName() const
const int MAX_REDIRECTIONS
QByteArray decompress(const QByteArray &data, bool *ok=nullptr)
nonstd::expected< void, QString > saveToFile(const QString &path, const QByteArray &data)
QString friendlyUnit(qint64 bytes, bool isSpeed=false)
nonstd::expected< QString, QString > saveToTempFile(const QByteArray &data)
file(GLOB QBT_TS_FILES "${qBittorrent_SOURCE_DIR}/src/lang/*.ts") set_source_files_properties($