Skip to content

Commit

Permalink
RSS defer matching articles for rules until idle. Closes #6166.
Browse files Browse the repository at this point in the history
--HG--
branch : magao-dev
  • Loading branch information
magao committed Jan 22, 2017
1 parent fcd10bb commit bd643b4
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 13 deletions.
48 changes: 46 additions & 2 deletions src/gui/rss/automatedrssdownloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* Contact : [email protected]
*/

#include <QCoreApplication>
#include <QMessageBox>
#include <QFileDialog>
#include <QDebug>
Expand All @@ -36,6 +37,7 @@
#include <QPair>
#include <QSet>
#include <QString>
#include <QTimer>

#include "base/preferences.h"
#include "base/bittorrent/session.h"
Expand All @@ -56,13 +58,17 @@ class AutomatedRssDownloader::DownloadRuleListMatchState
DownloadRuleListMatchState();
~DownloadRuleListMatchState();
void clear();
void start(int timeout);

public:
QTimer m_deferredMatchingTimer;
QSet<QPair<QString, QString >> m_treeListEntries;
};

AutomatedRssDownloader::DownloadRuleListMatchState::DownloadRuleListMatchState()
{
m_deferredMatchingTimer.setInterval(1);
m_deferredMatchingTimer.setSingleShot(true);
}

AutomatedRssDownloader::DownloadRuleListMatchState::~DownloadRuleListMatchState()
Expand All @@ -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<Rss::Manager> &manager, QWidget *parent)
: QDialog(parent)
, ui(new Ui::AutomatedRssDownloader)
Expand Down Expand Up @@ -116,6 +128,8 @@ AutomatedRssDownloader::AutomatedRssDownloader(const QWeakPointer<Rss::Manager>
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()));
Expand Down Expand Up @@ -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<QString, Rss::FeedPtr> 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;
Expand All @@ -582,6 +625,7 @@ void AutomatedRssDownloader::updateMatchingArticles()
}
}

ui->treeMatchingLoading->setPixmap(QPixmap());
m_ruleMatcher->clear();
}

Expand Down
1 change: 1 addition & 0 deletions src/gui/rss/automatedrssdownloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ private slots:
void on_importBtn_clicked();
void renameSelectedRule();
void updateMatchingArticles();
void deferredUpdateMatchingArticles();
void updateFieldsToolTips(bool regex);
void updateMustLineValidity();
void updateMustNotLineValidity();
Expand Down
36 changes: 25 additions & 11 deletions src/gui/rss/automatedrssdownloader.ui
Original file line number Diff line number Diff line change
Expand Up @@ -336,17 +336,31 @@
<widget class="QWidget" name="layoutWidget2">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="label_3">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Matching RSS Articles</string>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_10">
<item>
<widget class="QLabel" name="label_3">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Matching RSS Articles</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="treeMatchingLoading">
<property name="maximumSize">
<size>
<width>18</width>
<height>18</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTreeWidget" name="treeMatchingArticles">
Expand Down

0 comments on commit bd643b4

Please sign in to comment.