From 390d7a81244cdd17d6431144de198938dcfb2810 Mon Sep 17 00:00:00 2001 From: Tim Delaney Date: Mon, 7 Nov 2016 08:56:06 +1100 Subject: [PATCH] Improve UI responsiveness during RSS downloading. Closes #873, #1089, #1235, #5423. --HG-- branch : magao-dev --- src/base/rss/rssfeed.cpp | 8 ++++++++ src/base/rss/rssfeed.h | 3 +++ src/base/rss/rssmanager.cpp | 32 ++++++++++++++++++++++++++++++-- src/base/rss/rssmanager.h | 10 ++++++++++ 4 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/base/rss/rssfeed.cpp b/src/base/rss/rssfeed.cpp index 12437f308..60d0489e3 100644 --- a/src/base/rss/rssfeed.cpp +++ b/src/base/rss/rssfeed.cpp @@ -361,6 +361,14 @@ void Feed::handleFeedTitle(const QString &title) void Feed::downloadArticleTorrentIfMatching(const ArticlePtr &article) { Q_ASSERT(Preferences::instance()->isRssDownloadingEnabled()); + qDebug().nospace() << Q_FUNC_INFO << " Deferring matching of " << article->title() << " from " << displayName() << " RSS feed"; + m_manager->downloadArticleTorrentIfMatching(m_url, article); +} + +void Feed::deferredDownloadArticleTorrentIfMatching(const ArticlePtr &article) +{ + qDebug().nospace() << Q_FUNC_INFO << " Matching of " << article->title() << " from " << displayName() << " RSS feed"; + DownloadRuleList *rules = m_manager->downloadRules(); DownloadRulePtr matchingRule = rules->findMatchingRule(m_url, article->title()); if (!matchingRule) return; diff --git a/src/base/rss/rssfeed.h b/src/base/rss/rssfeed.h index 1dfe0fcba..7fcbcb361 100644 --- a/src/base/rss/rssfeed.h +++ b/src/base/rss/rssfeed.h @@ -98,10 +98,13 @@ namespace Rss void handleArticleRead(); private: + friend class Manager; + QString iconUrl() const; void loadItemsFromDisk(); void addArticle(const ArticlePtr &article); void downloadArticleTorrentIfMatching(const ArticlePtr &article); + void deferredDownloadArticleTorrentIfMatching(const ArticlePtr &article); private: Manager *m_manager; diff --git a/src/base/rss/rssmanager.cpp b/src/base/rss/rssmanager.cpp index 8fc936d6e..cce0cd828 100644 --- a/src/base/rss/rssmanager.cpp +++ b/src/base/rss/rssmanager.cpp @@ -54,6 +54,10 @@ Manager::Manager(QObject *parent) connect(&m_refreshTimer, SIGNAL(timeout()), SLOT(refresh())); m_refreshInterval = Preferences::instance()->getRSSRefreshInterval(); m_refreshTimer.start(m_refreshInterval * MSECS_PER_MIN); + + m_deferredDownloadTimer.setInterval(1); + m_deferredDownloadTimer.setSingleShot(true); + connect(&m_deferredDownloadTimer, SIGNAL(timeout()), SLOT(downloadNextArticleTorrentIfMatching())); } Manager::~Manager() @@ -72,7 +76,7 @@ void Manager::updateRefreshInterval(uint val) { if (m_refreshInterval != val) { m_refreshInterval = val; - m_refreshTimer.start(m_refreshInterval*60000); + m_refreshTimer.start(m_refreshInterval * 60000); qDebug("New RSS refresh interval is now every %dmin", m_refreshInterval); } } @@ -81,7 +85,7 @@ void Manager::loadStreamList() { const Preferences *const pref = Preferences::instance(); const QStringList streamsUrl = pref->getRssFeedsUrls(); - const QStringList aliases = pref->getRssFeedsAliases(); + const QStringList aliases = pref->getRssFeedsAliases(); if (streamsUrl.size() != aliases.size()) { Logger::instance()->addMessage("Corrupted RSS list, not loading it.", Log::WARNING); return; @@ -188,3 +192,27 @@ void Manager::refresh() { m_rootFolder->refresh(); } + +void Manager::downloadArticleTorrentIfMatching(const QString &url, const ArticlePtr &article) +{ + m_deferredDownloads.append(qMakePair(url, article)); + m_deferredDownloadTimer.start(); +} + +void Manager::downloadNextArticleTorrentIfMatching() +{ + if (m_deferredDownloads.empty()) + return; + + // Schedule to process the next article (if any) + m_deferredDownloadTimer.start(); + + QPair urlArticle(m_deferredDownloads.takeFirst()); + FeedList streams = m_rootFolder->getAllFeeds(); + foreach (const FeedPtr &stream, streams) { + if (stream->url() == urlArticle.first) { + stream->deferredDownloadArticleTorrentIfMatching(urlArticle.second); + break; + } + } +} diff --git a/src/base/rss/rssmanager.h b/src/base/rss/rssmanager.h index 3c7b81738..37254aeb2 100644 --- a/src/base/rss/rssmanager.h +++ b/src/base/rss/rssmanager.h @@ -32,19 +32,23 @@ #ifndef RSSMANAGER_H #define RSSMANAGER_H +#include #include +#include #include #include #include namespace Rss { + class Article; class DownloadRuleList; class File; class Folder; class Feed; class Manager; + typedef QSharedPointer
ArticlePtr; typedef QSharedPointer FilePtr; typedef QSharedPointer FolderPtr; typedef QSharedPointer FeedPtr; @@ -62,6 +66,7 @@ namespace Rss DownloadRuleList *downloadRules() const; FolderPtr rootFolder() const; QThread *workingThread() const; + void downloadArticleTorrentIfMatching(const QString &url, const ArticlePtr &article); public slots: void refresh(); @@ -78,12 +83,17 @@ namespace Rss void feedInfosChanged(const QString &url, const QString &displayName, uint unreadCount); void feedIconChanged(const QString &url, const QString &iconPath); + private slots: + void downloadNextArticleTorrentIfMatching(); + private: QTimer m_refreshTimer; uint m_refreshInterval; DownloadRuleList *m_downloadRules; FolderPtr m_rootFolder; QThread *m_workingThread; + QTimer m_deferredDownloadTimer; + QList> m_deferredDownloads; }; }