Browse Source

Allow to cancel download request

adaptive-webui-19844
Vladimir Golovnev (Glassez) 5 years ago
parent
commit
73ef69526d
No known key found for this signature in database
GPG Key ID: 52A2C7DEE2DFA6F7
  1. 13
      src/base/net/downloadmanager.cpp
  2. 5
      src/base/net/downloadmanager.h

13
src/base/net/downloadmanager.cpp

@ -121,6 +121,8 @@ namespace @@ -121,6 +121,8 @@ namespace
explicit DownloadHandlerImpl(const Net::DownloadRequest &downloadRequest, QObject *parent);
~DownloadHandlerImpl() override;
void cancel() override;
QString url() const;
const Net::DownloadRequest downloadRequest() const;
@ -416,6 +418,17 @@ namespace @@ -416,6 +418,17 @@ namespace
delete m_reply;
}
void DownloadHandlerImpl::cancel()
{
if (m_reply) {
m_reply->abort();
}
else {
setError(errorCodeToString(QNetworkReply::OperationCanceledError));
finish();
}
}
void DownloadHandlerImpl::assignNetworkReply(QNetworkReply *reply)
{
Q_ASSERT(reply);

5
src/base/net/downloadmanager.h

@ -104,6 +104,8 @@ namespace Net @@ -104,6 +104,8 @@ namespace Net
public:
using QObject::QObject;
virtual void cancel() = 0;
signals:
void finished(const DownloadResult &result);
};
@ -118,6 +120,8 @@ namespace Net @@ -118,6 +120,8 @@ namespace Net
static void freeInstance();
static DownloadManager *instance();
DownloadHandler *download(const DownloadRequest &downloadRequest);
template <typename Context, typename Func>
void download(const DownloadRequest &downloadRequest, Context context, Func &&slot);
@ -137,7 +141,6 @@ namespace Net @@ -137,7 +141,6 @@ namespace Net
private:
explicit DownloadManager(QObject *parent = nullptr);
DownloadHandler *download(const DownloadRequest &downloadRequest);
void applyProxySettings();
void handleReplyFinished(const QNetworkReply *reply);

Loading…
Cancel
Save