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

Implement save as html

parent 7971d2db
......@@ -21,6 +21,12 @@
#include <QKeyEvent>
#include <QMouseEvent>
#include <QWheelEvent>
#include <QFileDialog>
#include <QWebEngineProfile>
#include <KLocalizedString>
#include <QWebEngineDownloadItem>
using namespace WebEngineViewer;
......@@ -51,6 +57,9 @@ WebEngineView::WebEngineView(QWidget *parent)
installEventFilter(this);
connect(this, &WebEngineView::loadFinished, this, &WebEngineView::slotLoadFinished);
#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
connect(page()->profile(), &QWebEngineProfile::downloadRequested, this, &WebEngineView::saveHtml);
#endif
}
WebEngineView::~WebEngineView()
......@@ -193,3 +202,17 @@ bool WebEngineView::hasPrintPreviewSupport() const
return false;
#endif
}
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
}
......@@ -20,7 +20,7 @@
#include <QWebEngineView>
#include "webengineviewer_export.h"
class QWebEngineDownloadItem;
namespace WebEngineViewer
{
class WebEngineViewPrivate;
......@@ -36,6 +36,7 @@ public:
qreal relativePosition() const;
bool hasPrintPreviewSupport() const;
void saveHtml(QWebEngineDownloadItem *download);
protected:
bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE;
......
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