save
This commit is contained in:
parent
accb478bee
commit
6ef993045c
@ -9,6 +9,7 @@
|
|||||||
<file>text/COPYING_GNU_LGPL_21</file>
|
<file>text/COPYING_GNU_LGPL_21</file>
|
||||||
<file>text/COPYING_QT</file>
|
<file>text/COPYING_QT</file>
|
||||||
|
|
||||||
|
<file>scripts/builtin_js/observer.js</file>
|
||||||
<file>scripts/web_ui/rssguard.html</file>
|
<file>scripts/web_ui/rssguard.html</file>
|
||||||
|
|
||||||
<file>sounds/boing.wav</file>
|
<file>sounds/boing.wav</file>
|
||||||
|
@ -362,6 +362,9 @@
|
|||||||
#define APP_SQL_PATH QSL(":/sql")
|
#define APP_SQL_PATH QSL(":/sql")
|
||||||
#define APP_INFO_PATH QSL(":/text")
|
#define APP_INFO_PATH QSL(":/text")
|
||||||
|
|
||||||
|
#define BUILTIN_JS_FOLDER QSL(":/scripts/builtin_js")
|
||||||
|
#define OBSERVER_JS_FILE QSL("observer.js")
|
||||||
|
|
||||||
#define WEB_UI_FOLDER QSL(":/scripts/web_ui")
|
#define WEB_UI_FOLDER QSL(":/scripts/web_ui")
|
||||||
#define WEB_UI_FILE QSL("rssguard.html")
|
#define WEB_UI_FILE QSL("rssguard.html")
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#include "network-web/webfactory.h"
|
#include "network-web/webfactory.h"
|
||||||
|
|
||||||
#include <QFileIconProvider>
|
#include <QFileIconProvider>
|
||||||
|
#include <QGraphicsView>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QToolTip>
|
#include <QToolTip>
|
||||||
#include <QWheelEvent>
|
#include <QWheelEvent>
|
||||||
@ -201,6 +202,36 @@ QUrl WebEngineViewer::url() const {
|
|||||||
return QWebEngineView::url();
|
return QWebEngineView::url();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QByteArray WebEngineViewer::getJsEnabledHtml(QObject* parent, const QString& url) {
|
||||||
|
QByteArray res;
|
||||||
|
|
||||||
|
QMetaObject::invokeMethod(
|
||||||
|
qApp,
|
||||||
|
[&] {
|
||||||
|
QGraphicsScene* scene = new QGraphicsScene(parent);
|
||||||
|
QGraphicsView* view = new QGraphicsView(scene, qApp->mainFormWidget());
|
||||||
|
|
||||||
|
WebEngineViewer* viewer = new WebEngineViewer(qApp->mainFormWidget());
|
||||||
|
WebEnginePage* page = new WebEnginePage(viewer);
|
||||||
|
|
||||||
|
scene->addWidget(viewer);
|
||||||
|
|
||||||
|
viewer->resize(3800, 2100);
|
||||||
|
view->show();
|
||||||
|
viewer->setPage(page);
|
||||||
|
|
||||||
|
res = page->pageHtml(url).toUtf8();
|
||||||
|
|
||||||
|
delete scene;
|
||||||
|
// delete view;
|
||||||
|
// delete viewer;
|
||||||
|
// delete viewer;
|
||||||
|
},
|
||||||
|
Qt::ConnectionType::BlockingQueuedConnection);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
ContextMenuData WebEngineViewer::provideContextMenuData(QContextMenuEvent* event) const {
|
ContextMenuData WebEngineViewer::provideContextMenuData(QContextMenuEvent* event) const {
|
||||||
#if QT_VERSION_MAJOR == 6
|
#if QT_VERSION_MAJOR == 6
|
||||||
auto* menu_pointer = lastContextMenuRequest();
|
auto* menu_pointer = lastContextMenuRequest();
|
||||||
|
@ -37,6 +37,8 @@ class WebEngineViewer : public QWebEngineView, public WebViewer {
|
|||||||
virtual QString html() const;
|
virtual QString html() const;
|
||||||
virtual QUrl url() const;
|
virtual QUrl url() const;
|
||||||
|
|
||||||
|
static QByteArray getJsEnabledHtml(QObject* parent, const QString& url);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void pageTitleChanged(const QString& new_title);
|
void pageTitleChanged(const QString& new_title);
|
||||||
void pageUrlChanged(const QUrl& url);
|
void pageUrlChanged(const QUrl& url);
|
||||||
|
@ -34,16 +34,20 @@ WebEngineViewer* WebEnginePage::view() const {
|
|||||||
QString WebEnginePage::pageHtml(const QString& url) {
|
QString WebEnginePage::pageHtml(const QString& url) {
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
QString html;
|
QString html;
|
||||||
QTimer tmr;
|
|
||||||
|
|
||||||
tmr.setInterval(15000);
|
// Load initial DOM/page.
|
||||||
|
connect(this, &WebEnginePage::loadFinished, &loop, &QEventLoop::quit);
|
||||||
connect(&tmr, &QTimer::timeout, &loop, &QEventLoop::quit);
|
connect(this, &WebEnginePage::domIsIdle, &loop, &QEventLoop::quit);
|
||||||
connect(this, &WebEnginePage::loadFinished, &tmr, QOverload<>::of(&QTimer::start));
|
|
||||||
|
|
||||||
load(url);
|
load(url);
|
||||||
loop.exec();
|
loop.exec();
|
||||||
|
|
||||||
|
// Page is loaded. Send artificial scroll-to-bottom and wait for changes to end.
|
||||||
|
|
||||||
|
runJavaScript("window.resizeTo(3800, 2100);");
|
||||||
|
runJavaScript(IOFactory::readFile(BUILTIN_JS_FOLDER + QL1C('/') + OBSERVER_JS_FILE));
|
||||||
|
loop.exec();
|
||||||
|
|
||||||
toHtml([&](const QString& htm) {
|
toHtml([&](const QString& htm) {
|
||||||
html = htm;
|
html = htm;
|
||||||
loop.exit();
|
loop.exit();
|
||||||
@ -100,4 +104,8 @@ void WebEnginePage::javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level
|
|||||||
Q_UNUSED(level)
|
Q_UNUSED(level)
|
||||||
|
|
||||||
qWarningNN << LOGSEC_JS << message << QSL(" (source: %1:%2)").arg(source_id, QString::number(line_number));
|
qWarningNN << LOGSEC_JS << message << QSL(" (source: %1:%2)").arg(source_id, QString::number(line_number));
|
||||||
|
|
||||||
|
if (message.contains(QSL("iiddllee"))) {
|
||||||
|
emit domIsIdle();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,9 @@ class WebEnginePage : public QWebEnginePage {
|
|||||||
|
|
||||||
WebEngineViewer* view() const;
|
WebEngineViewer* view() const;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void domIsIdle();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
QString pageHtml(const QString& url);
|
QString pageHtml(const QString& url);
|
||||||
|
|
||||||
|
@ -205,7 +205,7 @@ QString StandardFeed::sourceTypeToString(StandardFeed::SourceType type) {
|
|||||||
return tr("Local file");
|
return tr("Local file");
|
||||||
|
|
||||||
case StandardFeed::SourceType::EmbeddedBrowser:
|
case StandardFeed::SourceType::EmbeddedBrowser:
|
||||||
return tr("Built-in web browser");
|
return tr("Built-in web browser with JavaScript support");
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return tr("Unknown");
|
return tr("Unknown");
|
||||||
@ -297,17 +297,7 @@ StandardFeed* StandardFeed::guessFeed(StandardFeed::SourceType source_type,
|
|||||||
}
|
}
|
||||||
else if (source_type == StandardFeed::SourceType::EmbeddedBrowser) {
|
else if (source_type == StandardFeed::SourceType::EmbeddedBrowser) {
|
||||||
#if defined(NO_LITE)
|
#if defined(NO_LITE)
|
||||||
WebEnginePage page;
|
feed_contents = WebEngineViewer::getJsEnabledHtml(qApp, source);
|
||||||
WebEngineViewer viewer;
|
|
||||||
|
|
||||||
// NOTE: Viewer must be present or JavaScript just does not run.
|
|
||||||
viewer.setPage(&page);
|
|
||||||
viewer.setAttribute(Qt::WA_DontShowOnScreen);
|
|
||||||
viewer.show();
|
|
||||||
|
|
||||||
feed_contents = page.pageHtml(source).toUtf8();
|
|
||||||
|
|
||||||
// IOFactory::writeFile("a.html", feed_contents);
|
|
||||||
#else
|
#else
|
||||||
throw ApplicationException(tr("this source type cannot be used on 'lite' %1 build").arg(QSL(APP_NAME)));
|
throw ApplicationException(tr("this source type cannot be used on 'lite' %1 build").arg(QSL(APP_NAME)));
|
||||||
#endif
|
#endif
|
||||||
|
@ -257,9 +257,20 @@ QList<Message> StandardServiceRoot::obtainNewMessages(Feed* feed,
|
|||||||
page->moveToThread(qApp->thread());
|
page->moveToThread(qApp->thread());
|
||||||
|
|
||||||
viewer->setPage(page);
|
viewer->setPage(page);
|
||||||
viewer->setAttribute(Qt::WA_DontShowOnScreen);
|
viewer->setAttribute(Qt::WidgetAttribute::WA_DontShowOnScreen, true);
|
||||||
|
viewer->setAttribute(Qt::WidgetAttribute::WA_DontShowOnScreen, true);
|
||||||
|
viewer->setAttribute(Qt::WidgetAttribute::WA_DeleteOnClose, true);
|
||||||
|
|
||||||
QMetaObject::invokeMethod(viewer, "show", Qt::ConnectionType::BlockingQueuedConnection);
|
// QMetaObject::invokeMethod(viewer, "show", Qt::ConnectionType::BlockingQueuedConnection);
|
||||||
|
|
||||||
|
QMetaObject::invokeMethod(
|
||||||
|
viewer,
|
||||||
|
[&] {
|
||||||
|
viewer->show();
|
||||||
|
viewer->resize(3800, 2100);
|
||||||
|
// viewer->hide();
|
||||||
|
},
|
||||||
|
Qt::ConnectionType::BlockingQueuedConnection);
|
||||||
|
|
||||||
QString html;
|
QString html;
|
||||||
QMetaObject::invokeMethod(page,
|
QMetaObject::invokeMethod(page,
|
||||||
@ -271,7 +282,8 @@ QList<Message> StandardServiceRoot::obtainNewMessages(Feed* feed,
|
|||||||
feed_contents = html.toUtf8();
|
feed_contents = html.toUtf8();
|
||||||
|
|
||||||
page->deleteLater();
|
page->deleteLater();
|
||||||
viewer->deleteLater();
|
viewer->close();
|
||||||
|
// viewer->deleteLater();
|
||||||
#else
|
#else
|
||||||
throw ApplicationException(tr("this source type cannot be used on 'lite' %1 build").arg(QSL(APP_NAME)));
|
throw ApplicationException(tr("this source type cannot be used on 'lite' %1 build").arg(QSL(APP_NAME)));
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user