diff options
author | Andreas Kling <kling@serenityos.org> | 2021-08-26 00:18:42 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-08-26 00:54:28 +0200 |
commit | 6ad63ae71c3a3d5f0dfcf286a356e62c467e2eaf (patch) | |
tree | ebdca1cdfd9f2b7d39b4bdc18d8b187e34fa8812 | |
parent | 0cd4b8cbb7529dbf108a5f6ecf7b86987a90c59c (diff) | |
download | serenity-6ad63ae71c3a3d5f0dfcf286a356e62c467e2eaf.zip |
Browser: Use LibConfig instead of Core::ConfigFile
-rw-r--r-- | Userland/Applications/Browser/BrowserWindow.cpp | 16 | ||||
-rw-r--r-- | Userland/Applications/Browser/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Userland/Applications/Browser/DownloadWidget.cpp | 10 | ||||
-rw-r--r-- | Userland/Applications/Browser/main.cpp | 9 |
4 files changed, 16 insertions, 21 deletions
diff --git a/Userland/Applications/Browser/BrowserWindow.cpp b/Userland/Applications/Browser/BrowserWindow.cpp index f35c918513..88d1fc6f34 100644 --- a/Userland/Applications/Browser/BrowserWindow.cpp +++ b/Userland/Applications/Browser/BrowserWindow.cpp @@ -13,7 +13,7 @@ #include "InspectorWidget.h" #include "Tab.h" #include <Applications/Browser/BrowserWindowGML.h> -#include <LibCore/ConfigFile.h> +#include <LibConfig/Client.h> #include <LibCore/StandardPaths.h> #include <LibGUI/AboutDialog.h> #include <LibGUI/Application.h> @@ -236,11 +236,10 @@ void BrowserWindow::build_menus() m_change_homepage_action = GUI::Action::create( "Set Homepage URL", [this](auto&) { - auto config = Core::ConfigFile::open_for_app("Browser", Core::ConfigFile::AllowWriting::Yes); - String homepage_url = config->read_entry("Preferences", "Home", "about:blank"); + auto homepage_url = Config::read_string("Browser", "Preferences", "Home", "about:blank"); if (GUI::InputBox::show(this, homepage_url, "Enter URL", "Change homepage URL") == GUI::InputBox::ExecOK) { if (URL(homepage_url).is_valid()) { - config->write_entry("Preferences", "Home", homepage_url); + Config::write_string("Browser", "Preferences", "Home", homepage_url); Browser::g_home_url = homepage_url; } else { GUI::MessageBox::show_error(this, "The URL you have entered is not valid"); @@ -259,8 +258,7 @@ void BrowserWindow::build_menus() auto action = GUI::Action::create_checkable( name, [&](auto&) { g_search_engine = url_format; - auto config = Core::ConfigFile::open_for_app("Browser", Core::ConfigFile::AllowWriting::Yes); - config->write_entry("Preferences", "SearchEngine", g_search_engine); + Config::write_string("Browser", "Preferences", "SearchEngine", g_search_engine); }, this); search_engine_menu.add_action(action); @@ -276,8 +274,7 @@ void BrowserWindow::build_menus() m_disable_search_engine_action = GUI::Action::create_checkable( "Disable", [](auto&) { g_search_engine = {}; - auto config = Core::ConfigFile::open_for_app("Browser", Core::ConfigFile::AllowWriting::Yes); - config->write_entry("Preferences", "SearchEngine", g_search_engine); + Config::write_string("Browser", "Preferences", "SearchEngine", g_search_engine); }, this); search_engine_menu.add_action(*m_disable_search_engine_action); @@ -306,8 +303,7 @@ void BrowserWindow::build_menus() } g_search_engine = search_engine; - auto config = Core::ConfigFile::open_for_app("Browser", Core::ConfigFile::AllowWriting::Yes); - config->write_entry("Preferences", "SearchEngine", g_search_engine); + Config::write_string("Browser", "Preferences", "SearchEngine", g_search_engine); action.set_status_tip(search_engine); }); search_engine_menu.add_action(custom_search_engine_action); diff --git a/Userland/Applications/Browser/CMakeLists.txt b/Userland/Applications/Browser/CMakeLists.txt index e37ceeb885..4cb8648b90 100644 --- a/Userland/Applications/Browser/CMakeLists.txt +++ b/Userland/Applications/Browser/CMakeLists.txt @@ -27,4 +27,4 @@ set(SOURCES ) serenity_app(Browser ICON app-browser) -target_link_libraries(Browser LibWeb LibProtocol LibGUI LibDesktop) +target_link_libraries(Browser LibWeb LibProtocol LibGUI LibDesktop LibConfig) diff --git a/Userland/Applications/Browser/DownloadWidget.cpp b/Userland/Applications/Browser/DownloadWidget.cpp index d18385be44..4b2fb937d6 100644 --- a/Userland/Applications/Browser/DownloadWidget.cpp +++ b/Userland/Applications/Browser/DownloadWidget.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -7,7 +7,7 @@ #include "DownloadWidget.h" #include <AK/NumberFormat.h> #include <AK/StringBuilder.h> -#include <LibCore/ConfigFile.h> +#include <LibConfig/Client.h> #include <LibCore/File.h> #include <LibCore/FileStream.h> #include <LibCore/StandardPaths.h> @@ -36,8 +36,7 @@ DownloadWidget::DownloadWidget(const URL& url) m_destination_path = builder.to_string(); } - auto browser_config = Core::ConfigFile::open_for_app("Browser"); - auto close_on_finish = browser_config->read_bool_entry("Preferences", "CloseDownloadWidgetOnFinish", false); + auto close_on_finish = Config::read_bool("Browser", "Preferences", "CloseDownloadWidgetOnFinish", false); m_elapsed_timer.start(); m_download = Web::ResourceLoader::the().protocol_client().start_request("GET", url); @@ -90,8 +89,7 @@ DownloadWidget::DownloadWidget(const URL& url) m_close_on_finish_checkbox->set_checked(close_on_finish); m_close_on_finish_checkbox->on_checked = [&](bool checked) { - auto browser_config = Core::ConfigFile::open_for_app("Browser", Core::ConfigFile::AllowWriting::Yes); - browser_config->write_bool_entry("Preferences", "CloseDownloadWidgetOnFinish", checked); + Config::write_bool("Browser", "Preferences", "CloseDownloadWidgetOnFinish", checked); }; auto& button_container = add<GUI::Widget>(); diff --git a/Userland/Applications/Browser/main.cpp b/Userland/Applications/Browser/main.cpp index 81d314e387..50cf2063fb 100644 --- a/Userland/Applications/Browser/main.cpp +++ b/Userland/Applications/Browser/main.cpp @@ -10,8 +10,8 @@ #include "Tab.h" #include "WindowActions.h" #include <AK/StringBuilder.h> +#include <LibConfig/Client.h> #include <LibCore/ArgsParser.h> -#include <LibCore/ConfigFile.h> #include <LibCore/File.h> #include <LibCore/StandardPaths.h> #include <LibDesktop/Launcher.h> @@ -52,6 +52,8 @@ int main(int argc, char** argv) auto app = GUI::Application::construct(argc, argv); + Config::pledge_domains("Browser"); + // Connect to LaunchServer immediately and let it know that we won't ask for anything other than opening // the user's downloads directory. // FIXME: This should go away with a standalone download manager at some point. @@ -95,9 +97,8 @@ int main(int argc, char** argv) auto app_icon = GUI::Icon::default_icon("app-browser"); - auto m_config = Core::ConfigFile::open_for_app("Browser"); - Browser::g_home_url = m_config->read_entry("Preferences", "Home", "about:blank"); - Browser::g_search_engine = m_config->read_entry("Preferences", "SearchEngine", {}); + Browser::g_home_url = Config::read_string("Browser", "Preferences", "Home", "about:blank"); + Browser::g_search_engine = Config::read_string("Browser", "Preferences", "SearchEngine", {}); auto ad_filter_list_or_error = Core::File::open(String::formatted("{}/BrowserContentFilters.txt", Core::StandardPaths::config_directory()), Core::OpenMode::ReadOnly); if (!ad_filter_list_or_error.is_error()) { |