Browse Source

Merge pull request #6212 from magao/issue2192

Follow project coding style. Issue #2192.
adaptive-webui-19844
sledgehammer999 8 years ago committed by GitHub
parent
commit
c8ddd68a7a
  1. 2
      src/base/rss/rssdownloadrule.cpp
  2. 20
      src/base/rss/rssfeed.cpp
  3. 69
      src/gui/rss/automatedrssdownloader.cpp
  4. 8
      src/gui/rss/rss_imp.cpp
  5. 1
      src/gui/rss/rss_imp.h

2
src/base/rss/rssdownloadrule.cpp

@ -110,7 +110,7 @@ bool DownloadRule::matches(const QString &articleTitle) const
pos = reg.indexIn(articleTitle); pos = reg.indexIn(articleTitle);
if (pos != -1) { if (pos != -1) {
int epTheirs = reg.cap(1).toInt(); int epTheirs = reg.cap(1).toInt();
if (epOursFirst <= epTheirs && epOursLast >= epTheirs) if ((epOursFirst <= epTheirs) && (epOursLast >= epTheirs))
return true; return true;
} }
} }

20
src/base/rss/rssfeed.cpp

@ -104,9 +104,8 @@ void Feed::saveItemsToDisk()
ArticleHash::ConstIterator it = m_articles.begin(); ArticleHash::ConstIterator it = m_articles.begin();
ArticleHash::ConstIterator itend = m_articles.end(); ArticleHash::ConstIterator itend = m_articles.end();
for ( ; it != itend; ++it) { for (; it != itend; ++it)
oldItems << it.value()->toHash(); oldItems << it.value()->toHash();
}
qDebug("Saving %d old items for feed %s", oldItems.size(), qPrintable(displayName())); qDebug("Saving %d old items for feed %s", oldItems.size(), qPrintable(displayName()));
QHash<QString, QVariant> allOldItems = qBTRSS.value("old_items", QHash<QString, QVariant>()).toHash(); QHash<QString, QVariant> allOldItems = qBTRSS.value("old_items", QHash<QString, QVariant>()).toHash();
allOldItems[m_url] = oldItems; allOldItems[m_url] = oldItems;
@ -155,23 +154,21 @@ void Feed::addArticle(const ArticlePtr &article)
} }
// Check if article was inserted at the end of the list and will break max_articles limit // Check if article was inserted at the end of the list and will break max_articles limit
if (Preferences::instance()->isRssDownloadingEnabled()) { if (Preferences::instance()->isRssDownloadingEnabled())
if ((lbIndex < maxArticles) && !article->isRead()) if ((lbIndex < maxArticles) && !article->isRead())
downloadArticleTorrentIfMatching(article); downloadArticleTorrentIfMatching(article);
} }
}
else { else {
// m_articles.contains(article->guid()) // m_articles.contains(article->guid())
// Try to download skipped articles // Try to download skipped articles
if (Preferences::instance()->isRssDownloadingEnabled()) { if (Preferences::instance()->isRssDownloadingEnabled()) {
ArticlePtr skipped = m_articles.value(article->guid(), ArticlePtr()); ArticlePtr skipped = m_articles.value(article->guid(), ArticlePtr());
if (skipped) { if (skipped)
if (!skipped->isRead()) if (!skipped->isRead())
downloadArticleTorrentIfMatching(skipped); downloadArticleTorrentIfMatching(skipped);
} }
} }
} }
}
bool Feed::refresh() bool Feed::refresh()
{ {
@ -260,7 +257,7 @@ bool Feed::hasCustomIcon() const
void Feed::setIconPath(const QString &path) void Feed::setIconPath(const QString &path)
{ {
QString nativePath = Utils::Fs::fromNativePath(path); QString nativePath = Utils::Fs::fromNativePath(path);
if (nativePath == m_icon || nativePath.isEmpty() || !QFile::exists(nativePath)) return; if ((nativePath == m_icon) || nativePath.isEmpty() || !QFile::exists(nativePath)) return;
if (!m_icon.startsWith(":/") && QFile::exists(m_icon)) if (!m_icon.startsWith(":/") && QFile::exists(m_icon))
Utils::Fs::forceRemove(m_icon); Utils::Fs::forceRemove(m_icon);
@ -282,9 +279,8 @@ void Feed::markAsRead()
{ {
ArticleHash::ConstIterator it = m_articles.begin(); ArticleHash::ConstIterator it = m_articles.begin();
ArticleHash::ConstIterator itend = m_articles.end(); ArticleHash::ConstIterator itend = m_articles.end();
for ( ; it != itend; ++it) { for (; it != itend; ++it)
it.value()->markAsRead(); it.value()->markAsRead();
}
m_unreadCount = 0; m_unreadCount = 0;
m_manager->forwardFeedInfosChanged(m_url, displayName(), 0); m_manager->forwardFeedInfosChanged(m_url, displayName(), 0);
} }
@ -310,10 +306,9 @@ ArticleList Feed::unreadArticleListByDateDesc() const
ArticleList::ConstIterator it = m_articlesByDate.begin(); ArticleList::ConstIterator it = m_articlesByDate.begin();
ArticleList::ConstIterator itend = m_articlesByDate.end(); ArticleList::ConstIterator itend = m_articlesByDate.end();
for ( ; it != itend; ++it) { for (; it != itend; ++it)
if (!(*it)->isRead()) if (!(*it)->isRead())
unreadNews << *it; unreadNews << *it;
}
return unreadNews; return unreadNews;
} }
@ -407,11 +402,10 @@ void Feed::downloadArticleTorrentIfMatching(const ArticlePtr &article)
void Feed::recheckRssItemsForDownload() void Feed::recheckRssItemsForDownload()
{ {
Q_ASSERT(Preferences::instance()->isRssDownloadingEnabled()); Q_ASSERT(Preferences::instance()->isRssDownloadingEnabled());
foreach (const ArticlePtr &article, m_articlesByDate) { foreach (const ArticlePtr &article, m_articlesByDate)
if (!article->isRead()) if (!article->isRead())
downloadArticleTorrentIfMatching(article); downloadArticleTorrentIfMatching(article);
} }
}
void Feed::handleNewArticle(const QVariantHash &articleData) void Feed::handleNewArticle(const QVariantHash &articleData)
{ {

69
src/gui/rss/automatedrssdownloader.cpp

@ -47,8 +47,8 @@
#include "ui_automatedrssdownloader.h" #include "ui_automatedrssdownloader.h"
#include "automatedrssdownloader.h" #include "automatedrssdownloader.h"
AutomatedRssDownloader::AutomatedRssDownloader(const QWeakPointer<Rss::Manager>& manager, QWidget *parent) : AutomatedRssDownloader::AutomatedRssDownloader(const QWeakPointer<Rss::Manager> &manager, QWidget *parent)
QDialog(parent), : QDialog(parent),
ui(new Ui::AutomatedRssDownloader), ui(new Ui::AutomatedRssDownloader),
m_manager(manager), m_editedRule(0) m_manager(manager), m_editedRule(0)
{ {
@ -76,15 +76,15 @@ AutomatedRssDownloader::AutomatedRssDownloader(const QWeakPointer<Rss::Manager>&
Qt::CaseInsensitive), Qt::CaseInsensitive),
ui->lineEFilter); ui->lineEFilter);
ui->lineEFilter->setValidator(m_episodeValidator); ui->lineEFilter->setValidator(m_episodeValidator);
QString tip = "<p>" + tr("Matches articles based on episode filter.") + "</p><p><b>" + tr("Example: ") + QString tip = "<p>" + tr("Matches articles based on episode filter.") + "</p><p><b>" + tr("Example: ")
"1x2;8-15;5;30-;</b>" + tr(" will match 2, 5, 8 through 15, 30 and onward episodes of season one", "example X will match") + "</p>"; + "1x2;8-15;5;30-;</b>" + tr(" will match 2, 5, 8 through 15, 30 and onward episodes of season one", "example X will match") + "</p>";
tip += "<p>" + tr("Episode filter rules: ") + "</p><ul><li>" + tr("Season number is a mandatory non-zero value") + "</li>" + tip += "<p>" + tr("Episode filter rules: ") + "</p><ul><li>" + tr("Season number is a mandatory non-zero value") + "</li>"
"<li>" + tr("Episode number is a mandatory non-zero value") + "</li>" + + "<li>" + tr("Episode number is a mandatory non-zero value") + "</li>"
"<li>" + tr("Filter must end with semicolon") + "</li>" + + "<li>" + tr("Filter must end with semicolon") + "</li>"
"<li>" + tr("Three range types for episodes are supported: ") + "</li>" + "<li><ul>" + "<li>" + tr("Three range types for episodes are supported: ") + "</li>" + "<li><ul>"
"<li>" + tr("Single number: <b>1x25;</b> matches episode 25 of season one") + "</li>" + "<li>" + tr("Single number: <b>1x25;</b> matches episode 25 of season one") + "</li>"
"<li>" + tr("Normal range: <b>1x25-40;</b> matches episodes 25 through 40 of season one") + "</li>" + + "<li>" + tr("Normal range: <b>1x25-40;</b> matches episodes 25 through 40 of season one") + "</li>"
"<li>" + tr("Infinite range: <b>1x25-;</b> matches episodes 25 and upward of season one") + "</li>" + "</ul></li></ul>"; + "<li>" + tr("Infinite range: <b>1x25-;</b> matches episodes 25 and upward of season one") + "</li>" + "</ul></li></ul>";
ui->lineEFilter->setToolTip(tip); ui->lineEFilter->setToolTip(tip);
initCategoryCombobox(); initCategoryCombobox();
loadFeedList(); loadFeedList();
@ -159,9 +159,8 @@ void AutomatedRssDownloader::saveSettings()
void AutomatedRssDownloader::loadRulesList() void AutomatedRssDownloader::loadRulesList()
{ {
// Make sure we save the current item before clearing // Make sure we save the current item before clearing
if (m_editedRule) { if (m_editedRule)
saveEditedRule(); saveEditedRule();
}
ui->listRules->clear(); ui->listRules->clear();
foreach (const QString &rule_name, m_editableRuleList->ruleNames()) { foreach (const QString &rule_name, m_editableRuleList->ruleNames()) {
QListWidgetItem *item = new QListWidgetItem(rule_name, ui->listRules); QListWidgetItem *item = new QListWidgetItem(rule_name, ui->listRules);
@ -171,7 +170,7 @@ void AutomatedRssDownloader::loadRulesList()
else else
item->setCheckState(Qt::Unchecked); item->setCheckState(Qt::Unchecked);
} }
if (ui->listRules->count() > 0 && !ui->listRules->currentItem()) if (( ui->listRules->count() > 0) && !ui->listRules->currentItem())
ui->listRules->setCurrentRow(0); ui->listRules->setCurrentRow(0);
} }
@ -204,13 +203,13 @@ void AutomatedRssDownloader::updateFeedList()
Rss::DownloadRulePtr rule = m_editableRuleList->getRule(ruleItem->text()); Rss::DownloadRulePtr rule = m_editableRuleList->getRule(ruleItem->text());
if (!rule) continue; if (!rule) continue;
qDebug() << "Rule" << rule->name() << "affects" << rule->rssFeeds().size() << "feeds."; qDebug() << "Rule" << rule->name() << "affects" << rule->rssFeeds().size() << "feeds.";
foreach (QString test, rule->rssFeeds()) { foreach (QString test, rule->rssFeeds())
qDebug() << "Feed is " << test; qDebug() << "Feed is " << test;
}
if (rule->rssFeeds().contains(feed_url)) { if (rule->rssFeeds().contains(feed_url)) {
qDebug() << "Rule " << rule->name() << " affects feed " << feed_url; qDebug() << "Rule " << rule->name() << " affects feed " << feed_url;
all_enabled = true; all_enabled = true;
} else { }
else {
qDebug() << "Rule " << rule->name() << " does NOT affect feed " << feed_url; qDebug() << "Rule " << rule->name() << " does NOT affect feed " << feed_url;
all_enabled = false; all_enabled = false;
break; break;
@ -257,7 +256,8 @@ void AutomatedRssDownloader::updateRuleDefinitionBox()
if (rule->category().isEmpty()) { if (rule->category().isEmpty()) {
ui->comboCategory->setCurrentIndex(-1); ui->comboCategory->setCurrentIndex(-1);
ui->comboCategory->clearEditText(); ui->comboCategory->clearEditText();
} else { }
else {
ui->comboCategory->setCurrentIndex(ui->comboCategory->findText(rule->category())); ui->comboCategory->setCurrentIndex(ui->comboCategory->findText(rule->category()));
} }
ui->comboAddPaused->setCurrentIndex(rule->addPaused()); ui->comboAddPaused->setCurrentIndex(rule->addPaused());
@ -271,7 +271,8 @@ void AutomatedRssDownloader::updateRuleDefinitionBox()
ui->lblLastMatch->setText(lMatch); ui->lblLastMatch->setText(lMatch);
updateMustLineValidity(); updateMustLineValidity();
updateMustNotLineValidity(); updateMustNotLineValidity();
} else { }
else {
// New rule // New rule
clearRuleDefinitionBox(); clearRuleDefinitionBox();
ui->lineContains->setText(selection.first()->text()); ui->lineContains->setText(selection.first()->text());
@ -280,7 +281,8 @@ void AutomatedRssDownloader::updateRuleDefinitionBox()
updateFieldsToolTips(ui->checkRegex->isChecked()); updateFieldsToolTips(ui->checkRegex->isChecked());
// Enable // Enable
ui->ruleDefBox->setEnabled(true); ui->ruleDefBox->setEnabled(true);
} else { }
else {
m_editedRule = 0; m_editedRule = 0;
// Clear // Clear
clearRuleDefinitionBox(); clearRuleDefinitionBox();
@ -353,7 +355,6 @@ void AutomatedRssDownloader::saveEditedRule()
m_editableRuleList->saveRule(rule); m_editableRuleList->saveRule(rule);
} }
void AutomatedRssDownloader::on_addRuleBtn_clicked() void AutomatedRssDownloader::on_addRuleBtn_clicked()
{ {
// Ask for a rule name // Ask for a rule name
@ -447,7 +448,8 @@ void AutomatedRssDownloader::displayRulesListMenu(const QPoint &pos)
delAct = menu.addAction(GuiIconProvider::instance()->getIcon("list-remove"), tr("Delete rule")); delAct = menu.addAction(GuiIconProvider::instance()->getIcon("list-remove"), tr("Delete rule"));
menu.addSeparator(); menu.addSeparator();
renameAct = menu.addAction(GuiIconProvider::instance()->getIcon("edit-rename"), tr("Rename rule...")); renameAct = menu.addAction(GuiIconProvider::instance()->getIcon("edit-rename"), tr("Rename rule..."));
} else { }
else {
delAct = menu.addAction(GuiIconProvider::instance()->getIcon("list-remove"), tr("Delete selected rules")); delAct = menu.addAction(GuiIconProvider::instance()->getIcon("list-remove"), tr("Delete selected rules"));
} }
} }
@ -480,7 +482,8 @@ void AutomatedRssDownloader::renameSelectedRule()
if (new_name.isEmpty()) return; if (new_name.isEmpty()) return;
if (m_editableRuleList->ruleNames().contains(new_name, Qt::CaseInsensitive)) { if (m_editableRuleList->ruleNames().contains(new_name, Qt::CaseInsensitive)) {
QMessageBox::warning(this, tr("Rule name conflict"), tr("A rule with this name already exists, please choose another name.")); QMessageBox::warning(this, tr("Rule name conflict"), tr("A rule with this name already exists, please choose another name."));
} else { }
else {
// Rename the rule // Rename the rule
m_editableRuleList->renameRule(item->text(), new_name); m_editableRuleList->renameRule(item->text(), new_name);
item->setText(new_name); item->setText(new_name);
@ -491,10 +494,9 @@ void AutomatedRssDownloader::renameSelectedRule()
void AutomatedRssDownloader::handleFeedCheckStateChange(QListWidgetItem *feed_item) void AutomatedRssDownloader::handleFeedCheckStateChange(QListWidgetItem *feed_item)
{ {
if (ui->ruleDefBox->isEnabled()) { if (ui->ruleDefBox->isEnabled())
// Make sure the current rule is saved // Make sure the current rule is saved
saveEditedRule(); saveEditedRule();
}
const QString feed_url = feed_item->data(Qt::UserRole).toString(); const QString feed_url = feed_item->data(Qt::UserRole).toString();
foreach (QListWidgetItem *rule_item, ui->listRules->selectedItems()) { foreach (QListWidgetItem *rule_item, ui->listRules->selectedItems()) {
Rss::DownloadRulePtr rule = m_editableRuleList->getRule(rule_item->text()); Rss::DownloadRulePtr rule = m_editableRuleList->getRule(rule_item->text());
@ -503,10 +505,9 @@ void AutomatedRssDownloader::handleFeedCheckStateChange(QListWidgetItem *feed_it
if (feed_item->checkState() == Qt::Checked) { if (feed_item->checkState() == Qt::Checked) {
if (!affected_feeds.contains(feed_url)) if (!affected_feeds.contains(feed_url))
affected_feeds << feed_url; affected_feeds << feed_url;
} else {
if (affected_feeds.contains(feed_url))
affected_feeds.removeOne(feed_url);
} }
else if (affected_feeds.contains(feed_url))
affected_feeds.removeOne(feed_url);
// Save the updated rule // Save the updated rule
if (affected_feeds.size() != rule->rssFeeds().size()) { if (affected_feeds.size() != rule->rssFeeds().size()) {
rule->setRssFeeds(affected_feeds); rule->setRssFeeds(affected_feeds);
@ -580,7 +581,8 @@ void AutomatedRssDownloader::updateFieldsToolTips(bool regex)
tip = tr("Regex mode: use Perl-like regular expressions"); tip = tr("Regex mode: use Perl-like regular expressions");
ui->lineContains->setToolTip(tip); ui->lineContains->setToolTip(tip);
ui->lineNotContains->setToolTip(tip); ui->lineNotContains->setToolTip(tip);
} else { }
else {
tip = tr("Wildcard mode: you can use<ul><li>? to match any single character</li><li>* to match zero or more of any characters</li><li>Whitespaces count as AND operators</li></ul>"); tip = tr("Wildcard mode: you can use<ul><li>? to match any single character</li><li>* to match zero or more of any characters</li><li>Whitespaces count as AND operators</li></ul>");
ui->lineContains->setToolTip(tip); ui->lineContains->setToolTip(tip);
tip = tr("Wildcard mode: you can use<ul><li>? to match any single character</li><li>* to match zero or more of any characters</li><li>| is used as OR operator</li></ul>"); tip = tr("Wildcard mode: you can use<ul><li>? to match any single character</li><li>* to match zero or more of any characters</li><li>| is used as OR operator</li></ul>");
@ -607,7 +609,8 @@ void AutomatedRssDownloader::updateMustLineValidity()
if (valid) { if (valid) {
ui->lineContains->setStyleSheet(""); ui->lineContains->setStyleSheet("");
ui->lbl_must_stat->setPixmap(QPixmap()); ui->lbl_must_stat->setPixmap(QPixmap());
} else { }
else {
ui->lineContains->setStyleSheet("QLineEdit { color: #ff0000; }"); ui->lineContains->setStyleSheet("QLineEdit { color: #ff0000; }");
ui->lbl_must_stat->setPixmap(GuiIconProvider::instance()->getIcon("task-attention").pixmap(16, 16)); ui->lbl_must_stat->setPixmap(GuiIconProvider::instance()->getIcon("task-attention").pixmap(16, 16));
} }
@ -632,13 +635,15 @@ void AutomatedRssDownloader::updateMustNotLineValidity()
if (valid) { if (valid) {
ui->lineNotContains->setStyleSheet(""); ui->lineNotContains->setStyleSheet("");
ui->lbl_mustnot_stat->setPixmap(QPixmap()); ui->lbl_mustnot_stat->setPixmap(QPixmap());
} else { }
else {
ui->lineNotContains->setStyleSheet("QLineEdit { color: #ff0000; }"); ui->lineNotContains->setStyleSheet("QLineEdit { color: #ff0000; }");
ui->lbl_mustnot_stat->setPixmap(GuiIconProvider::instance()->getIcon("task-attention").pixmap(16, 16)); ui->lbl_mustnot_stat->setPixmap(GuiIconProvider::instance()->getIcon("task-attention").pixmap(16, 16));
} }
} }
void AutomatedRssDownloader::onFinished(int result) { void AutomatedRssDownloader::onFinished(int result)
{
Q_UNUSED(result); Q_UNUSED(result);
// Save current item on exit // Save current item on exit
saveEditedRule(); saveEditedRule();

8
src/gui/rss/rss_imp.cpp

@ -259,7 +259,6 @@ void RSSImp::deleteSelectedItems()
updateItemInfos(m_feedList->stickyUnreadItem()); updateItemInfos(m_feedList->stickyUnreadItem());
if (m_feedList->currentItem() == m_feedList->stickyUnreadItem()) if (m_feedList->currentItem() == m_feedList->stickyUnreadItem())
populateArticleList(m_feedList->stickyUnreadItem()); populateArticleList(m_feedList->stickyUnreadItem());
} }
void RSSImp::loadFoldersOpenState() void RSSImp::loadFoldersOpenState()
@ -636,8 +635,9 @@ void RSSImp::updateItemInfos(QTreeWidgetItem *item)
name = tr("Unread"); name = tr("Unread");
emit updateRSSCount(rss_item->unreadCount()); emit updateRSSCount(rss_item->unreadCount());
} }
else else {
name = rss_item->displayName(); name = rss_item->displayName();
}
item->setText(0, name + QString::fromUtf8(" (") + QString::number(rss_item->unreadCount()) + QString(")")); item->setText(0, name + QString::fromUtf8(" (") + QString::number(rss_item->unreadCount()) + QString(")"));
// If item has a parent, update it too // If item has a parent, update it too
if (item->parent()) if (item->parent())
@ -682,8 +682,8 @@ void RSSImp::updateRefreshInterval(uint val)
m_rssManager->updateRefreshInterval(val); m_rssManager->updateRefreshInterval(val);
} }
RSSImp::RSSImp(QWidget *parent): RSSImp::RSSImp(QWidget *parent)
QWidget(parent), : QWidget(parent),
m_rssManager(new Rss::Manager) m_rssManager(new Rss::Manager)
{ {
setupUi(this); setupUi(this);

1
src/gui/rss/rss_imp.h

@ -97,7 +97,6 @@ private:
QListWidgetItem *m_currentArticle; QListWidgetItem *m_currentArticle;
QShortcut *editHotkey; QShortcut *editHotkey;
QShortcut *deleteHotkey; QShortcut *deleteHotkey;
}; };
#endif #endif

Loading…
Cancel
Save