From d5b4433c44f99bb30a6282c247de3938f3f8c987 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sun, 30 Dec 2018 16:10:17 +0100 Subject: Fix filter.header not working --- doc/smolbote.5.asciidoc | 7 +++++-- include/profileinterface.h | 4 ++-- lib/configuration/configuration.h | 7 ++++--- src/webengine/filter.cpp | 35 ++++++----------------------------- 4 files changed, 17 insertions(+), 36 deletions(-) diff --git a/doc/smolbote.5.asciidoc b/doc/smolbote.5.asciidoc index 6b48def..5b17a36 100644 --- a/doc/smolbote.5.asciidoc +++ b/doc/smolbote.5.asciidoc @@ -17,6 +17,9 @@ The settings in this file change your preferences and keybindings. Lines starting with *#* are considered comments and ignored. +Options taking multiple values (list options) can have multiple values set by +using the same option name multiple times. + == Sections === Browser Options @@ -90,11 +93,11 @@ Show/Hide downloads widget shortcut. *subwindow.shortcuts.moveRight* (arg=Ctrl+Shift+P):: Move tab to the right *subwindow.shortcuts.fullscreen* (arg=F11):: Show page fullscreen -=== Secutiry Options +=== Security Options *filter.hosts* (arg=~/.config/smolbote/hosts.d):: Hostlist *filter.adblock* arg:: TODO -*filter.header* arg:: +*filter.header* (list):: A list of HTTP headers to set. Each header should be given as a colon-separated name:value pair. diff --git a/include/profileinterface.h b/include/profileinterface.h index c24a4ae..e25b085 100644 --- a/include/profileinterface.h +++ b/include/profileinterface.h @@ -36,8 +36,8 @@ class Profile : public QWebEngineProfile Q_PROPERTY(bool spellCheckEnabled READ isSpellCheckEnabled WRITE setSpellCheckEnabled NOTIFY propertyChanged) protected: - explicit Profile(QObject *parent = nullptr) : QWebEngineProfile(parent) {}; - explicit Profile(const QString &storageName, QObject *parent = nullptr) : QWebEngineProfile(storageName, parent) {}; + explicit Profile(QObject *parent = nullptr) : QWebEngineProfile(parent) {} + explicit Profile(const QString &storageName, QObject *parent = nullptr) : QWebEngineProfile(storageName, parent) {} public: virtual const QString name() const = 0; diff --git a/lib/configuration/configuration.h b/lib/configuration/configuration.h index 4f9eafd..2bdd2c5 100644 --- a/lib/configuration/configuration.h +++ b/lib/configuration/configuration.h @@ -44,13 +44,14 @@ public: return std::nullopt; } + // path is guaranteed to exist, so using vm[path] is safe + if constexpr(std::is_same_v) { - return std::optional(QString::fromStdString(this->value(path).value())); - //return std::optional(vm[path].as()); + return std::optional(QString::fromStdString(vm[path].as())); } else if constexpr(std::is_same_v) { QStringList r; - for(const std::string &item : this->value>(path).value()) { + for(const std::string &item : vm[path].as>()) { r.append(QString::fromStdString(item)); } return std::optional(r); diff --git a/src/webengine/filter.cpp b/src/webengine/filter.cpp index 6941ac4..f1a38af 100644 --- a/src/webengine/filter.cpp +++ b/src/webengine/filter.cpp @@ -15,37 +15,20 @@ #include #include -/* -inline std::vector parseAdBlockList(const QString &filename) -{ - std::vector rules; - QFile list(filename); - - if(list.open(QIODevice::ReadOnly | QIODevice::Text), true) { - QTextStream l(&list); - QString line; - while(l.readLineInto(&line)) { - AdBlockRule rule(line); - if(rule.isEnabled()) { - rules.emplace_back(std::move(rule)); - } - } - list.close(); - } - - return rules; -}*/ - Filter::Filter::Filter(const std::unique_ptr &config, QObject *parent) : QObject(parent) { // parse headers - if(const auto headers = config->value("filter.header"); headers) { - for(const QString &header : headers.value()) { + if(config->exists("filter.header")) { + const auto headers = config->value("filter.header").value(); + for(const QString header : headers) { const auto list = header.split(QLatin1Literal(":")); if(list.length() == 2) m_headers.insert(list.at(0).toLatin1(), list.at(1).toLatin1()); } +#ifdef QT_DEBUG + qDebug("Added %i custom http headers", m_headers.size()); +#endif } const QStringList hostfiles = Util::files(config->value("filter.hosts").value()); @@ -60,12 +43,6 @@ Filter::Filter::Filter(const std::unique_ptr &config, QObject *pa f.close(); } } - - /* - auto filtersPath = config->value("filter.adblock"); - if(filtersPath) - filters = parseAdBlockList(filtersPath.value()); - */ } void Filter::filterRequest(QWebEngineUrlRequestInfo &info) const -- cgit v1.2.1