summaryrefslogtreecommitdiff
path: root/Userland/Applications/DisplaySettings/MonitorSettingsWidget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Userland/Applications/DisplaySettings/MonitorSettingsWidget.cpp')
-rw-r--r--Userland/Applications/DisplaySettings/MonitorSettingsWidget.cpp110
1 files changed, 75 insertions, 35 deletions
diff --git a/Userland/Applications/DisplaySettings/MonitorSettingsWidget.cpp b/Userland/Applications/DisplaySettings/MonitorSettingsWidget.cpp
index 2702c7be8d..20d2a655fb 100644
--- a/Userland/Applications/DisplaySettings/MonitorSettingsWidget.cpp
+++ b/Userland/Applications/DisplaySettings/MonitorSettingsWidget.cpp
@@ -67,7 +67,7 @@ ErrorOr<void> MonitorSettingsWidget::create_resolution_list()
i32 aspect_width = resolution.width() / gcf;
i32 aspect_height = resolution.height() / gcf;
- TRY(m_resolution_strings.try_append(DeprecatedString::formatted("{}x{} ({}:{})", resolution.width(), resolution.height(), aspect_width, aspect_height)));
+ TRY(m_resolution_strings.try_append(TRY(String::formatted("{}x{} ({}:{})", resolution.width(), resolution.height(), aspect_width, aspect_height))));
}
return {};
@@ -81,21 +81,27 @@ ErrorOr<void> MonitorSettingsWidget::create_frame()
m_screen_combo = *find_descendant_of_type_named<GUI::ComboBox>("screen_combo");
m_screen_combo->set_only_allow_values_from_model(true);
- m_screen_combo->set_model(*GUI::ItemListModel<DeprecatedString>::create(m_screens));
+ m_screen_combo->set_model(*GUI::ItemListModel<String>::create(m_screens));
m_screen_combo->on_change = [this](auto&, const GUI::ModelIndex& index) {
m_selected_screen_index = index.row();
- selected_screen_index_or_resolution_changed();
+ auto result = selected_screen_index_or_resolution_changed();
+ if (result.is_error())
+ GUI::MessageBox::show_error(window(), "Screen info could not be updated"sv);
};
m_resolution_combo = *find_descendant_of_type_named<GUI::ComboBox>("resolution_combo");
m_resolution_combo->set_only_allow_values_from_model(true);
- m_resolution_combo->set_model(*GUI::ItemListModel<DeprecatedString>::create(m_resolution_strings));
+ m_resolution_combo->set_model(*GUI::ItemListModel<String>::create(m_resolution_strings));
m_resolution_combo->on_change = [this](auto&, const GUI::ModelIndex& index) {
auto& selected_screen = m_screen_layout.screens[m_selected_screen_index];
selected_screen.resolution = m_resolutions.at(index.row());
// Try to auto re-arrange things if there are overlaps or disconnected screens
m_screen_layout.normalize();
- selected_screen_index_or_resolution_changed();
+ auto result = selected_screen_index_or_resolution_changed();
+ if (result.is_error()) {
+ GUI::MessageBox::show_error(window(), "Screen info could not be updated"sv);
+ return;
+ }
set_modified(true);
};
@@ -129,20 +135,20 @@ ErrorOr<void> MonitorSettingsWidget::create_frame()
return {};
}
-static DeprecatedString display_name_from_edid(EDID::Parser const& edid)
+static ErrorOr<String> display_name_from_edid(EDID::Parser const& edid)
{
auto manufacturer_name = edid.manufacturer_name();
auto product_name = edid.display_product_name();
- auto build_manufacturer_product_name = [&]() {
+ auto build_manufacturer_product_name = [&]() -> ErrorOr<String> {
if (product_name.is_null() || product_name.is_empty())
- return manufacturer_name;
- return DeprecatedString::formatted("{} {}", manufacturer_name, product_name);
+ return TRY(String::from_deprecated_string(manufacturer_name));
+ return String::formatted("{} {}", manufacturer_name, product_name);
};
if (auto screen_size = edid.screen_size(); screen_size.has_value()) {
auto diagonal_inch = hypot(screen_size.value().horizontal_cm(), screen_size.value().vertical_cm()) / 2.54;
- return DeprecatedString::formatted("{} {}\"", build_manufacturer_product_name(), roundf(diagonal_inch));
+ return String::formatted("{} {}\"", TRY(build_manufacturer_product_name()), roundf(diagonal_inch));
}
return build_manufacturer_product_name();
@@ -157,34 +163,34 @@ ErrorOr<void> MonitorSettingsWidget::load_current_settings()
size_t virtual_screen_count = 0;
for (size_t i = 0; i < m_screen_layout.screens.size(); i++) {
- DeprecatedString screen_display_name;
+ String screen_display_name;
if (m_screen_layout.screens[i].mode == WindowServer::ScreenLayout::Screen::Mode::Device) {
if (auto edid = EDID::Parser::from_display_connector_device(m_screen_layout.screens[i].device.value()); !edid.is_error()) { // TODO: multihead
- screen_display_name = display_name_from_edid(edid.value());
+ screen_display_name = TRY(display_name_from_edid(edid.value()));
TRY(m_screen_edids.try_append(edid.release_value()));
} else {
dbgln("Error getting EDID from device {}: {}", m_screen_layout.screens[i].device.value(), edid.error());
- screen_display_name = m_screen_layout.screens[i].device.value();
+ screen_display_name = TRY(String::from_deprecated_string(m_screen_layout.screens[i].device.value()));
TRY(m_screen_edids.try_append({}));
}
} else {
dbgln("Frame buffer {} is virtual.", i);
- screen_display_name = DeprecatedString::formatted("Virtual screen {}", virtual_screen_count++);
+ screen_display_name = TRY(String::formatted("Virtual screen {}", virtual_screen_count++));
TRY(m_screen_edids.try_append({}));
}
if (i == m_screen_layout.main_screen_index)
- TRY(m_screens.try_append(DeprecatedString::formatted("{}: {} (main screen)", i + 1, screen_display_name)));
+ TRY(m_screens.try_append(TRY(String::formatted("{}: {} (main screen)", i + 1, screen_display_name))));
else
- TRY(m_screens.try_append(DeprecatedString::formatted("{}: {}", i + 1, screen_display_name)));
+ TRY(m_screens.try_append(TRY(String::formatted("{}: {}", i + 1, screen_display_name))));
}
m_selected_screen_index = m_screen_layout.main_screen_index;
m_screen_combo->set_selected_index(m_selected_screen_index);
- selected_screen_index_or_resolution_changed();
+ TRY(selected_screen_index_or_resolution_changed());
return {};
}
-void MonitorSettingsWidget::selected_screen_index_or_resolution_changed()
+ErrorOr<void> MonitorSettingsWidget::selected_screen_index_or_resolution_changed()
{
auto& screen = m_screen_layout.screens[m_selected_screen_index];
@@ -193,7 +199,7 @@ void MonitorSettingsWidget::selected_screen_index_or_resolution_changed()
Gfx::IntSize current_resolution = m_resolutions.at(index);
Optional<unsigned> screen_dpi;
- DeprecatedString screen_dpi_tooltip;
+ String screen_dpi_tooltip;
if (m_screen_edids[m_selected_screen_index].has_value()) {
auto& edid = m_screen_edids[m_selected_screen_index];
if (auto screen_size = edid.value().screen_size(); screen_size.has_value()) {
@@ -203,14 +209,15 @@ void MonitorSettingsWidget::selected_screen_index_or_resolution_changed()
auto diagonal_pixels = hypot(current_resolution.width(), current_resolution.height());
if (diagonal_pixels != 0.0) {
screen_dpi = diagonal_pixels / diagonal_inch;
- screen_dpi_tooltip = DeprecatedString::formatted("{} inch display ({}cm x {}cm)", roundf(diagonal_inch), x_cm, y_cm);
+ screen_dpi_tooltip = TRY(String::formatted("{} inch display ({}cm x {}cm)", roundf(diagonal_inch), x_cm, y_cm));
}
}
}
- if (screen_dpi.has_value()) {
- m_dpi_label->set_tooltip(screen_dpi_tooltip);
- m_dpi_label->set_text(DeprecatedString::formatted("{} dpi", screen_dpi.value()));
+ auto dpi_label_value = String::formatted("{} dpi", screen_dpi.value());
+ if (screen_dpi.has_value() && !dpi_label_value.is_error()) {
+ m_dpi_label->set_tooltip(screen_dpi_tooltip.to_deprecated_string());
+ m_dpi_label->set_text(dpi_label_value.release_value().to_deprecated_string());
m_dpi_label->set_visible(true);
} else {
m_dpi_label->set_visible(false);
@@ -228,6 +235,8 @@ void MonitorSettingsWidget::selected_screen_index_or_resolution_changed()
m_resolution_combo->set_selected_index(index, GUI::AllowCallback::No);
m_monitor_widget->update();
+
+ return {};
}
void MonitorSettingsWidget::apply_settings()
@@ -241,42 +250,73 @@ void MonitorSettingsWidget::apply_settings()
if (result.success() && !load_current_settings().is_error()) {
auto seconds_until_revert = 10;
- auto box_text = [&seconds_until_revert] {
- return DeprecatedString::formatted("Do you want to keep the new settings? They will be reverted after {} {}.",
+ auto box_text = [this, &seconds_until_revert]() -> ErrorOr<String> {
+ auto output = String::formatted("Do you want to keep the new settings? They will be reverted after {} {}.",
seconds_until_revert, seconds_until_revert == 1 ? "second" : "seconds");
+ if (output.is_error()) {
+ GUI::MessageBox::show_error(window(), "Unable to apply changes"sv);
+ return Error::from_string_literal("Unable to create a formatted string");
+ }
+ return output.release_value();
};
- auto box = GUI::MessageBox::construct(window(), box_text(), "Apply new screen layout"sv,
+ auto current_box_text_or_error = box_text();
+ if (current_box_text_or_error.is_error())
+ return;
+ auto current_box_text = current_box_text_or_error.release_value();
+
+ auto box = GUI::MessageBox::construct(window(), current_box_text, "Apply new screen layout"sv,
GUI::MessageBox::Type::Question, GUI::MessageBox::InputType::YesNo);
box->set_icon(window()->icon());
// If after 10 seconds the user doesn't close the message box, just close it.
- auto revert_timer = Core::Timer::create_repeating(1000, [&] {
+ auto revert_timer_or_error = Core::Timer::create_repeating(1000, [&] {
seconds_until_revert -= 1;
- box->set_text(box_text());
+ current_box_text_or_error = box_text();
+ if (current_box_text_or_error.is_error()) {
+ seconds_until_revert = 0;
+ box->close();
+ return;
+ }
+ auto current_box_text = current_box_text_or_error.release_value();
+ box->set_text(current_box_text.to_deprecated_string());
if (seconds_until_revert <= 0) {
box->close();
}
- }).release_value_but_fixme_should_propagate_errors();
+ });
+ if (revert_timer_or_error.is_error()) {
+ GUI::MessageBox::show_error(window(), "Unable to apply changes"sv);
+ return;
+ }
+ auto revert_timer = revert_timer_or_error.release_value();
revert_timer->start();
// If the user selects "No", closes the window or the window gets closed by the 10 seconds timer, revert the changes.
if (box->exec() == GUI::MessageBox::ExecResult::Yes) {
auto save_result = GUI::ConnectionToWindowServer::the().save_screen_layout();
if (!save_result.success()) {
- GUI::MessageBox::show(window(), DeprecatedString::formatted("Error saving settings: {}", save_result.error_msg()),
- "Unable to save setting"sv, GUI::MessageBox::Type::Error);
+ auto detailed_error_message = String::formatted("Error saving settings: {}", save_result.error_msg());
+ if (!detailed_error_message.is_error())
+ GUI::MessageBox::show_error(window(), detailed_error_message.release_value());
+ else
+ GUI::MessageBox::show_error(window(), "Unable to save settings"sv);
}
} else {
auto restore_result = GUI::ConnectionToWindowServer::the().set_screen_layout(current_layout, false);
if (!restore_result.success() || load_current_settings().is_error()) {
- GUI::MessageBox::show(window(), DeprecatedString::formatted("Error restoring settings: {}", restore_result.error_msg()),
- "Unable to restore setting"sv, GUI::MessageBox::Type::Error);
+ auto detailed_error_message = String::formatted("Error restoring settings: {}", restore_result.error_msg());
+ if (!detailed_error_message.is_error())
+ GUI::MessageBox::show_error(window(), detailed_error_message.release_value());
+ else
+ GUI::MessageBox::show_error(window(), "Unable to restore settings"sv);
}
}
} else {
- GUI::MessageBox::show(window(), DeprecatedString::formatted("Error setting screen layout: {}", result.error_msg()),
- "Unable to apply changes"sv, GUI::MessageBox::Type::Error);
+ auto detailed_error_message = String::formatted("Error setting screen layout: {}", result.error_msg());
+ if (!detailed_error_message.is_error())
+ GUI::MessageBox::show_error(window(), detailed_error_message.release_value());
+ else
+ GUI::MessageBox::show_error(window(), "Unable to set screen layout"sv);
}
}
}