Skip to content

Commit

Permalink
Merge pull request #6176 from magao/issue873
Browse files Browse the repository at this point in the history
Improve UI responsiveness during RSS downloading. Closes #873, #1089, #1235, #5423
  • Loading branch information
sledgehammer999 authored Feb 6, 2017
2 parents 2a7f421 + 390d7a8 commit 179b686
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/base/rss/rssfeed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/base/rss/rssfeed.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
32 changes: 30 additions & 2 deletions src/base/rss/rssmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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);
}
}
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
}
}
10 changes: 10 additions & 0 deletions src/base/rss/rssmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -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;
};
}

Expand Down

0 comments on commit 179b686

Please sign in to comment.