From 48891635fc5c5f3fc194b0617edb6dd321a4fe5d Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Sun, 21 Jun 2015 21:29:58 +0200 Subject: [PATCH] Correct base directory for adblock subscriptions + more fixes. --- src/definitions/definitions.h.in | 6 ++- src/gui/lineeditwithstatus.cpp | 2 + .../adblock/adblockaddsubscriptiondialog.cpp | 4 ++ .../adblock/adblockaddsubscriptiondialog.ui | 6 +++ src/network-web/adblock/adblockdialog.ui | 22 ++++------ src/network-web/adblock/adblockicon.cpp | 2 +- src/network-web/adblock/adblockmanager.cpp | 40 +++++++++++++------ src/network-web/adblock/adblockmanager.h | 1 + .../adblock/adblocksubscription.cpp | 3 +- 9 files changed, 55 insertions(+), 31 deletions(-) diff --git a/src/definitions/definitions.h.in b/src/definitions/definitions.h.in index ec0addee1..5f317b82f 100755 --- a/src/definitions/definitions.h.in +++ b/src/definitions/definitions.h.in @@ -93,8 +93,10 @@ #define PLACEHOLDER_UNREAD_COUNTS "%unread" #define PLACEHOLDER_ALL_COUNTS "%all" -#define ADBLOCK_FILTERS_HELP "http://adblockplus.org/en/filters" -#define ADBLOCK_EASYLIST_URL "https://easylist-downloads.adblockplus.org/easylist.txt" +#define ADBLOCK_CUSTOM_LIST_FILENAME "customlist.txt" +#define ADBLOCK_BASE_DIRECTORY_NAME "data/adblock" +#define ADBLOCK_FILTERS_HELP "https://adblockplus.org/en/filters" +#define ADBLOCK_EASYLIST_URL "https://easylist-downloads.adblockplus.org/easylist.txt" #define BACKUP_NAME_SETTINGS "config" #define BACKUP_SUFFIX_SETTINGS ".ini.backup" diff --git a/src/gui/lineeditwithstatus.cpp b/src/gui/lineeditwithstatus.cpp index 69c508852..fb95183a4 100644 --- a/src/gui/lineeditwithstatus.cpp +++ b/src/gui/lineeditwithstatus.cpp @@ -27,6 +27,8 @@ LineEditWithStatus::LineEditWithStatus(QWidget *parent) : WidgetWithStatus(parent) { m_wdgInput = new BaseLineEdit(this); + setFocusProxy(m_wdgInput); + // Set correct size for the tool button. int txt_input_height = m_wdgInput->sizeHint().height(); m_btnStatus->setFixedSize(txt_input_height, txt_input_height); diff --git a/src/network-web/adblock/adblockaddsubscriptiondialog.cpp b/src/network-web/adblock/adblockaddsubscriptiondialog.cpp index 0f8207879..842e1d193 100755 --- a/src/network-web/adblock/adblockaddsubscriptiondialog.cpp +++ b/src/network-web/adblock/adblockaddsubscriptiondialog.cpp @@ -34,6 +34,10 @@ AdBlockAddSubscriptionDialog::AdBlockAddSubscriptionDialog(QWidget *parent) setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog | Qt::WindowSystemMenuHint); setWindowIcon(qApp->icons()->fromTheme("web-adblock")); + setTabOrder(m_ui->m_cmbPresets, m_ui->m_txtTitle->lineEdit()); + setTabOrder(m_ui->m_txtTitle->lineEdit(), m_ui->m_txtUrl->lineEdit()); + setTabOrder(m_ui->m_txtUrl->lineEdit(), m_ui->m_buttonBox); + m_knownSubscriptions << Subscription("EasyList (English)", ADBLOCK_EASYLIST_URL) << Subscription("Fanboy's List (English)", "http://www.fanboy.co.nz/adblock/fanboy-adblock.txt") << Subscription("Adversity (English)", "http://adversity.googlecode.com/hg/Adversity.txt") diff --git a/src/network-web/adblock/adblockaddsubscriptiondialog.ui b/src/network-web/adblock/adblockaddsubscriptiondialog.ui index 9b26ff423..ba06aeaee 100755 --- a/src/network-web/adblock/adblockaddsubscriptiondialog.ui +++ b/src/network-web/adblock/adblockaddsubscriptiondialog.ui @@ -22,6 +22,9 @@ Title: + + m_txtTitle + @@ -29,6 +32,9 @@ Address: + + m_txtUrl + diff --git a/src/network-web/adblock/adblockdialog.ui b/src/network-web/adblock/adblockdialog.ui index fac98169c..467345ec7 100755 --- a/src/network-web/adblock/adblockdialog.ui +++ b/src/network-web/adblock/adblockdialog.ui @@ -6,7 +6,7 @@ 0 0 - 451 + 535 408 @@ -73,19 +73,6 @@ - - - - Qt::Horizontal - - - - 40 - 20 - - - - @@ -120,6 +107,13 @@ + + m_checkEnable + m_tabs + m_btnOptions + m_txtFilter + m_checkUseLimitedEasyList + diff --git a/src/network-web/adblock/adblockicon.cpp b/src/network-web/adblock/adblockicon.cpp index fa6ac8173..7d61be288 100755 --- a/src/network-web/adblock/adblockicon.cpp +++ b/src/network-web/adblock/adblockicon.cpp @@ -35,7 +35,7 @@ AdBlockIcon::AdBlockIcon(QWidget *window, QWidget *parent) - : PlainToolButton(parent), m_window(window), m_menuAction(NULL), m_flashTimer(NULL), m_timerTicks(NULL), m_enabled(false) { + : PlainToolButton(parent), m_window(window), m_menuAction(NULL), m_flashTimer(NULL), m_timerTicks(0), m_enabled(false) { connect(this, SIGNAL(clicked(QPoint)), this, SLOT(showMenu(QPoint))); connect(AdBlockManager::instance(), SIGNAL(enabledChanged(bool)), this, SLOT(setEnabled(bool))); } diff --git a/src/network-web/adblock/adblockmanager.cpp b/src/network-web/adblock/adblockmanager.cpp index 08b1a6a05..54a9f7936 100755 --- a/src/network-web/adblock/adblockmanager.cpp +++ b/src/network-web/adblock/adblockmanager.cpp @@ -27,6 +27,7 @@ #include "network-web/silentnetworkaccessmanager.h" #include "miscellaneous/application.h" #include "miscellaneous/settings.h" +#include "definitions/definitions.h" #include "gui/formmain.h" #include @@ -36,11 +37,11 @@ #include -AdBlockManager* AdBlockManager::s_adBlockManager = NULL; +AdBlockManager *AdBlockManager::s_adBlockManager = NULL; AdBlockManager::AdBlockManager(QObject* parent) : QObject(parent), m_loaded(false), m_enabled(false), m_useLimitedEasyList(true), - m_matcher(new AdBlockMatcher(this)), m_subscriptions(QList()) { + m_subscriptions(QList()), m_matcher(new AdBlockMatcher(this)) { load(); } @@ -85,21 +86,21 @@ QNetworkReply *AdBlockManager::block(const QNetworkRequest &request) { return NULL; } - const AdBlockRule* blocked_rule = m_matcher->match(request, url_domain, url_string); + const AdBlockRule *blocked_rule = m_matcher->match(request, url_domain, url_string); if (blocked_rule != NULL) { QVariant v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100)); - WebPage* webPage = static_cast(v.value()); + WebPage *web_page = static_cast(v.value()); - if (WebPage::isPointerSafeToUse(webPage)) { - if (!canBeBlocked(webPage->mainFrame()->url())) { + if (WebPage::isPointerSafeToUse(web_page)) { + if (!canBeBlocked(web_page->mainFrame()->url())) { return NULL; } - webPage->addAdBlockRule(blocked_rule, request.url()); + web_page->addAdBlockRule(blocked_rule, request.url()); } - AdBlockBlockedNetworkReply* reply = new AdBlockBlockedNetworkReply(blocked_rule, this); + AdBlockBlockedNetworkReply *reply = new AdBlockBlockedNetworkReply(blocked_rule, this); reply->setRequest(request); return reply; @@ -126,7 +127,7 @@ AdBlockSubscription *AdBlockManager::addSubscription(const QString &title, const } QString file_name = IOFactory::filterBadCharsFromFilename(title.toLower()) + QL1S(".txt"); - QString file_path = IOFactory::ensureUniqueFilename(qApp->homeFolderPath() + QL1S("/adblock/") + file_name); + QString file_path = IOFactory::ensureUniqueFilename(baseSubscriptionDirectory() + QDir::separator() + file_name); QFile file(file_path); if (!file.open(QFile::WriteOnly | QFile::Truncate | QFile::Unbuffered)) { @@ -180,6 +181,21 @@ AdBlockCustomList *AdBlockManager::customList() const { return NULL; } +QString AdBlockManager::baseSubscriptionDirectory() { + QString directory; + + if (qApp->settings()->type() == SettingsProperties::Portable) { + directory = qApp->applicationDirPath(); + } + else { + directory = qApp->homeFolderPath() + QDir::separator() + QString(APP_LOW_H_NAME); + } + + directory += QDir::separator() + ADBLOCK_BASE_DIRECTORY_NAME; + + return QDir::toNativeSeparators(directory); +} + bool AdBlockManager::shouldBeEnabled() { return qApp->settings()->value(GROUP(AdBlock), SETTING(AdBlock::Enabled)).toBool(); } @@ -202,14 +218,14 @@ void AdBlockManager::load() { return; } - QDir adblock_dir(qApp->homeFolderPath() + QL1S("/adblock")); + QDir adblock_dir(baseSubscriptionDirectory()); if (!adblock_dir.exists()) { - QDir(qApp->homeFolderPath()).mkdir(QSL("adblock")); + adblock_dir.mkpath(adblock_dir.absolutePath()); } foreach (const QString &file_name, adblock_dir.entryList(QStringList(QL1S("*.txt")), QDir::Files)) { - if (file_name == QSL("customlist.txt")) { + if (file_name == QSL(ADBLOCK_CUSTOM_LIST_FILENAME)) { continue; } diff --git a/src/network-web/adblock/adblockmanager.h b/src/network-web/adblock/adblockmanager.h index fd3aaf213..b588e7cd8 100755 --- a/src/network-web/adblock/adblockmanager.h +++ b/src/network-web/adblock/adblockmanager.h @@ -71,6 +71,7 @@ class AdBlockManager : public QObject { bool shouldBeEnabled(); + static QString baseSubscriptionDirectory(); static AdBlockManager *instance(); signals: diff --git a/src/network-web/adblock/adblocksubscription.cpp b/src/network-web/adblock/adblocksubscription.cpp index 045d4a089..3cbcbde6e 100755 --- a/src/network-web/adblock/adblocksubscription.cpp +++ b/src/network-web/adblock/adblocksubscription.cpp @@ -299,8 +299,7 @@ AdBlockSubscription::~AdBlockSubscription() { AdBlockCustomList::AdBlockCustomList(QObject *parent) : AdBlockSubscription(tr("Custom rules"), parent) { setTitle(tr("Custom rules")); - // TODO cesta - setFilePath(qApp->homeFolderPath() + "/adblock/customlist.txt"); + setFilePath(AdBlockManager::baseSubscriptionDirectory() + QDir::separator() + ADBLOCK_CUSTOM_LIST_FILENAME); } AdBlockCustomList::~AdBlockCustomList() {