Commit 3273874b authored by Laurent Montel's avatar Laurent Montel 😁

move savehtml to webenginepage directly

parent af411a45
......@@ -21,10 +21,15 @@
#include "webhittest.h"
#include "webhittestresult.h"
#include <KLocalizedString>
#include <QEventLoop>
#include <QWebEngineSettings>
#include <QWebEngineDownloadItem>
#include <QPointer>
#include <QTimer>
#include <QFileDialog>
#include <QWebEngineProfile>
using namespace WebEngineViewer;
......@@ -41,13 +46,14 @@ WebEnginePage::WebEnginePage(QObject *parent)
: QWebEnginePage(parent),
d(new WebEnginePagePrivate)
{
init();
}
WebEnginePage::WebEnginePage(QWebEngineProfile *profile, QObject *parent)
: QWebEnginePage(profile, parent),
d(new WebEnginePagePrivate)
{
init();
}
WebEnginePage::~WebEnginePage()
......@@ -55,11 +61,33 @@ WebEnginePage::~WebEnginePage()
delete d;
}
void WebEnginePage::init()
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
connect(profile(), &QWebEngineProfile::downloadRequested, this, &WebEnginePage::saveHtml);
#endif
}
WebEngineViewer::WebHitTest *WebEnginePage::hitTestContent(const QPoint &pos)
{
return new WebHitTest(this, pos);
}
void WebEnginePage::saveHtml(QWebEngineDownloadItem *download)
{
#if QT_VERSION >= 0x050700
const QString fileName = QFileDialog::getSaveFileName(view(), i18n("Save HTML Page"));
if (!fileName.isEmpty()) {
download->setSavePageFormat(QWebEngineDownloadItem::SingleHtmlSaveFormat);
download->setPath(fileName);
download->accept();
}
#else
Q_UNUSED(download);
#endif
}
QVariant WebEnginePage::execJavaScript(const QString &scriptSource, int timeout)
{
QVariant result;
......
......@@ -24,6 +24,7 @@
#include "webengineviewer_export.h"
#include <QVariant>
class QWebEngineProfile;
class QWebEngineDownloadItem;
namespace WebEngineViewer
{
class WebHitTest;
......@@ -39,6 +40,7 @@ public:
WebEngineViewer::WebHitTest *hitTestContent(const QPoint &pos);
QVariant execJavaScript(const QString &scriptSource, int timeout = 500);
void saveHtml(QWebEngineDownloadItem *download);
Q_SIGNALS:
void urlClicked(const QUrl &url);
......@@ -46,6 +48,7 @@ protected:
bool acceptNavigationRequest(const QUrl &url, NavigationType type, bool isMainFrame) Q_DECL_OVERRIDE;
private:
void init();
WebEnginePagePrivate *const d;
};
}
......
......@@ -25,7 +25,6 @@
#include <QKeyEvent>
#include <QMouseEvent>
#include <QWheelEvent>
#include <QFileDialog>
#include <QWebEngineProfile>
#include <KLocalizedString>
......@@ -53,9 +52,6 @@ WebEngineView::WebEngineView(QWidget *parent)
{
installEventFilter(this);
d->mManagerScript = new WebEngineManageScript(this);
#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
connect(page()->profile(), &QWebEngineProfile::downloadRequested, this, &WebEngineView::saveHtml);
#endif
}
WebEngineView::~WebEngineView()
......@@ -218,16 +214,3 @@ bool WebEngineView::hasPrintPreviewSupport() const
return true;
}
void WebEngineView::saveHtml(QWebEngineDownloadItem *download)
{
#if QT_VERSION >= 0x050700
const QString fileName = QFileDialog::getSaveFileName(this, i18n("Save HTML Page"));
if (!fileName.isEmpty()) {
download->setSavePageFormat(QWebEngineDownloadItem::SingleHtmlSaveFormat);
download->setPath(fileName);
download->accept();
}
#else
Q_UNUSED(download);
#endif
}
......@@ -23,7 +23,6 @@
#include <QWebEngineView>
#include <QWebEngineScript>
#include "webengineviewer_export.h"
class QWebEngineDownloadItem;
namespace WebEngineViewer
{
class WebEngineViewPrivate;
......@@ -39,7 +38,6 @@ public:
qreal relativePosition() const;
bool hasPrintPreviewSupport() const;
void saveHtml(QWebEngineDownloadItem *download);
void addScript(const QString &source, const QString &scriptName, QWebEngineScript::InjectionPoint injectionPoint);
void initializeJQueryScript();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment