From c646efaf49e2d79d7cbcabb561c62977f2f084d3 Mon Sep 17 00:00:00 2001 From: Mustafa Quraish Date: Fri, 27 Aug 2021 09:37:36 -0400 Subject: AudioApplet: Use LibConfig instead of Core::ConfigFile No longer need to store `RefPtr` :^) --- Userland/Applets/Audio/CMakeLists.txt | 2 +- Userland/Applets/Audio/main.cpp | 28 +++++++++------------------- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/Userland/Applets/Audio/CMakeLists.txt b/Userland/Applets/Audio/CMakeLists.txt index fbd99a8b36..0d5aa97591 100644 --- a/Userland/Applets/Audio/CMakeLists.txt +++ b/Userland/Applets/Audio/CMakeLists.txt @@ -9,4 +9,4 @@ set(SOURCES ) serenity_app(Audio.Applet ICON audio-volume-high) -target_link_libraries(Audio.Applet LibGUI LibGfx LibAudio LibCore) +target_link_libraries(Audio.Applet LibGUI LibGfx LibAudio LibCore LibConfig) diff --git a/Userland/Applets/Audio/main.cpp b/Userland/Applets/Audio/main.cpp index ed868c643a..b7542d57a3 100644 --- a/Userland/Applets/Audio/main.cpp +++ b/Userland/Applets/Audio/main.cpp @@ -6,7 +6,7 @@ */ #include -#include +#include #include #include #include @@ -22,10 +22,9 @@ class AudioWidget final : public GUI::Widget { C_OBJECT(AudioWidget) public: - AudioWidget(NonnullRefPtr config, int initial_volume, bool initial_mute_state) + AudioWidget(int initial_volume, bool initial_mute_state) : m_audio_client(Audio::ClientConnection::construct()) - , m_config(move(config)) - , m_show_percent(m_config->read_bool_entry("Applet", "ShowPercent", false)) + , m_show_percent(Config::read_bool("AudioApplet", "Applet", "ShowPercent", false)) , m_audio_muted(initial_mute_state) , m_audio_volume(initial_volume) { @@ -85,10 +84,7 @@ public: reposition_slider_window(); GUI::Application::the()->hide_tooltip(); - m_config->write_bool_entry("Applet", "ShowPercent", m_show_percent); - auto sync_success = m_config->sync(); - if (!sync_success) - warnln("Could not write applet configuration."); + Config::write_bool("AudioApplet", "Applet", "ShowPercent", m_show_percent); }; m_slider = m_root_container->add(); @@ -191,7 +187,6 @@ private: }; NonnullRefPtr m_audio_client; - NonnullRefPtr m_config; Vector m_volume_level_bitmaps; bool m_show_percent { false }; bool m_audio_muted { false }; @@ -211,22 +206,21 @@ int main(int argc, char** argv) return 1; } - auto config = Core::ConfigFile::open_for_app("AudioApplet", Core::ConfigFile::AllowWriting::Yes); - // To not upset the audio server state, we responsibly read this once. - auto audio_master_config = Core::ConfigFile::open_for_app("Audio"); - auto app = GUI::Application::construct(argc, argv); + Config::pledge_domains({ "Audio", "AudioApplet" }); auto window = GUI::Window::construct(); window->set_has_alpha_channel(true); window->set_title("Audio"); window->set_window_type(GUI::WindowType::Applet); - window->set_main_widget(config, audio_master_config->read_num_entry("Master", "Volume", 100), audio_master_config->read_bool_entry("Master", "Mute", false)); + auto initial_volume = Config::read_i32("Audio", "Master", "Volume", 100); + auto initial_muted = Config::read_bool("Audio", "Master", "Muted", false); + window->set_main_widget(initial_volume, initial_muted); window->show(); // This positioning code depends on the window actually existing. - if (!config->read_bool_entry("Applet", "ShowPercent")) { + if (!Config::read_bool("AudioApplet", "Applet", "ShowPercent", false)) { window->resize(16, 16); } else { window->resize(44, 16); @@ -236,10 +230,6 @@ int main(int argc, char** argv) perror("unveil"); return 1; } - if (unveil(config->filename().characters(), "rwc") < 0) { - perror("unveil"); - return 1; - } unveil(nullptr, nullptr); -- cgit v1.2.3