do not fetch some resources when they are not enabled

This commit is contained in:
Martin Rotter 2022-04-28 10:38:37 +02:00
parent 5e2cfbd778
commit 871c92c1b6
1 changed files with 23 additions and 18 deletions

View File

@ -433,28 +433,33 @@ void TextBrowserViewer::onAnchorClicked(const QUrl& url) {
void TextBrowserViewer::setHtml(const QString& html, const QUrl& base_url) { void TextBrowserViewer::setHtml(const QString& html, const QUrl& base_url) {
setVerticalScrollBarPosition(0.0); setVerticalScrollBarPosition(0.0);
static QRegularExpression img_tag_rgx("\\<img[^\\>]*src\\s*=\\s*[\"\']([^\"\']*)[\"\'][^\\>]*\\>", if (m_resourcesEnabled) {
QRegularExpression::PatternOption::CaseInsensitiveOption | static QRegularExpression img_tag_rgx("\\<img[^\\>]*src\\s*=\\s*[\"\']([^\"\']*)[\"\'][^\\>]*\\>",
QRegularExpression::PatternOption::InvertedGreedinessOption); QRegularExpression::PatternOption::CaseInsensitiveOption |
QRegularExpressionMatchIterator i = img_tag_rgx.globalMatch(html); QRegularExpression::PatternOption::InvertedGreedinessOption);
QList<QUrl> found_resources; QRegularExpressionMatchIterator i = img_tag_rgx.globalMatch(html);
QList<QUrl> found_resources;
while (i.hasNext()) { while (i.hasNext()) {
QRegularExpressionMatch match = i.next(); QRegularExpressionMatch match = i.next();
auto captured_url = match.captured(1); auto captured_url = match.captured(1);
if (!found_resources.contains(captured_url)) { if (!found_resources.contains(captured_url)) {
found_resources.append(captured_url); found_resources.append(captured_url);
}
} }
auto really_needed_resources = boolinq::from(found_resources)
.where([this](const QUrl& res) {
return !m_loadedResources.contains(res);
})
.toStdList();
m_neededResources = FROM_STD_LIST(QList<QUrl>, really_needed_resources);
}
else {
m_neededResources = {};
} }
auto really_needed_resources = boolinq::from(found_resources)
.where([this](const QUrl& res) {
return !m_loadedResources.contains(res);
})
.toStdList();
m_neededResources = FROM_STD_LIST(QList<QUrl>, really_needed_resources);
setHtmlPrivate(html, base_url); setHtmlPrivate(html, base_url);