aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2024-05-11 12:23:17 +0200
committerNathan Reiner <nathan@nathanreiner.xyz>2024-05-11 12:23:17 +0200
commit74bb7167422be687c3358ed10b9dab37cdd490a0 (patch)
tree51847ce45d42383848b0fc21c4f388fecd36a182 /src
parent23d60a7aeaafcae3f0613d3ce2169a437170458b (diff)
add basic download support
Diffstat (limited to 'src')
-rw-r--r--src/webwindow.cpp44
1 files changed, 32 insertions, 12 deletions
diff --git a/src/webwindow.cpp b/src/webwindow.cpp
index 0449bc9..0c8b663 100644
--- a/src/webwindow.cpp
+++ b/src/webwindow.cpp
@@ -1,13 +1,15 @@
+#include <QtCore/QProcess>
#include <QtGui/QCloseEvent>
#include <QtGui/QDesktopServices>
-#include <QtWebEngineCore/QWebEngineFullScreenRequest>
#include <QtWebEngineCore/QWebEngineCookieStore>
+#include <QtWebEngineCore/QWebEngineFullScreenRequest>
#include <QtWebEngineCore/QWebEngineNewWindowRequest>
#include <QtWidgets/QApplication>
-#include <QtCore/QProcess>
+#include <QtWidgets/QFileDialog>
#include <filesystem>
#include <iostream>
+#include "QtWebEngineCore/qwebenginedownloadrequest.h"
#include "permissionmanager.hpp"
#include "webwindow.hpp"
@@ -39,7 +41,8 @@ WebWindow::web_configure()
this->page.settings()->setAttribute(QWebEngineSettings::ScrollAnimatorEnabled,
false);
- this->page.settings()->setAttribute(QWebEngineSettings::FullScreenSupportEnabled, true);
+ this->page.settings()->setAttribute(
+ QWebEngineSettings::FullScreenSupportEnabled, true);
this->profile.setPushServiceEnabled(true);
@@ -49,20 +52,36 @@ WebWindow::web_configure()
this->permission_requested(origin, feature);
});
+ this->profile.connect(
+ &this->profile,
+ &QWebEngineProfile::downloadRequested,
+ [&](QWebEngineDownloadRequest *request) {
+ const QUrl url = QFileDialog::getSaveFileUrl(
+ this,
+ "",
+ QUrl(this->profile.downloadPath() + "/" + request->downloadFileName()));
+ if (!url.isEmpty()) {
+ request->setDownloadFileName(url.path());
+ request->accept();
+ }
+ });
+
this->page.connect(&this->page,
&QWebEnginePage::newWindowRequested,
[=](QWebEngineNewWindowRequest &request) {
QDesktopServices::openUrl(request.requestedUrl());
});
- this->page.connect(&this->page, &QWebEnginePage::fullScreenRequested, [=](QWebEngineFullScreenRequest request) {
- request.accept();
- if (request.toggleOn()) {
- this->showFullScreen();
- } else {
- this->showNormal();
- }
- });
+ this->page.connect(&this->page,
+ &QWebEnginePage::fullScreenRequested,
+ [=](QWebEngineFullScreenRequest request) {
+ request.accept();
+ if (request.toggleOn()) {
+ this->showFullScreen();
+ } else {
+ this->showNormal();
+ }
+ });
}
void
@@ -115,7 +134,8 @@ WebWindow::permissions()
void
WebWindow::reset_cookies()
{
- std::filesystem::remove_all(this->profile.persistentStoragePath().toStdString());
+ std::filesystem::remove_all(
+ this->profile.persistentStoragePath().toStdString());
QProcess process;
QStringList args = QApplication::instance()->arguments();