mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-22 17:31:58 -05:00
Ladybird+BrowserSettings: Load the NTP/home resource files with LibWeb
This commit is contained in:
parent
947136ca8d
commit
bacf3cede4
7 changed files with 12 additions and 34 deletions
|
@ -40,7 +40,7 @@
|
|||
<body>
|
||||
<main>
|
||||
<br>
|
||||
<img src="../icons/32x32/app-browser.png" width="64" height="64"><br><br>
|
||||
<img src="resource://icons/32x32/app-browser.png" width="64" height="64"><br><br>
|
||||
<form>
|
||||
<input type="search" name="q" id="user_query"><br><br>
|
||||
<div id="search-buttons">
|
||||
|
|
|
@ -57,7 +57,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto database = TRY(WebView::Database::create(move(sql_server_paths)));
|
||||
auto cookie_jar = TRY(WebView::CookieJar::create(*database));
|
||||
|
||||
URL new_tab_page_url = Browser::default_new_tab_url();
|
||||
URL new_tab_page_url = Browser::default_new_tab_url;
|
||||
Vector<URL> initial_urls;
|
||||
|
||||
for (auto const& raw_url : raw_urls) {
|
||||
|
|
|
@ -82,7 +82,7 @@ void Settings::set_autocomplete_engine(EngineProvider const& engine_provider)
|
|||
|
||||
QString Settings::new_tab_page()
|
||||
{
|
||||
static auto const default_new_tab_url = qstring_from_ak_string(Browser::default_new_tab_url());
|
||||
static auto const default_new_tab_url = qstring_from_ak_string(Browser::default_new_tab_url);
|
||||
return m_qsettings->value("new_tab_page", default_new_tab_url).toString();
|
||||
}
|
||||
|
||||
|
|
|
@ -275,7 +275,7 @@ void BrowserWindow::build_menus()
|
|||
|
||||
m_change_homepage_action = GUI::Action::create(
|
||||
"Set Homepage URL...", g_icon_bag.go_home, [this](auto&) {
|
||||
String homepage_url = String::from_byte_string(Config::read_string("Browser"sv, "Preferences"sv, "Home"sv, Browser::default_homepage_url())).release_value_but_fixme_should_propagate_errors();
|
||||
String homepage_url = String::from_byte_string(Config::read_string("Browser"sv, "Preferences"sv, "Home"sv, Browser::default_homepage_url)).release_value_but_fixme_should_propagate_errors();
|
||||
if (GUI::InputBox::show(this, homepage_url, "Enter a URL:"sv, "Change Homepage"sv) == GUI::InputBox::ExecResult::OK) {
|
||||
if (URL(homepage_url).is_valid()) {
|
||||
Config::write_string("Browser"sv, "Preferences"sv, "Home"sv, homepage_url);
|
||||
|
|
|
@ -133,8 +133,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
|
||||
auto app_icon = GUI::Icon::default_icon("app-browser"sv);
|
||||
|
||||
Browser::g_home_url = Config::read_string("Browser"sv, "Preferences"sv, "Home"sv, Browser::default_homepage_url());
|
||||
Browser::g_new_tab_url = Config::read_string("Browser"sv, "Preferences"sv, "NewTab"sv, Browser::default_new_tab_url());
|
||||
Browser::g_home_url = Config::read_string("Browser"sv, "Preferences"sv, "Home"sv, Browser::default_homepage_url);
|
||||
Browser::g_new_tab_url = Config::read_string("Browser"sv, "Preferences"sv, "NewTab"sv, Browser::default_new_tab_url);
|
||||
Browser::g_search_engine = Config::read_string("Browser"sv, "Preferences"sv, "SearchEngine"sv, WebView::default_search_engine().query_url);
|
||||
Browser::g_content_filters_enabled = Config::read_bool("Browser"sv, "Preferences"sv, "EnableContentFilters"sv, Browser::default_enable_content_filters);
|
||||
Browser::g_autoplay_allowed_on_all_websites = Config::read_bool("Browser"sv, "Preferences"sv, "AllowAutoplayOnAllWebsites"sv, Browser::default_allow_autoplay_on_all_websites);
|
||||
|
|
|
@ -107,11 +107,11 @@ ErrorOr<NonnullRefPtr<BrowserSettingsWidget>> BrowserSettingsWidget::create()
|
|||
ErrorOr<void> BrowserSettingsWidget::setup()
|
||||
{
|
||||
m_homepage_url_textbox = find_descendant_of_type_named<GUI::TextBox>("homepage_url_textbox");
|
||||
m_homepage_url_textbox->set_text(Config::read_string("Browser"sv, "Preferences"sv, "Home"sv, Browser::default_homepage_url()), GUI::AllowCallback::No);
|
||||
m_homepage_url_textbox->set_text(Config::read_string("Browser"sv, "Preferences"sv, "Home"sv, Browser::default_homepage_url), GUI::AllowCallback::No);
|
||||
m_homepage_url_textbox->on_change = [&]() { set_modified(true); };
|
||||
|
||||
m_new_tab_url_textbox = find_descendant_of_type_named<GUI::TextBox>("new_tab_url_textbox");
|
||||
m_new_tab_url_textbox->set_text(Config::read_string("Browser"sv, "Preferences"sv, "NewTab"sv, Browser::default_new_tab_url()), GUI::AllowCallback::No);
|
||||
m_new_tab_url_textbox->set_text(Config::read_string("Browser"sv, "Preferences"sv, "NewTab"sv, Browser::default_new_tab_url), GUI::AllowCallback::No);
|
||||
m_new_tab_url_textbox->on_change = [&]() { set_modified(true); };
|
||||
|
||||
m_color_scheme_combobox = find_descendant_of_type_named<GUI::ComboBox>("color_scheme_combobox");
|
||||
|
@ -244,8 +244,8 @@ void BrowserSettingsWidget::apply_settings()
|
|||
|
||||
void BrowserSettingsWidget::reset_default_values()
|
||||
{
|
||||
m_homepage_url_textbox->set_text(Browser::default_homepage_url());
|
||||
m_new_tab_url_textbox->set_text(Browser::default_new_tab_url());
|
||||
m_homepage_url_textbox->set_text(Browser::default_homepage_url);
|
||||
m_new_tab_url_textbox->set_text(Browser::default_new_tab_url);
|
||||
m_show_bookmarks_bar_checkbox->set_checked(Browser::default_show_bookmarks_bar);
|
||||
set_color_scheme(Browser::default_color_scheme);
|
||||
m_auto_close_download_windows_checkbox->set_checked(Browser::default_close_download_widget_on_finish);
|
||||
|
|
|
@ -6,38 +6,16 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/String.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <LibCore/Resource.h>
|
||||
|
||||
namespace Browser {
|
||||
|
||||
static constexpr StringView default_homepage_url = "resource://html/misc/welcome.html"sv;
|
||||
static constexpr StringView default_new_tab_url = "resource://ladybird/new-tab.html"sv;
|
||||
static constexpr StringView default_color_scheme = "auto"sv;
|
||||
static constexpr bool default_enable_content_filters = true;
|
||||
static constexpr bool default_show_bookmarks_bar = true;
|
||||
static constexpr bool default_close_download_widget_on_finish = false;
|
||||
static constexpr bool default_allow_autoplay_on_all_websites = false;
|
||||
|
||||
inline String const& default_homepage_url()
|
||||
{
|
||||
// FIXME: Teach LibWeb how to load resource:// URLs, rather than converting to a file:// URL here.
|
||||
static auto default_homepage_url = []() {
|
||||
static constexpr auto url = "resource://html/misc/welcome.html"sv;
|
||||
return MUST(Core::Resource::load_from_uri(url))->file_url();
|
||||
}();
|
||||
|
||||
return default_homepage_url;
|
||||
}
|
||||
|
||||
inline String const& default_new_tab_url()
|
||||
{
|
||||
// FIXME: Teach LibWeb how to load resource:// URLs, rather than converting to a file:// URL here.
|
||||
static auto default_new_tab_url = []() {
|
||||
static constexpr auto url = "resource://ladybird/new-tab.html"sv;
|
||||
return MUST(Core::Resource::load_from_uri(url))->file_url();
|
||||
}();
|
||||
|
||||
return default_new_tab_url;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue