diff options
Diffstat (limited to 'src/widgets')
| -rw-r--r-- | src/widgets/BrowserApp.cpp | 8 | ||||
| -rw-r--r-- | src/widgets/BrowserApp.hpp | 3 | ||||
| -rw-r--r-- | src/widgets/BrowserWindow.cpp | 7 | ||||
| -rw-r--r-- | src/widgets/WebViewStack.cpp | 7 | ||||
| -rw-r--r-- | src/widgets/WebViewStack.hpp | 1 |
5 files changed, 25 insertions, 1 deletions
diff --git a/src/widgets/BrowserApp.cpp b/src/widgets/BrowserApp.cpp index 4a43dfb..9b65b3a 100644 --- a/src/widgets/BrowserApp.cpp +++ b/src/widgets/BrowserApp.cpp @@ -20,6 +20,13 @@ BrowserApp::BrowserApp() { // NOTE: TMP lua.load_file_sync("./config.lua"); + // Initializes profile + QList profiles{&default_profile}; + for (auto *profile : profiles) { + profile->setDownloadPath(configuration.downloads_dir()); + profile->setHttpUserAgent(configuration.user_agent()); + } + connect(&window_action_router, &WindowActionRouter::new_window_requested, this, [this](const QUrl &url) { create_window({url.toString()}); }); }; @@ -28,6 +35,7 @@ BrowserWindow *BrowserApp::create_window(const QStringList &urls) { auto *window = new BrowserWindow((const Configuration &)configuration, urls); window->setWindowTitle("null-browser"); WindowActionRouter::instance().add_window(window); + window->show(); return window; } diff --git a/src/widgets/BrowserApp.hpp b/src/widgets/BrowserApp.hpp index 1b8fdcf..90d1ae7 100644 --- a/src/widgets/BrowserApp.hpp +++ b/src/widgets/BrowserApp.hpp @@ -1,6 +1,7 @@ #pragma once #include "widgets/BrowserWindow.hpp" +#include <qlist.h> class BrowserApp : public QObject { Q_OBJECT @@ -15,4 +16,6 @@ protected: private: Configuration configuration; + QWebEngineProfile default_profile{"default"}; + QList<QWebEngineProfile *> profiles{&default_profile}; }; diff --git a/src/widgets/BrowserWindow.cpp b/src/widgets/BrowserWindow.cpp index dbefdd6..5a8a062 100644 --- a/src/widgets/BrowserWindow.cpp +++ b/src/widgets/BrowserWindow.cpp @@ -21,8 +21,13 @@ BrowserWindow::BrowserWindow(const Configuration &configuration, const QStringLi layout->setStackingMode(QStackedLayout::StackAll); centralWidget()->setLayout(layout); + // Webengine profile + auto *profile = new QWebEngineProfile("null-browser"); + profile->setDownloadPath(configuration.downloads_dir()); + profile->setHttpUserAgent(configuration.user_agent()); + // Web engine - auto *webview_stack = new WebViewStack(&configuration, new QWebEngineProfile("null-browser")); + auto *webview_stack = new WebViewStack(&configuration, profile); layout->addWidget(webview_stack); // Open webviews for given urls diff --git a/src/widgets/WebViewStack.cpp b/src/widgets/WebViewStack.cpp index bdec508..258fbc6 100644 --- a/src/widgets/WebViewStack.cpp +++ b/src/widgets/WebViewStack.cpp @@ -21,6 +21,7 @@ WebViewStack::WebViewStack(const Configuration *configuration, QWebEngineProfile connect(layout, &QStackedLayout::currentChanged, this, &WebViewStack::current_webview_title_changed); + connect(profile, &QWebEngineProfile::downloadRequested, this, &WebViewStack::on_download_request); } void WebViewStack::open_url(const QUrl &url, OpenType open_type, WebViewId webview_id) { @@ -93,6 +94,12 @@ void WebViewStack::on_new_webview_request(const QWebEngineNewWindowRequest &requ } } +void WebViewStack::on_download_request(QWebEngineDownloadRequest *download) { + qDebug() << "DOWNLOADING" << download->downloadDirectory() << download->downloadFileName(); + emit download->accept(); + // TODO: Emit event to see download progress +} + int32_t WebViewStack::get_webview_index(WebViewId webview_id) { if (webview_id == 0) { // TODO: Check how to detect "active" window before qapp start (lua init)? diff --git a/src/widgets/WebViewStack.hpp b/src/widgets/WebViewStack.hpp index 8f66c09..05362d6 100644 --- a/src/widgets/WebViewStack.hpp +++ b/src/widgets/WebViewStack.hpp @@ -57,6 +57,7 @@ protected: WebView *create_new_webview(const QUrl &url, bool focus = false); int32_t get_webview_index(WebViewId webview_id); WebView *get_webview(WebViewId webview_id); + void on_download_request(QWebEngineDownloadRequest *download); public slots: void open_url(const QUrl &url, OpenType open_type = OpenType::OpenUrl, WebViewId webview_id = 0); |
