1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 01:22:10 +01:00

Added option to delete AdBlock rule, renamed Custom List to Custom

Rules, updated Czech translation
This commit is contained in:
nowrep 2011-03-29 21:51:27 +02:00
parent d7f7f7843f
commit 687b5684ba
8 changed files with 616 additions and 330 deletions

Binary file not shown.

View File

@ -55,16 +55,49 @@ AdBlockDialog::AdBlockDialog(QWidget *parent)
{ {
setupUi(this); setupUi(this);
adblockCheckBox->setChecked(m_manager->isEnabled()); adblockCheckBox->setChecked(m_manager->isEnabled());
treeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
connect(adblockCheckBox, SIGNAL(toggled(bool)), m_manager, SLOT(setEnabled(bool))); connect(adblockCheckBox, SIGNAL(toggled(bool)), m_manager, SLOT(setEnabled(bool)));
connect(addButton, SIGNAL(clicked()), this, SLOT(addCustomRule())); connect(addButton, SIGNAL(clicked()), this, SLOT(addCustomRule()));
connect(reloadButton, SIGNAL(clicked()), this, SLOT(updateSubscription())); connect(reloadButton, SIGNAL(clicked()), this, SLOT(updateSubscription()));
connect(search, SIGNAL(textChanged(QString)), treeWidget, SLOT(filterStringWithoutTopItems(QString))); connect(search, SIGNAL(textChanged(QString)), treeWidget, SLOT(filterStringWithoutTopItems(QString)));
connect(m_manager->subscription(), SIGNAL(changed()), this, SLOT(refreshAfterUpdate())); connect(m_manager->subscription(), SIGNAL(changed()), this, SLOT(refreshAfterUpdate()));
connect(treeWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(customContextMenuRequested()));
// QTimer::singleShot(0, this, SLOT(firstRefresh())); // QTimer::singleShot(0, this, SLOT(firstRefresh()));
firstRefresh(); firstRefresh();
} }
void AdBlockDialog::editRule()
{
QTreeWidgetItem* item = treeWidget->currentItem();
if (!item || !(item->flags() & Qt::ItemIsEditable))
return;
item->setSelected(true);
}
void AdBlockDialog::deleteRule()
{
QTreeWidgetItem* item = treeWidget->currentItem();
if (!item)
return;
int offset = item->whatsThis(0).toInt();
m_manager->subscription()->removeRule(offset);
delete item;
refresh();
}
void AdBlockDialog::customContextMenuRequested()
{
QMenu menu;
menu.addAction(tr("Add Rule"), this, SLOT(addCustomRule()));
menu.addSeparator();
menu.addAction(tr("Delete Rule"), this, SLOT(deleteRule()));
menu.exec(QCursor::pos());
}
void AdBlockDialog::firstRefresh() void AdBlockDialog::firstRefresh()
{ {
refresh(); refresh();
@ -88,10 +121,10 @@ void AdBlockDialog::refresh()
QFont italicFont; QFont italicFont;
italicFont.setItalic(true); italicFont.setItalic(true);
m_customListItem = new QTreeWidgetItem(treeWidget); m_customRulesItem = new QTreeWidgetItem(treeWidget);
m_customListItem->setText(0,tr("Custom List")); m_customRulesItem->setText(0,tr("Custom Rules"));
m_customListItem->setFont(0, boldFont); m_customRulesItem->setFont(0, boldFont);
treeWidget->addTopLevelItem(m_customListItem); treeWidget->addTopLevelItem(m_customRulesItem);
m_easyListItem = new QTreeWidgetItem(treeWidget); m_easyListItem = new QTreeWidgetItem(treeWidget);
m_easyListItem->setText(0,"EasyList"); m_easyListItem->setText(0,"EasyList");
@ -108,8 +141,8 @@ void AdBlockDialog::refresh()
customRulesStarted = true; customRulesStarted = true;
continue; continue;
} }
QTreeWidgetItem* item = new QTreeWidgetItem(customRulesStarted ? m_customListItem : m_easyListItem); QTreeWidgetItem* item = new QTreeWidgetItem(customRulesStarted ? m_customRulesItem : m_easyListItem);
if (item->parent() == m_customListItem) if (item->parent() == m_customRulesItem)
item->setFlags(item->flags() | Qt::ItemIsEditable); item->setFlags(item->flags() | Qt::ItemIsEditable);
item->setFlags(item->flags() | Qt::ItemIsUserCheckable); item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
item->setCheckState(0, (rule.filter().startsWith("!") ) ? Qt::Unchecked : Qt::Checked); item->setCheckState(0, (rule.filter().startsWith("!") ) ? Qt::Unchecked : Qt::Checked);
@ -168,10 +201,11 @@ void AdBlockDialog::addCustomRule()
return; return;
AdBlockSubscription *subscription = m_manager->subscription(); AdBlockSubscription *subscription = m_manager->subscription();
subscription->addRule(AdBlockRule(newRule)); int offset = subscription->addRule(AdBlockRule(newRule));
m_itemChangingBlock = true; m_itemChangingBlock = true;
QTreeWidgetItem* item = new QTreeWidgetItem(m_customListItem); QTreeWidgetItem* item = new QTreeWidgetItem(m_customRulesItem);
item->setText(0, newRule); item->setText(0, newRule);
item->setWhatsThis(0, QString::number(offset));
item->setFlags(item->flags() | Qt::ItemIsEditable); item->setFlags(item->flags() | Qt::ItemIsEditable);
item->setFlags(item->flags() | Qt::ItemIsUserCheckable); item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
item->setCheckState(0, Qt::Checked); item->setCheckState(0, Qt::Checked);

