Fixed main adblock dialog.
This commit is contained in:
parent
d34767d1c4
commit
f02f8bab09
2 changed files with 139 additions and 153 deletions
|
@ -16,35 +16,30 @@
|
||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with RSS Guard. If not, see <http://www.gnu.org/licenses/>.
|
// along with RSS Guard. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
#include "adblockdialog.h"
|
#include "network-web/adblock/adblockdialog.h"
|
||||||
#include "adblockmanager.h"
|
#include "network-web/adblock/adblockmanager.h"
|
||||||
#include "adblocksubscription.h"
|
#include "network-web/adblock/adblocksubscription.h"
|
||||||
#include "adblocktreewidget.h"
|
#include "network-web/adblock/adblocktreewidget.h"
|
||||||
#include "adblockaddsubscriptiondialog.h"
|
#include "network-web/adblock/adblockaddsubscriptiondialog.h"
|
||||||
#include "mainapplication.h"
|
|
||||||
#include "qztools.h"
|
#include "network-web/webfactory.h"
|
||||||
|
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
|
|
||||||
AdBlockDialog::AdBlockDialog(QWidget* parent)
|
|
||||||
: QWidget(parent)
|
|
||||||
, m_manager(AdBlockManager::instance())
|
|
||||||
, m_currentTreeWidget(0)
|
|
||||||
, m_currentSubscription(0)
|
|
||||||
, m_loaded(false)
|
|
||||||
{
|
|
||||||
setAttribute(Qt::WA_DeleteOnClose);
|
|
||||||
setupUi(this);
|
|
||||||
|
|
||||||
QzTools::centerWidgetOnScreen(this);
|
AdBlockDialog::AdBlockDialog(QWidget* parent)
|
||||||
|
: QWidget(parent), m_ui(new Ui::AdBlockDialog), m_manager(AdBlockManager::instance()), m_currentTreeWidget(0), m_currentSubscription(0), m_loaded(false) {
|
||||||
|
setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
m_ui->setupUi(this);
|
||||||
|
|
||||||
#ifdef Q_OS_MACOS
|
#ifdef Q_OS_MACOS
|
||||||
tabWidget->setDocumentMode(false);
|
m_ui->tabWidget->setDocumentMode(false);
|
||||||
#endif
|
#endif
|
||||||
adblockCheckBox->setChecked(m_manager->isEnabled());
|
|
||||||
|
m_ui->adblockCheckBox->setChecked(m_manager->isEnabled());
|
||||||
|
|
||||||
QMenu* menu = new QMenu(buttonOptions);
|
QMenu* menu = new QMenu(buttonOptions);
|
||||||
m_actionAddRule = menu->addAction(tr("Add Rule"), this, SLOT(addRule()));
|
m_actionAddRule = menu->addAction(tr("Add Rule"), this, SLOT(addRule()));
|
||||||
|
@ -56,7 +51,7 @@ AdBlockDialog::AdBlockDialog(QWidget* parent)
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
menu->addAction(tr("Learn about writing rules..."), this, SLOT(learnAboutRules()));
|
menu->addAction(tr("Learn about writing rules..."), this, SLOT(learnAboutRules()));
|
||||||
|
|
||||||
buttonOptions->setMenu(menu);
|
m_ui->buttonOptions->setMenu(menu);
|
||||||
connect(menu, SIGNAL(aboutToShow()), this, SLOT(aboutToShowMenu()));
|
connect(menu, SIGNAL(aboutToShow()), this, SLOT(aboutToShowMenu()));
|
||||||
|
|
||||||
connect(adblockCheckBox, SIGNAL(toggled(bool)), this, SLOT(enableAdBlock(bool)));
|
connect(adblockCheckBox, SIGNAL(toggled(bool)), this, SLOT(enableAdBlock(bool)));
|
||||||
|
@ -66,12 +61,12 @@ AdBlockDialog::AdBlockDialog(QWidget* parent)
|
||||||
|
|
||||||
load();
|
load();
|
||||||
|
|
||||||
buttonBox->setFocus();
|
m_ui->buttonBox->setFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdBlockDialog::showRule(const AdBlockRule* rule) const
|
void AdBlockDialog::showRule(const AdBlockRule* rule) const {
|
||||||
{
|
|
||||||
AdBlockSubscription *subscription = rule->subscription();
|
AdBlockSubscription *subscription = rule->subscription();
|
||||||
|
|
||||||
if (!subscription) {
|
if (!subscription) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -87,19 +82,17 @@ void AdBlockDialog::showRule(const AdBlockRule* rule) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdBlockDialog::addRule()
|
void AdBlockDialog::addRule() {
|
||||||
{
|
|
||||||
m_currentTreeWidget->addRule();
|
m_currentTreeWidget->addRule();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdBlockDialog::removeRule()
|
void AdBlockDialog::removeRule() {
|
||||||
{
|
|
||||||
m_currentTreeWidget->removeRule();
|
m_currentTreeWidget->removeRule();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdBlockDialog::addSubscription()
|
void AdBlockDialog::addSubscription() {
|
||||||
{
|
|
||||||
AdBlockAddSubscriptionDialog dialog(this);
|
AdBlockAddSubscriptionDialog dialog(this);
|
||||||
|
|
||||||
if (dialog.exec() != QDialog::Accepted) {
|
if (dialog.exec() != QDialog::Accepted) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -115,30 +108,26 @@ void AdBlockDialog::addSubscription()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdBlockDialog::removeSubscription()
|
void AdBlockDialog::removeSubscription() {
|
||||||
{
|
|
||||||
if (m_manager->removeSubscription(m_currentSubscription)) {
|
if (m_manager->removeSubscription(m_currentSubscription)) {
|
||||||
delete m_currentTreeWidget;
|
delete m_currentTreeWidget;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdBlockDialog::currentChanged(int index)
|
void AdBlockDialog::currentChanged(int index) {
|
||||||
{
|
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
m_currentTreeWidget = qobject_cast<AdBlockTreeWidget*>(tabWidget->widget(index));
|
m_currentTreeWidget = qobject_cast<AdBlockTreeWidget*>(tabWidget->widget(index));
|
||||||
m_currentSubscription = m_currentTreeWidget->subscription();
|
m_currentSubscription = m_currentTreeWidget->subscription();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdBlockDialog::filterString(const QString &string)
|
void AdBlockDialog::filterString(const QString &string) {
|
||||||
{
|
|
||||||
if (m_currentTreeWidget && adblockCheckBox->isChecked()) {
|
if (m_currentTreeWidget && adblockCheckBox->isChecked()) {
|
||||||
m_currentTreeWidget->filterString(string);
|
m_currentTreeWidget->filterString(string);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdBlockDialog::enableAdBlock(bool state)
|
void AdBlockDialog::enableAdBlock(bool state) {
|
||||||
{
|
|
||||||
m_manager->setEnabled(state);
|
m_manager->setEnabled(state);
|
||||||
|
|
||||||
if (state) {
|
if (state) {
|
||||||
|
@ -146,8 +135,7 @@ void AdBlockDialog::enableAdBlock(bool state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdBlockDialog::aboutToShowMenu()
|
void AdBlockDialog::aboutToShowMenu() {
|
||||||
{
|
|
||||||
bool subscriptionEditable = m_currentSubscription && m_currentSubscription->canEditRules();
|
bool subscriptionEditable = m_currentSubscription && m_currentSubscription->canEditRules();
|
||||||
bool subscriptionRemovable = m_currentSubscription && m_currentSubscription->canBeRemoved();
|
bool subscriptionRemovable = m_currentSubscription && m_currentSubscription->canBeRemoved();
|
||||||
|
|
||||||
|
@ -156,21 +144,18 @@ void AdBlockDialog::aboutToShowMenu()
|
||||||
m_actionRemoveSubscription->setEnabled(subscriptionRemovable);
|
m_actionRemoveSubscription->setEnabled(subscriptionRemovable);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdBlockDialog::learnAboutRules()
|
void AdBlockDialog::learnAboutRules() {
|
||||||
{
|
WebFactory::instance()->openUrlInExternalBrowser(QSL("http://adblockplus.org/en/filters"));
|
||||||
mApp->addNewTab(QUrl("http://adblockplus.org/en/filters"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdBlockDialog::loadSubscriptions()
|
void AdBlockDialog::loadSubscriptions() {
|
||||||
{
|
|
||||||
for (int i = 0; i < tabWidget->count(); ++i) {
|
for (int i = 0; i < tabWidget->count(); ++i) {
|
||||||
AdBlockTreeWidget* treeWidget = qobject_cast<AdBlockTreeWidget*>(tabWidget->widget(i));
|
AdBlockTreeWidget* treeWidget = qobject_cast<AdBlockTreeWidget*>(tabWidget->widget(i));
|
||||||
treeWidget->refresh();
|
treeWidget->refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdBlockDialog::load()
|
void AdBlockDialog::load() {
|
||||||
{
|
|
||||||
if (m_loaded || !adblockCheckBox->isChecked()) {
|
if (m_loaded || !adblockCheckBox->isChecked()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,16 +21,15 @@
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
#include "qzcommon.h"
|
|
||||||
#include "ui_adblockdialog.h"
|
#include "ui_adblockdialog.h"
|
||||||
|
|
||||||
|
|
||||||
class AdBlockSubscription;
|
class AdBlockSubscription;
|
||||||
class AdBlockTreeWidget;
|
class AdBlockTreeWidget;
|
||||||
class AdBlockManager;
|
class AdBlockManager;
|
||||||
class AdBlockRule;
|
class AdBlockRule;
|
||||||
|
|
||||||
class QUPZILLA_EXPORT AdBlockDialog : public QWidget, public Ui_AdBlockDialog
|
class AdBlockDialog : public QWidget {
|
||||||
{
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -66,6 +65,8 @@ private:
|
||||||
QAction *m_actionRemoveSubscription;
|
QAction *m_actionRemoveSubscription;
|
||||||
|
|
||||||
bool m_loaded;
|
bool m_loaded;
|
||||||
|
|
||||||
|
Ui::AdBlockDialog *m_ui;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ADBLOCKDIALOG_H
|
#endif // ADBLOCKDIALOG_H
|
||||||
|
|
Loading…
Add table
Reference in a new issue