diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2021-11-24 16:47:39 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-11-26 22:14:56 +0100 |
commit | 8a284be5c72242e847db7bc831ed2752b78fede6 (patch) | |
tree | 241dc074826b5e8ffecab7d9474c3585d9207156 /Userland | |
parent | 16ee8ebc04354809b763a82b6d3a4eb40a47d412 (diff) | |
download | serenity-8a284be5c72242e847db7bc831ed2752b78fede6.zip |
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.
Diffstat (limited to 'Userland')
6 files changed, 174 insertions, 0 deletions
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 <atkinssj@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "BrowserSettingsWidget.h" +#include <Applications/BrowserSettings/BrowserSettingsWidgetGML.h> +#include <LibConfig/Client.h> + +BrowserSettingsWidget::BrowserSettingsWidget() +{ + load_from_gml(browser_settings_widget_gml); + + m_homepage_url_textbox = find_descendant_of_type_named<GUI::TextBox>("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<GUI::CheckBox>("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 <atkinssj@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include <LibGUI/CheckBox.h> +#include <LibGUI/SettingsWindow.h> +#include <LibGUI/TextBox.h> + +class BrowserSettingsWidget final : public GUI::SettingsWindow::Tab { + C_OBJECT(BrowserSettingsWidget) +public: + virtual ~BrowserSettingsWidget() override; + + virtual void apply_settings() override; + +private: + BrowserSettingsWidget(); + + RefPtr<GUI::TextBox> m_homepage_url_textbox; + RefPtr<GUI::CheckBox> 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 <atkinssj@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "BrowserSettingsWidget.h" +#include <LibConfig/Client.h> +#include <LibCore/System.h> +#include <LibGUI/Application.h> +#include <LibGUI/Icon.h> +#include <LibGUI/SettingsWindow.h> +#include <LibMain/Main.h> + +ErrorOr<int> 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<BrowserSettingsWidget>("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) |