From 8a284be5c72242e847db7bc831ed2752b78fede6 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Wed, 24 Nov 2021 16:47:39 +0000 Subject: [PATCH] BrowserSettings: Create a BrowserSettings application :^) Browser has a bunch of settings, but most are non-trivial to add here. So far, these are implemented: - Homepage URL - Whether to close download windows when they complete The others will be added in subsequent commits. --- Base/home/anon/BrowserSettingsWidget.gml | 93 +++++++++++++++++++ Base/res/apps/BrowserSettings.af | 5 + .../BrowserSettings/BrowserSettingsWidget.cpp | 32 +++++++ .../BrowserSettings/BrowserSettingsWidget.gml | 68 ++++++++++++++ .../BrowserSettings/BrowserSettingsWidget.h | 25 +++++ .../BrowserSettings/CMakeLists.txt | 16 ++++ .../Applications/BrowserSettings/main.cpp | 32 +++++++ Userland/Applications/CMakeLists.txt | 1 + 8 files changed, 272 insertions(+) create mode 100644 Base/home/anon/BrowserSettingsWidget.gml create mode 100644 Base/res/apps/BrowserSettings.af create mode 100644 Userland/Applications/BrowserSettings/BrowserSettingsWidget.cpp create mode 100644 Userland/Applications/BrowserSettings/BrowserSettingsWidget.gml create mode 100644 Userland/Applications/BrowserSettings/BrowserSettingsWidget.h create mode 100644 Userland/Applications/BrowserSettings/CMakeLists.txt create mode 100644 Userland/Applications/BrowserSettings/main.cpp diff --git a/Base/home/anon/BrowserSettingsWidget.gml b/Base/home/anon/BrowserSettingsWidget.gml new file mode 100644 index 0000000000..0d623b229a --- /dev/null +++ b/Base/home/anon/BrowserSettingsWidget.gml @@ -0,0 +1,93 @@ +@GUI::Frame { + fill_with_background_color: true + + layout: @GUI::VerticalBoxLayout { + margins: [10] + spacing: 5 + } + + @GUI::GroupBox { + title: "Homepage" + fixed_height: 60 + + layout: @GUI::VerticalBoxLayout { + margins: [16, 8, 8] + spacing: 2 + } + + @GUI::Widget { + layout: @GUI::HorizontalBoxLayout { + spacing: 16 + } + + @GUI::Label { + fixed_width: 32 + fixed_height: 32 + name: "homepage_image_label" + } + + @GUI::Label { + text: "URL:" + text_alignment: "CenterLeft" + } + + @GUI::TextBox { + name: "homepage_url_textbox" + placeholder: "https://example.com" + } + } + } + + @GUI::GroupBox { + title: "Search Engine" + fixed_height: 100 + + layout: @GUI::VerticalBoxLayout { + margins: [16, 8, 8] + spacing: 2 + } + + @GUI::Widget { + layout: @GUI::HorizontalBoxLayout { + spacing: 16 + } + + @GUI::Label { + fixed_width: 32 + fixed_height: 32 + name: "search_engine_image_label" + } + + @GUI::Label { + text: "Search engine:" + text_alignment: "CenterLeft" + } + + @GUI::ComboBox { + name: "search_engine_combobox" + } + } + + @GUI::Widget { + layout: @GUI::HorizontalBoxLayout { + spacing: 16 + } + + name: "search_engine_custom_group" + + @GUI::Widget { + fixed_width: 32 + } + + @GUI::Label { + text: "Enter URL template:" + text_alignment: "CenterLeft" + } + + @GUI::TextBox { + name: "search_engine_custom_textbox" + placeholder: "https://host/search?q={}" + } + } + } +} diff --git a/Base/res/apps/BrowserSettings.af b/Base/res/apps/BrowserSettings.af new file mode 100644 index 0000000000..4e8b837e05 --- /dev/null +++ b/Base/res/apps/BrowserSettings.af @@ -0,0 +1,5 @@ +[App] +Name=Browser Settings +Executable=/bin/BrowserSettings +Category=Settings +Description=Configure Browser diff --git a/Userland/Applications/BrowserSettings/BrowserSettingsWidget.cpp b/Userland/Applications/BrowserSettings/BrowserSettingsWidget.cpp new file mode 100644 index 0000000000..35ce49f4fd --- /dev/null +++ b/Userland/Applications/BrowserSettings/BrowserSettingsWidget.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2021, Sam Atkins + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "BrowserSettingsWidget.h" +#include +#include + +BrowserSettingsWidget::BrowserSettingsWidget() +{ + load_from_gml(browser_settings_widget_gml); + + m_homepage_url_textbox = find_descendant_of_type_named("homepage_url_textbox"); + m_homepage_url_textbox->set_text(Config::read_string("Browser", "Preferences", "Home", "about:blank")); + + m_auto_close_download_windows_checkbox = find_descendant_of_type_named("auto_close_download_windows_checkbox"); + m_auto_close_download_windows_checkbox->set_checked(Config::read_bool("Browser", "Preferences", "CloseDownloadWidgetOnFinish", false), GUI::AllowCallback::No); +} + +BrowserSettingsWidget::~BrowserSettingsWidget() +{ +} + +void BrowserSettingsWidget::apply_settings() +{ + // TODO: Ensure that the URL is valid, as we do in the BrowserWindow's change-homepage dialog + Config::write_string("Browser", "Preferences", "Home", m_homepage_url_textbox->text()); + + Config::write_bool("Browser", "Preferences", "CloseDownloadWidgetOnFinish", m_auto_close_download_windows_checkbox->is_checked()); +} diff --git a/Userland/Applications/BrowserSettings/BrowserSettingsWidget.gml b/Userland/Applications/BrowserSettings/BrowserSettingsWidget.gml new file mode 100644 index 0000000000..d92a5dbffa --- /dev/null +++ b/Userland/Applications/BrowserSettings/BrowserSettingsWidget.gml @@ -0,0 +1,68 @@ +@GUI::Frame { + fill_with_background_color: true + + layout: @GUI::VerticalBoxLayout { + margins: [10] + spacing: 5 + } + + @GUI::GroupBox { + title: "Homepage" + fixed_height: 70 + + layout: @GUI::VerticalBoxLayout { + margins: [16, 8, 8] + spacing: 2 + } + + @GUI::Widget { + layout: @GUI::HorizontalBoxLayout { + spacing: 16 + } + + @GUI::Label { + fixed_width: 32 + fixed_height: 32 + name: "homepage_image_label" + } + + @GUI::Label { + text: "URL:" + text_alignment: "CenterLeft" + fixed_width: 30 + } + + @GUI::TextBox { + name: "homepage_url_textbox" + placeholder: "https://example.com" + } + } + } + + @GUI::GroupBox { + title: "Downloads" + fixed_height: 70 + + layout: @GUI::VerticalBoxLayout { + margins: [16, 8, 8] + spacing: 2 + } + + @GUI::Widget { + layout: @GUI::HorizontalBoxLayout { + spacing: 16 + } + + @GUI::Label { + fixed_width: 32 + fixed_height: 32 + name: "download_image_label" + } + + @GUI::CheckBox { + name: "auto_close_download_windows_checkbox" + text: "Automatically close download window when complete" + } + } + } +} diff --git a/Userland/Applications/BrowserSettings/BrowserSettingsWidget.h b/Userland/Applications/BrowserSettings/BrowserSettingsWidget.h new file mode 100644 index 0000000000..3720c86a5c --- /dev/null +++ b/Userland/Applications/BrowserSettings/BrowserSettingsWidget.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2021, Sam Atkins + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include + +class BrowserSettingsWidget final : public GUI::SettingsWindow::Tab { + C_OBJECT(BrowserSettingsWidget) +public: + virtual ~BrowserSettingsWidget() override; + + virtual void apply_settings() override; + +private: + BrowserSettingsWidget(); + + RefPtr m_homepage_url_textbox; + RefPtr m_auto_close_download_windows_checkbox; +}; diff --git a/Userland/Applications/BrowserSettings/CMakeLists.txt b/Userland/Applications/BrowserSettings/CMakeLists.txt new file mode 100644 index 0000000000..ede8a20d1e --- /dev/null +++ b/Userland/Applications/BrowserSettings/CMakeLists.txt @@ -0,0 +1,16 @@ +serenity_component( + BrowserSettings + RECOMMENDED + TARGETS BrowserSettings +) + +compile_gml(BrowserSettingsWidget.gml BrowserSettingsWidgetGML.h browser_settings_widget_gml) + +set(SOURCES + main.cpp + BrowserSettingsWidget.cpp + BrowserSettingsWidgetGML.h +) + +serenity_app(BrowserSettings ICON app-browser) +target_link_libraries(BrowserSettings LibGUI LibConfig LibMain) diff --git a/Userland/Applications/BrowserSettings/main.cpp b/Userland/Applications/BrowserSettings/main.cpp new file mode 100644 index 0000000000..0192da727a --- /dev/null +++ b/Userland/Applications/BrowserSettings/main.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2021, Sam Atkins + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "BrowserSettingsWidget.h" +#include +#include +#include +#include +#include +#include + +ErrorOr serenity_main(Main::Arguments arguments) +{ + TRY(Core::System::pledge("stdio rpath recvfd sendfd unix", nullptr)); + auto app = TRY(GUI::Application::try_create(arguments)); + Config::pledge_domains("Browser"); + + TRY(Core::System::unveil("/res", "r")); + TRY(Core::System::unveil(nullptr, nullptr)); + + auto app_icon = GUI::Icon::default_icon("app-browser"); + + auto window = TRY(GUI::SettingsWindow::try_create("Browser Settings")); + window->set_icon(app_icon.bitmap_for_size(16)); + window->add_tab("Browser"); + + window->show(); + return app->exec(); +} diff --git a/Userland/Applications/CMakeLists.txt b/Userland/Applications/CMakeLists.txt index 2af39f0b82..a9b4961240 100644 --- a/Userland/Applications/CMakeLists.txt +++ b/Userland/Applications/CMakeLists.txt @@ -3,6 +3,7 @@ add_subdirectory(About) add_subdirectory(AnalogClock) add_subdirectory(Assistant) add_subdirectory(Browser) +add_subdirectory(BrowserSettings) add_subdirectory(Calculator) add_subdirectory(Calendar) add_subdirectory(CrashReporter)