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

12
src/rss/rssdownloadrulelist.cpp

@ -128,6 +128,9 @@ void RssDownloadRuleList::loadRulesFromVariantHash(const QVariantHash &h) @@ -128,6 +128,9 @@ void RssDownloadRuleList::loadRulesFromVariantHash(const QVariantHash &h)
void RssDownloadRuleList::saveRule(const RssDownloadRule &rule)
{
Q_ASSERT(rule.isValid());
if(m_rules.contains(rule.name())) {
removeRule(rule.name());
}
m_rules.insert(rule.name(), rule);
// Update feedRules hashtable
foreach(const QString &feed_url, rule.rssFeeds()) {
@ -150,15 +153,6 @@ void RssDownloadRuleList::removeRule(const QString &name) @@ -150,15 +153,6 @@ void RssDownloadRuleList::removeRule(const QString &name)
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)
{
if(!m_rules.contains(old_name)) return;

1
src/rss/rssdownloadrulelist.h

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

Loading…
Cancel
Save