Serenity Operating System

SoundPlayer: Add action with icon for toggling mute

This adds a button on the menubar next to the volume slider to
indicate mute state and allow toggling the mute. Pressing the M key
will still toggle the mute, as before. When muted, the volume scroll
bar now gets disabled.

authored by

Andreas Oppebøen and committed by
Sam Atkins
60908adc e3379150

+15 -5
+12 -5
Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp
··· 46 46 m_stop_icon = Gfx::Bitmap::load_from_file("/res/icons/16x16/stop.png"sv).release_value_but_fixme_should_propagate_errors(); 47 47 m_back_icon = Gfx::Bitmap::load_from_file("/res/icons/16x16/go-back.png"sv).release_value_but_fixme_should_propagate_errors(); 48 48 m_next_icon = Gfx::Bitmap::load_from_file("/res/icons/16x16/go-forward.png"sv).release_value_but_fixme_should_propagate_errors(); 49 + m_volume_icon = Gfx::Bitmap::load_from_file("/res/icons/16x16/audio-volume-medium.png"sv).release_value_but_fixme_should_propagate_errors(); 50 + m_muted_icon = Gfx::Bitmap::load_from_file("/res/icons/16x16/audio-volume-muted.png"sv).release_value_but_fixme_should_propagate_errors(); 49 51 50 52 m_visualization = m_player_view->add<BarsVisualizationWidget>(); 51 53 ··· 98 100 99 101 menubar.add_separator(); 100 102 103 + m_mute_action = GUI::Action::create("Mute", { Key_M }, m_volume_icon, [&](auto&) { 104 + toggle_mute(); 105 + }); 106 + m_mute_action->set_enabled(true); 107 + menubar.add_action(*m_mute_action); 108 + 101 109 m_volume_label = &menubar.add<GUI::Label>(); 102 110 m_volume_label->set_fixed_width(30); 103 111 ··· 145 153 146 154 void SoundPlayerWidgetAdvancedView::keydown_event(GUI::KeyEvent& event) 147 155 { 148 - if (event.key() == Key_M) 149 - toggle_mute(); 150 - 151 156 if (event.key() == Key_Up) 152 157 m_volume_slider->increase_slider_by_page_steps(1); 153 158 ··· 184 189 { 185 190 } 186 191 187 - void SoundPlayerWidgetAdvancedView::mute_changed(bool) 192 + void SoundPlayerWidgetAdvancedView::mute_changed(bool muted) 188 193 { 189 - // FIXME: Update the volume slider when player is muted 194 + m_mute_action->set_text(muted ? "Unmute"sv : "Mute"sv); 195 + m_mute_action->set_icon(muted ? m_muted_icon : m_volume_icon); 196 + m_volume_slider->set_enabled(!muted); 190 197 } 191 198 192 199 void SoundPlayerWidgetAdvancedView::sync_previous_next_actions()
+3
Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.h
··· 71 71 RefPtr<Gfx::Bitmap> m_stop_icon; 72 72 RefPtr<Gfx::Bitmap> m_back_icon; 73 73 RefPtr<Gfx::Bitmap> m_next_icon; 74 + RefPtr<Gfx::Bitmap> m_volume_icon; 75 + RefPtr<Gfx::Bitmap> m_muted_icon; 74 76 75 77 RefPtr<GUI::Action> m_play_action; 76 78 RefPtr<GUI::Action> m_stop_action; 77 79 RefPtr<GUI::Action> m_back_action; 78 80 RefPtr<GUI::Action> m_next_action; 81 + RefPtr<GUI::Action> m_mute_action; 79 82 80 83 RefPtr<GUI::HorizontalSlider> m_playback_progress_slider; 81 84 RefPtr<GUI::Label> m_volume_label;