add support for fetching URL content via embedded browser
This commit is contained in:
parent
2dda0599df
commit
567c0e1906
6 changed files with 72 additions and 4 deletions
|
@ -30,6 +30,24 @@ WebEngineViewer* WebEnginePage::view() const {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString WebEnginePage::pageHtml(const QString& url) {
|
||||||
|
QEventLoop loop;
|
||||||
|
QString html;
|
||||||
|
|
||||||
|
connect(this, &WebEnginePage::loadFinished, &loop, &QEventLoop::quit);
|
||||||
|
|
||||||
|
load(url);
|
||||||
|
loop.exec();
|
||||||
|
|
||||||
|
toHtml([&](const QString& htm) {
|
||||||
|
html = htm;
|
||||||
|
loop.exit();
|
||||||
|
});
|
||||||
|
loop.exec();
|
||||||
|
|
||||||
|
return html;
|
||||||
|
}
|
||||||
|
|
||||||
void WebEnginePage::hideUnwantedElements() {
|
void WebEnginePage::hideUnwantedElements() {
|
||||||
if (!qApp->web()->adBlock()->isEnabled()) {
|
if (!qApp->web()->adBlock()->isEnabled()) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -8,20 +8,25 @@
|
||||||
class WebEngineViewer;
|
class WebEngineViewer;
|
||||||
|
|
||||||
class WebEnginePage : public QWebEnginePage {
|
class WebEnginePage : public QWebEnginePage {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit WebEnginePage(QObject* parent = nullptr);
|
explicit WebEnginePage(QObject* parent = nullptr);
|
||||||
|
|
||||||
WebEngineViewer* view() const;
|
WebEngineViewer* view() const;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
QString pageHtml(const QString& url);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void hideUnwantedElements();
|
void hideUnwantedElements();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool acceptNavigationRequest(const QUrl& url, NavigationType type, bool is_main_frame);
|
virtual bool acceptNavigationRequest(const QUrl& url, NavigationType type, bool is_main_frame);
|
||||||
virtual void javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level, const QString& message,
|
virtual void javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level,
|
||||||
int line_number, const QString& source_id);
|
const QString& message,
|
||||||
|
int line_number,
|
||||||
|
const QString& source_id);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // WEBENGINEPAGE_H
|
#endif // WEBENGINEPAGE_H
|
||||||
|
|
|
@ -41,6 +41,8 @@ StandardFeedDetails::StandardFeedDetails(QWidget* parent) : QWidget(parent) {
|
||||||
QVariant::fromValue(StandardFeed::SourceType::Script));
|
QVariant::fromValue(StandardFeed::SourceType::Script));
|
||||||
m_ui.m_cmbSourceType->addItem(StandardFeed::sourceTypeToString(StandardFeed::SourceType::LocalFile),
|
m_ui.m_cmbSourceType->addItem(StandardFeed::sourceTypeToString(StandardFeed::SourceType::LocalFile),
|
||||||
QVariant::fromValue(StandardFeed::SourceType::LocalFile));
|
QVariant::fromValue(StandardFeed::SourceType::LocalFile));
|
||||||
|
m_ui.m_cmbSourceType->addItem(StandardFeed::sourceTypeToString(StandardFeed::SourceType::EmbeddedBrowser),
|
||||||
|
QVariant::fromValue(StandardFeed::SourceType::EmbeddedBrowser));
|
||||||
|
|
||||||
// Add standard feed types.
|
// Add standard feed types.
|
||||||
m_ui.m_cmbType->addItem(StandardFeed::typeToString(StandardFeed::Type::Atom10),
|
m_ui.m_cmbType->addItem(StandardFeed::typeToString(StandardFeed::Type::Atom10),
|
||||||
|
@ -251,6 +253,7 @@ void StandardFeedDetails::onDescriptionChanged(const QString& new_description) {
|
||||||
|
|
||||||
void StandardFeedDetails::onUrlChanged(const QString& new_url) {
|
void StandardFeedDetails::onUrlChanged(const QString& new_url) {
|
||||||
switch (sourceType()) {
|
switch (sourceType()) {
|
||||||
|
case StandardFeed::SourceType::EmbeddedBrowser:
|
||||||
case StandardFeed::SourceType::Url: {
|
case StandardFeed::SourceType::Url: {
|
||||||
if (QUrl(new_url).isValid()) {
|
if (QUrl(new_url).isValid()) {
|
||||||
m_ui.m_txtSource->setStatus(LineEditWithStatus::StatusType::Ok, tr("The URL is ok."));
|
m_ui.m_txtSource->setStatus(LineEditWithStatus::StatusType::Ok, tr("The URL is ok."));
|
||||||
|
|
|
@ -13,6 +13,10 @@
|
||||||
#include "services/standard/gui/formstandardfeeddetails.h"
|
#include "services/standard/gui/formstandardfeeddetails.h"
|
||||||
#include "services/standard/standardserviceroot.h"
|
#include "services/standard/standardserviceroot.h"
|
||||||
|
|
||||||
|
#if defined(NO_LITE)
|
||||||
|
#include "network-web/webengine/webenginepage.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "services/standard/parsers/atomparser.h"
|
#include "services/standard/parsers/atomparser.h"
|
||||||
#include "services/standard/parsers/jsonparser.h"
|
#include "services/standard/parsers/jsonparser.h"
|
||||||
#include "services/standard/parsers/rdfparser.h"
|
#include "services/standard/parsers/rdfparser.h"
|
||||||
|
@ -199,6 +203,9 @@ QString StandardFeed::sourceTypeToString(StandardFeed::SourceType type) {
|
||||||
case StandardFeed::SourceType::LocalFile:
|
case StandardFeed::SourceType::LocalFile:
|
||||||
return tr("Local file");
|
return tr("Local file");
|
||||||
|
|
||||||
|
case StandardFeed::SourceType::EmbeddedBrowser:
|
||||||
|
return tr("Built-in web browser");
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return tr("Unknown");
|
return tr("Unknown");
|
||||||
}
|
}
|
||||||
|
@ -287,6 +294,15 @@ StandardFeed* StandardFeed::guessFeed(StandardFeed::SourceType source_type,
|
||||||
throw NetworkException(network_result.m_networkError);
|
throw NetworkException(network_result.m_networkError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (source_type == StandardFeed::SourceType::EmbeddedBrowser) {
|
||||||
|
#if defined(NO_LITE)
|
||||||
|
WebEnginePage page;
|
||||||
|
|
||||||
|
feed_contents = page.pageHtml(source).toUtf8();
|
||||||
|
#else
|
||||||
|
throw ApplicationException(tr("this source type cannot be used on 'lite' %1 build").arg(QSL(APP_NAME)));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
else if (source_type == StandardFeed::SourceType::LocalFile) {
|
else if (source_type == StandardFeed::SourceType::LocalFile) {
|
||||||
feed_contents = IOFactory::readFile(source);
|
feed_contents = IOFactory::readFile(source);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,8 @@ class StandardFeed : public Feed {
|
||||||
enum class SourceType {
|
enum class SourceType {
|
||||||
Url = 0,
|
Url = 0,
|
||||||
Script = 1,
|
Script = 1,
|
||||||
LocalFile = 2
|
LocalFile = 2,
|
||||||
|
EmbeddedBrowser = 3
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class Type {
|
enum class Type {
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include "miscellaneous/mutex.h"
|
#include "miscellaneous/mutex.h"
|
||||||
#include "miscellaneous/settings.h"
|
#include "miscellaneous/settings.h"
|
||||||
#include "network-web/networkfactory.h"
|
#include "network-web/networkfactory.h"
|
||||||
|
|
||||||
#include "services/abstract/gui/formcategorydetails.h"
|
#include "services/abstract/gui/formcategorydetails.h"
|
||||||
#include "services/standard/definitions.h"
|
#include "services/standard/definitions.h"
|
||||||
#include "services/standard/gui/formdiscoverfeeds.h"
|
#include "services/standard/gui/formdiscoverfeeds.h"
|
||||||
|
@ -29,6 +30,10 @@
|
||||||
#include "services/standard/standardfeedsimportexportmodel.h"
|
#include "services/standard/standardfeedsimportexportmodel.h"
|
||||||
#include "services/standard/standardserviceentrypoint.h"
|
#include "services/standard/standardserviceentrypoint.h"
|
||||||
|
|
||||||
|
#if defined(NO_LITE)
|
||||||
|
#include "network-web/webengine/webenginepage.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(ENABLE_COMPRESSED_SITEMAP)
|
#if defined(ENABLE_COMPRESSED_SITEMAP)
|
||||||
#include "3rd-party/qcompressor/qcompressor.h"
|
#include "3rd-party/qcompressor/qcompressor.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -234,6 +239,26 @@ QList<Message> StandardServiceRoot::obtainNewMessages(Feed* feed,
|
||||||
f->setLastEtag(network_result.m_headers.value(QSL("etag")));
|
f->setLastEtag(network_result.m_headers.value(QSL("etag")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (f->sourceType() == StandardFeed::SourceType::EmbeddedBrowser) {
|
||||||
|
#if defined(NO_LITE)
|
||||||
|
WebEnginePage* page = new WebEnginePage();
|
||||||
|
|
||||||
|
page->moveToThread(qApp->thread());
|
||||||
|
|
||||||
|
QString html;
|
||||||
|
QMetaObject::invokeMethod(page,
|
||||||
|
"pageHtml",
|
||||||
|
Qt::ConnectionType::BlockingQueuedConnection,
|
||||||
|
Q_RETURN_ARG(QString, html),
|
||||||
|
Q_ARG(QString, f->source()));
|
||||||
|
|
||||||
|
feed_contents = html.toUtf8();
|
||||||
|
|
||||||
|
page->deleteLater();
|
||||||
|
#else
|
||||||
|
throw ApplicationException(tr("this source type cannot be used on 'lite' %1 build").arg(QSL(APP_NAME)));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
else if (f->sourceType() == StandardFeed::SourceType::LocalFile) {
|
else if (f->sourceType() == StandardFeed::SourceType::LocalFile) {
|
||||||
feed_contents = IOFactory::readFile(feed->source());
|
feed_contents = IOFactory::readFile(feed->source());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue