From 17e9db4fa153f5ee0149f5de1b212984522d7d48 Mon Sep 17 00:00:00 2001 From: Federico Guerinoni Date: Sat, 21 Jan 2023 00:30:05 +0100 Subject: [PATCH] Ladybird: Add setting for page to open on new tab --- Ladybird/BrowserWindow.cpp | 5 ++--- Ladybird/Settings.cpp | 14 ++++++++++++-- Ladybird/Settings.h | 7 +++++-- Ladybird/SettingsDialog.cpp | 3 +++ Ladybird/SettingsDialog.h | 1 + Ladybird/main.cpp | 5 +++-- 6 files changed, 26 insertions(+), 9 deletions(-) diff --git a/Ladybird/BrowserWindow.cpp b/Ladybird/BrowserWindow.cpp index df3648ca5b..faccfc978a 100644 --- a/Ladybird/BrowserWindow.cpp +++ b/Ladybird/BrowserWindow.cpp @@ -305,7 +305,7 @@ BrowserWindow::BrowserWindow(Browser::CookieJar& cookie_jar, StringView webdrive }); QObject::connect(new_tab_action, &QAction::triggered, this, [this] { - new_tab("about:blank", Activate::Yes); + new_tab(s_settings->new_tab_page(), Activate::Yes); }); QObject::connect(settings_action, &QAction::triggered, this, [this] { new SettingsDialog(this); @@ -319,8 +319,7 @@ BrowserWindow::BrowserWindow(Browser::CookieJar& cookie_jar, StringView webdrive QObject::connect(m_tabs_container, &QTabWidget::tabCloseRequested, this, &BrowserWindow::close_tab); QObject::connect(close_current_tab_action, &QAction::triggered, this, &BrowserWindow::close_current_tab); - // We need to load *something* to make the JS console usable. - new_tab("about:blank", Activate::Yes); + new_tab(s_settings->new_tab_page(), Activate::Yes); setCentralWidget(m_tabs_container); } diff --git a/Ladybird/Settings.cpp b/Ladybird/Settings.cpp index 3e4e0fef3e..56baafb05d 100644 --- a/Ladybird/Settings.cpp +++ b/Ladybird/Settings.cpp @@ -8,9 +8,9 @@ namespace Browser { -Settings::Settings(QObject* parent) +Settings::Settings() { - m_qsettings = new QSettings("Serenity", "Ladybird", parent); + m_qsettings = new QSettings("Serenity", "Ladybird", this); } QString Settings::homepage() @@ -23,4 +23,14 @@ void Settings::set_homepage(QString const& homepage) m_qsettings->setValue("homepage", homepage); } +QString Settings::new_tab_page() +{ + return m_qsettings->value("new_tab_page", "about:blank").toString(); +} + +void Settings::set_new_tab_page(QString const& page) +{ + m_qsettings->setValue("new_tab_page", page); +} + } diff --git a/Ladybird/Settings.h b/Ladybird/Settings.h index dad9f1b9be..9069ba09aa 100644 --- a/Ladybird/Settings.h +++ b/Ladybird/Settings.h @@ -13,13 +13,16 @@ namespace Browser { -class Settings { +class Settings : public QObject { public: - Settings(QObject* parent); + Settings(); QString homepage(); void set_homepage(QString const& homepage); + QString new_tab_page(); + void set_new_tab_page(QString const& page); + private: QSettings* m_qsettings; }; diff --git a/Ladybird/SettingsDialog.cpp b/Ladybird/SettingsDialog.cpp index a9d231ad30..a3449d5929 100644 --- a/Ladybird/SettingsDialog.cpp +++ b/Ladybird/SettingsDialog.cpp @@ -16,9 +16,11 @@ SettingsDialog::SettingsDialog(QMainWindow* window) { m_layout = new QFormLayout(this); m_homepage = new QLineEdit(this); + m_new_tab_page = new QLineEdit(this); m_ok_button = new QPushButton("&Save", this); m_layout->addRow(new QLabel("HomePage", this), m_homepage); + m_layout->addRow(new QLabel("Page on New Tab", this), m_new_tab_page); m_layout->addWidget(m_ok_button); m_homepage->setText(s_settings->homepage()); @@ -44,4 +46,5 @@ void SettingsDialog::save() { // FIXME: Validate data. s_settings->set_homepage(m_homepage->text()); + s_settings->set_new_tab_page(m_new_tab_page->text()); } diff --git a/Ladybird/SettingsDialog.h b/Ladybird/SettingsDialog.h index 710f2b84bc..412186bfe1 100644 --- a/Ladybird/SettingsDialog.h +++ b/Ladybird/SettingsDialog.h @@ -25,5 +25,6 @@ private: QFormLayout* m_layout; QPushButton* m_ok_button { nullptr }; QLineEdit* m_homepage { nullptr }; + QLineEdit* m_new_tab_page { nullptr }; QMainWindow* m_window { nullptr }; }; diff --git a/Ladybird/main.cpp b/Ladybird/main.cpp index d8302b65c3..1e8c0aa5e6 100644 --- a/Ladybird/main.cpp +++ b/Ladybird/main.cpp @@ -9,6 +9,7 @@ #include "Settings.h" #include "Utilities.h" #include "WebContentView.h" +#include #include #include #include @@ -21,7 +22,7 @@ #include #include -Browser::Settings* s_settings; +AK::OwnPtr s_settings; static ErrorOr handle_attached_debugger() { @@ -106,8 +107,8 @@ ErrorOr serenity_main(Main::Arguments arguments) auto cookie_jar = TRY(Browser::CookieJar::create(*database)); + s_settings = adopt_own_if_nonnull(new Browser::Settings()); BrowserWindow window(cookie_jar, webdriver_content_ipc_path); - s_settings = new Browser::Settings(&window); window.setWindowTitle("Ladybird"); window.resize(800, 600); window.show();