diff options
author | Nathan Reiner <nathan@nathanreiner.xyz> | 2024-09-21 12:55:37 +0200 |
---|---|---|
committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2024-09-21 12:55:37 +0200 |
commit | 21afec7d459855808444ef8157a2249b2fb2782c (patch) | |
tree | 837a9914bc75314ab6946f8b1a2a9f87c19cb0dc /src/webwindow.cpp | |
parent | 121297159b40b9cd8d5016893e83e9f01d0795ec (diff) |
resolve quit segfault
Diffstat (limited to 'src/webwindow.cpp')
-rw-r--r-- | src/webwindow.cpp | 129 |
1 files changed, 69 insertions, 60 deletions
diff --git a/src/webwindow.cpp b/src/webwindow.cpp index e8a83ad..823eec7 100644 --- a/src/webwindow.cpp +++ b/src/webwindow.cpp @@ -14,87 +14,90 @@ WebWindow::WebWindow(const QString &url) : QMainWindow() - , profile(QUrl(url).host()) - , page(&profile) - , perm((profile.persistentStoragePath() + "/permissions.state").toStdString()) { + this->profile = new QWebEngineProfile(QUrl(url).host()); + + this->page = new QWebEnginePage(this->profile); + this->perm = new PermissionManager( + (profile->persistentStoragePath() + "/permissions.state").toStdString()); + this->view = new QWebEngineView(this->page); + this->web_configure(); - this->profile.setPersistentCookiesPolicy( + this->profile->setPersistentCookiesPolicy( QWebEngineProfile::AllowPersistentCookies); - this->view.setPage(&this->page); - this->view.setUrl(url); + this->view->setUrl(url); - this->setCentralWidget(&this->view); + this->setCentralWidget(this->view); } void WebWindow::web_configure() { - this->page.settings()->setAttribute(QWebEngineSettings::ScreenCaptureEnabled, - true); + this->page->settings()->setAttribute(QWebEngineSettings::ScreenCaptureEnabled, + true); - this->page.settings()->setAttribute( + this->page->settings()->setAttribute( QWebEngineSettings::WebRTCPublicInterfacesOnly, false); - this->page.settings()->setAttribute(QWebEngineSettings::ScrollAnimatorEnabled, - false); - this->page.settings()->setAttribute( + this->page->settings()->setAttribute( + QWebEngineSettings::ScrollAnimatorEnabled, false); + this->page->settings()->setAttribute( QWebEngineSettings::FullScreenSupportEnabled, true); - this->profile.setPushServiceEnabled(true); - - this->page.connect(&this->page, - &QWebEnginePage::featurePermissionRequested, - [&](const QUrl origin, QWebEnginePage::Feature feature) { - 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->profile->setPushServiceEnabled(true); + + this->page->connect(this->page, + &QWebEnginePage::featurePermissionRequested, + [&](const QUrl origin, QWebEnginePage::Feature feature) { + 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(); + } + }); } void WebWindow::permission_requested(const QUrl origin, QWebEnginePage::Feature feature) { - if (this->perm.get(feature)) { - this->page.setFeaturePermission( + if (this->perm->get(feature)) { + this->page->setFeaturePermission( origin, feature, QWebEnginePage::PermissionGrantedByUser); } else { - this->page.setFeaturePermission( + this->page->setFeaturePermission( origin, feature, QWebEnginePage::PermissionDeniedByUser); } - this->page.setFeaturePermission( + this->page->setFeaturePermission( origin, feature, QWebEnginePage::PermissionUnknown); } @@ -108,33 +111,33 @@ WebWindow::closeEvent(QCloseEvent *event) void WebWindow::connect_icon_changed(std::function<void(const QIcon)> fn) { - this->view.connect(&this->view, &QWebEngineView::iconChanged, fn); + this->view->connect(this->view, &QWebEngineView::iconChanged, fn); } void WebWindow::connect_notification( std::function<void(std::unique_ptr<QWebEngineNotification>)> fn) { - this->profile.setNotificationPresenter(fn); + this->profile->setNotificationPresenter(fn); } void WebWindow::connect_title_changed(std::function<void(const QString)> fn) { - this->view.connect(&this->view, &QWebEngineView::titleChanged, fn); + this->view->connect(this->view, &QWebEngineView::titleChanged, fn); } PermissionManager & WebWindow::permissions() { - return this->perm; + return *this->perm; } void WebWindow::reset_cookies() { std::filesystem::remove_all( - this->profile.persistentStoragePath().toStdString()); + this->profile->persistentStoragePath().toStdString()); QProcess process; QStringList args = QApplication::instance()->arguments(); @@ -155,5 +158,11 @@ WebWindow::toggle_visibility() void WebWindow::quit() { + this->page->disconnect(); + this->view->disconnect(); + this->profile->disconnect(); + delete this->view; + delete this->page; + delete this->perm; QApplication::instance()->quit(); } |