Merge pull request #6176 from magao/issue873

Improve UI responsiveness during RSS downloading. Closes #873, #1089, #1235, #5423
This commit is contained in:
sledgehammer999 2017-02-06 16:17:08 +02:00 committed by GitHub
commit 179b686e42
4 changed files with 51 additions and 2 deletions

View file

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

View file

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

View file

@ -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<QString, ArticlePtr> urlArticle(m_deferredDownloads.takeFirst());
FeedList streams = m_rootFolder->getAllFeeds();
foreach (const FeedPtr &stream, streams) {
if (stream->url() == urlArticle.first) {
stream->deferredDownloadArticleTorrentIfMatching(urlArticle.second);
break;
}
}
}

View file

@ -32,19 +32,23 @@
#ifndef RSSMANAGER_H
#define RSSMANAGER_H
#include <QList>
#include <QObject>
#include <QPair>
#include <QTimer>
#include <QSharedPointer>
#include <QThread>
namespace Rss
{
class Article;
class DownloadRuleList;
class File;
class Folder;
class Feed;
class Manager;
typedef QSharedPointer<Article> ArticlePtr;
typedef QSharedPointer<File> FilePtr;
typedef QSharedPointer<Folder> FolderPtr;
typedef QSharedPointer<Feed> 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<QPair<QString, ArticlePtr>> m_deferredDownloads;
};
}