aboutsummaryrefslogtreecommitdiff
path: root/src/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/BrowserManager.cpp27
-rw-r--r--src/widgets/MainWindow.cpp19
2 files changed, 43 insertions, 3 deletions
diff --git a/src/widgets/BrowserManager.cpp b/src/widgets/BrowserManager.cpp
index a2390fc..5ac6479 100644
--- a/src/widgets/BrowserManager.cpp
+++ b/src/widgets/BrowserManager.cpp
@@ -16,6 +16,23 @@ BrowserManager::BrowserManager(QWebEngineProfile *profile) : QWidget() {
createNewWebView(BrowserManager::NewtabURL, true);
}
+void BrowserManager::openUrl(QUrl url, OpenType openType) {
+ switch (openType) {
+ case OpenType::OpenUrl:
+ setCurrentUrl(url);
+ break;
+ case OpenType::OpenUrlInTab:
+ createNewWebView(url, true);
+ break;
+ case OpenType::OpenUrlInBgTab:
+ createNewWebView(url, false);
+ break;
+ case OpenType::OpenUrlInWindow:
+ // TODO: impl
+ break;
+ }
+}
+
QWebEngineView *BrowserManager::createNewWebView(QUrl url, bool focus) {
auto webview = new QWebEngineView(profile);
webview->setUrl(url);
@@ -24,6 +41,16 @@ QWebEngineView *BrowserManager::createNewWebView(QUrl url, bool focus) {
connect(webview->page(), &QWebEnginePage::newWindowRequested, this,
&BrowserManager::onNewWebViewRequest);
+ // connect(webview->page(), &QWebEnginePage::windowCloseRequested, this,
+ // [this, webview]() {
+ // for (int i = 0; i <= this->webViewList.length(); i++) {
+ // auto w = this->webViewList.at(0);
+ // printf("::::: %d\n\n", w == webview);
+ // if (w == webview) {
+ // this->closeWebView(i);
+ // }
+ // }
+ // });
if (focus)
focusWebView(webViewList.length() - 1);
diff --git a/src/widgets/MainWindow.cpp b/src/widgets/MainWindow.cpp
index e660e52..14f6aa7 100644
--- a/src/widgets/MainWindow.cpp
+++ b/src/widgets/MainWindow.cpp
@@ -23,7 +23,7 @@ MainWindow::MainWindow() {
layout->addWidget(browserManager);
// Command input
- commandInput = new CommandInput(browserManager->currentUrl().toString());
+ commandInput = new CommandInput;
hideURLInput();
commandInput->move(0, 0);
connect(commandInput, &CommandInput::submitted, this,
@@ -31,6 +31,13 @@ MainWindow::MainWindow() {
connect(commandInput, &CommandInput::cancelled, this,
&MainWindow::hideURLInput);
layout->addWidget(commandInput);
+
+ // Lua runtime
+ luaRuntime = LuaRuntime::instance();
+ connect(luaRuntime, &LuaRuntime::urlOpenned, this,
+ [this](QString url, OpenType openType) {
+ this->browserManager->openUrl(QUrl(url), openType);
+ });
}
void MainWindow::hideURLInput() {
@@ -46,8 +53,14 @@ void MainWindow::showURLInput() {
}
void MainWindow::evaluateCommand(QString command) {
- if (!command.isEmpty())
- browserManager->setCurrentUrl(command);
+ if (!command.isEmpty()) {
+ // TODO: Temporary hack
+ if (command.startsWith("lua ")) {
+ luaRuntime->evaluate(command.slice(4).toStdString().c_str());
+ } else {
+ browserManager->setCurrentUrl(command);
+ }
+ }
hideURLInput();
}