Commit 85fbf073 authored by Laurent Montel's avatar Laurent Montel 😁

Look at to save html page on disk

parent 73a6fb1b
...@@ -18,13 +18,17 @@ ...@@ -18,13 +18,17 @@
#include "sieveeditorwebengineview.h" #include "sieveeditorwebengineview.h"
#include <QContextMenuEvent> #include <QContextMenuEvent>
#include <QMenu> #include <QMenu>
#include <QWebEngineDownloadItem>
#include <QWebEngineProfile>
using namespace KSieveUi; using namespace KSieveUi;
SieveEditorWebEngineView::SieveEditorWebEngineView(QWidget *parent) SieveEditorWebEngineView::SieveEditorWebEngineView(QWidget *parent)
: QWebEngineView(parent) : QWebEngineView(parent)
{ {
#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
connect(page()->profile(), &QWebEngineProfile::downloadRequested, this, &SieveEditorWebEngineView::downloadRequested);
#endif
} }
SieveEditorWebEngineView::~SieveEditorWebEngineView() SieveEditorWebEngineView::~SieveEditorWebEngineView()
...@@ -32,6 +36,27 @@ SieveEditorWebEngineView::~SieveEditorWebEngineView() ...@@ -32,6 +36,27 @@ SieveEditorWebEngineView::~SieveEditorWebEngineView()
} }
void SieveEditorWebEngineView::downloadRequested(QWebEngineDownloadItem *download)
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
//TODO save as
#if 0
if (download->savePageFormat() != QWebEngineDownloadItem::UnknownSaveFormat) {
SavePageDialog dlg(this, download->savePageFormat(), download->path());
if (dlg.exec() != SavePageDialog::Accepted)
return;
download->setSavePageFormat(dlg.pageFormat());
download->setPath(dlg.filePath());
}
BrowserApplication::downloadManager()->download(download);
download->accept();
#endif
#else
Q_UNUSED(download);
#endif
}
void SieveEditorWebEngineView::contextMenuEvent(QContextMenuEvent *ev) void SieveEditorWebEngineView::contextMenuEvent(QContextMenuEvent *ev)
{ {
QMenu menu; QMenu menu;
...@@ -74,6 +99,12 @@ void SieveEditorWebEngineView::contextMenuEvent(QContextMenuEvent *ev) ...@@ -74,6 +99,12 @@ void SieveEditorWebEngineView::contextMenuEvent(QContextMenuEvent *ev)
if (act->isEnabled()) { if (act->isEnabled()) {
menu.addAction(act); menu.addAction(act);
} }
#endif
#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
act = pageAction(QWebEnginePage::SavePage);
if (act->isEnabled()) {
menu.addAction(act);
}
#endif #endif
menu.exec(ev->globalPos()); menu.exec(ev->globalPos());
} }
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#define SIEVEEDITORWEBENGINEVIEW_H #define SIEVEEDITORWEBENGINEVIEW_H
#include <QWebEngineView> #include <QWebEngineView>
class QWebEngineDownloadItem;
namespace KSieveUi namespace KSieveUi
{ {
class SieveEditorWebEngineView : public QWebEngineView class SieveEditorWebEngineView : public QWebEngineView
...@@ -29,6 +29,8 @@ public: ...@@ -29,6 +29,8 @@ public:
explicit SieveEditorWebEngineView(QWidget *parent = Q_NULLPTR); explicit SieveEditorWebEngineView(QWidget *parent = Q_NULLPTR);
~SieveEditorWebEngineView(); ~SieveEditorWebEngineView();
private Q_SLOTS:
void downloadRequested(QWebEngineDownloadItem*);
protected: protected:
void contextMenuEvent(QContextMenuEvent *ev) Q_DECL_OVERRIDE; void contextMenuEvent(QContextMenuEvent *ev) 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