Merge pull request #11235 from glassez/retry-fetch-rss

Allow to retry fetching RSS feeds. Closes #11168
This commit is contained in:
Vladimir Golovnev 2019-09-16 09:58:44 +03:00 committed by GitHub
commit 19c70fd659
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 3 deletions

View file

@ -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
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);

View file

@ -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
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
private:
explicit DownloadManager(QObject *parent = nullptr);
DownloadHandler *download(const DownloadRequest &downloadRequest);
void applyProxySettings();
void handleReplyFinished(const QNetworkReply *reply);

View file

@ -125,11 +125,13 @@ void Feed::markAsRead()
void Feed::refresh()
{
if (isLoading()) return;
if (isLoading())
m_downloadHandler->cancel();
// NOTE: Should we allow manually refreshing for disabled session?
Net::DownloadManager::instance()->download(m_url, this, &Feed::handleDownloadFinished);
m_downloadHandler = Net::DownloadManager::instance()->download(m_url);
connect(m_downloadHandler, &Net::DownloadHandler::finished, this, &Feed::handleDownloadFinished);
m_isLoading = true;
emit stateChanged(this);

View file

@ -41,6 +41,7 @@ class AsyncFileStorage;
namespace Net
{
class DownloadHandler;
struct DownloadResult;
}
@ -125,5 +126,6 @@ namespace RSS
QString m_dataFileName;
QBasicTimer m_savingTimer;
bool m_dirty = false;
Net::DownloadHandler *m_downloadHandler = nullptr;
};
}