mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-11 09:18:05 +03:00
SoundPlayer: Keep track of the selected visualization in the config
This commit is contained in:
parent
4c49e0f4a3
commit
23d31ac11d
Notes:
sideshowbarker
2024-07-17 17:49:11 +09:00
Author: https://github.com/caoimhebyrne Commit: https://github.com/SerenityOS/serenity/commit/23d31ac11d Pull-request: https://github.com/SerenityOS/serenity/pull/17925 Reviewed-by: https://github.com/linusg ✅
@ -19,4 +19,4 @@ set(SOURCES
|
||||
)
|
||||
|
||||
serenity_app(SoundPlayer ICON app-sound-player)
|
||||
target_link_libraries(SoundPlayer PRIVATE LibAudio LibCore LibDSP LibGfx LibGUI LibIPC LibMain LibThreading LibImageDecoderClient)
|
||||
target_link_libraries(SoundPlayer PRIVATE LibAudio LibConfig LibCore LibDSP LibGfx LibGUI LibIPC LibMain LibThreading LibImageDecoderClient)
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include <AK/DeprecatedString.h>
|
||||
#include <AK/LexicalPath.h>
|
||||
#include <AK/SIMD.h>
|
||||
#include <LibConfig/Client.h>
|
||||
#include <LibGUI/Action.h>
|
||||
#include <LibGUI/BoxLayout.h>
|
||||
#include <LibGUI/Button.h>
|
||||
@ -53,7 +54,16 @@ SoundPlayerWidgetAdvancedView::SoundPlayerWidgetAdvancedView(GUI::Window& window
|
||||
m_volume_icon = Gfx::Bitmap::load_from_file("/res/icons/16x16/audio-volume-medium.png"sv).release_value_but_fixme_should_propagate_errors();
|
||||
m_muted_icon = Gfx::Bitmap::load_from_file("/res/icons/16x16/audio-volume-muted.png"sv).release_value_but_fixme_should_propagate_errors();
|
||||
|
||||
m_visualization = m_player_view->add<BarsVisualizationWidget>();
|
||||
auto visualization = Config::read_string("SoundPlayer"sv, "Preferences"sv, "Visualization"sv, "bars"sv);
|
||||
if (visualization == "samples") {
|
||||
m_visualization = m_player_view->add<SampleWidget>();
|
||||
} else if (visualization == "album_cover") {
|
||||
m_visualization = m_player_view->add<AlbumCoverVisualizationWidget>([this]() {
|
||||
return get_image_from_music_file();
|
||||
});
|
||||
} else {
|
||||
m_visualization = m_player_view->add<BarsVisualizationWidget>();
|
||||
}
|
||||
|
||||
m_playback_progress_slider = m_player_view->add<GUI::HorizontalSlider>();
|
||||
m_playback_progress_slider->set_fixed_height(20);
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "SoundPlayerWidgetAdvancedView.h"
|
||||
#include <LibAudio/ConnectionToServer.h>
|
||||
#include <LibAudio/FlacLoader.h>
|
||||
#include <LibConfig/Client.h>
|
||||
#include <LibCore/ArgsParser.h>
|
||||
#include <LibCore/System.h>
|
||||
#include <LibGUI/Action.h>
|
||||
@ -39,6 +40,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
auto audio_client = TRY(Audio::ConnectionToServer::try_create());
|
||||
auto decoder_client = TRY(ImageDecoderClient::Client::try_create());
|
||||
|
||||
Config::pledge_domain("SoundPlayer");
|
||||
app->set_config_domain(TRY("SoundPlayer"_string));
|
||||
|
||||
TRY(Core::System::pledge("stdio recvfd sendfd rpath thread proc"));
|
||||
|
||||
auto app_icon = GUI::Icon::default_icon("app-sound-player"sv);
|
||||
@ -120,15 +124,20 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
GUI::ActionGroup visualization_actions;
|
||||
visualization_actions.set_exclusive(true);
|
||||
|
||||
auto set_selected_visualization_in_config = [](StringView name) {
|
||||
Config::write_string("SoundPlayer"sv, "Preferences"sv, "Visualization"sv, name);
|
||||
};
|
||||
|
||||
auto bars = GUI::Action::create_checkable("&Bars", [&](auto&) {
|
||||
static_cast<SoundPlayerWidgetAdvancedView*>(player)->set_visualization<BarsVisualizationWidget>();
|
||||
set_selected_visualization_in_config("bars"sv);
|
||||
});
|
||||
bars->set_checked(true);
|
||||
TRY(visualization_menu->try_add_action(bars));
|
||||
visualization_actions.add_action(bars);
|
||||
|
||||
auto samples = GUI::Action::create_checkable("&Samples", [&](auto&) {
|
||||
static_cast<SoundPlayerWidgetAdvancedView*>(player)->set_visualization<SampleWidget>();
|
||||
set_selected_visualization_in_config("samples"sv);
|
||||
});
|
||||
TRY(visualization_menu->try_add_action(samples));
|
||||
visualization_actions.add_action(samples);
|
||||
@ -138,10 +147,22 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
view->set_visualization<AlbumCoverVisualizationWidget>([&view]() {
|
||||
return view->get_image_from_music_file();
|
||||
});
|
||||
|
||||
set_selected_visualization_in_config("album_cover"sv);
|
||||
});
|
||||
TRY(visualization_menu->try_add_action(album_cover_visualization));
|
||||
visualization_actions.add_action(album_cover_visualization);
|
||||
|
||||
auto selected_visualization_widget = bars;
|
||||
auto visualization = Config::read_string("SoundPlayer"sv, "Preferences"sv, "Visualization"sv, "bars"sv);
|
||||
|
||||
if (visualization == "samples")
|
||||
selected_visualization_widget = samples;
|
||||
else if (visualization == "album_cover")
|
||||
selected_visualization_widget = album_cover_visualization;
|
||||
|
||||
selected_visualization_widget->set_checked(true);
|
||||
|
||||
auto help_menu = TRY(window->try_add_menu("&Help"));
|
||||
TRY(help_menu->try_add_action(GUI::CommonActions::make_command_palette_action(window)));
|
||||
TRY(help_menu->try_add_action(GUI::CommonActions::make_about_action("Sound Player", app_icon, window)));
|
||||
|
Loading…
Reference in New Issue
Block a user