2022-07-14 04:08:30 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2022, Filiph Sandström <filiph.sandstrom@filfatstudios.com>
|
2023-05-31 01:44:16 +00:00
|
|
|
* Copyright (c) 2023, Cameron Youell <cameronyouell@gmail.com>
|
2022-07-14 04:08:30 +00:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
2024-03-18 03:22:27 +00:00
|
|
|
#include <LibURL/URL.h>
|
2024-09-22 22:12:36 +00:00
|
|
|
#include <LibWebView/Application.h>
|
2023-10-19 20:08:31 +00:00
|
|
|
#include <LibWebView/SearchEngine.h>
|
2024-11-09 17:50:33 +00:00
|
|
|
#include <UI/Qt/Settings.h>
|
|
|
|
#include <UI/Qt/SettingsDialog.h>
|
|
|
|
#include <UI/Qt/StringUtils.h>
|
|
|
|
|
2022-07-14 04:36:11 +00:00
|
|
|
#include <QLabel>
|
2023-05-31 01:44:16 +00:00
|
|
|
#include <QMenu>
|
2022-07-14 04:36:11 +00:00
|
|
|
|
2023-08-02 17:52:59 +00:00
|
|
|
namespace Ladybird {
|
|
|
|
|
2022-07-14 04:08:30 +00:00
|
|
|
SettingsDialog::SettingsDialog(QMainWindow* window)
|
2023-12-04 14:39:22 +00:00
|
|
|
: QDialog(window)
|
|
|
|
, m_window(window)
|
2022-07-14 04:08:30 +00:00
|
|
|
{
|
2022-10-01 18:46:24 +00:00
|
|
|
m_layout = new QFormLayout(this);
|
2022-07-14 04:36:11 +00:00
|
|
|
|
2023-12-04 14:39:22 +00:00
|
|
|
m_enable_search = new QCheckBox(this);
|
2023-05-31 01:44:16 +00:00
|
|
|
m_enable_search->setChecked(Settings::the()->enable_search());
|
|
|
|
|
2023-12-04 14:39:22 +00:00
|
|
|
m_search_engine_dropdown = new QPushButton(this);
|
2023-12-04 14:55:47 +00:00
|
|
|
m_search_engine_dropdown->setText(qstring_from_ak_string(Settings::the()->search_engine().name));
|
2023-10-20 14:00:41 +00:00
|
|
|
m_search_engine_dropdown->setMaximumWidth(200);
|
2023-05-31 01:44:16 +00:00
|
|
|
|
2024-07-23 20:11:47 +00:00
|
|
|
m_preferred_languages = new QLineEdit(this);
|
|
|
|
m_preferred_languages->setText(Settings::the()->preferred_languages().join(","));
|
|
|
|
QObject::connect(m_preferred_languages, &QLineEdit::editingFinished, this, [this] {
|
|
|
|
Settings::the()->set_preferred_languages(m_preferred_languages->text().split(","));
|
|
|
|
});
|
|
|
|
QObject::connect(m_preferred_languages, &QLineEdit::returnPressed, this, [this] {
|
|
|
|
close();
|
|
|
|
});
|
|
|
|
|
2023-12-04 14:39:22 +00:00
|
|
|
m_enable_autocomplete = new QCheckBox(this);
|
2023-05-31 01:44:16 +00:00
|
|
|
m_enable_autocomplete->setChecked(Settings::the()->enable_autocomplete());
|
|
|
|
|
2023-12-04 14:39:22 +00:00
|
|
|
m_autocomplete_engine_dropdown = new QPushButton(this);
|
2023-05-31 01:44:16 +00:00
|
|
|
m_autocomplete_engine_dropdown->setText(Settings::the()->autocomplete_engine().name);
|
2023-10-20 14:00:41 +00:00
|
|
|
m_autocomplete_engine_dropdown->setMaximumWidth(200);
|
2023-05-31 01:44:16 +00:00
|
|
|
|
2023-12-04 14:39:22 +00:00
|
|
|
m_new_tab_page = new QLineEdit(this);
|
2023-05-31 01:44:16 +00:00
|
|
|
m_new_tab_page->setText(Settings::the()->new_tab_page());
|
2023-08-31 10:51:27 +00:00
|
|
|
QObject::connect(m_new_tab_page, &QLineEdit::textChanged, this, [this] {
|
2023-12-04 15:08:16 +00:00
|
|
|
auto url_string = ak_string_from_qstring(m_new_tab_page->text());
|
2024-03-18 03:22:27 +00:00
|
|
|
m_new_tab_page->setStyleSheet(URL::URL(url_string).is_valid() ? "" : "border: 1px solid red;");
|
2023-08-31 10:51:27 +00:00
|
|
|
});
|
|
|
|
QObject::connect(m_new_tab_page, &QLineEdit::editingFinished, this, [this] {
|
2023-12-04 15:08:16 +00:00
|
|
|
auto url_string = ak_string_from_qstring(m_new_tab_page->text());
|
2024-03-18 03:22:27 +00:00
|
|
|
if (URL::URL(url_string).is_valid())
|
2023-08-31 10:51:27 +00:00
|
|
|
Settings::the()->set_new_tab_page(m_new_tab_page->text());
|
|
|
|
});
|
|
|
|
QObject::connect(m_new_tab_page, &QLineEdit::returnPressed, this, [this] {
|
|
|
|
close();
|
|
|
|
});
|
2023-05-31 01:44:16 +00:00
|
|
|
|
2024-07-02 19:31:14 +00:00
|
|
|
m_enable_do_not_track = new QCheckBox(this);
|
|
|
|
m_enable_do_not_track->setChecked(Settings::the()->enable_do_not_track());
|
2024-10-15 06:39:22 +00:00
|
|
|
#if (QT_VERSION > QT_VERSION_CHECK(6, 7, 0))
|
|
|
|
QObject::connect(m_enable_do_not_track, &QCheckBox::checkStateChanged, this, [&](int state) {
|
|
|
|
#else
|
2024-07-02 19:31:14 +00:00
|
|
|
QObject::connect(m_enable_do_not_track, &QCheckBox::stateChanged, this, [&](int state) {
|
2024-10-15 06:39:22 +00:00
|
|
|
#endif
|
2024-07-02 19:31:14 +00:00
|
|
|
Settings::the()->set_enable_do_not_track(state == Qt::Checked);
|
|
|
|
});
|
|
|
|
|
2024-09-22 22:12:36 +00:00
|
|
|
m_enable_autoplay = new QCheckBox(this);
|
|
|
|
if (WebView::Application::web_content_options().enable_autoplay == WebView::EnableAutoplay::Yes) {
|
|
|
|
m_enable_autoplay->setChecked(true);
|
|
|
|
} else {
|
|
|
|
m_enable_autoplay->setChecked(Settings::the()->enable_autoplay());
|
|
|
|
}
|
|
|
|
|
2024-10-15 06:39:22 +00:00
|
|
|
#if (QT_VERSION > QT_VERSION_CHECK(6, 7, 0))
|
|
|
|
QObject::connect(m_enable_autoplay, &QCheckBox::checkStateChanged, this, [&](int state) {
|
|
|
|
#else
|
2024-09-22 22:12:36 +00:00
|
|
|
QObject::connect(m_enable_autoplay, &QCheckBox::stateChanged, this, [&](int state) {
|
2024-10-15 06:39:22 +00:00
|
|
|
#endif
|
2024-09-22 22:12:36 +00:00
|
|
|
Settings::the()->set_enable_autoplay(state == Qt::Checked);
|
|
|
|
});
|
|
|
|
|
2023-05-31 01:44:16 +00:00
|
|
|
setup_search_engines();
|
|
|
|
|
2023-01-20 23:30:05 +00:00
|
|
|
m_layout->addRow(new QLabel("Page on New Tab", this), m_new_tab_page);
|
2023-05-31 01:44:16 +00:00
|
|
|
m_layout->addRow(new QLabel("Enable Search", this), m_enable_search);
|
|
|
|
m_layout->addRow(new QLabel("Search Engine", this), m_search_engine_dropdown);
|
2024-07-23 20:11:47 +00:00
|
|
|
m_layout->addRow(new QLabel("Preferred Language(s)", this), m_preferred_languages);
|
2023-05-31 01:44:16 +00:00
|
|
|
m_layout->addRow(new QLabel("Enable Autocomplete", this), m_enable_autocomplete);
|
|
|
|
m_layout->addRow(new QLabel("Autocomplete Engine", this), m_autocomplete_engine_dropdown);
|
2024-07-02 19:31:14 +00:00
|
|
|
m_layout->addRow(new QLabel("Send web sites a \"Do Not Track\" request", this), m_enable_do_not_track);
|
2024-09-22 22:12:36 +00:00
|
|
|
m_layout->addRow(new QLabel("Enable autoplay on all websites", this), m_enable_autoplay);
|
2022-07-14 04:08:30 +00:00
|
|
|
|
|
|
|
setWindowTitle("Settings");
|
|
|
|
setLayout(m_layout);
|
2023-10-20 13:40:11 +00:00
|
|
|
resize(600, 250);
|
2022-07-14 04:08:30 +00:00
|
|
|
}
|
2022-07-14 04:36:11 +00:00
|
|
|
|
2023-05-31 01:44:16 +00:00
|
|
|
void SettingsDialog::setup_search_engines()
|
|
|
|
{
|
2023-10-19 20:08:31 +00:00
|
|
|
// FIXME: These should be centralized in LibWebView.
|
2023-05-31 01:44:16 +00:00
|
|
|
Vector<Settings::EngineProvider> autocomplete_engines = {
|
|
|
|
{ "DuckDuckGo", "https://duckduckgo.com/ac/?q={}" },
|
|
|
|
{ "Google", "https://www.google.com/complete/search?client=chrome&q={}" },
|
|
|
|
{ "Yahoo", "https://search.yahoo.com/sugg/gossip/gossip-us-ura/?output=sd1&command={}" },
|
|
|
|
};
|
|
|
|
|
|
|
|
QMenu* search_engine_menu = new QMenu(this);
|
2023-10-19 20:08:31 +00:00
|
|
|
for (auto const& search_engine : WebView::search_engines()) {
|
2023-12-04 14:55:47 +00:00
|
|
|
auto search_engine_name = qstring_from_ak_string(search_engine.name);
|
2023-10-19 20:08:31 +00:00
|
|
|
QAction* action = new QAction(search_engine_name, this);
|
|
|
|
|
|
|
|
connect(action, &QAction::triggered, this, [&, search_engine_name = std::move(search_engine_name)]() {
|
2023-05-31 01:44:16 +00:00
|
|
|
Settings::the()->set_search_engine(search_engine);
|
2023-10-19 20:08:31 +00:00
|
|
|
m_search_engine_dropdown->setText(search_engine_name);
|
2023-05-31 01:44:16 +00:00
|
|
|
});
|
2023-10-19 20:08:31 +00:00
|
|
|
|
2023-05-31 01:44:16 +00:00
|
|
|
search_engine_menu->addAction(action);
|
|
|
|
}
|
|
|
|
m_search_engine_dropdown->setMenu(search_engine_menu);
|
|
|
|
m_search_engine_dropdown->setEnabled(Settings::the()->enable_search());
|
|
|
|
|
|
|
|
QMenu* autocomplete_engine_menu = new QMenu(this);
|
|
|
|
for (auto& autocomplete_engine : autocomplete_engines) {
|
|
|
|
QAction* action = new QAction(autocomplete_engine.name, this);
|
|
|
|
connect(action, &QAction::triggered, this, [&, autocomplete_engine] {
|
|
|
|
Settings::the()->set_autocomplete_engine(autocomplete_engine);
|
|
|
|
m_autocomplete_engine_dropdown->setText(autocomplete_engine.name);
|
|
|
|
});
|
|
|
|
autocomplete_engine_menu->addAction(action);
|
|
|
|
}
|
|
|
|
m_autocomplete_engine_dropdown->setMenu(autocomplete_engine_menu);
|
|
|
|
m_autocomplete_engine_dropdown->setEnabled(Settings::the()->enable_autocomplete());
|
|
|
|
|
2024-10-15 06:39:22 +00:00
|
|
|
#if (QT_VERSION > QT_VERSION_CHECK(6, 7, 0))
|
|
|
|
connect(m_enable_search, &QCheckBox::checkStateChanged, this, [&](int state) {
|
|
|
|
#else
|
2023-05-31 01:44:16 +00:00
|
|
|
connect(m_enable_search, &QCheckBox::stateChanged, this, [&](int state) {
|
2024-10-15 06:39:22 +00:00
|
|
|
#endif
|
2023-05-31 01:44:16 +00:00
|
|
|
Settings::the()->set_enable_search(state == Qt::Checked);
|
|
|
|
m_search_engine_dropdown->setEnabled(state == Qt::Checked);
|
|
|
|
});
|
|
|
|
|
2024-10-15 06:39:22 +00:00
|
|
|
#if (QT_VERSION > QT_VERSION_CHECK(6, 7, 0))
|
|
|
|
connect(m_enable_autocomplete, &QCheckBox::checkStateChanged, this, [&](int state) {
|
|
|
|
#else
|
2023-05-31 01:44:16 +00:00
|
|
|
connect(m_enable_autocomplete, &QCheckBox::stateChanged, this, [&](int state) {
|
2024-10-15 06:39:22 +00:00
|
|
|
#endif
|
2023-05-31 01:44:16 +00:00
|
|
|
Settings::the()->set_enable_autocomplete(state == Qt::Checked);
|
|
|
|
m_autocomplete_engine_dropdown->setEnabled(state == Qt::Checked);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-08-02 17:52:59 +00:00
|
|
|
}
|