Browse Source

Follow project coding style. Issue #2192.

--HG--
branch : magao-dev
adaptive-webui-19844
Tim Delaney 8 years ago
parent
commit
70ce12372d
  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 @@ -110,7 +110,7 @@ bool DownloadRule::matches(const QString &articleTitle) const
pos = reg.indexIn(articleTitle);
if (pos != -1) {
int epTheirs = reg.cap(1).toInt();
if (epOursFirst <= epTheirs && epOursLast >= epTheirs)
if ((epOursFirst <= epTheirs) && (epOursLast >= epTheirs))
return true;
}
}

20
src/base/rss/rssfeed.cpp

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

69
src/gui/rss/automatedrssdownloader.cpp

@ -47,8 +47,8 @@ @@ -47,8 +47,8 @@
#include "ui_automatedrssdownloader.h"
#include "automatedrssdownloader.h"
AutomatedRssDownloader::AutomatedRssDownloader(const QWeakPointer<Rss::Manager>& manager, QWidget *parent) :
QDialog(parent),
AutomatedRssDownloader::AutomatedRssDownloader(const QWeakPointer<Rss::Manager> &manager, QWidget *parent)
: QDialog(parent),
ui(new Ui::AutomatedRssDownloader),
m_manager(manager), m_editedRule(0)
{
@ -76,15 +76,15 @@ AutomatedRssDownloader::AutomatedRssDownloader(const QWeakPointer<Rss::Manager>& @@ -76,15 +76,15 @@ AutomatedRssDownloader::AutomatedRssDownloader(const QWeakPointer<Rss::Manager>&
Qt::CaseInsensitive),
ui->lineEFilter);
ui->lineEFilter->setValidator(m_episodeValidator);
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>";
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("Filter must end with semicolon") + "</li>" +
"<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("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>";
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>";
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("Filter must end with semicolon") + "</li>"
+ "<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("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>";
ui->lineEFilter->setToolTip(tip);
initCategoryCombobox();
loadFeedList();
@ -159,9 +159,8 @@ void AutomatedRssDownloader::saveSettings() @@ -159,9 +159,8 @@ void AutomatedRssDownloader::saveSettings()
void AutomatedRssDownloader::loadRulesList()
{
// Make sure we save the current item before clearing
if (m_editedRule) {
if (m_editedRule)
saveEditedRule();
}
ui->listRules->clear();
foreach (const QString &rule_name, m_editableRuleList->ruleNames()) {
QListWidgetItem *item = new QListWidgetItem(rule_name, ui->listRules);
@ -171,7 +170,7 @@ void AutomatedRssDownloader::loadRulesList() @@ -171,7 +170,7 @@ void AutomatedRssDownloader::loadRulesList()
else
item->setCheckState(Qt::Unchecked);
}
if (ui->listRules->count() > 0 && !ui->listRules->currentItem())
if (( ui->listRules->count() > 0) && !ui->listRules->currentItem())
ui->listRules->setCurrentRow(0);
}
@ -204,13 +203,13 @@ void AutomatedRssDownloader::updateFeedList() @@ -204,13 +203,13 @@ void AutomatedRssDownloader::updateFeedList()
Rss::DownloadRulePtr rule = m_editableRuleList->getRule(ruleItem->text());
if (!rule) continue;
qDebug() << "Rule" << rule->name() << "affects" << rule->rssFeeds().size() << "feeds.";
foreach (QString test, rule->rssFeeds()) {
foreach (QString test, rule->rssFeeds())
qDebug() << "Feed is " << test;
}
if (rule->rssFeeds().contains(feed_url)) {
qDebug() << "Rule " << rule->name() << " affects feed " << feed_url;
all_enabled = true;
} else {
}
else {
qDebug() << "Rule " << rule->name() << " does NOT affect feed " << feed_url;
all_enabled = false;
break;
@ -257,7 +256,8 @@ void AutomatedRssDownloader::updateRuleDefinitionBox() @@ -257,7 +256,8 @@ void AutomatedRssDownloader::updateRuleDefinitionBox()
if (rule->category().isEmpty()) {
ui->comboCategory->setCurrentIndex(-1);
ui->comboCategory->clearEditText();
} else {
}
else {
ui->comboCategory->setCurrentIndex(ui->comboCategory->findText(rule->category()));
}
ui->comboAddPaused->setCurrentIndex(rule->addPaused());
@ -271,7 +271,8 @@ void AutomatedRssDownloader::updateRuleDefinitionBox() @@ -271,7 +271,8 @@ void AutomatedRssDownloader::updateRuleDefinitionBox()
ui->lblLastMatch->setText(lMatch);
updateMustLineValidity();
updateMustNotLineValidity();
} else {
}
else {
// New rule
clearRuleDefinitionBox();
ui->lineContains->setText(selection.first()->text());
@ -280,7 +281,8 @@ void AutomatedRssDownloader::updateRuleDefinitionBox() @@ -280,7 +281,8 @@ void AutomatedRssDownloader::updateRuleDefinitionBox()
updateFieldsToolTips(ui->checkRegex->isChecked());
// Enable
ui->ruleDefBox->setEnabled(true);
} else {
}
else {
m_editedRule = 0;
// Clear
clearRuleDefinitionBox();
@ -353,7 +355,6 @@ void AutomatedRssDownloader::saveEditedRule() @@ -353,7 +355,6 @@ void AutomatedRssDownloader::saveEditedRule()
m_editableRuleList->saveRule(rule);
}
void AutomatedRssDownloader::on_addRuleBtn_clicked()
{
// Ask for a rule name
@ -447,7 +448,8 @@ void AutomatedRssDownloader::displayRulesListMenu(const QPoint &pos) @@ -447,7 +448,8 @@ void AutomatedRssDownloader::displayRulesListMenu(const QPoint &pos)
delAct = menu.addAction(GuiIconProvider::instance()->getIcon("list-remove"), tr("Delete rule"));
menu.addSeparator();
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"));
}
}
@ -480,7 +482,8 @@ void AutomatedRssDownloader::renameSelectedRule() @@ -480,7 +482,8 @@ void AutomatedRssDownloader::renameSelectedRule()
if (new_name.isEmpty()) return;
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."));
} else {
}
else {
// Rename the rule
m_editableRuleList->renameRule(item->text(), new_name);
item->setText(new_name);
@ -491,10 +494,9 @@ void AutomatedRssDownloader::renameSelectedRule() @@ -491,10 +494,9 @@ void AutomatedRssDownloader::renameSelectedRule()
void AutomatedRssDownloader::handleFeedCheckStateChange(QListWidgetItem *feed_item)
{
if (ui->ruleDefBox->isEnabled()) {
if (ui->ruleDefBox->isEnabled())
// Make sure the current rule is saved
saveEditedRule();
}
const QString feed_url = feed_item->data(Qt::UserRole).toString();
foreach (QListWidgetItem *rule_item, ui->listRules->selectedItems()) {
Rss::DownloadRulePtr rule = m_editableRuleList->getRule(rule_item->text());
@ -503,10 +505,9 @@ void AutomatedRssDownloader::handleFeedCheckStateChange(QListWidgetItem *feed_it @@ -503,10 +505,9 @@ void AutomatedRssDownloader::handleFeedCheckStateChange(QListWidgetItem *feed_it
if (feed_item->checkState() == Qt::Checked) {
if (!affected_feeds.contains(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
if (affected_feeds.size() != rule->rssFeeds().size()) {
rule->setRssFeeds(affected_feeds);
@ -580,7 +581,8 @@ void AutomatedRssDownloader::updateFieldsToolTips(bool regex) @@ -580,7 +581,8 @@ void AutomatedRssDownloader::updateFieldsToolTips(bool regex)
tip = tr("Regex mode: use Perl-like regular expressions");
ui->lineContains->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>");
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>");
@ -607,7 +609,8 @@ void AutomatedRssDownloader::updateMustLineValidity() @@ -607,7 +609,8 @@ void AutomatedRssDownloader::updateMustLineValidity()
if (valid) {
ui->lineContains->setStyleSheet("");
ui->lbl_must_stat->setPixmap(QPixmap());
} else {
}
else {
ui->lineContains->setStyleSheet("QLineEdit { color: #ff0000; }");
ui->lbl_must_stat->setPixmap(GuiIconProvider::instance()->getIcon("task-attention").pixmap(16, 16));
}
@ -632,13 +635,15 @@ void AutomatedRssDownloader::updateMustNotLineValidity() @@ -632,13 +635,15 @@ void AutomatedRssDownloader::updateMustNotLineValidity()
if (valid) {
ui->lineNotContains->setStyleSheet("");
ui->lbl_mustnot_stat->setPixmap(QPixmap());
} else {
}
else {
ui->lineNotContains->setStyleSheet("QLineEdit { color: #ff0000; }");
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);
// Save current item on exit
saveEditedRule();

8
src/gui/rss/rss_imp.cpp

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

1
src/gui/rss/rss_imp.h

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

Loading…
Cancel
Save