Some refactoring again.

This commit is contained in:
Martin Rotter 2016-01-15 07:37:22 +01:00
parent d788356b93
commit a77a0a20cb
8 changed files with 36 additions and 40 deletions

View File

@ -46,6 +46,7 @@ ToolBarEditor::ToolBarEditor(QWidget *parent)
}
ToolBarEditor::~ToolBarEditor() {
qDebug("Destroying ToolBarEditor instance.");
}
void ToolBarEditor::loadFromToolBar(BaseToolBar *tool_bar) {

View File

@ -125,5 +125,5 @@ void AdBlockAddSubscriptionDialog::checkInputs() {
}
AdBlockAddSubscriptionDialog::~AdBlockAddSubscriptionDialog() {
delete m_ui;
qDebug("Destroying AdBlockAddSubscriptionDialog instance.");
}

View File

@ -63,7 +63,7 @@ class AdBlockAddSubscriptionDialog : public QDialog {
}
};
Ui::AdBlockAddSubscriptionDialog *m_ui;
QScopedPointer<Ui::AdBlockAddSubscriptionDialog> m_ui;
QVector<Subscription> m_knownSubscriptions;
};

View File

@ -59,7 +59,6 @@ AdBlockDialog::AdBlockDialog(QWidget* parent) : QDialog(parent), m_ui(new Ui::Ad
AdBlockDialog::~AdBlockDialog() {
qDebug("Destroying AdBlockDialog instance.");
delete m_ui;
}
void AdBlockDialog::setupMenu() {
@ -113,24 +112,22 @@ void AdBlockDialog::removeRule() {
}
void AdBlockDialog::addSubscription() {
QPointer<AdBlockAddSubscriptionDialog> dialog = new AdBlockAddSubscriptionDialog(this);
QScopedPointer<AdBlockAddSubscriptionDialog> dialog(new AdBlockAddSubscriptionDialog(this));
if (dialog.data()->exec() == QDialog::Accepted) {
QString title = dialog.data()->title();
QString url = dialog.data()->url();
const QString title = dialog.data()->title();
const QString url = dialog.data()->url();
if (AdBlockSubscription *subscription = m_manager->addSubscription(title, url)) {
AdBlockTreeWidget *tree = new AdBlockTreeWidget(subscription, this);
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);
}
}
delete dialog.data();
//delete dialog.data();
}
void AdBlockDialog::removeSubscription() {
@ -144,7 +141,7 @@ void AdBlockDialog::currentChanged(int index) {
m_currentTreeWidget = qobject_cast<AdBlockTreeWidget*>(m_ui->m_tabs->widget(index));
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->setVisible(is_easylist);
@ -169,12 +166,12 @@ void AdBlockDialog::enableAdBlock(bool state) {
}
void AdBlockDialog::aboutToShowMenu() {
bool subscriptionEditable = m_currentSubscription && m_currentSubscription->canEditRules();
bool subscriptionRemovable = m_currentSubscription && m_currentSubscription->canBeRemoved();
const bool subscription_editable = m_currentSubscription && m_currentSubscription->canEditRules();
const bool subscription_removable = m_currentSubscription && m_currentSubscription->canBeRemoved();
m_actionAddRule->setEnabled(subscriptionEditable);
m_actionRemoveRule->setEnabled(subscriptionEditable);
m_actionRemoveSubscription->setEnabled(subscriptionRemovable);
m_actionAddRule->setEnabled(subscription_editable);
m_actionRemoveRule->setEnabled(subscription_editable);
m_actionRemoveSubscription->setEnabled(subscription_removable);
}
void AdBlockDialog::learnAboutRules() {
@ -197,13 +194,11 @@ void AdBlockDialog::load() {
AdBlockTreeWidget *tree = new AdBlockTreeWidget(subscription, this);
connect(tree, SIGNAL(refreshStatusChanged(bool)), this, SLOT(setDisabled(bool)));
m_ui->m_tabs->addTab(tree, subscription->title());
}
m_useLimitedEasyList = m_manager->useLimitedEasyList();
m_ui->m_checkUseLimitedEasyList->setChecked(m_useLimitedEasyList);
m_loaded = true;
QTimer::singleShot(100, this, SLOT(loadSubscriptions()));

View File

@ -67,15 +67,15 @@ class AdBlockDialog : public QDialog {
void setupMenu();
void createConnections();
Ui::AdBlockDialog *m_ui;
AdBlockManager* m_manager;
AdBlockTreeWidget* m_currentTreeWidget;
AdBlockSubscription* m_currentSubscription;
QScopedPointer<Ui::AdBlockDialog> m_ui;
AdBlockManager *m_manager;
AdBlockTreeWidget *m_currentTreeWidget;
AdBlockSubscription *m_currentSubscription;
QAction* m_actionAddRule;
QAction* m_actionRemoveRule;
QAction* m_actionAddSubscription;
QAction* m_actionRemoveSubscription;
QAction *m_actionAddRule;
QAction *m_actionRemoveRule;
QAction *m_actionAddSubscription;
QAction *m_actionRemoveSubscription;
bool m_loaded;
bool m_useLimitedEasyList;

View File

@ -70,7 +70,7 @@ void AdBlockIcon::createMenu(QMenu *menu) {
AdBlockManager *manager = AdBlockManager::instance();
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();
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++) {
const QPair<AdBlockRule*,QUrl> &pair = m_blockedPopups.at(i);
QString address = pair.second.toString().right(55);
QString actionText = tr("%1 with (%2)").arg(address,
pair.first->filter()).replace(QLatin1Char('&'), QLatin1String("&&"));
const QString address = pair.second.toString().right(55);
QString action_text = tr("%1 with (%2)").arg(address,
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));
}
}
menu->addSeparator();
QVector<WebPage::AdBlockedEntry> entries = page->adBlockedEntries();
const QVector<WebPage::AdBlockedEntry> entries = page->adBlockedEntries();
if (entries.isEmpty()) {
menu->addAction(tr("No content blocked"))->setEnabled(false);
@ -141,7 +141,7 @@ void AdBlockIcon::showMenu(const QPoint &pos) {
}
void AdBlockIcon::toggleCustomFilter() {
QAction *action = qobject_cast<QAction*>(sender());
const QAction *action = qobject_cast<QAction*>(sender());
if (action == NULL) {
return;

View File

@ -123,8 +123,8 @@ AdBlockSubscription *AdBlockManager::addSubscription(const QString &title, const
return NULL;
}
QString file_name = IOFactory::filterBadCharsFromFilename(title.toLower()) + QL1S(".txt");
QString file_path = IOFactory::ensureUniqueFilename(baseSubscriptionDirectory() + QDir::separator() + file_name);
const QString file_name = IOFactory::filterBadCharsFromFilename(title.toLower()) + QL1S(".txt");
const QString file_path = IOFactory::ensureUniqueFilename(baseSubscriptionDirectory() + QDir::separator() + file_name);
QFile file(file_path);
if (!file.open(QFile::WriteOnly | QFile::Truncate | QFile::Unbuffered)) {
@ -187,7 +187,7 @@ QString AdBlockManager::baseSubscriptionDirectory() {
return QDir::toNativeSeparators(directory);
}
bool AdBlockManager::shouldBeEnabled() {
bool AdBlockManager::shouldBeEnabled() const {
return qApp->settings()->value(GROUP(AdBlock), SETTING(AdBlock::Enabled)).toBool();
}
@ -198,7 +198,7 @@ void AdBlockManager::load() {
return;
}
Settings *settings = qApp->settings();
const Settings *settings = qApp->settings();
m_enabled = settings->value(GROUP(AdBlock), SETTING(AdBlock::Enabled)).toBool();
m_useLimitedEasyList = settings->value(GROUP(AdBlock), SETTING(AdBlock::UseLimitedEasyList)).toBool();
m_disabledRules = settings->value(GROUP(AdBlock), SETTING(AdBlock::DisabledRules)).toStringList();
@ -228,8 +228,8 @@ void AdBlockManager::load() {
QTextStream stream(&file);
stream.setCodec("UTF-8");
QString title = stream.readLine(1024).remove(QSL("Title: "));
QUrl url = QUrl(stream.readLine(1024).remove(QSL("Url: ")));
const QString title = stream.readLine(1024).remove(QSL("Title: "));
const QUrl url = QUrl(stream.readLine(1024).remove(QSL("Url: ")));
// Close the file.
file.close();

View File

@ -69,7 +69,7 @@ class AdBlockManager : public QObject {
AdBlockCustomList *customList() const;
bool shouldBeEnabled();
bool shouldBeEnabled() const;
static QString baseSubscriptionDirectory();
static AdBlockManager *instance();