Browse Source

Fix selection behavior

adaptive-webui-19844
Christophe Dumez 14 years ago
parent
commit
adffd7df74
  1. 106
      src/rss/automatedrssdownloader.cpp
  2. 7
      src/rss/automatedrssdownloader.h
  3. 220
      src/rss/automatedrssdownloader.ui

106
src/rss/automatedrssdownloader.cpp

@ -54,9 +54,12 @@ AutomatedRssDownloader::AutomatedRssDownloader(QWidget *parent) :
initLabelCombobox(); initLabelCombobox();
loadFeedList(); loadFeedList();
loadSettings(); loadSettings();
connect(ui->listRules, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), SLOT(updateRuleDefinitionBox(QListWidgetItem*,QListWidgetItem*))); connect(ui->listRules, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), SLOT(handleCurrentItemChange(QListWidgetItem*,QListWidgetItem*)));
connect(ui->listRules, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), SLOT(updateFeedList(QListWidgetItem*,QListWidgetItem*))); connect(ui->listRules, SIGNAL(itemSelectionChanged()), SLOT(updateRuleDefinitionBox()));
connect(ui->listRules, SIGNAL(itemSelectionChanged()), SLOT(updateFeedList()));
connect(ui->listFeeds, SIGNAL(itemChanged(QListWidgetItem*)), SLOT(handleFeedCheckStateChange(QListWidgetItem*)));
updateRuleDefinitionBox(); updateRuleDefinitionBox();
updateFeedList();
} }
AutomatedRssDownloader::~AutomatedRssDownloader() AutomatedRssDownloader::~AutomatedRssDownloader()
@ -101,6 +104,8 @@ void AutomatedRssDownloader::loadRulesList()
else else
item->setCheckState(Qt::Unchecked); item->setCheckState(Qt::Unchecked);
} }
if(ui->listRules->count() > 0 && !ui->listRules->currentItem())
ui->listRules->setCurrentRow(0);
} }
void AutomatedRssDownloader::loadFeedList() void AutomatedRssDownloader::loadFeedList()
@ -112,8 +117,6 @@ void AutomatedRssDownloader::loadFeedList()
item->setData(Qt::UserRole, feed_urls.at(i)); item->setData(Qt::UserRole, feed_urls.at(i));
item->setFlags(item->flags()|Qt::ItemIsUserCheckable); item->setFlags(item->flags()|Qt::ItemIsUserCheckable);
} }
if(ui->listRules->count() > 0 && !ui->listRules->currentItem())
ui->listRules->setCurrentRow(0);
} }
QStringList AutomatedRssDownloader::getSelectedFeeds() const QStringList AutomatedRssDownloader::getSelectedFeeds() const
@ -127,20 +130,28 @@ QStringList AutomatedRssDownloader::getSelectedFeeds() const
return feeds; return feeds;
} }
void AutomatedRssDownloader::updateFeedList(QListWidgetItem* current, QListWidgetItem* previous) void AutomatedRssDownloader::updateFeedList()
{ {
Q_UNUSED(previous);
RssDownloadRule rule = getCurrentRule();
const QStringList affected_feeds = rule.rssFeeds();
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();
if(affected_feeds.contains(feed_url)) 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;
}
}
if(all_enabled)
item->setCheckState(Qt::Checked); item->setCheckState(Qt::Checked);
else else
item->setCheckState(Qt::Unchecked); item->setCheckState(Qt::Unchecked);
} }
ui->listFeeds->setEnabled(current != 0); ui->listFeeds->setEnabled(!ui->listRules->selectedItems().isEmpty());
} }
bool AutomatedRssDownloader::isRssDownloaderEnabled() const bool AutomatedRssDownloader::isRssDownloaderEnabled() const
@ -148,44 +159,47 @@ bool AutomatedRssDownloader::isRssDownloaderEnabled() const
return ui->checkEnableDownloader->isChecked(); return ui->checkEnableDownloader->isChecked();
} }
void AutomatedRssDownloader::updateRuleDefinitionBox(QListWidgetItem* current, QListWidgetItem* previous) void AutomatedRssDownloader::updateRuleDefinitionBox()
{ {
qDebug() << Q_FUNC_INFO << current << previous; qDebug() << Q_FUNC_INFO;
// Save previous item
saveCurrentRule(previous);
// Update rule definition box // Update rule definition box
const QList<QListWidgetItem*> selection = ui->listRules->selectedItems(); const QList<QListWidgetItem*> selection = ui->listRules->selectedItems();
RssDownloadRule rule = getCurrentRule(); if(selection.count() == 1) {
if(selection.count() == 1 && rule.isValid()) { RssDownloadRule rule = getCurrentRule();
ui->lineContains->setText(rule.mustContain()); if(rule.isValid()) {
ui->lineNotContains->setText(rule.mustNotContain()); ui->lineContains->setText(rule.mustContain());
ui->saveDiffDir_check->setChecked(!rule.savePath().isEmpty()); ui->lineNotContains->setText(rule.mustNotContain());
ui->lineSavePath->setText(rule.savePath()); ui->saveDiffDir_check->setChecked(!rule.savePath().isEmpty());
if(rule.label().isEmpty()) { ui->lineSavePath->setText(rule.savePath());
ui->comboLabel->setCurrentIndex(-1); if(rule.label().isEmpty()) {
ui->comboLabel->clearEditText(); ui->comboLabel->setCurrentIndex(-1);
ui->comboLabel->clearEditText();
} else {
ui->comboLabel->setCurrentIndex(ui->comboLabel->findText(rule.label()));
}
} else { } else {
ui->comboLabel->setCurrentIndex(ui->comboLabel->findText(rule.label())); // New rule
clearRuleDefinitionBox();
ui->lineContains->setText(selection.first()->text());
} }
// Enable // Enable
ui->ruleDefBox->setEnabled(true); ui->ruleDefBox->setEnabled(true);
} else { } else {
// Clear // Clear
ui->lineNotContains->clear(); clearRuleDefinitionBox();
ui->saveDiffDir_check->setChecked(false); ui->ruleDefBox->setEnabled(false);
ui->lineSavePath->clear();
ui->comboLabel->clearEditText();
if(current && selection.count() == 1) {
// Use the rule name as a default for the "contains" field
ui->lineContains->setText(current->text());
ui->ruleDefBox->setEnabled(true);
} else {
ui->lineContains->clear();
ui->ruleDefBox->setEnabled(false);
}
} }
} }
void AutomatedRssDownloader::clearRuleDefinitionBox()
{
ui->lineContains->clear();
ui->lineNotContains->clear();
ui->saveDiffDir_check->setChecked(false);
ui->lineSavePath->clear();
ui->comboLabel->clearEditText();
}
RssDownloadRule AutomatedRssDownloader::getCurrentRule() const RssDownloadRule AutomatedRssDownloader::getCurrentRule() const
{ {
QListWidgetItem * current_item = ui->listRules->currentItem(); QListWidgetItem * current_item = ui->listRules->currentItem();
@ -203,6 +217,12 @@ void AutomatedRssDownloader::initLabelCombobox()
} }
} }
void AutomatedRssDownloader::handleCurrentItemChange(QListWidgetItem *current, QListWidgetItem *previous)
{
Q_UNUSED(current);
saveCurrentRule(previous);
}
void AutomatedRssDownloader::saveCurrentRule(QListWidgetItem * item) void AutomatedRssDownloader::saveCurrentRule(QListWidgetItem * item)
{ {
qDebug() << Q_FUNC_INFO << item; qDebug() << Q_FUNC_INFO << item;
@ -360,3 +380,17 @@ void AutomatedRssDownloader::renameSelectedRule()
} }
} }
} }
void AutomatedRssDownloader::handleFeedCheckStateChange(QListWidgetItem *feed_item)
{
if(ui->ruleDefBox->isEnabled()) {
// Make sure the current rule is saved
saveCurrentRule(ui->listRules->currentItem());
}
foreach (QListWidgetItem* rule_item, ui->listRules->selectedItems()) {
RssDownloadRule rule = m_ruleList->getRule(rule_item->text());
// TODO
}
}

