From bd643b4e2df98e73b5292f620c6ccaf638810cb0 Mon Sep 17 00:00:00 2001 From: Tim Delaney Date: Sun, 22 Jan 2017 17:25:02 +1100 Subject: [PATCH] RSS defer matching articles for rules until idle. Closes #6166. --HG-- branch : magao-dev --- src/gui/rss/automatedrssdownloader.cpp | 48 ++++++++++++++++++++++++-- src/gui/rss/automatedrssdownloader.h | 1 + src/gui/rss/automatedrssdownloader.ui | 36 +++++++++++++------ 3 files changed, 72 insertions(+), 13 deletions(-) diff --git a/src/gui/rss/automatedrssdownloader.cpp b/src/gui/rss/automatedrssdownloader.cpp index c272dc6aedd1..733a90195937 100644 --- a/src/gui/rss/automatedrssdownloader.cpp +++ b/src/gui/rss/automatedrssdownloader.cpp @@ -28,6 +28,7 @@ * Contact : chris@qbittorrent.org */ +#include #include #include #include @@ -36,6 +37,7 @@ #include #include #include +#include #include "base/preferences.h" #include "base/bittorrent/session.h" @@ -56,13 +58,17 @@ class AutomatedRssDownloader::DownloadRuleListMatchState DownloadRuleListMatchState(); ~DownloadRuleListMatchState(); void clear(); + void start(int timeout); public: + QTimer m_deferredMatchingTimer; QSet> m_treeListEntries; }; AutomatedRssDownloader::DownloadRuleListMatchState::DownloadRuleListMatchState() { + m_deferredMatchingTimer.setInterval(1); + m_deferredMatchingTimer.setSingleShot(true); } AutomatedRssDownloader::DownloadRuleListMatchState::~DownloadRuleListMatchState() @@ -71,9 +77,15 @@ AutomatedRssDownloader::DownloadRuleListMatchState::~DownloadRuleListMatchState( void AutomatedRssDownloader::DownloadRuleListMatchState::clear() { + m_deferredMatchingTimer.stop(); m_treeListEntries.clear(); } +void AutomatedRssDownloader::DownloadRuleListMatchState::start(int timeout) +{ + m_deferredMatchingTimer.start(timeout); +} + AutomatedRssDownloader::AutomatedRssDownloader(const QWeakPointer &manager, QWidget *parent) : QDialog(parent) , ui(new Ui::AutomatedRssDownloader) @@ -116,6 +128,8 @@ AutomatedRssDownloader::AutomatedRssDownloader(const QWeakPointer initCategoryCombobox(); loadFeedList(); loadSettings(); + ok = connect(&m_ruleMatcher->m_deferredMatchingTimer, SIGNAL(timeout()), SLOT(deferredUpdateMatchingArticles())); + Q_ASSERT(ok); ok = connect(ui->listRules, SIGNAL(itemSelectionChanged()), SLOT(updateRuleDefinitionBox())); Q_ASSERT(ok); ok = connect(ui->listRules, SIGNAL(itemSelectionChanged()), SLOT(updateFeedList())); @@ -561,12 +575,41 @@ void AutomatedRssDownloader::handleFeedCheckStateChange(QListWidgetItem *feed_it void AutomatedRssDownloader::updateMatchingArticles() { ui->treeMatchingArticles->clear(); + saveEditedRule(); + m_ruleMatcher->start(1000); +} + +void AutomatedRssDownloader::deferredUpdateMatchingArticles() +{ + QStringList ruleNames; + + foreach (const QListWidgetItem *rule_item, ui->listRules->selectedItems()) { + Rss::DownloadRulePtr rule = m_editableRuleList->getRule(rule_item->text()); + if (rule) + ruleNames.append(rule->name()); + } + + if (ruleNames.empty()) + return; + + qDebug() << Q_FUNC_INFO << "Matching articles for RSS rules:" << ruleNames.join(", "); + + ui->treeMatchingArticles->clear(); + Rss::ManagerPtr manager = m_manager.toStrongRef(); - if (!manager) + if (!manager) { + ui->treeMatchingLoading->setPixmap(QPixmap()); return; + } + + if ((ui->treeMatchingLoading->pixmap() == 0) || ui->treeMatchingLoading->pixmap()->isNull()) { + // Set the loading icon and allow it to be displayed + ui->treeMatchingLoading->setPixmap(QIcon(":/icons/loading.png").pixmap(16, 16)); + QCoreApplication::instance()->processEvents(QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers); + } + const QHash all_feeds = manager->rootFolder()->getAllFeedsAsHash(); - saveEditedRule(); foreach (const QListWidgetItem *rule_item, ui->listRules->selectedItems()) { Rss::DownloadRulePtr rule = m_editableRuleList->getRule(rule_item->text()); if (!rule) continue; @@ -582,6 +625,7 @@ void AutomatedRssDownloader::updateMatchingArticles() } } + ui->treeMatchingLoading->setPixmap(QPixmap()); m_ruleMatcher->clear(); } diff --git a/src/gui/rss/automatedrssdownloader.h b/src/gui/rss/automatedrssdownloader.h index 29971b038155..7a603b7da843 100644 --- a/src/gui/rss/automatedrssdownloader.h +++ b/src/gui/rss/automatedrssdownloader.h @@ -84,6 +84,7 @@ private slots: void on_importBtn_clicked(); void renameSelectedRule(); void updateMatchingArticles(); + void deferredUpdateMatchingArticles(); void updateFieldsToolTips(bool regex); void updateMustLineValidity(); void updateMustNotLineValidity(); diff --git a/src/gui/rss/automatedrssdownloader.ui b/src/gui/rss/automatedrssdownloader.ui index 0338419cd85c..410b16ba6ae1 100644 --- a/src/gui/rss/automatedrssdownloader.ui +++ b/src/gui/rss/automatedrssdownloader.ui @@ -336,17 +336,31 @@ - - - - 75 - true - - - - Matching RSS Articles - - + + + + + + 75 + true + + + + Matching RSS Articles + + + + + + + + 18 + 18 + + + + +