mirror of
https://github.com/martinrotter/rssguard.git
synced 2025-02-02 18:36:49 +01:00
Correct base directory for adblock subscriptions + more fixes.
This commit is contained in:
parent
55c664afc4
commit
48891635fc
@ -93,7 +93,9 @@
|
|||||||
#define PLACEHOLDER_UNREAD_COUNTS "%unread"
|
#define PLACEHOLDER_UNREAD_COUNTS "%unread"
|
||||||
#define PLACEHOLDER_ALL_COUNTS "%all"
|
#define PLACEHOLDER_ALL_COUNTS "%all"
|
||||||
|
|
||||||
#define ADBLOCK_FILTERS_HELP "http://adblockplus.org/en/filters"
|
#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 ADBLOCK_EASYLIST_URL "https://easylist-downloads.adblockplus.org/easylist.txt"
|
||||||
|
|
||||||
#define BACKUP_NAME_SETTINGS "config"
|
#define BACKUP_NAME_SETTINGS "config"
|
||||||
|
@ -27,6 +27,8 @@ LineEditWithStatus::LineEditWithStatus(QWidget *parent)
|
|||||||
: WidgetWithStatus(parent) {
|
: WidgetWithStatus(parent) {
|
||||||
m_wdgInput = new BaseLineEdit(this);
|
m_wdgInput = new BaseLineEdit(this);
|
||||||
|
|
||||||
|
setFocusProxy(m_wdgInput);
|
||||||
|
|
||||||
// Set correct size for the tool button.
|
// Set correct size for the tool button.
|
||||||
int txt_input_height = m_wdgInput->sizeHint().height();
|
int txt_input_height = m_wdgInput->sizeHint().height();
|
||||||
m_btnStatus->setFixedSize(txt_input_height, txt_input_height);
|
m_btnStatus->setFixedSize(txt_input_height, txt_input_height);
|
||||||
|
@ -34,6 +34,10 @@ AdBlockAddSubscriptionDialog::AdBlockAddSubscriptionDialog(QWidget *parent)
|
|||||||
setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog | Qt::WindowSystemMenuHint);
|
setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog | Qt::WindowSystemMenuHint);
|
||||||
setWindowIcon(qApp->icons()->fromTheme("web-adblock"));
|
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)
|
m_knownSubscriptions << Subscription("EasyList (English)", ADBLOCK_EASYLIST_URL)
|
||||||
<< Subscription("Fanboy's List (English)", "http://www.fanboy.co.nz/adblock/fanboy-adblock.txt")
|
<< Subscription("Fanboy's List (English)", "http://www.fanboy.co.nz/adblock/fanboy-adblock.txt")
|
||||||
<< Subscription("Adversity (English)", "http://adversity.googlecode.com/hg/Adversity.txt")
|
<< Subscription("Adversity (English)", "http://adversity.googlecode.com/hg/Adversity.txt")
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Title:</string>
|
<string>Title:</string>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="buddy">
|
||||||
|
<cstring>m_txtTitle</cstring>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="0">
|
<item row="2" column="0">
|
||||||
@ -29,6 +32,9 @@
|
|||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Address:</string>
|
<string>Address:</string>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="buddy">
|
||||||
|
<cstring>m_txtUrl</cstring>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="4" column="1">
|
<item row="4" column="1">
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>451</width>
|
<width>535</width>
|
||||||
<height>408</height>
|
<height>408</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
@ -73,19 +73,6 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
|
||||||
<spacer name="horizontalSpacer">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Horizontal</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>40</width>
|
|
||||||
<height>20</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="0">
|
<item row="2" column="0">
|
||||||
@ -120,6 +107,13 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
<tabstops>
|
||||||
|
<tabstop>m_checkEnable</tabstop>
|
||||||
|
<tabstop>m_tabs</tabstop>
|
||||||
|
<tabstop>m_btnOptions</tabstop>
|
||||||
|
<tabstop>m_txtFilter</tabstop>
|
||||||
|
<tabstop>m_checkUseLimitedEasyList</tabstop>
|
||||||
|
</tabstops>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections>
|
<connections>
|
||||||
<connection>
|
<connection>
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
|
|
||||||
|
|
||||||
AdBlockIcon::AdBlockIcon(QWidget *window, QWidget *parent)
|
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(this, SIGNAL(clicked(QPoint)), this, SLOT(showMenu(QPoint)));
|
||||||
connect(AdBlockManager::instance(), SIGNAL(enabledChanged(bool)), this, SLOT(setEnabled(bool)));
|
connect(AdBlockManager::instance(), SIGNAL(enabledChanged(bool)), this, SLOT(setEnabled(bool)));
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include "network-web/silentnetworkaccessmanager.h"
|
#include "network-web/silentnetworkaccessmanager.h"
|
||||||
#include "miscellaneous/application.h"
|
#include "miscellaneous/application.h"
|
||||||
#include "miscellaneous/settings.h"
|
#include "miscellaneous/settings.h"
|
||||||
|
#include "definitions/definitions.h"
|
||||||
#include "gui/formmain.h"
|
#include "gui/formmain.h"
|
||||||
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
@ -36,11 +37,11 @@
|
|||||||
#include <QWebFrame>
|
#include <QWebFrame>
|
||||||
|
|
||||||
|
|
||||||
AdBlockManager* AdBlockManager::s_adBlockManager = NULL;
|
AdBlockManager *AdBlockManager::s_adBlockManager = NULL;
|
||||||
|
|
||||||
AdBlockManager::AdBlockManager(QObject* parent)
|
AdBlockManager::AdBlockManager(QObject* parent)
|
||||||
: QObject(parent), m_loaded(false), m_enabled(false), m_useLimitedEasyList(true),
|
: QObject(parent), m_loaded(false), m_enabled(false), m_useLimitedEasyList(true),
|
||||||
m_matcher(new AdBlockMatcher(this)), m_subscriptions(QList<AdBlockSubscription*>()) {
|
m_subscriptions(QList<AdBlockSubscription*>()), m_matcher(new AdBlockMatcher(this)) {
|
||||||
load();
|
load();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,21 +86,21 @@ QNetworkReply *AdBlockManager::block(const QNetworkRequest &request) {
|
|||||||
return NULL;
|
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) {
|
if (blocked_rule != NULL) {
|
||||||
QVariant v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100));
|
QVariant v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100));
|
||||||
WebPage* webPage = static_cast<WebPage*>(v.value<void*>());
|
WebPage *web_page = static_cast<WebPage*>(v.value<void*>());
|
||||||
|
|
||||||
if (WebPage::isPointerSafeToUse(webPage)) {
|
if (WebPage::isPointerSafeToUse(web_page)) {
|
||||||
if (!canBeBlocked(webPage->mainFrame()->url())) {
|
if (!canBeBlocked(web_page->mainFrame()->url())) {
|
||||||
return NULL;
|
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);
|
reply->setRequest(request);
|
||||||
|
|
||||||
return reply;
|
return reply;
|
||||||
@ -126,7 +127,7 @@ AdBlockSubscription *AdBlockManager::addSubscription(const QString &title, const
|
|||||||
}
|
}
|
||||||
|
|
||||||
QString file_name = IOFactory::filterBadCharsFromFilename(title.toLower()) + QL1S(".txt");
|
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);
|
QFile file(file_path);
|
||||||
|
|
||||||
if (!file.open(QFile::WriteOnly | QFile::Truncate | QFile::Unbuffered)) {
|
if (!file.open(QFile::WriteOnly | QFile::Truncate | QFile::Unbuffered)) {
|
||||||
@ -180,6 +181,21 @@ AdBlockCustomList *AdBlockManager::customList() const {
|
|||||||
return NULL;
|
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() {
|
bool AdBlockManager::shouldBeEnabled() {
|
||||||
return qApp->settings()->value(GROUP(AdBlock), SETTING(AdBlock::Enabled)).toBool();
|
return qApp->settings()->value(GROUP(AdBlock), SETTING(AdBlock::Enabled)).toBool();
|
||||||
}
|
}
|
||||||
@ -202,14 +218,14 @@ void AdBlockManager::load() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QDir adblock_dir(qApp->homeFolderPath() + QL1S("/adblock"));
|
QDir adblock_dir(baseSubscriptionDirectory());
|
||||||
|
|
||||||
if (!adblock_dir.exists()) {
|
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)) {
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,6 +71,7 @@ class AdBlockManager : public QObject {
|
|||||||
|
|
||||||
bool shouldBeEnabled();
|
bool shouldBeEnabled();
|
||||||
|
|
||||||
|
static QString baseSubscriptionDirectory();
|
||||||
static AdBlockManager *instance();
|
static AdBlockManager *instance();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
@ -299,8 +299,7 @@ AdBlockSubscription::~AdBlockSubscription() {
|
|||||||
|
|
||||||
AdBlockCustomList::AdBlockCustomList(QObject *parent) : AdBlockSubscription(tr("Custom rules"), parent) {
|
AdBlockCustomList::AdBlockCustomList(QObject *parent) : AdBlockSubscription(tr("Custom rules"), parent) {
|
||||||
setTitle(tr("Custom rules"));
|
setTitle(tr("Custom rules"));
|
||||||
// TODO cesta
|
setFilePath(AdBlockManager::baseSubscriptionDirectory() + QDir::separator() + ADBLOCK_CUSTOM_LIST_FILENAME);
|
||||||
setFilePath(qApp->homeFolderPath() + "/adblock/customlist.txt");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AdBlockCustomList::~AdBlockCustomList() {
|
AdBlockCustomList::~AdBlockCustomList() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user