View File

@ -76,12 +76,16 @@ private slots:
void addCustomRule(); void addCustomRule();
void firstRefresh(); void firstRefresh();
void refreshAfterUpdate(); void refreshAfterUpdate();
void customContextMenuRequested();
void editRule();
void deleteRule();
private: private:
void refresh(); void refresh();
bool m_itemChangingBlock; bool m_itemChangingBlock;
QTreeWidgetItem* m_customListItem; QTreeWidgetItem* m_customRulesItem;
QTreeWidgetItem* m_easyListItem; QTreeWidgetItem* m_easyListItem;
AdBlockManager* m_manager; AdBlockManager* m_manager;

View File

@ -176,11 +176,12 @@ QList<AdBlockRule> AdBlockSubscription::allRules() const
return m_rules; return m_rules;
} }
void AdBlockSubscription::addRule(const AdBlockRule &rule) int AdBlockSubscription::addRule(const AdBlockRule &rule)
{ {
m_rules.append(rule); m_rules.append(rule);
populateCache(); populateCache();
emit rulesChanged(); emit rulesChanged();
return m_rules.count() - 1;
} }
void AdBlockSubscription::removeRule(int offset) void AdBlockSubscription::removeRule(int offset)

View File

@ -82,7 +82,7 @@ public:
QList<const AdBlockRule*> pageRules() const { return m_pageRules; } QList<const AdBlockRule*> pageRules() const { return m_pageRules; }
QList<AdBlockRule> allRules() const; QList<AdBlockRule> allRules() const;
void addRule(const AdBlockRule &rule); int addRule(const AdBlockRule &rule);
void removeRule(int offset); void removeRule(int offset);
void replaceRule(const AdBlockRule &rule, int offset); void replaceRule(const AdBlockRule &rule, int offset);

View File

@ -213,7 +213,6 @@ bool MainApplication::isChanged()
void MainApplication::sendMessages(MainApplication::MessageType mes, bool state) void MainApplication::sendMessages(MainApplication::MessageType mes, bool state)
{ {
qDebug() << mes << state;
emit message(mes, state); emit message(mes, state);
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff