mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:37:34 +00:00
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.
This commit is contained in:
parent
16ee8ebc04
commit
8a284be5c7
8 changed files with 272 additions and 0 deletions
93
Base/home/anon/BrowserSettingsWidget.gml
Normal file
93
Base/home/anon/BrowserSettingsWidget.gml
Normal file
|
@ -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={}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
5
Base/res/apps/BrowserSettings.af
Normal file
5
Base/res/apps/BrowserSettings.af
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
[App]
|
||||||
|
Name=Browser Settings
|
||||||
|
Executable=/bin/BrowserSettings
|
||||||
|
Category=Settings
|
||||||
|
Description=Configure Browser
|
|
@ -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());
|
||||||
|
}
|
|
@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
};
|
16
Userland/Applications/BrowserSettings/CMakeLists.txt
Normal file
16
Userland/Applications/BrowserSettings/CMakeLists.txt
Normal file
|
@ -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)
|
32
Userland/Applications/BrowserSettings/main.cpp
Normal file
32
Userland/Applications/BrowserSettings/main.cpp
Normal file
|
@ -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();
|
||||||
|
}
|
|
@ -3,6 +3,7 @@ add_subdirectory(About)
|
||||||
add_subdirectory(AnalogClock)
|
add_subdirectory(AnalogClock)
|
||||||
add_subdirectory(Assistant)
|
add_subdirectory(Assistant)
|
||||||
add_subdirectory(Browser)
|
add_subdirectory(Browser)
|
||||||
|
add_subdirectory(BrowserSettings)
|
||||||
add_subdirectory(Calculator)
|
add_subdirectory(Calculator)
|
||||||
add_subdirectory(Calendar)
|
add_subdirectory(Calendar)
|
||||||
add_subdirectory(CrashReporter)
|
add_subdirectory(CrashReporter)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue