aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2024-09-11 01:49:10 +0200
committerdec05eba <dec05eba@protonmail.com>2024-09-11 01:49:10 +0200
commit234cc3391eba6be67964e5c98beeecd318b8e779 (patch)
tree32bc82687245ebb5d43faf8b6e116883535a9688
parent8746e8e43c9c47454ca7a115969cd07746fd832e (diff)
Load settings from config file
-rw-r--r--TODO2
m---------depends/mglpp0
-rw-r--r--include/SafeVector.hpp2
-rw-r--r--include/gui/List.hpp1
-rw-r--r--include/gui/SettingsPage.hpp24
-rw-r--r--src/gui/List.cpp4
-rw-r--r--src/gui/SettingsPage.cpp127
7 files changed, 135 insertions, 25 deletions
diff --git a/TODO b/TODO
index 09f80fb..8a97c51 100644
--- a/TODO
+++ b/TODO
@@ -30,3 +30,5 @@ Make hotkeys configurable.
Move hotkey to gsr-overlay-daemon which should execute gpu-screen-recorder --info on start, write that output to /tmp/blabla (or $XDG_RUNTIME_DIR) and gsr-overlay
should read that tmp file. gsr-overlay should remove show/hide functions for overlay and run show on startup.
+
+Combobox shouldn't show all items if its the combobox at the bottom and scrolling is needed to show them all. \ No newline at end of file
diff --git a/depends/mglpp b/depends/mglpp
-Subproject 818092cd16431ed258e8de51fa24a5c6b074317
+Subproject 23b75905a53abb2e4d5a44b16e0496e7fa4c7e3
diff --git a/include/SafeVector.hpp b/include/SafeVector.hpp
index 916b547..6cb4725 100644
--- a/include/SafeVector.hpp
+++ b/include/SafeVector.hpp
@@ -15,6 +15,7 @@ public:
}
// Safe to call when vector is empty
+ // TODO: Make this iterator safe
void pop_back() {
if(!data.empty())
data.pop_back();
@@ -37,6 +38,7 @@ public:
return &data.back();
}
+ // TODO: Make this iterator safe
void clear() {
data.clear();
remove_queue.clear();
diff --git a/include/gui/List.hpp b/include/gui/List.hpp
index 55a5b84..72c5353 100644
--- a/include/gui/List.hpp
+++ b/include/gui/List.hpp
@@ -29,6 +29,7 @@ namespace gsr {
void add_widget(std::unique_ptr<Widget> widget);
void remove_widget(Widget *widget);
+ void clear();
// Return true from |callback| to continue
void for_each_child_widget(std::function<bool(std::unique_ptr<Widget> &widget)> callback);
// Returns nullptr if index is invalid
diff --git a/include/gui/SettingsPage.hpp b/include/gui/SettingsPage.hpp
index a9d79bc..ebbc98c 100644
--- a/include/gui/SettingsPage.hpp
+++ b/include/gui/SettingsPage.hpp
@@ -23,10 +23,11 @@ namespace gsr {
STREAM
};
- SettingsPage(Type type, const GsrInfo &gsr_info, const std::vector<AudioDevice> &audio_devices, std::optional<Config> &config, PageStack *page_stack);
+ SettingsPage(Type type, const GsrInfo &gsr_info, std::vector<AudioDevice> audio_devices, std::optional<Config> &config, PageStack *page_stack);
SettingsPage(const SettingsPage&) = delete;
SettingsPage& operator=(const SettingsPage&) = delete;
+ void load();
void save();
void on_navigate_away_from_page() override;
private:
@@ -41,13 +42,13 @@ namespace gsr {
std::unique_ptr<CheckBox> create_restore_portal_session_checkbox();
std::unique_ptr<List> create_restore_portal_session_section();
std::unique_ptr<Widget> create_capture_target(const GsrInfo &gsr_info);
- std::unique_ptr<ComboBox> create_audio_track_selection_checkbox(const std::vector<AudioDevice> &audio_devices);
+ std::unique_ptr<ComboBox> create_audio_track_selection_checkbox();
std::unique_ptr<Button> create_remove_audio_track_button(List *audio_device_list_ptr);
- std::unique_ptr<List> create_audio_track(const std::vector<AudioDevice> &audio_devices);
- std::unique_ptr<Button> create_add_audio_track_button(const std::vector<AudioDevice> &audio_devices);
- std::unique_ptr<List> create_audio_track_section(const std::vector<AudioDevice> &audio_devices);
+ std::unique_ptr<List> create_audio_track();
+ std::unique_ptr<Button> create_add_audio_track_button();
+ std::unique_ptr<List> create_audio_track_section();
std::unique_ptr<CheckBox> create_merge_audio_tracks_checkbox();
- std::unique_ptr<Widget> create_audio_device_section(const std::vector<AudioDevice> &audio_devices);
+ std::unique_ptr<Widget> create_audio_device_section();
std::unique_ptr<ComboBox> create_video_quality_box();
std::unique_ptr<List> create_video_quality();
std::unique_ptr<ComboBox> create_color_range_box();
@@ -64,8 +65,8 @@ namespace gsr {
std::unique_ptr<List> create_framerate_section();
std::unique_ptr<Widget> create_record_cursor_section();
std::unique_ptr<Widget> create_video_section(const GsrInfo &gsr_info);
- std::unique_ptr<Widget> create_settings(const GsrInfo &gsr_info, const std::vector<AudioDevice> &audio_devices);
- void add_widgets(const GsrInfo &gsr_info, const std::vector<AudioDevice> &audio_devices);
+ std::unique_ptr<Widget> create_settings(const GsrInfo &gsr_info);
+ void add_widgets(const GsrInfo &gsr_info);
void add_page_specific_widgets();
@@ -85,6 +86,12 @@ namespace gsr {
std::unique_ptr<List> create_stream_container_section();
void add_stream_widgets();
+ void load_audio_tracks();
+ void load_common(RecordOptions &record_options);
+ void load_replay();
+ void load_record();
+ void load_stream();
+
void save_common(RecordOptions &record_options);
void save_replay();
void save_record();
@@ -92,6 +99,7 @@ namespace gsr {
private:
Type type;
std::optional<Config> &config;
+ std::vector<AudioDevice> audio_devices;
GsrPage *content_page_ptr = nullptr;
ScrollablePage *settings_scrollable_page_ptr = nullptr;
diff --git a/src/gui/List.cpp b/src/gui/List.cpp
index 81f0e80..510de6b 100644
--- a/src/gui/List.cpp
+++ b/src/gui/List.cpp
@@ -119,6 +119,10 @@ namespace gsr {
widgets.remove(widget);
}
+ void List::clear() {
+ widgets.clear();
+ }
+
void List::for_each_child_widget(std::function<bool(std::unique_ptr<Widget> &widget)> callback) {
widgets.for_each(callback);
}
diff --git a/src/gui/SettingsPage.cpp b/src/gui/SettingsPage.cpp
index cd5c97d..8304147 100644
--- a/src/gui/SettingsPage.cpp
+++ b/src/gui/SettingsPage.cpp
@@ -14,10 +14,11 @@
#include <mglpp/window/Window.hpp>
namespace gsr {
- SettingsPage::SettingsPage(Type type, const GsrInfo &gsr_info, const std::vector<AudioDevice> &audio_devices, std::optional<Config> &config, PageStack *page_stack) :
+ SettingsPage::SettingsPage(Type type, const GsrInfo &gsr_info, std::vector<AudioDevice> audio_devices, std::optional<Config> &config, PageStack *page_stack) :
StaticPage(mgl::vec2f(get_theme().window_width, get_theme().window_height).floor()),
type(type),
config(config),
+ audio_devices(std::move(audio_devices)),
page_stack(page_stack),
settings_title_text("Settings", get_theme().title_font)
{
@@ -30,8 +31,9 @@ namespace gsr {
content_page_ptr = content_page.get();
add_widget(std::move(content_page));
- add_widgets(gsr_info, audio_devices);
+ add_widgets(gsr_info);
add_page_specific_widgets();
+ load();
}
std::unique_ptr<RadioButton> SettingsPage::create_view_radio_button() {
@@ -133,7 +135,7 @@ namespace gsr {
return std::make_unique<Subsection>("Record area", std::move(capture_target_list), mgl::vec2f(settings_scrollable_page_ptr->get_inner_size().x, 0.0f));
}
- std::unique_ptr<ComboBox> SettingsPage::create_audio_track_selection_checkbox(const std::vector<AudioDevice> &audio_devices) {
+ std::unique_ptr<ComboBox> SettingsPage::create_audio_track_selection_checkbox() {
auto audio_device_box = std::make_unique<ComboBox>(&get_theme().body_font);
for(const auto &audio_device : audio_devices) {
audio_device_box->add_item(audio_device.description, audio_device.name);
@@ -149,26 +151,26 @@ namespace gsr {
return remove_audio_track_button;
}
- std::unique_ptr<List> SettingsPage::create_audio_track(const std::vector<AudioDevice> &audio_devices) {
+ std::unique_ptr<List> SettingsPage::create_audio_track() {
auto audio_device_list = std::make_unique<List>(List::Orientation::HORIZONTAL, List::Alignment::CENTER);
- audio_device_list->add_widget(create_audio_track_selection_checkbox(audio_devices));
+ audio_device_list->add_widget(create_audio_track_selection_checkbox());
audio_device_list->add_widget(create_remove_audio_track_button(audio_device_list.get()));
return audio_device_list;
}
- std::unique_ptr<Button> SettingsPage::create_add_audio_track_button(const std::vector<AudioDevice> &audio_devices) {
+ std::unique_ptr<Button> SettingsPage::create_add_audio_track_button() {
auto add_audio_track_button = std::make_unique<Button>(&get_theme().body_font, "Add audio track", mgl::vec2f(0.0f, 0.0f), mgl::Color(0, 0, 0, 120));
- auto add_audio_track = [&audio_devices, this]() {
- audio_devices_list_ptr->add_widget(create_audio_track(audio_devices));
+ auto add_audio_track = [this]() {
+ audio_devices_list_ptr->add_widget(create_audio_track());
};
add_audio_track_button->on_click = add_audio_track;
return add_audio_track_button;
}
- std::unique_ptr<List> SettingsPage::create_audio_track_section(const std::vector<AudioDevice> &audio_devices) {
+ std::unique_ptr<List> SettingsPage::create_audio_track_section() {
auto audio_devices_list = std::make_unique<List>(List::Orientation::VERTICAL);
audio_devices_list_ptr = audio_devices_list.get();
- audio_devices_list_ptr->add_widget(create_audio_track(audio_devices));
+ audio_devices_list_ptr->add_widget(create_audio_track());
return audio_devices_list;
}
@@ -179,10 +181,10 @@ namespace gsr {
return merge_audio_tracks_checkbox;
}
- std::unique_ptr<Widget> SettingsPage::create_audio_device_section(const std::vector<AudioDevice> &audio_devices) {
+ std::unique_ptr<Widget> SettingsPage::create_audio_device_section() {
auto audio_device_section_list = std::make_unique<List>(List::Orientation::VERTICAL);
- audio_device_section_list->add_widget(create_add_audio_track_button(audio_devices));
- audio_device_section_list->add_widget(create_audio_track_section(audio_devices));
+ audio_device_section_list->add_widget(create_add_audio_track_button());
+ audio_device_section_list->add_widget(create_audio_track_section());
audio_device_section_list->add_widget(create_merge_audio_tracks_checkbox());
audio_device_section_list->add_widget(create_audio_codec());
return std::make_unique<Subsection>("Audio", std::move(audio_device_section_list), mgl::vec2f(settings_scrollable_page_ptr->get_inner_size().x, 0.0f));
@@ -337,7 +339,7 @@ namespace gsr {
return std::make_unique<Subsection>("Video", std::move(video_section_list), mgl::vec2f(settings_scrollable_page_ptr->get_inner_size().x, 0.0f));
}
- std::unique_ptr<Widget> SettingsPage::create_settings(const GsrInfo &gsr_info, const std::vector<AudioDevice> &audio_devices) {
+ std::unique_ptr<Widget> SettingsPage::create_settings(const GsrInfo &gsr_info) {
auto page_list = std::make_unique<List>(List::Orientation::VERTICAL);
page_list->set_spacing(0.018f);
page_list->add_widget(create_view_radio_button());
@@ -348,15 +350,15 @@ namespace gsr {
auto settings_list = std::make_unique<List>(List::Orientation::VERTICAL);
settings_list->set_spacing(0.018f);
settings_list->add_widget(create_capture_target(gsr_info));
- settings_list->add_widget(create_audio_device_section(audio_devices));
+ settings_list->add_widget(create_audio_device_section());
settings_list->add_widget(create_video_section(gsr_info));
settings_list_ptr = settings_list.get();
settings_scrollable_page_ptr->add_widget(std::move(settings_list));
return page_list;
}
- void SettingsPage::add_widgets(const GsrInfo &gsr_info, const std::vector<AudioDevice> &audio_devices) {
- content_page_ptr->add_widget(create_settings(gsr_info, audio_devices));
+ void SettingsPage::add_widgets(const GsrInfo &gsr_info) {
+ content_page_ptr->add_widget(create_settings(gsr_info));
record_area_box_ptr->on_selection_changed = [this](const std::string &text, const std::string &id) {
(void)text;
@@ -643,6 +645,23 @@ namespace gsr {
save();
}
+ void SettingsPage::load() {
+ if(!config)
+ return;
+
+ switch(type) {
+ case Type::REPLAY:
+ load_replay();
+ break;
+ case Type::RECORD:
+ load_record();
+ break;
+ case Type::STREAM:
+ load_stream();
+ break;
+ }
+ }
+
void SettingsPage::save() {
if(!config)
config = Config();
@@ -661,6 +680,80 @@ namespace gsr {
save_config(config.value());
}
+ void SettingsPage::load_audio_tracks() {
+ audio_devices_list_ptr->clear();
+ for(const std::string &audio_track : config->replay_config.record_options.audio_tracks) {
+ std::unique_ptr<List> audio_track_widget = create_audio_track();
+ ComboBox *audio_device_box = static_cast<ComboBox*>(audio_track_widget->get_child_widget_by_index(0));
+ audio_device_box->set_selected_item(audio_track);
+ audio_devices_list_ptr->add_widget(std::move(audio_track_widget));
+ }
+ }
+
+ void SettingsPage::load_common(RecordOptions &record_options) {
+ record_area_box_ptr->set_selected_item(record_options.record_area_option);
+ area_width_entry_ptr->set_text(std::to_string(record_options.record_area_width));
+ area_height_entry_ptr->set_text(std::to_string(record_options.record_area_height));
+ framerate_entry_ptr->set_text(std::to_string(record_options.fps));
+ merge_audio_tracks_checkbox_ptr->set_checked(record_options.merge_audio_tracks);
+
+ load_audio_tracks();
+ color_range_box_ptr->set_selected_item(record_options.color_range);
+ video_quality_box_ptr->set_selected_item(record_options.video_quality);
+ video_codec_box_ptr->set_selected_item(record_options.video_codec);
+ audio_codec_box_ptr->set_selected_item(record_options.audio_codec);
+ framerate_mode_box_ptr->set_selected_item(record_options.framerate_mode);
+ view_radio_button_ptr->set_selected_item(record_options.advanced_view ? "advanced" : "simple");
+ // TODO:
+ //record_options.overclock = false;
+ record_cursor_checkbox_ptr->set_checked(record_options.record_cursor);
+ restore_portal_session_checkbox_ptr->set_checked(record_options.restore_portal_session);
+
+ if(record_options.record_area_width < 32)
+ record_options.record_area_width = 32;
+ area_width_entry_ptr->set_text(std::to_string(record_options.record_area_width));
+
+ if(record_options.record_area_height < 32)
+ record_options.record_area_height = 32;
+ area_height_entry_ptr->set_text(std::to_string(record_options.record_area_height));
+
+ if(record_options.fps < 1)
+ record_options.fps = 1;
+ framerate_entry_ptr->set_text(std::to_string(record_options.fps));
+ }
+
+ void SettingsPage::load_replay() {
+ load_common(config->replay_config.record_options);
+ show_replay_started_notification_checkbox_ptr->set_checked(config->replay_config.show_replay_started_notifications);
+ show_replay_stopped_notification_checkbox_ptr->set_checked(config->replay_config.show_replay_stopped_notifications);
+ show_replay_saved_notification_checkbox_ptr->set_checked(config->replay_config.show_replay_saved_notifications);
+ save_directory_button_ptr->set_text(config->replay_config.save_directory);
+ container_box_ptr->set_selected_item(config->replay_config.container);
+
+ if(config->replay_config.replay_time < 5)
+ config->replay_config.replay_time = 5;
+ replay_time_entry_ptr->set_text(std::to_string(config->replay_config.replay_time));
+ }
+
+ void SettingsPage::load_record() {
+ load_common(config->record_config.record_options);
+ show_recording_started_notification_checkbox_ptr->set_checked(config->record_config.show_recording_started_notifications);
+ show_video_saved_notification_checkbox_ptr->set_checked(config->record_config.show_video_saved_notifications);
+ save_directory_button_ptr->set_text(config->record_config.save_directory);
+ container_box_ptr->set_selected_item(config->record_config.container);
+ }
+
+ void SettingsPage::load_stream() {
+ load_common(config->streaming_config.record_options);
+ show_streaming_started_notification_checkbox_ptr->set_checked(config->streaming_config.show_streaming_started_notifications);
+ show_streaming_stopped_notification_checkbox_ptr->set_checked(config->streaming_config.show_streaming_stopped_notifications);
+ streaming_service_box_ptr->set_selected_item(config->streaming_config.streaming_service);
+ youtube_stream_key_entry_ptr->set_text(config->streaming_config.youtube.stream_key);
+ twitch_stream_key_entry_ptr->set_text(config->streaming_config.twitch.stream_key);
+ stream_url_entry_ptr->set_text(config->streaming_config.custom.url);
+ container_box_ptr->set_selected_item(config->streaming_config.custom.container);
+ }
+
static void save_audio_tracks(std::vector<std::string> &audio_tracks, List *audio_devices_list_ptr) {
audio_tracks.clear();
audio_devices_list_ptr->for_each_child_widget([&audio_tracks](std::unique_ptr<Widget> &child_widget) {