Browse Source

Improved feed assignment behavior

adaptive-webui-19844
Christophe Dumez 14 years ago
parent
commit
345222cf42
  1. 55
      src/rss/automatedrssdownloader.cpp
  2. 1
      src/rss/automatedrssdownloader.h
  3. 12
      src/rss/rssdownloadrulelist.cpp
  4. 1
      src/rss/rssdownloadrulelist.h

55
src/rss/automatedrssdownloader.cpp

@ -119,32 +119,28 @@ void AutomatedRssDownloader::loadFeedList()
} }
} }
QStringList AutomatedRssDownloader::getSelectedFeeds() const
{
QStringList feeds;
for(int i=0; i<ui->listFeeds->count(); ++i) {
QListWidgetItem *item = ui->listFeeds->item(i);
if(item->checkState() != Qt::Unchecked)
feeds << item->data(Qt::UserRole).toString();
}
return feeds;
}
void AutomatedRssDownloader::updateFeedList() void AutomatedRssDownloader::updateFeedList()
{ {
disconnect(ui->listFeeds, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(handleFeedCheckStateChange(QListWidgetItem*)));
for(int i=0; i<ui->listFeeds->count(); ++i) { for(int i=0; i<ui->listFeeds->count(); ++i) {
QListWidgetItem *item = ui->listFeeds->item(i); QListWidgetItem *item = ui->listFeeds->item(i);
const QString feed_url = item->data(Qt::UserRole).toString(); const QString feed_url = item->data(Qt::UserRole).toString();
bool all_enabled = false; bool all_enabled = false;
foreach(QListWidgetItem *ruleItem, ui->listRules->selectedItems()) { foreach(const QListWidgetItem *ruleItem, ui->listRules->selectedItems()) {
RssDownloadRule rule = m_ruleList->getRule(ruleItem->text()); RssDownloadRule rule = m_ruleList->getRule(ruleItem->text());
if(!rule.isValid()) continue; if(!rule.isValid()) continue;
if(rule.rssFeeds().contains(feed_url)) { qDebug() << "Rule" << rule.name() << "affects" << rule.rssFeeds().size() << "feeds.";
all_enabled = true; foreach(QString test, rule.rssFeeds()) {
} else { qDebug() << "Feed is " << test;
all_enabled = false; }
break; if(rule.rssFeeds().contains(feed_url)) {
} qDebug() << "Rule " << rule.name() << " affects feed " << feed_url;
all_enabled = true;
} else {
qDebug() << "Rule " << rule.name() << " does NOT affect feed " << feed_url;
all_enabled = false;
break;
}
} }
if(all_enabled) if(all_enabled)
item->setCheckState(Qt::Checked); item->setCheckState(Qt::Checked);
@ -152,6 +148,7 @@ void AutomatedRssDownloader::updateFeedList()
item->setCheckState(Qt::Unchecked); item->setCheckState(Qt::Unchecked);
} }
ui->listFeeds->setEnabled(!ui->listRules->selectedItems().isEmpty()); ui->listFeeds->setEnabled(!ui->listRules->selectedItems().isEmpty());
connect(ui->listFeeds, SIGNAL(itemChanged(QListWidgetItem*)), SLOT(handleFeedCheckStateChange(QListWidgetItem*)));
} }
bool AutomatedRssDownloader::isRssDownloaderEnabled() const bool AutomatedRssDownloader::isRssDownloaderEnabled() const
@ -246,7 +243,7 @@ void AutomatedRssDownloader::saveCurrentRule(QListWidgetItem * item)
// Save new label // Save new label
if(!rule.label().isEmpty()) if(!rule.label().isEmpty())
Preferences::addTorrentLabel(rule.label()); Preferences::addTorrentLabel(rule.label());
rule.setRssFeeds(getSelectedFeeds()); //rule.setRssFeeds(getSelectedFeeds());
// Save it // Save it
m_ruleList->saveRule(rule); m_ruleList->saveRule(rule);
} }
@ -387,9 +384,23 @@ void AutomatedRssDownloader::handleFeedCheckStateChange(QListWidgetItem *feed_it
// Make sure the current rule is saved // Make sure the current rule is saved
saveCurrentRule(ui->listRules->currentItem()); saveCurrentRule(ui->listRules->currentItem());
} }
const QString feed_url = feed_item->data(Qt::UserRole).toString();
foreach (QListWidgetItem* rule_item, ui->listRules->selectedItems()) { foreach (QListWidgetItem* rule_item, ui->listRules->selectedItems()) {
RssDownloadRule rule = m_ruleList->getRule(rule_item->text()); RssDownloadRule rule = m_ruleList->getRule(rule_item->text());
// TODO Q_ASSERT(rule.isValid());
QStringList affected_feeds = rule.rssFeeds();
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);
}
// Save the updated rule
if(affected_feeds.size() != rule.rssFeeds().size()) {
rule.setRssFeeds(affected_feeds);
m_ruleList->saveRule(rule);
}
} }
} }

1
src/rss/automatedrssdownloader.h

@ -74,7 +74,6 @@ private slots:
private: private:
RssDownloadRule getCurrentRule() const; RssDownloadRule getCurrentRule() const;
void initLabelCombobox(); void initLabelCombobox();
QStringList getSelectedFeeds() const;
private: private:
Ui::AutomatedRssDownloader *ui; Ui::AutomatedRssDownloader *ui;

12
src/rss/rssdownloadrulelist.cpp

@ -128,6 +128,9 @@ void RssDownloadRuleList::loadRulesFromVariantHash(const QVariantHash &h)
void RssDownloadRuleList::saveRule(const RssDownloadRule &rule) void RssDownloadRuleList::saveRule(const RssDownloadRule &rule)
{ {
Q_ASSERT(rule.isValid()); Q_ASSERT(rule.isValid());
if(m_rules.contains(rule.name())) {
removeRule(rule.name());
}
m_rules.insert(rule.name(), rule); m_rules.insert(rule.name(), rule);
// Update feedRules hashtable // Update feedRules hashtable
foreach(const QString &feed_url, rule.rssFeeds()) { foreach(const QString &feed_url, rule.rssFeeds()) {
@ -150,15 +153,6 @@ void RssDownloadRuleList::removeRule(const QString &name)
saveRulesToStorage(); saveRulesToStorage();
} }
void RssDownloadRuleList::updateRule(const RssDownloadRule &rule)
{
if(!m_rules.contains(rule.name())) return;
removeRule(rule.name());
saveRule(rule);
// Save rules
saveRulesToStorage();
}
void RssDownloadRuleList::renameRule(const QString &old_name, const QString &new_name) void RssDownloadRuleList::renameRule(const QString &old_name, const QString &new_name)
{ {
if(!m_rules.contains(old_name)) return; if(!m_rules.contains(old_name)) return;

1
src/rss/rssdownloadrulelist.h

@ -53,7 +53,6 @@ public:
// Operators // Operators
void saveRule(const RssDownloadRule &rule); void saveRule(const RssDownloadRule &rule);
void removeRule(const QString &name); void removeRule(const QString &name);
void updateRule(const RssDownloadRule &rule);
void renameRule(const QString &old_name, const QString &new_name); void renameRule(const QString &old_name, const QString &new_name);
RssDownloadRule getRule(const QString &name) const; RssDownloadRule getRule(const QString &name) const;
inline QStringList ruleNames() const { return m_rules.keys(); } inline QStringList ruleNames() const { return m_rules.keys(); }

Loading…
Cancel
Save