summaryrefslogtreecommitdiff
path: root/Userland/Applications
diff options
context:
space:
mode:
authorCaoimhe <caoimhebyrne06@gmail.com>2023-05-11 12:00:20 +0100
committerAndrew Kaster <andrewdkaster@gmail.com>2023-05-14 15:56:49 -0600
commit69396d4c4d6aab71fde06a261ba8fab92a884b5f (patch)
treef068755ca12ed9d4fca647e831fc64f99ac19179 /Userland/Applications
parent61add64f0f6766160716a771ca30a562ba2a50bd (diff)
downloadserenity-69396d4c4d6aab71fde06a261ba8fab92a884b5f.zip
VideoPlayer: Store video sizing mode in the configuration
Diffstat (limited to 'Userland/Applications')
-rw-r--r--Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp37
-rw-r--r--Userland/Applications/VideoPlayer/VideoPlayerWidget.h2
2 files changed, 32 insertions, 7 deletions
diff --git a/Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp b/Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp
index db0368f149..3c1bb57880 100644
--- a/Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp
+++ b/Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp
@@ -5,6 +5,7 @@
*/
#include <AK/NumberFormat.h>
+#include <LibConfig/Client.h>
#include <LibFileSystemAccessClient/Client.h>
#include <LibGUI/Action.h>
#include <LibGUI/BoxLayout.h>
@@ -87,21 +88,30 @@ ErrorOr<void> VideoPlayerWidget::setup_interface()
find_descendant_of_type_named<GUI::Button>("fullscreen")->set_action(*m_toggle_fullscreen_action);
m_size_fit_action = GUI::Action::create_checkable("&Fit", [&](auto&) {
- m_video_display->set_sizing_mode(VideoSizingMode::Fit);
+ set_sizing_mode(VideoSizingMode::Fit);
});
m_size_fill_action = GUI::Action::create_checkable("Fi&ll", [&](auto&) {
- m_video_display->set_sizing_mode(VideoSizingMode::Fill);
+ set_sizing_mode(VideoSizingMode::Fill);
});
m_size_stretch_action = GUI::Action::create_checkable("&Stretch", [&](auto&) {
- m_video_display->set_sizing_mode(VideoSizingMode::Stretch);
+ set_sizing_mode(VideoSizingMode::Stretch);
});
m_size_fullsize_action = GUI::Action::create_checkable("F&ull Size", [&](auto&) {
- m_video_display->set_sizing_mode(VideoSizingMode::FullSize);
+ set_sizing_mode(VideoSizingMode::FullSize);
});
+ // Load the current video sizing mode
+ // The default fallback for `read_u32` is 0, which is also our desired default for the sizing mode, VideoSizingMode::Fit
+ auto sizing_mode_value = Config::read_u32("VideoPlayer"sv, "Playback"sv, "SizingMode"sv);
+ if (sizing_mode_value >= to_underlying(VideoSizingMode::Sentinel)) {
+ sizing_mode_value = 0;
+ }
+
+ set_sizing_mode(static_cast<VideoSizingMode>(sizing_mode_value));
+
return {};
}
@@ -290,9 +300,12 @@ void VideoPlayerWidget::cycle_sizing_modes()
{
auto sizing_mode = m_video_display->sizing_mode();
sizing_mode = static_cast<VideoSizingMode>((to_underlying(sizing_mode) + 1) % to_underlying(VideoSizingMode::Sentinel));
- m_video_display->set_sizing_mode(sizing_mode);
+ set_sizing_mode(sizing_mode);
+}
- switch (sizing_mode) {
+void VideoPlayerWidget::set_current_sizing_mode_checked()
+{
+ switch (m_video_display->sizing_mode()) {
case VideoSizingMode::Fit:
m_size_fit_action->set_checked(true);
break;
@@ -349,6 +362,17 @@ void VideoPlayerWidget::set_seek_mode(Video::PlaybackManager::SeekMode seek_mode
m_use_fast_seeking->set_checked(seek_mode == Video::PlaybackManager::SeekMode::Fast);
}
+void VideoPlayerWidget::set_sizing_mode(VideoSizingMode sizing_mode)
+{
+ if (m_video_display->sizing_mode() == sizing_mode)
+ return;
+
+ m_video_display->set_sizing_mode(sizing_mode);
+ Config::write_u32("VideoPlayer"sv, "Playback"sv, "SizingMode"sv, to_underlying(sizing_mode));
+
+ set_current_sizing_mode_checked();
+}
+
ErrorOr<void> VideoPlayerWidget::initialize_menubar(GUI::Window& window)
{
// File menu
@@ -385,7 +409,6 @@ ErrorOr<void> VideoPlayerWidget::initialize_menubar(GUI::Window& window)
m_sizing_mode_group->add_action(*m_size_fill_action);
m_sizing_mode_group->add_action(*m_size_stretch_action);
m_sizing_mode_group->add_action(*m_size_fullsize_action);
- m_size_fit_action->set_checked(true);
TRY(sizing_mode_menu->try_add_action(*m_size_fit_action));
TRY(sizing_mode_menu->try_add_action(*m_size_fill_action));
diff --git a/Userland/Applications/VideoPlayer/VideoPlayerWidget.h b/Userland/Applications/VideoPlayer/VideoPlayerWidget.h
index 20fdaacc54..739ec68efd 100644
--- a/Userland/Applications/VideoPlayer/VideoPlayerWidget.h
+++ b/Userland/Applications/VideoPlayer/VideoPlayerWidget.h
@@ -35,6 +35,7 @@ public:
Video::PlaybackManager::SeekMode seek_mode();
void set_seek_mode(Video::PlaybackManager::SeekMode seek_mode);
+ void set_sizing_mode(VideoSizingMode sizing_mode);
ErrorOr<void> initialize_menubar(GUI::Window&);
@@ -48,6 +49,7 @@ private:
void on_decoding_error(Video::DecoderError const&);
void cycle_sizing_modes();
+ void set_current_sizing_mode_checked();
void toggle_fullscreen();