7
src/rss/automatedrssdownloader.h

@ -54,10 +54,13 @@ protected slots:
void loadSettings(); void loadSettings();
void saveSettings(); void saveSettings();
void loadRulesList(); void loadRulesList();
void updateRuleDefinitionBox(QListWidgetItem* current = 0, QListWidgetItem* previous = 0); void handleCurrentItemChange(QListWidgetItem* current, QListWidgetItem* previous);
void handleFeedCheckStateChange(QListWidgetItem* feed_item);
void updateRuleDefinitionBox();
void clearRuleDefinitionBox();
void saveCurrentRule(QListWidgetItem * item); void saveCurrentRule(QListWidgetItem * item);
void loadFeedList(); void loadFeedList();
void updateFeedList(QListWidgetItem* current, QListWidgetItem* previous); void updateFeedList();
private slots: private slots:
void displayRulesListMenu(const QPoint& pos); void displayRulesListMenu(const QPoint& pos);

220
src/rss/automatedrssdownloader.ui

@ -13,7 +13,7 @@
<property name="windowTitle"> <property name="windowTitle">
<string>Automated RSS Downloader</string> <string>Automated RSS Downloader</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_4"> <layout class="QVBoxLayout" name="verticalLayout_5">
<item> <item>
<widget class="QCheckBox" name="checkEnableDownloader"> <widget class="QCheckBox" name="checkEnableDownloader">
<property name="font"> <property name="font">
@ -121,130 +121,127 @@
</layout> </layout>
</item> </item>
<item> <item>
<widget class="Line" name="line"> <layout class="QVBoxLayout" name="verticalLayout_4">
<property name="orientation"> <item>
<enum>Qt::Vertical</enum> <widget class="QGroupBox" name="ruleDefBox">
</property> <property name="title">
</widget> <string>Rule definition</string>
</item> </property>
<item> <layout class="QGridLayout" name="gridLayout">
<widget class="QGroupBox" name="ruleDefBox"> <property name="leftMargin">
<property name="title"> <number>0</number>
<string>Rule definition</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Must contain:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineContains"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Must not contain:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="lineNotContains"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_6">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Save to:</string>
</property> </property>
<property name="alignment"> <property name="bottomMargin">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <number>0</number>
</property> </property>
</widget> <item row="0" column="0">
</item> <widget class="QLabel" name="label_4">
<item row="4" column="1"> <property name="text">
<layout class="QHBoxLayout" name="horizontalLayout"> <string>Must contain:</string>
<item> </property>
<widget class="QLineEdit" name="lineSavePath"> <property name="alignment">
<property name="enabled"> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
<bool>false</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="0" column="1">
<widget class="QToolButton" name="browseSP"> <widget class="QLineEdit" name="lineContains"/>
<property name="enabled"> </item>
<bool>false</bool> <item row="1" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Must not contain:</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="lineNotContains"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_7">
<property name="text"> <property name="text">
<string>...</string> <string>Assign label:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property> </property>
</widget> </widget>
</item> </item>
</layout> <item row="2" column="1">
</item> <widget class="QComboBox" name="comboLabel">
<item row="6" column="0" colspan="2"> <property name="editable">
<layout class="QVBoxLayout" name="verticalLayout"> <bool>true</bool>
<item> </property>
<widget class="QLabel" name="label_2"> </widget>
<property name="font"> </item>
<font> <item row="3" column="0" colspan="2">
<weight>50</weight> <widget class="QCheckBox" name="saveDiffDir_check">
<bold>false</bold> <property name="text">
</font> <string>Save to a different directory</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_6">
<property name="enabled">
<bool>false</bool>
</property> </property>
<property name="text"> <property name="text">
<string>Apply rule to feeds:</string> <string>Save to:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="4" column="1">
<widget class="QListWidget" name="listFeeds"/> <layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="lineSavePath">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="browseSP">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</item> </item>
</layout> </layout>
</item> </widget>
<item row="3" column="0" colspan="2"> </item>
<widget class="QCheckBox" name="saveDiffDir_check"> <item>
<property name="text"> <layout class="QVBoxLayout" name="verticalLayout">
<string>Save to a different directory</string> <item>
</property> <widget class="QLabel" name="label_2">
</widget> <property name="font">
</item> <font>
<item row="2" column="0"> <weight>50</weight>
<widget class="QLabel" name="label_7"> <bold>false</bold>
<property name="text"> </font>
<string>Assign label:</string> </property>
</property> <property name="text">
<property name="alignment"> <string>Apply rule to feeds:</string>
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> </property>
</property> </widget>
</widget> </item>
</item> <item>
<item row="2" column="1"> <widget class="QListWidget" name="listFeeds"/>
<widget class="QComboBox" name="comboLabel"> </item>
<property name="editable"> </layout>
<bool>true</bool> </item>
</property> </layout>
</widget>
</item>
</layout>
</widget>
</item> </item>
<item> <item>
<widget class="Line" name="line_2"> <widget class="Line" name="line_2">
@ -279,6 +276,13 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_4"> <layout class="QHBoxLayout" name="horizontalLayout_4">
<item> <item>

Loading…
Cancel
Save