mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 16:07:45 +00:00
Userland: Port to automatic GML initializer where possible
This commit is contained in:
parent
dec066fa5c
commit
adc845e0cb
41 changed files with 148 additions and 245 deletions
|
@ -29,47 +29,46 @@ void AutoplayAllowlistModel::reset_default_values()
|
|||
|
||||
namespace BrowserSettings {
|
||||
|
||||
ErrorOr<NonnullRefPtr<AutoplaySettingsWidget>> AutoplaySettingsWidget::create()
|
||||
ErrorOr<void> AutoplaySettingsWidget::initialize()
|
||||
{
|
||||
auto allowlist_model = TRY(try_make_ref_counted<AutoplayAllowlistModel>());
|
||||
TRY(allowlist_model->load());
|
||||
|
||||
auto widget = TRY(AutoplaySettingsWidget::try_create());
|
||||
widget->set_allowlist_model(move(allowlist_model));
|
||||
set_allowlist_model(move(allowlist_model));
|
||||
|
||||
widget->m_allow_autoplay_on_all_websites_checkbox = widget->find_descendant_of_type_named<GUI::CheckBox>("allow_autoplay_on_all_websites_checkbox");
|
||||
widget->m_allow_autoplay_on_all_websites_checkbox->set_checked(Config::read_bool("Browser"sv, "Preferences"sv, "AllowAutoplayOnAllWebsites"sv, Browser::default_allow_autoplay_on_all_websites), GUI::AllowCallback::No);
|
||||
widget->m_allow_autoplay_on_all_websites_checkbox->on_checked = [widget](auto) {
|
||||
widget->set_modified(true);
|
||||
m_allow_autoplay_on_all_websites_checkbox = find_descendant_of_type_named<GUI::CheckBox>("allow_autoplay_on_all_websites_checkbox");
|
||||
m_allow_autoplay_on_all_websites_checkbox->set_checked(Config::read_bool("Browser"sv, "Preferences"sv, "AllowAutoplayOnAllWebsites"sv, Browser::default_allow_autoplay_on_all_websites), GUI::AllowCallback::No);
|
||||
m_allow_autoplay_on_all_websites_checkbox->on_checked = [this](auto) {
|
||||
set_modified(true);
|
||||
};
|
||||
|
||||
widget->m_allowlist_view = widget->find_descendant_of_type_named<GUI::ListView>("allowlist_view");
|
||||
widget->m_allowlist_view->set_model(widget->m_allowlist_model);
|
||||
widget->m_allowlist_view->on_context_menu_request = [widget](GUI::ModelIndex const& index, GUI::ContextMenuEvent const& event) {
|
||||
widget->m_allowlist_view->set_cursor(index, GUI::AbstractView::SelectionUpdate::Set);
|
||||
widget->m_entry_context_menu->popup(event.screen_position());
|
||||
m_allowlist_view = find_descendant_of_type_named<GUI::ListView>("allowlist_view");
|
||||
m_allowlist_view->set_model(m_allowlist_model);
|
||||
m_allowlist_view->on_context_menu_request = [this](GUI::ModelIndex const& index, GUI::ContextMenuEvent const& event) {
|
||||
m_allowlist_view->set_cursor(index, GUI::AbstractView::SelectionUpdate::Set);
|
||||
m_entry_context_menu->popup(event.screen_position());
|
||||
};
|
||||
|
||||
widget->m_add_website_button = widget->find_descendant_of_type_named<GUI::Button>("add_website_button");
|
||||
widget->m_add_website_button->on_click = [widget](unsigned) {
|
||||
m_add_website_button = find_descendant_of_type_named<GUI::Button>("add_website_button");
|
||||
m_add_website_button->on_click = [this](unsigned) {
|
||||
String text;
|
||||
|
||||
if (GUI::InputBox::show(widget->window(), text, "Enter a website:"sv, "Add Autoplay Entry"sv, GUI::InputType::NonemptyText) == GUI::Dialog::ExecResult::OK) {
|
||||
widget->m_allowlist_model->add_domain(move(text));
|
||||
widget->set_modified(true);
|
||||
if (GUI::InputBox::show(window(), text, "Enter a website:"sv, "Add Autoplay Entry"sv, GUI::InputType::NonemptyText) == GUI::Dialog::ExecResult::OK) {
|
||||
m_allowlist_model->add_domain(move(text));
|
||||
set_modified(true);
|
||||
}
|
||||
};
|
||||
|
||||
auto delete_action = GUI::CommonActions::make_delete_action([widget](GUI::Action const&) {
|
||||
if (!widget->m_allowlist_view->selection().is_empty()) {
|
||||
widget->m_allowlist_model->delete_domain(widget->m_allowlist_view->selection().first().row());
|
||||
widget->set_modified(true);
|
||||
auto delete_action = GUI::CommonActions::make_delete_action([this](GUI::Action const&) {
|
||||
if (!m_allowlist_view->selection().is_empty()) {
|
||||
m_allowlist_model->delete_domain(m_allowlist_view->selection().first().row());
|
||||
set_modified(true);
|
||||
}
|
||||
});
|
||||
widget->m_entry_context_menu = GUI::Menu::construct();
|
||||
widget->m_entry_context_menu->add_action(move(delete_action));
|
||||
m_entry_context_menu = GUI::Menu::construct();
|
||||
m_entry_context_menu->add_action(move(delete_action));
|
||||
|
||||
return widget;
|
||||
return {};
|
||||
}
|
||||
|
||||
void AutoplaySettingsWidget::set_allowlist_model(NonnullRefPtr<AutoplayAllowlistModel> model)
|
||||
|
|
|
@ -27,13 +27,13 @@ class AutoplaySettingsWidget : public GUI::SettingsWindow::Tab {
|
|||
C_OBJECT_ABSTRACT(AutoplaySettingsWidget)
|
||||
|
||||
public:
|
||||
static ErrorOr<NonnullRefPtr<AutoplaySettingsWidget>> create();
|
||||
static ErrorOr<NonnullRefPtr<AutoplaySettingsWidget>> try_create();
|
||||
ErrorOr<void> initialize();
|
||||
|
||||
virtual void apply_settings() override;
|
||||
virtual void reset_default_values() override;
|
||||
|
||||
private:
|
||||
static ErrorOr<NonnullRefPtr<AutoplaySettingsWidget>> try_create();
|
||||
AutoplaySettingsWidget() = default;
|
||||
|
||||
void set_allowlist_model(NonnullRefPtr<AutoplayAllowlistModel> model);
|
||||
|
|
|
@ -95,16 +95,7 @@ private:
|
|||
Vector<WebView::SearchEngine> m_search_engines;
|
||||
};
|
||||
|
||||
ErrorOr<NonnullRefPtr<BrowserSettingsWidget>> BrowserSettingsWidget::create()
|
||||
{
|
||||
auto widget = TRY(BrowserSettingsWidget::try_create());
|
||||
|
||||
TRY(widget->setup());
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
ErrorOr<void> BrowserSettingsWidget::setup()
|
||||
ErrorOr<void> BrowserSettingsWidget::initialize()
|
||||
{
|
||||
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);
|
||||
|
|
|
@ -17,17 +17,15 @@ namespace BrowserSettings {
|
|||
class BrowserSettingsWidget final : public GUI::SettingsWindow::Tab {
|
||||
C_OBJECT_ABSTRACT(BrowserSettingsWidget)
|
||||
public:
|
||||
static ErrorOr<NonnullRefPtr<BrowserSettingsWidget>> create();
|
||||
static ErrorOr<NonnullRefPtr<BrowserSettingsWidget>> try_create();
|
||||
virtual ~BrowserSettingsWidget() override = default;
|
||||
|
||||
virtual void apply_settings() override;
|
||||
virtual void reset_default_values() override;
|
||||
|
||||
ErrorOr<void> initialize();
|
||||
|
||||
private:
|
||||
static ErrorOr<NonnullRefPtr<BrowserSettingsWidget>> try_create();
|
||||
|
||||
ErrorOr<void> setup();
|
||||
|
||||
RefPtr<GUI::TextBox> m_homepage_url_textbox;
|
||||
RefPtr<GUI::TextBox> m_new_tab_url_textbox;
|
||||
void set_color_scheme(StringView);
|
||||
|
|
|
@ -117,47 +117,46 @@ void DomainListModel::reset_default_values()
|
|||
|
||||
namespace BrowserSettings {
|
||||
|
||||
ErrorOr<NonnullRefPtr<ContentFilterSettingsWidget>> ContentFilterSettingsWidget::create()
|
||||
ErrorOr<void> ContentFilterSettingsWidget::initialize()
|
||||
{
|
||||
auto domain_list_model = TRY(try_make_ref_counted<DomainListModel>());
|
||||
TRY(domain_list_model->load());
|
||||
|
||||
auto widget = TRY(ContentFilterSettingsWidget::try_create());
|
||||
widget->set_domain_list_model(move(domain_list_model));
|
||||
set_domain_list_model(move(domain_list_model));
|
||||
|
||||
widget->m_enable_content_filtering_checkbox = widget->find_descendant_of_type_named<GUI::CheckBox>("enable_content_filtering_checkbox");
|
||||
widget->m_enable_content_filtering_checkbox->set_checked(Config::read_bool("Browser"sv, "Preferences"sv, "EnableContentFilters"sv, Browser::default_enable_content_filters), GUI::AllowCallback::No);
|
||||
widget->m_enable_content_filtering_checkbox->on_checked = [widget](auto) {
|
||||
widget->set_modified(true);
|
||||
m_enable_content_filtering_checkbox = find_descendant_of_type_named<GUI::CheckBox>("enable_content_filtering_checkbox");
|
||||
m_enable_content_filtering_checkbox->set_checked(Config::read_bool("Browser"sv, "Preferences"sv, "EnableContentFilters"sv, Browser::default_enable_content_filters), GUI::AllowCallback::No);
|
||||
m_enable_content_filtering_checkbox->on_checked = [this](auto) {
|
||||
set_modified(true);
|
||||
};
|
||||
|
||||
widget->m_domain_list_view = widget->find_descendant_of_type_named<GUI::ListView>("domain_list_view");
|
||||
widget->m_domain_list_view->set_model(widget->m_domain_list_model);
|
||||
widget->m_domain_list_view->on_context_menu_request = [widget](GUI::ModelIndex const& index, GUI::ContextMenuEvent const& event) {
|
||||
widget->m_domain_list_view->set_cursor(index, GUI::AbstractView::SelectionUpdate::Set);
|
||||
widget->m_entry_context_menu->popup(event.screen_position());
|
||||
m_domain_list_view = find_descendant_of_type_named<GUI::ListView>("domain_list_view");
|
||||
m_domain_list_view->set_model(m_domain_list_model);
|
||||
m_domain_list_view->on_context_menu_request = [this](GUI::ModelIndex const& index, GUI::ContextMenuEvent const& event) {
|
||||
m_domain_list_view->set_cursor(index, GUI::AbstractView::SelectionUpdate::Set);
|
||||
m_entry_context_menu->popup(event.screen_position());
|
||||
};
|
||||
|
||||
widget->m_add_new_domain_button = widget->find_descendant_of_type_named<GUI::Button>("add_new_domain_button");
|
||||
widget->m_add_new_domain_button->on_click = [widget](unsigned) {
|
||||
m_add_new_domain_button = find_descendant_of_type_named<GUI::Button>("add_new_domain_button");
|
||||
m_add_new_domain_button->on_click = [this](unsigned) {
|
||||
String text;
|
||||
|
||||
if (GUI::InputBox::show(widget->window(), text, "Enter a domain:"sv, "Add Content Filter"sv, GUI::InputType::NonemptyText) == GUI::Dialog::ExecResult::OK) {
|
||||
widget->m_domain_list_model->add_domain(move(text));
|
||||
widget->set_modified(true);
|
||||
if (GUI::InputBox::show(window(), text, "Enter a domain:"sv, "Add Content Filter"sv, GUI::InputType::NonemptyText) == GUI::Dialog::ExecResult::OK) {
|
||||
m_domain_list_model->add_domain(move(text));
|
||||
set_modified(true);
|
||||
}
|
||||
};
|
||||
|
||||
auto delete_action = GUI::CommonActions::make_delete_action([widget](GUI::Action const&) {
|
||||
if (!widget->m_domain_list_view->selection().is_empty()) {
|
||||
widget->m_domain_list_model->delete_domain(widget->m_domain_list_view->selection().first().row());
|
||||
widget->set_modified(true);
|
||||
auto delete_action = GUI::CommonActions::make_delete_action([this](GUI::Action const&) {
|
||||
if (!m_domain_list_view->selection().is_empty()) {
|
||||
m_domain_list_model->delete_domain(m_domain_list_view->selection().first().row());
|
||||
set_modified(true);
|
||||
}
|
||||
});
|
||||
widget->m_entry_context_menu = GUI::Menu::construct();
|
||||
widget->m_entry_context_menu->add_action(delete_action);
|
||||
m_entry_context_menu = GUI::Menu::construct();
|
||||
m_entry_context_menu->add_action(delete_action);
|
||||
|
||||
return widget;
|
||||
return {};
|
||||
}
|
||||
|
||||
void ContentFilterSettingsWidget::set_domain_list_model(NonnullRefPtr<DomainListModel> domain_list_model)
|
||||
|
|
|
@ -37,13 +37,13 @@ class ContentFilterSettingsWidget : public GUI::SettingsWindow::Tab {
|
|||
C_OBJECT_ABSTRACT(ContentFilterSettingsWidget)
|
||||
|
||||
public:
|
||||
static ErrorOr<NonnullRefPtr<ContentFilterSettingsWidget>> create();
|
||||
static ErrorOr<NonnullRefPtr<ContentFilterSettingsWidget>> try_create();
|
||||
ErrorOr<void> initialize();
|
||||
|
||||
virtual void apply_settings() override;
|
||||
virtual void reset_default_values() override;
|
||||
|
||||
private:
|
||||
static ErrorOr<NonnullRefPtr<ContentFilterSettingsWidget>> try_create();
|
||||
ContentFilterSettingsWidget() = default;
|
||||
|
||||
void set_domain_list_model(NonnullRefPtr<DomainListModel>);
|
||||
|
|
|
@ -37,9 +37,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto window = TRY(GUI::SettingsWindow::create("Browser Settings", GUI::SettingsWindow::ShowDefaultsButton::Yes));
|
||||
window->set_icon(app_icon.bitmap_for_size(16));
|
||||
|
||||
(void)TRY(window->add_tab(TRY(BrowserSettings::BrowserSettingsWidget::create()), "Browser"_string, "browser"sv));
|
||||
(void)TRY(window->add_tab(TRY(BrowserSettings::ContentFilterSettingsWidget::create()), "Content Filtering"_string, "content-filtering"sv));
|
||||
(void)TRY(window->add_tab(TRY(BrowserSettings::AutoplaySettingsWidget::create()), "Autoplay"_string, "autoplay"sv));
|
||||
(void)TRY(window->add_tab<BrowserSettings::BrowserSettingsWidget>("Browser"_string, "browser"sv));
|
||||
(void)TRY(window->add_tab<BrowserSettings::ContentFilterSettingsWidget>("Content Filtering"_string, "content-filtering"sv));
|
||||
(void)TRY(window->add_tab<BrowserSettings::AutoplaySettingsWidget>("Autoplay"_string, "autoplay"sv));
|
||||
window->set_active_tab(selected_tab);
|
||||
|
||||
window->show();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue