mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-23 17:56:50 +03:00
Fix rule saving issue
This commit is contained in:
parent
c387c15eb0
commit
ad087d7e88
3 changed files with 27 additions and 25 deletions
|
@ -46,7 +46,8 @@
|
||||||
|
|
||||||
AutomatedRssDownloader::AutomatedRssDownloader(QWidget *parent) :
|
AutomatedRssDownloader::AutomatedRssDownloader(QWidget *parent) :
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
ui(new Ui::AutomatedRssDownloader)
|
ui(new Ui::AutomatedRssDownloader),
|
||||||
|
m_editedRule(0)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
ui->listRules->setSortingEnabled(true);
|
ui->listRules->setSortingEnabled(true);
|
||||||
|
@ -58,7 +59,6 @@ AutomatedRssDownloader::AutomatedRssDownloader(QWidget *parent) :
|
||||||
initLabelCombobox();
|
initLabelCombobox();
|
||||||
loadFeedList();
|
loadFeedList();
|
||||||
loadSettings();
|
loadSettings();
|
||||||
connect(ui->listRules, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), SLOT(handleCurrentItemChange(QListWidgetItem*,QListWidgetItem*)));
|
|
||||||
connect(ui->listRules, SIGNAL(itemSelectionChanged()), SLOT(updateRuleDefinitionBox()));
|
connect(ui->listRules, SIGNAL(itemSelectionChanged()), SLOT(updateRuleDefinitionBox()));
|
||||||
connect(ui->listRules, SIGNAL(itemSelectionChanged()), SLOT(updateFeedList()));
|
connect(ui->listRules, SIGNAL(itemSelectionChanged()), SLOT(updateFeedList()));
|
||||||
connect(ui->listFeeds, SIGNAL(itemChanged(QListWidgetItem*)), SLOT(handleFeedCheckStateChange(QListWidgetItem*)));
|
connect(ui->listFeeds, SIGNAL(itemChanged(QListWidgetItem*)), SLOT(handleFeedCheckStateChange(QListWidgetItem*)));
|
||||||
|
@ -73,7 +73,7 @@ AutomatedRssDownloader::~AutomatedRssDownloader()
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
// Save current item on exit
|
// Save current item on exit
|
||||||
saveCurrentRule(ui->listRules->currentItem());
|
saveEditedRule();
|
||||||
saveSettings();
|
saveSettings();
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
@ -99,8 +99,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(ui->listRules->currentItem()) {
|
if(m_editedRule) {
|
||||||
saveCurrentRule(ui->listRules->currentItem());
|
saveEditedRule();
|
||||||
}
|
}
|
||||||
ui->listRules->clear();
|
ui->listRules->clear();
|
||||||
foreach (const QString &rule_name, m_ruleList->ruleNames()) {
|
foreach (const QString &rule_name, m_ruleList->ruleNames()) {
|
||||||
|
@ -167,9 +167,12 @@ bool AutomatedRssDownloader::isRssDownloaderEnabled() const
|
||||||
void AutomatedRssDownloader::updateRuleDefinitionBox()
|
void AutomatedRssDownloader::updateRuleDefinitionBox()
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
// Save previous rule first
|
||||||
|
saveEditedRule();
|
||||||
// Update rule definition box
|
// Update rule definition box
|
||||||
const QList<QListWidgetItem*> selection = ui->listRules->selectedItems();
|
const QList<QListWidgetItem*> selection = ui->listRules->selectedItems();
|
||||||
if(selection.count() == 1) {
|
if(selection.count() == 1) {
|
||||||
|
m_editedRule = selection.first();
|
||||||
RssDownloadRule rule = getCurrentRule();
|
RssDownloadRule rule = getCurrentRule();
|
||||||
if(rule.isValid()) {
|
if(rule.isValid()) {
|
||||||
ui->lineContains->setText(rule.mustContain());
|
ui->lineContains->setText(rule.mustContain());
|
||||||
|
@ -190,6 +193,7 @@ void AutomatedRssDownloader::updateRuleDefinitionBox()
|
||||||
// Enable
|
// Enable
|
||||||
ui->ruleDefBox->setEnabled(true);
|
ui->ruleDefBox->setEnabled(true);
|
||||||
} else {
|
} else {
|
||||||
|
m_editedRule = 0;
|
||||||
// Clear
|
// Clear
|
||||||
clearRuleDefinitionBox();
|
clearRuleDefinitionBox();
|
||||||
ui->ruleDefBox->setEnabled(false);
|
ui->ruleDefBox->setEnabled(false);
|
||||||
|
@ -222,26 +226,20 @@ void AutomatedRssDownloader::initLabelCombobox()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AutomatedRssDownloader::handleCurrentItemChange(QListWidgetItem *current, QListWidgetItem *previous)
|
void AutomatedRssDownloader::saveEditedRule()
|
||||||
{
|
{
|
||||||
Q_UNUSED(current);
|
if(!m_editedRule) return;
|
||||||
saveCurrentRule(previous);
|
qDebug() << Q_FUNC_INFO << m_editedRule;
|
||||||
}
|
if(ui->listRules->findItems(m_editedRule->text(), Qt::MatchExactly).isEmpty()) {
|
||||||
|
qDebug() << "Could not find rule" << m_editedRule->text() << "in the UI list";
|
||||||
void AutomatedRssDownloader::saveCurrentRule(QListWidgetItem * item)
|
|
||||||
{
|
|
||||||
qDebug() << Q_FUNC_INFO << item;
|
|
||||||
if(!item) return;
|
|
||||||
if(ui->listRules->findItems(item->text(), Qt::MatchExactly).isEmpty()) {
|
|
||||||
qDebug() << "Could not find rule" << item->text() << "in the UI list";
|
|
||||||
qDebug() << "Probably removed the item, no need to save it";
|
qDebug() << "Probably removed the item, no need to save it";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
RssDownloadRule rule = m_ruleList->getRule(item->text());
|
RssDownloadRule rule = m_ruleList->getRule(m_editedRule->text());
|
||||||
if(!rule.isValid()) {
|
if(!rule.isValid()) {
|
||||||
rule.setName(item->text());
|
rule.setName(m_editedRule->text());
|
||||||
}
|
}
|
||||||
if(item->checkState() == Qt::Unchecked)
|
if(m_editedRule->checkState() == Qt::Unchecked)
|
||||||
rule.setEnabled(false);
|
rule.setEnabled(false);
|
||||||
else
|
else
|
||||||
rule.setEnabled(true);
|
rule.setEnabled(true);
|
||||||
|
@ -294,10 +292,12 @@ void AutomatedRssDownloader::on_removeRuleBtn_clicked()
|
||||||
foreach(QListWidgetItem *item, selection) {
|
foreach(QListWidgetItem *item, selection) {
|
||||||
// Actually remove the item
|
// Actually remove the item
|
||||||
ui->listRules->removeItemWidget(item);
|
ui->listRules->removeItemWidget(item);
|
||||||
// Remove it from the m_ruleList
|
const QString rule_name = item->text();
|
||||||
m_ruleList->removeRule(item->text());
|
|
||||||
// Clean up memory
|
// Clean up memory
|
||||||
delete item;
|
delete item;
|
||||||
|
qDebug("Removed item for the UI list");
|
||||||
|
// Remove it from the m_ruleList
|
||||||
|
m_ruleList->removeRule(rule_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -395,7 +395,7 @@ void AutomatedRssDownloader::handleFeedCheckStateChange(QListWidgetItem *feed_it
|
||||||
{
|
{
|
||||||
if(ui->ruleDefBox->isEnabled()) {
|
if(ui->ruleDefBox->isEnabled()) {
|
||||||
// Make sure the current rule is saved
|
// Make sure the current rule is saved
|
||||||
saveCurrentRule(ui->listRules->currentItem());
|
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()) {
|
||||||
|
@ -423,7 +423,7 @@ void AutomatedRssDownloader::updateMatchingArticles()
|
||||||
{
|
{
|
||||||
ui->treeMatchingArticles->clear();
|
ui->treeMatchingArticles->clear();
|
||||||
if(ui->ruleDefBox->isEnabled()) {
|
if(ui->ruleDefBox->isEnabled()) {
|
||||||
saveCurrentRule(ui->listRules->currentItem());
|
saveEditedRule();
|
||||||
}
|
}
|
||||||
const QHash<QString, RssFeed*> all_feeds = RssManager::instance()->getAllFeedsAsHash();
|
const QHash<QString, RssFeed*> all_feeds = RssManager::instance()->getAllFeedsAsHash();
|
||||||
|
|
||||||
|
|
|
@ -54,11 +54,10 @@ protected slots:
|
||||||
void loadSettings();
|
void loadSettings();
|
||||||
void saveSettings();
|
void saveSettings();
|
||||||
void loadRulesList();
|
void loadRulesList();
|
||||||
void handleCurrentItemChange(QListWidgetItem* current, QListWidgetItem* previous);
|
|
||||||
void handleFeedCheckStateChange(QListWidgetItem* feed_item);
|
void handleFeedCheckStateChange(QListWidgetItem* feed_item);
|
||||||
void updateRuleDefinitionBox();
|
void updateRuleDefinitionBox();
|
||||||
void clearRuleDefinitionBox();
|
void clearRuleDefinitionBox();
|
||||||
void saveCurrentRule(QListWidgetItem * item);
|
void saveEditedRule();
|
||||||
void loadFeedList();
|
void loadFeedList();
|
||||||
void updateFeedList();
|
void updateFeedList();
|
||||||
|
|
||||||
|
@ -79,6 +78,7 @@ private:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::AutomatedRssDownloader *ui;
|
Ui::AutomatedRssDownloader *ui;
|
||||||
|
QListWidgetItem* m_editedRule;
|
||||||
RssDownloadRuleList *m_ruleList;
|
RssDownloadRuleList *m_ruleList;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -132,6 +132,7 @@ void RssDownloadRuleList::saveRule(const RssDownloadRule &rule)
|
||||||
qDebug() << Q_FUNC_INFO << rule.name();
|
qDebug() << Q_FUNC_INFO << rule.name();
|
||||||
Q_ASSERT(rule.isValid());
|
Q_ASSERT(rule.isValid());
|
||||||
if(m_rules.contains(rule.name())) {
|
if(m_rules.contains(rule.name())) {
|
||||||
|
qDebug("This is an update, removing old rule first");
|
||||||
removeRule(rule.name());
|
removeRule(rule.name());
|
||||||
}
|
}
|
||||||
m_rules.insert(rule.name(), rule);
|
m_rules.insert(rule.name(), rule);
|
||||||
|
@ -141,6 +142,7 @@ void RssDownloadRuleList::saveRule(const RssDownloadRule &rule)
|
||||||
}
|
}
|
||||||
// Save rules
|
// Save rules
|
||||||
saveRulesToStorage();
|
saveRulesToStorage();
|
||||||
|
qDebug() << Q_FUNC_INFO << "EXIT";
|
||||||
}
|
}
|
||||||
|
|
||||||
void RssDownloadRuleList::removeRule(const QString &name)
|
void RssDownloadRuleList::removeRule(const QString &name)
|
||||||
|
|
Loading…
Reference in a new issue