aboutsummaryrefslogtreecommitdiff
path: root/src/webengine
diff options
context:
space:
mode:
Diffstat (limited to 'src/webengine')
-rw-r--r--src/webengine/urlinterceptor.cpp31
-rw-r--r--src/webengine/webprofile.cpp24
2 files changed, 34 insertions, 21 deletions
diff --git a/src/webengine/urlinterceptor.cpp b/src/webengine/urlinterceptor.cpp
index e88e5b7..5e17e78 100644
--- a/src/webengine/urlinterceptor.cpp
+++ b/src/webengine/urlinterceptor.cpp
@@ -25,13 +25,7 @@ UrlRequestInterceptor::UrlRequestInterceptor(const QString &path, QObject *paren
#endif
rulesLock.lock();
- for(const auto &k : r.keys()) {
- if(rules.contains(k)) {
- //
- } else {
- rules.insert(k, r.value(k));
- }
- }
+ rules.unite(r);
rulesLock.unlock();
});
}
@@ -57,28 +51,41 @@ QHash<QString, UrlRequestInterceptor::HostRule> parse(const QString &filename)
// with a QTextStream we can read lines without getting linebreaks at the end
QTextStream hostfile_stream(&hostfile);
+
while(!hostfile_stream.atEnd()) {
+
// read line and remove any whitespace at the end
const QString &line = hostfile_stream.readLine().trimmed();
// skip comments and empty lines
+ if(line.isEmpty() || line.startsWith('#'))
+ continue;
+
// everything else should be a rule
// format is <redirect> <host>
// 0.0.0.0 hostname
const QStringList &parts = line.split(' ');
const QString &redirect = parts.at(0);
- for(const QString &host : parts.mid(1)) {
- if(!rules.contains(host)) {
+ for(auto i = parts.constBegin() + 1; i != parts.constEnd(); ++i) {
+ if(!rules.contains(*i)) {
UrlRequestInterceptor::HostRule rule{};
- rule.isBlocking = redirect == "0.0.0.0";
- rules.insert(host, rule);
+ rule.isBlocking = (redirect == "0.0.0.0");
+ rules.insert(*i, rule);
}
}
+
+// for(const QString &host : parts.mid(1)) {
+// if(!rules.contains(host)) {
+// UrlRequestInterceptor::HostRule rule{};
+// rule.isBlocking = redirect == "0.0.0.0";
+// rules.insert(host, rule);
+// }
+// }
}
hostfile.close();
}
return rules;
-}; \ No newline at end of file
+};
diff --git a/src/webengine/webprofile.cpp b/src/webengine/webprofile.cpp
index 081e091..5b07645 100644
--- a/src/webengine/webprofile.cpp
+++ b/src/webengine/webprofile.cpp
@@ -21,27 +21,33 @@ void loadProfile(WebProfile *profile, const QString &path)
return;
#ifdef QT_DEBUG
- qDebug("Reading config for profile '%s': %s", qUtf8Printable(profile->name()), qUtf8Printable(path));
+ qDebug("+ Reading config for profile '%s': %s", qUtf8Printable(profile->name()), qUtf8Printable(path));
#endif
QSettings config(path, QSettings::IniFormat);
config.beginGroup("properties");
- for(const QString &key : config.childKeys()) {
+ {
+ const auto keys = config.childKeys();
+ for(const QString &key : keys) {
#ifdef QT_DEBUG
- qDebug("set property %s to %s", qUtf8Printable(key), qUtf8Printable(config.value(key).toString()));
+ qDebug("- set property %s to %s", qUtf8Printable(key), qUtf8Printable(config.value(key).toString()));
#endif
- profile->setProperty(qUtf8Printable(key), config.value(key));
+ profile->setProperty(qUtf8Printable(key), config.value(key));
+ }
}
config.endGroup(); // properties
config.beginGroup("attributes");
- auto *settings = profile->settings();
- for(const QString &key : config.childKeys()) {
+ {
+ const auto keys = config.childKeys();
+ auto *settings = profile->settings();
+ for(const QString &key : keys) {
#ifdef QT_DEBUG
- qDebug("set attribute %s to %s", qUtf8Printable(key), qUtf8Printable(config.value(key).toString()));
+ qDebug("- set attribute %s to %s", qUtf8Printable(key), qUtf8Printable(config.value(key).toString()));
#endif
- auto attribute = static_cast<QWebEngineSettings::WebAttribute>(key.toInt());
- settings->setAttribute(attribute, config.value(key).toBool());
+ auto attribute = static_cast<QWebEngineSettings::WebAttribute>(key.toInt());
+ settings->setAttribute(attribute, config.value(key).toBool());
+ }
}
config.endGroup();