Browse Source

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

Allow to retry fetching RSS feeds. Closes #11168
adaptive-webui-19844
Vladimir Golovnev 5 years ago committed by GitHub
parent
commit
19c70fd659
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      src/base/net/downloadmanager.cpp
  2. 5
      src/base/net/downloadmanager.h
  3. 6
      src/base/rss/rss_feed.cpp
  4. 2
      src/base/rss/rss_feed.h

13
src/base/net/downloadmanager.cpp

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

5
src/base/net/downloadmanager.h

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

6
src/base/rss/rss_feed.cpp

@ -125,11 +125,13 @@ void Feed::markAsRead()
void Feed::refresh() void Feed::refresh()
{ {
if (isLoading()) return; if (isLoading())
m_downloadHandler->cancel();
// NOTE: Should we allow manually refreshing for disabled session? // 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; m_isLoading = true;
emit stateChanged(this); emit stateChanged(this);

2
src/base/rss/rss_feed.h

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

Loading…
Cancel
Save