mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-22 17:24:48 -05:00
Ladybird/Qt: Add setting for preferred languages
This commit is contained in:
parent
2ca8fd1832
commit
132ab775d8
Notes:
github-actions[bot]
2024-07-25 10:39:53 +00:00
Author: https://github.com/jamierocks Commit: https://github.com/LadybirdBrowser/ladybird/commit/132ab775d8b Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/796 Reviewed-by: https://github.com/tcl3 ✅
7 changed files with 52 additions and 0 deletions
|
@ -104,6 +104,18 @@ BrowserWindow::BrowserWindow(Vector<URL::URL> const& initial_urls, WebView::Cook
|
|||
});
|
||||
});
|
||||
|
||||
QObject::connect(Settings::the(), &Settings::preferred_languages_changed, this, [this](QStringList languages) {
|
||||
Vector<String> preferred_languages;
|
||||
preferred_languages.ensure_capacity(languages.length());
|
||||
for (auto& language : languages) {
|
||||
preferred_languages.append(ak_string_from_qstring(language));
|
||||
}
|
||||
|
||||
for_each_tab([preferred_languages](auto& tab) {
|
||||
tab.set_preferred_languages(preferred_languages);
|
||||
});
|
||||
});
|
||||
|
||||
m_hamburger_menu = new HamburgerMenu(this);
|
||||
|
||||
if (!Settings::the()->show_menubar())
|
||||
|
@ -826,11 +838,18 @@ void BrowserWindow::initialize_tab(Tab* tab)
|
|||
m_tabs_container->setTabIcon(m_tabs_container->indexOf(tab), tab->favicon());
|
||||
create_close_button_for_tab(tab);
|
||||
|
||||
Vector<String> preferred_languages;
|
||||
preferred_languages.ensure_capacity(Settings::the()->preferred_languages().length());
|
||||
for (auto& language : Settings::the()->preferred_languages()) {
|
||||
preferred_languages.append(ak_string_from_qstring(language));
|
||||
}
|
||||
|
||||
tab->set_line_box_borders(m_show_line_box_borders_action->isChecked());
|
||||
tab->set_scripting(m_enable_scripting_action->isChecked());
|
||||
tab->set_block_popups(m_block_pop_ups_action->isChecked());
|
||||
tab->set_same_origin_policy(m_enable_same_origin_policy_action->isChecked());
|
||||
tab->set_user_agent_string(user_agent_string());
|
||||
tab->set_preferred_languages(preferred_languages);
|
||||
tab->set_navigator_compatibility_mode(navigator_compatibility_mode());
|
||||
tab->set_enable_do_not_track(Settings::the()->enable_do_not_track());
|
||||
tab->view().set_preferred_color_scheme(m_preferred_color_scheme);
|
||||
|
|
|
@ -74,6 +74,17 @@ void Settings::set_search_engine(WebView::SearchEngine search_engine)
|
|||
emit search_engine_changed(m_search_engine);
|
||||
}
|
||||
|
||||
QStringList Settings::preferred_languages()
|
||||
{
|
||||
return m_qsettings->value("preferred_languages").toStringList();
|
||||
}
|
||||
|
||||
void Settings::set_preferred_languages(QStringList const& languages)
|
||||
{
|
||||
m_qsettings->setValue("preferred_languages", languages);
|
||||
emit preferred_languages_changed(languages);
|
||||
}
|
||||
|
||||
Settings::EngineProvider Settings::autocomplete_engine()
|
||||
{
|
||||
EngineProvider engine_provider;
|
||||
|
|
|
@ -47,6 +47,9 @@ public:
|
|||
WebView::SearchEngine search_engine() const { return m_search_engine; }
|
||||
void set_search_engine(WebView::SearchEngine engine);
|
||||
|
||||
QStringList preferred_languages();
|
||||
void set_preferred_languages(QStringList const& languages);
|
||||
|
||||
struct EngineProvider {
|
||||
QString name;
|
||||
QString url;
|
||||
|
@ -71,6 +74,7 @@ signals:
|
|||
void show_menubar_changed(bool show_menubar);
|
||||
void enable_search_changed(bool enable);
|
||||
void search_engine_changed(WebView::SearchEngine engine);
|
||||
void preferred_languages_changed(QStringList const& languages);
|
||||
void enable_do_not_track_changed(bool enable);
|
||||
|
||||
protected:
|
||||
|
|
|
@ -28,6 +28,15 @@ SettingsDialog::SettingsDialog(QMainWindow* window)
|
|||
m_search_engine_dropdown->setText(qstring_from_ak_string(Settings::the()->search_engine().name));
|
||||
m_search_engine_dropdown->setMaximumWidth(200);
|
||||
|
||||
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();
|
||||
});
|
||||
|
||||
m_enable_autocomplete = new QCheckBox(this);
|
||||
m_enable_autocomplete->setChecked(Settings::the()->enable_autocomplete());
|
||||
|
||||
|
@ -61,6 +70,7 @@ SettingsDialog::SettingsDialog(QMainWindow* window)
|
|||
m_layout->addRow(new QLabel("Page on New Tab", this), m_new_tab_page);
|
||||
m_layout->addRow(new QLabel("Enable Search", this), m_enable_search);
|
||||
m_layout->addRow(new QLabel("Search Engine", this), m_search_engine_dropdown);
|
||||
m_layout->addRow(new QLabel("Preferred Language(s)", this), m_preferred_languages);
|
||||
m_layout->addRow(new QLabel("Enable Autocomplete", this), m_enable_autocomplete);
|
||||
m_layout->addRow(new QLabel("Autocomplete Engine", this), m_autocomplete_engine_dropdown);
|
||||
m_layout->addRow(new QLabel("Send web sites a \"Do Not Track\" request", this), m_enable_do_not_track);
|
||||
|
|
|
@ -30,6 +30,7 @@ private:
|
|||
QLineEdit* m_new_tab_page { nullptr };
|
||||
QCheckBox* m_enable_search { nullptr };
|
||||
QPushButton* m_search_engine_dropdown { nullptr };
|
||||
QLineEdit* m_preferred_languages { nullptr };
|
||||
QCheckBox* m_enable_autocomplete { nullptr };
|
||||
QPushButton* m_autocomplete_engine_dropdown { nullptr };
|
||||
QCheckBox* m_enable_do_not_track { nullptr };
|
||||
|
|
|
@ -1005,6 +1005,11 @@ void Tab::set_navigator_compatibility_mode(ByteString const& compatibility_mode)
|
|||
debug_request("navigator-compatibility-mode", compatibility_mode);
|
||||
}
|
||||
|
||||
void Tab::set_preferred_languages(Vector<String> const& preferred_languages)
|
||||
{
|
||||
m_view->set_preferred_languages(preferred_languages);
|
||||
}
|
||||
|
||||
void Tab::set_enable_do_not_track(bool enable)
|
||||
{
|
||||
m_view->set_enable_do_not_track(enable);
|
||||
|
|
|
@ -74,6 +74,8 @@ public:
|
|||
void set_user_agent_string(ByteString const&);
|
||||
void set_navigator_compatibility_mode(ByteString const&);
|
||||
|
||||
void set_preferred_languages(Vector<String> const& preferred_languages);
|
||||
|
||||
void set_enable_do_not_track(bool);
|
||||
|
||||
bool url_is_hidden() const { return m_location_edit->url_is_hidden(); }
|
||||
|
|
Loading…
Reference in a new issue