mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:28:11 +00:00
BrowserSettings+Ladybird: Convert home / new tab page to resource URIs
This commit is contained in:
parent
1b30b510b9
commit
818471b7a7
6 changed files with 33 additions and 45 deletions
|
@ -24,22 +24,6 @@
|
||||||
# error "This project requires ARC"
|
# error "This project requires ARC"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static URL rebase_url_on_serenity_resource_root(StringView url_string)
|
|
||||||
{
|
|
||||||
URL url { url_string };
|
|
||||||
Vector<DeprecatedString> paths;
|
|
||||||
|
|
||||||
for (auto segment : s_serenity_resource_root.split('/'))
|
|
||||||
paths.append(move(segment));
|
|
||||||
|
|
||||||
for (size_t i = 0; i < url.path_segment_count(); ++i)
|
|
||||||
paths.append(url.path_segment_at_index(i));
|
|
||||||
|
|
||||||
url.set_paths(move(paths));
|
|
||||||
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
{
|
{
|
||||||
[Application sharedApplication];
|
[Application sharedApplication];
|
||||||
|
@ -66,7 +50,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
auto database = TRY(WebView::Database::create(move(sql_server_paths)));
|
auto database = TRY(WebView::Database::create(move(sql_server_paths)));
|
||||||
auto cookie_jar = TRY(WebView::CookieJar::create(*database));
|
auto cookie_jar = TRY(WebView::CookieJar::create(*database));
|
||||||
|
|
||||||
auto new_tab_page_url = rebase_url_on_serenity_resource_root(Browser::default_new_tab_url);
|
URL new_tab_page_url = Browser::default_new_tab_url();
|
||||||
Vector<URL> initial_urls;
|
Vector<URL> initial_urls;
|
||||||
|
|
||||||
for (auto const& raw_url : raw_urls) {
|
for (auto const& raw_url : raw_urls) {
|
||||||
|
|
|
@ -7,28 +7,10 @@
|
||||||
|
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
#include "StringUtils.h"
|
#include "StringUtils.h"
|
||||||
#include <AK/URL.h>
|
|
||||||
#include <BrowserSettings/Defaults.h>
|
#include <BrowserSettings/Defaults.h>
|
||||||
#include <Ladybird/Utilities.h>
|
|
||||||
|
|
||||||
namespace Ladybird {
|
namespace Ladybird {
|
||||||
|
|
||||||
static QString rebase_default_url_on_serenity_resource_root(StringView default_url)
|
|
||||||
{
|
|
||||||
URL url { default_url };
|
|
||||||
Vector<DeprecatedString> paths;
|
|
||||||
|
|
||||||
for (auto segment : s_serenity_resource_root.split('/'))
|
|
||||||
paths.append(move(segment));
|
|
||||||
|
|
||||||
for (size_t i = 0; i < url.path_segment_count(); ++i)
|
|
||||||
paths.append(url.path_segment_at_index(i));
|
|
||||||
|
|
||||||
url.set_paths(move(paths));
|
|
||||||
|
|
||||||
return qstring_from_ak_deprecated_string(url.to_deprecated_string());
|
|
||||||
}
|
|
||||||
|
|
||||||
Settings::Settings()
|
Settings::Settings()
|
||||||
: m_search_engine(WebView::default_search_engine())
|
: m_search_engine(WebView::default_search_engine())
|
||||||
{
|
{
|
||||||
|
@ -100,7 +82,7 @@ void Settings::set_autocomplete_engine(EngineProvider const& engine_provider)
|
||||||
|
|
||||||
QString Settings::new_tab_page()
|
QString Settings::new_tab_page()
|
||||||
{
|
{
|
||||||
static auto const default_new_tab_url = rebase_default_url_on_serenity_resource_root(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();
|
return m_qsettings->value("new_tab_page", default_new_tab_url).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -284,7 +284,7 @@ void BrowserWindow::build_menus()
|
||||||
|
|
||||||
m_change_homepage_action = GUI::Action::create(
|
m_change_homepage_action = GUI::Action::create(
|
||||||
"Set Homepage URL...", g_icon_bag.go_home, [this](auto&) {
|
"Set Homepage URL...", g_icon_bag.go_home, [this](auto&) {
|
||||||
String homepage_url = String::from_deprecated_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_deprecated_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 (GUI::InputBox::show(this, homepage_url, "Enter a URL:"sv, "Change Homepage"sv) == GUI::InputBox::ExecResult::OK) {
|
||||||
if (URL(homepage_url).is_valid()) {
|
if (URL(homepage_url).is_valid()) {
|
||||||
Config::write_string("Browser"sv, "Preferences"sv, "Home"sv, homepage_url);
|
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);
|
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_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_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_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_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);
|
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()
|
ErrorOr<void> BrowserSettingsWidget::setup()
|
||||||
{
|
{
|
||||||
m_homepage_url_textbox = find_descendant_of_type_named<GUI::TextBox>("homepage_url_textbox");
|
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_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 = 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_new_tab_url_textbox->on_change = [&]() { set_modified(true); };
|
||||||
|
|
||||||
m_color_scheme_combobox = find_descendant_of_type_named<GUI::ComboBox>("color_scheme_combobox");
|
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()
|
void BrowserSettingsWidget::reset_default_values()
|
||||||
{
|
{
|
||||||
m_homepage_url_textbox->set_text(Browser::default_homepage_url);
|
m_homepage_url_textbox->set_text(Browser::default_homepage_url());
|
||||||
m_new_tab_url_textbox->set_text(Browser::default_new_tab_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);
|
m_show_bookmarks_bar_checkbox->set_checked(Browser::default_show_bookmarks_bar);
|
||||||
set_color_scheme(Browser::default_color_scheme);
|
set_color_scheme(Browser::default_color_scheme);
|
||||||
m_auto_close_download_windows_checkbox->set_checked(Browser::default_close_download_widget_on_finish);
|
m_auto_close_download_windows_checkbox->set_checked(Browser::default_close_download_widget_on_finish);
|
||||||
|
|
|
@ -6,16 +6,38 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/String.h>
|
||||||
#include <AK/StringView.h>
|
#include <AK/StringView.h>
|
||||||
|
#include <LibCore/Resource.h>
|
||||||
|
|
||||||
namespace Browser {
|
namespace Browser {
|
||||||
|
|
||||||
static constexpr StringView default_homepage_url = "file:///res/html/misc/welcome.html"sv;
|
|
||||||
static constexpr StringView default_new_tab_url = "file:///res/html/misc/new-tab.html"sv;
|
|
||||||
static constexpr StringView default_color_scheme = "auto"sv;
|
static constexpr StringView default_color_scheme = "auto"sv;
|
||||||
static constexpr bool default_enable_content_filters = true;
|
static constexpr bool default_enable_content_filters = true;
|
||||||
static constexpr bool default_show_bookmarks_bar = true;
|
static constexpr bool default_show_bookmarks_bar = true;
|
||||||
static constexpr bool default_close_download_widget_on_finish = false;
|
static constexpr bool default_close_download_widget_on_finish = false;
|
||||||
static constexpr bool default_allow_autoplay_on_all_websites = 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://html/misc/new-tab.html"sv;
|
||||||
|
return MUST(Core::Resource::load_from_uri(url))->file_url();
|
||||||
|
}();
|
||||||
|
|
||||||
|
return default_new_tab_url;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue