Some refactoring again.
This commit is contained in:
parent
d788356b93
commit
a77a0a20cb
@ -46,6 +46,7 @@ ToolBarEditor::ToolBarEditor(QWidget *parent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ToolBarEditor::~ToolBarEditor() {
|
ToolBarEditor::~ToolBarEditor() {
|
||||||
|
qDebug("Destroying ToolBarEditor instance.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToolBarEditor::loadFromToolBar(BaseToolBar *tool_bar) {
|
void ToolBarEditor::loadFromToolBar(BaseToolBar *tool_bar) {
|
||||||
|
@ -125,5 +125,5 @@ void AdBlockAddSubscriptionDialog::checkInputs() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
AdBlockAddSubscriptionDialog::~AdBlockAddSubscriptionDialog() {
|
AdBlockAddSubscriptionDialog::~AdBlockAddSubscriptionDialog() {
|
||||||
delete m_ui;
|
qDebug("Destroying AdBlockAddSubscriptionDialog instance.");
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ class AdBlockAddSubscriptionDialog : public QDialog {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Ui::AdBlockAddSubscriptionDialog *m_ui;
|
QScopedPointer<Ui::AdBlockAddSubscriptionDialog> m_ui;
|
||||||
QVector<Subscription> m_knownSubscriptions;
|
QVector<Subscription> m_knownSubscriptions;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -59,7 +59,6 @@ AdBlockDialog::AdBlockDialog(QWidget* parent) : QDialog(parent), m_ui(new Ui::Ad
|
|||||||
|
|
||||||
AdBlockDialog::~AdBlockDialog() {
|
AdBlockDialog::~AdBlockDialog() {
|
||||||
qDebug("Destroying AdBlockDialog instance.");
|
qDebug("Destroying AdBlockDialog instance.");
|
||||||
delete m_ui;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdBlockDialog::setupMenu() {
|
void AdBlockDialog::setupMenu() {
|
||||||
@ -113,24 +112,22 @@ void AdBlockDialog::removeRule() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AdBlockDialog::addSubscription() {
|
void AdBlockDialog::addSubscription() {
|
||||||
QPointer<AdBlockAddSubscriptionDialog> dialog = new AdBlockAddSubscriptionDialog(this);
|
QScopedPointer<AdBlockAddSubscriptionDialog> dialog(new AdBlockAddSubscriptionDialog(this));
|
||||||
|
|
||||||
if (dialog.data()->exec() == QDialog::Accepted) {
|
if (dialog.data()->exec() == QDialog::Accepted) {
|
||||||
QString title = dialog.data()->title();
|
const QString title = dialog.data()->title();
|
||||||
QString url = dialog.data()->url();
|
const QString url = dialog.data()->url();
|
||||||
|
|
||||||
if (AdBlockSubscription *subscription = m_manager->addSubscription(title, url)) {
|
if (AdBlockSubscription *subscription = m_manager->addSubscription(title, url)) {
|
||||||
AdBlockTreeWidget *tree = new AdBlockTreeWidget(subscription, this);
|
AdBlockTreeWidget *tree = new AdBlockTreeWidget(subscription, this);
|
||||||
|
|
||||||
connect(tree, SIGNAL(refreshStatusChanged(bool)), this, SLOT(setDisabled(bool)));
|
connect(tree, SIGNAL(refreshStatusChanged(bool)), this, SLOT(setDisabled(bool)));
|
||||||
|
|
||||||
int index = m_ui->m_tabs->insertTab(m_ui->m_tabs->count() - 1, tree, subscription->title());
|
const int index = m_ui->m_tabs->insertTab(m_ui->m_tabs->count() - 1, tree, subscription->title());
|
||||||
|
|
||||||
m_ui->m_tabs->setCurrentIndex(index);
|
m_ui->m_tabs->setCurrentIndex(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete dialog.data();
|
//delete dialog.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdBlockDialog::removeSubscription() {
|
void AdBlockDialog::removeSubscription() {
|
||||||
@ -144,7 +141,7 @@ void AdBlockDialog::currentChanged(int index) {
|
|||||||
m_currentTreeWidget = qobject_cast<AdBlockTreeWidget*>(m_ui->m_tabs->widget(index));
|
m_currentTreeWidget = qobject_cast<AdBlockTreeWidget*>(m_ui->m_tabs->widget(index));
|
||||||
m_currentSubscription = m_currentTreeWidget->subscription();
|
m_currentSubscription = m_currentTreeWidget->subscription();
|
||||||
|
|
||||||
bool is_easylist = m_currentSubscription->url() == QUrl(ADBLOCK_EASYLIST_URL);
|
const bool is_easylist = m_currentSubscription->url() == QUrl(ADBLOCK_EASYLIST_URL);
|
||||||
m_ui->m_checkUseLimitedEasyList->setEnabled(is_easylist && m_ui->m_checkEnable->isChecked());
|
m_ui->m_checkUseLimitedEasyList->setEnabled(is_easylist && m_ui->m_checkEnable->isChecked());
|
||||||
m_ui->m_checkUseLimitedEasyList->setVisible(is_easylist);
|
m_ui->m_checkUseLimitedEasyList->setVisible(is_easylist);
|
||||||
|
|
||||||
@ -169,12 +166,12 @@ void AdBlockDialog::enableAdBlock(bool state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AdBlockDialog::aboutToShowMenu() {
|
void AdBlockDialog::aboutToShowMenu() {
|
||||||
bool subscriptionEditable = m_currentSubscription && m_currentSubscription->canEditRules();
|
const bool subscription_editable = m_currentSubscription && m_currentSubscription->canEditRules();
|
||||||
bool subscriptionRemovable = m_currentSubscription && m_currentSubscription->canBeRemoved();
|
const bool subscription_removable = m_currentSubscription && m_currentSubscription->canBeRemoved();
|
||||||
|
|
||||||
m_actionAddRule->setEnabled(subscriptionEditable);
|
m_actionAddRule->setEnabled(subscription_editable);
|
||||||
m_actionRemoveRule->setEnabled(subscriptionEditable);
|
m_actionRemoveRule->setEnabled(subscription_editable);
|
||||||
m_actionRemoveSubscription->setEnabled(subscriptionRemovable);
|
m_actionRemoveSubscription->setEnabled(subscription_removable);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdBlockDialog::learnAboutRules() {
|
void AdBlockDialog::learnAboutRules() {
|
||||||
@ -197,13 +194,11 @@ void AdBlockDialog::load() {
|
|||||||
AdBlockTreeWidget *tree = new AdBlockTreeWidget(subscription, this);
|
AdBlockTreeWidget *tree = new AdBlockTreeWidget(subscription, this);
|
||||||
|
|
||||||
connect(tree, SIGNAL(refreshStatusChanged(bool)), this, SLOT(setDisabled(bool)));
|
connect(tree, SIGNAL(refreshStatusChanged(bool)), this, SLOT(setDisabled(bool)));
|
||||||
|
|
||||||
m_ui->m_tabs->addTab(tree, subscription->title());
|
m_ui->m_tabs->addTab(tree, subscription->title());
|
||||||
}
|
}
|
||||||
|
|
||||||
m_useLimitedEasyList = m_manager->useLimitedEasyList();
|
m_useLimitedEasyList = m_manager->useLimitedEasyList();
|
||||||
m_ui->m_checkUseLimitedEasyList->setChecked(m_useLimitedEasyList);
|
m_ui->m_checkUseLimitedEasyList->setChecked(m_useLimitedEasyList);
|
||||||
|
|
||||||
m_loaded = true;
|
m_loaded = true;
|
||||||
|
|
||||||
QTimer::singleShot(100, this, SLOT(loadSubscriptions()));
|
QTimer::singleShot(100, this, SLOT(loadSubscriptions()));
|
||||||
|
@ -67,15 +67,15 @@ class AdBlockDialog : public QDialog {
|
|||||||
void setupMenu();
|
void setupMenu();
|
||||||
void createConnections();
|
void createConnections();
|
||||||
|
|
||||||
Ui::AdBlockDialog *m_ui;
|
QScopedPointer<Ui::AdBlockDialog> m_ui;
|
||||||
AdBlockManager* m_manager;
|
AdBlockManager *m_manager;
|
||||||
AdBlockTreeWidget* m_currentTreeWidget;
|
AdBlockTreeWidget *m_currentTreeWidget;
|
||||||
AdBlockSubscription* m_currentSubscription;
|
AdBlockSubscription *m_currentSubscription;
|
||||||
|
|
||||||
QAction* m_actionAddRule;
|
QAction *m_actionAddRule;
|
||||||
QAction* m_actionRemoveRule;
|
QAction *m_actionRemoveRule;
|
||||||
QAction* m_actionAddSubscription;
|
QAction *m_actionAddSubscription;
|
||||||
QAction* m_actionRemoveSubscription;
|
QAction *m_actionRemoveSubscription;
|
||||||
|
|
||||||
bool m_loaded;
|
bool m_loaded;
|
||||||
bool m_useLimitedEasyList;
|
bool m_useLimitedEasyList;
|
||||||
|
@ -70,7 +70,7 @@ void AdBlockIcon::createMenu(QMenu *menu) {
|
|||||||
AdBlockManager *manager = AdBlockManager::instance();
|
AdBlockManager *manager = AdBlockManager::instance();
|
||||||
AdBlockCustomList *custom_list = manager->customList();
|
AdBlockCustomList *custom_list = manager->customList();
|
||||||
|
|
||||||
WebPage* page = qApp->mainForm()->tabWidget()->currentWidget()->webBrowser()->view()->page();
|
WebPage *page = qApp->mainForm()->tabWidget()->currentWidget()->webBrowser()->view()->page();
|
||||||
const QUrl page_url = page->mainFrame()->url();
|
const QUrl page_url = page->mainFrame()->url();
|
||||||
|
|
||||||
menu->addAction(tr("Show Adblock &settings"), manager, SLOT(showDialog()));
|
menu->addAction(tr("Show Adblock &settings"), manager, SLOT(showDialog()));
|
||||||
@ -104,18 +104,18 @@ void AdBlockIcon::createMenu(QMenu *menu) {
|
|||||||
for (int i = 0; i < m_blockedPopups.count(); i++) {
|
for (int i = 0; i < m_blockedPopups.count(); i++) {
|
||||||
const QPair<AdBlockRule*,QUrl> &pair = m_blockedPopups.at(i);
|
const QPair<AdBlockRule*,QUrl> &pair = m_blockedPopups.at(i);
|
||||||
|
|
||||||
QString address = pair.second.toString().right(55);
|
const QString address = pair.second.toString().right(55);
|
||||||
QString actionText = tr("%1 with (%2)").arg(address,
|
QString action_text = tr("%1 with (%2)").arg(address,
|
||||||
pair.first->filter()).replace(QLatin1Char('&'), QLatin1String("&&"));
|
pair.first->filter()).replace(QLatin1Char('&'), QLatin1String("&&"));
|
||||||
|
|
||||||
QAction *action = menu->addAction(actionText, manager, SLOT(showRule()));
|
QAction *action = menu->addAction(action_text, manager, SLOT(showRule()));
|
||||||
action->setData(QVariant::fromValue((void*)pair.first));
|
action->setData(QVariant::fromValue((void*)pair.first));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
|
|
||||||
QVector<WebPage::AdBlockedEntry> entries = page->adBlockedEntries();
|
const QVector<WebPage::AdBlockedEntry> entries = page->adBlockedEntries();
|
||||||
|
|
||||||
if (entries.isEmpty()) {
|
if (entries.isEmpty()) {
|
||||||
menu->addAction(tr("No content blocked"))->setEnabled(false);
|
menu->addAction(tr("No content blocked"))->setEnabled(false);
|
||||||
@ -141,7 +141,7 @@ void AdBlockIcon::showMenu(const QPoint &pos) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AdBlockIcon::toggleCustomFilter() {
|
void AdBlockIcon::toggleCustomFilter() {
|
||||||
QAction *action = qobject_cast<QAction*>(sender());
|
const QAction *action = qobject_cast<QAction*>(sender());
|
||||||
|
|
||||||
if (action == NULL) {
|
if (action == NULL) {
|
||||||
return;
|
return;
|
||||||
|
@ -123,8 +123,8 @@ AdBlockSubscription *AdBlockManager::addSubscription(const QString &title, const
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString file_name = IOFactory::filterBadCharsFromFilename(title.toLower()) + QL1S(".txt");
|
const QString file_name = IOFactory::filterBadCharsFromFilename(title.toLower()) + QL1S(".txt");
|
||||||
QString file_path = IOFactory::ensureUniqueFilename(baseSubscriptionDirectory() + QDir::separator() + file_name);
|
const QString file_path = IOFactory::ensureUniqueFilename(baseSubscriptionDirectory() + QDir::separator() + file_name);
|
||||||
QFile file(file_path);
|
QFile file(file_path);
|
||||||
|
|
||||||
if (!file.open(QFile::WriteOnly | QFile::Truncate | QFile::Unbuffered)) {
|
if (!file.open(QFile::WriteOnly | QFile::Truncate | QFile::Unbuffered)) {
|
||||||
@ -187,7 +187,7 @@ QString AdBlockManager::baseSubscriptionDirectory() {
|
|||||||
return QDir::toNativeSeparators(directory);
|
return QDir::toNativeSeparators(directory);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AdBlockManager::shouldBeEnabled() {
|
bool AdBlockManager::shouldBeEnabled() const {
|
||||||
return qApp->settings()->value(GROUP(AdBlock), SETTING(AdBlock::Enabled)).toBool();
|
return qApp->settings()->value(GROUP(AdBlock), SETTING(AdBlock::Enabled)).toBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,7 +198,7 @@ void AdBlockManager::load() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Settings *settings = qApp->settings();
|
const Settings *settings = qApp->settings();
|
||||||
m_enabled = settings->value(GROUP(AdBlock), SETTING(AdBlock::Enabled)).toBool();
|
m_enabled = settings->value(GROUP(AdBlock), SETTING(AdBlock::Enabled)).toBool();
|
||||||
m_useLimitedEasyList = settings->value(GROUP(AdBlock), SETTING(AdBlock::UseLimitedEasyList)).toBool();
|
m_useLimitedEasyList = settings->value(GROUP(AdBlock), SETTING(AdBlock::UseLimitedEasyList)).toBool();
|
||||||
m_disabledRules = settings->value(GROUP(AdBlock), SETTING(AdBlock::DisabledRules)).toStringList();
|
m_disabledRules = settings->value(GROUP(AdBlock), SETTING(AdBlock::DisabledRules)).toStringList();
|
||||||
@ -228,8 +228,8 @@ void AdBlockManager::load() {
|
|||||||
|
|
||||||
QTextStream stream(&file);
|
QTextStream stream(&file);
|
||||||
stream.setCodec("UTF-8");
|
stream.setCodec("UTF-8");
|
||||||
QString title = stream.readLine(1024).remove(QSL("Title: "));
|
const QString title = stream.readLine(1024).remove(QSL("Title: "));
|
||||||
QUrl url = QUrl(stream.readLine(1024).remove(QSL("Url: ")));
|
const QUrl url = QUrl(stream.readLine(1024).remove(QSL("Url: ")));
|
||||||
|
|
||||||
// Close the file.
|
// Close the file.
|
||||||
file.close();
|
file.close();
|
||||||
|
@ -69,7 +69,7 @@ class AdBlockManager : public QObject {
|
|||||||
|
|
||||||
AdBlockCustomList *customList() const;
|
AdBlockCustomList *customList() const;
|
||||||
|
|
||||||
bool shouldBeEnabled();
|
bool shouldBeEnabled() const;
|
||||||
|
|
||||||
static QString baseSubscriptionDirectory();
|
static QString baseSubscriptionDirectory();
|
||||||
static AdBlockManager *instance();
|
static AdBlockManager *instance();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user