summaryrefslogtreecommitdiff
path: root/Userland/Applications/DisplaySettings/BackgroundSettingsWidget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Userland/Applications/DisplaySettings/BackgroundSettingsWidget.cpp')
-rw-r--r--Userland/Applications/DisplaySettings/BackgroundSettingsWidget.cpp62
1 files changed, 41 insertions, 21 deletions
diff --git a/Userland/Applications/DisplaySettings/BackgroundSettingsWidget.cpp b/Userland/Applications/DisplaySettings/BackgroundSettingsWidget.cpp
index cd48d92011..1ceada02c9 100644
--- a/Userland/Applications/DisplaySettings/BackgroundSettingsWidget.cpp
+++ b/Userland/Applications/DisplaySettings/BackgroundSettingsWidget.cpp
@@ -34,9 +34,9 @@ ErrorOr<NonnullRefPtr<BackgroundSettingsWidget>> BackgroundSettingsWidget::try_c
{
auto background_settings_widget = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) BackgroundSettingsWidget(background_settings_changed)));
- TRY(background_settings_widget->m_modes.try_append("Tile"));
- TRY(background_settings_widget->m_modes.try_append("Center"));
- TRY(background_settings_widget->m_modes.try_append("Stretch"));
+ TRY(background_settings_widget->m_modes.try_append(TRY(String::from_utf8("Tile"sv))));
+ TRY(background_settings_widget->m_modes.try_append(TRY(String::from_utf8("Center"sv))));
+ TRY(background_settings_widget->m_modes.try_append(TRY(String::from_utf8("Stretch"sv))));
TRY(background_settings_widget->create_frame());
TRY(background_settings_widget->load_current_settings());
@@ -59,12 +59,15 @@ ErrorOr<void> BackgroundSettingsWidget::create_frame()
m_wallpaper_view->set_model(GUI::FileSystemModel::create("/res/wallpapers"));
m_wallpaper_view->set_model_column(GUI::FileSystemModel::Column::Name);
m_wallpaper_view->on_selection_change = [this] {
- DeprecatedString path;
- if (m_wallpaper_view->selection().is_empty()) {
- path = "";
- } else {
+ String path = String::from_utf8_short_string(""sv);
+ if (!m_wallpaper_view->selection().is_empty()) {
auto index = m_wallpaper_view->selection().first();
- path = static_cast<GUI::FileSystemModel*>(m_wallpaper_view->model())->full_path(index);
+ auto path_or_error = String::from_deprecated_string(static_cast<GUI::FileSystemModel*>(m_wallpaper_view->model())->full_path(index));
+ if (path_or_error.is_error()) {
+ GUI::MessageBox::show_error(window(), "Unable to load wallpaper"sv);
+ return;
+ }
+ path = path_or_error.release_value();
}
m_monitor_widget->set_wallpaper(path);
@@ -74,7 +77,7 @@ ErrorOr<void> BackgroundSettingsWidget::create_frame()
m_context_menu = GUI::Menu::construct();
auto const file_manager_icon = TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-file-manager.png"sv));
m_show_in_file_manager_action = GUI::Action::create("Show in File Manager", file_manager_icon, [this](GUI::Action const&) {
- LexicalPath path { m_monitor_widget->wallpaper() };
+ LexicalPath path { m_monitor_widget->wallpaper().value().to_deprecated_string() };
Desktop::Launcher::open(URL::create_with_file_scheme(path.dirname(), path.basename()));
});
m_context_menu->add_action(*m_show_in_file_manager_action);
@@ -82,8 +85,9 @@ ErrorOr<void> BackgroundSettingsWidget::create_frame()
TRY(m_context_menu->try_add_separator());
m_copy_action = GUI::CommonActions::make_copy_action(
[this](auto&) {
- auto url = URL::create_with_file_scheme(m_monitor_widget->wallpaper()).to_deprecated_string();
- GUI::Clipboard::the().set_data(url.bytes(), "text/uri-list");
+ auto wallpaper = m_monitor_widget->wallpaper();
+ if (wallpaper.has_value())
+ GUI::Clipboard::the().set_data(URL::create_with_file_scheme(wallpaper.value().to_deprecated_string()).to_deprecated_string().bytes(), "text/uri-list");
},
this);
m_context_menu->add_action(*m_copy_action);
@@ -96,18 +100,23 @@ ErrorOr<void> BackgroundSettingsWidget::create_frame()
auto& button = *find_descendant_of_type_named<GUI::Button>("wallpaper_open_button");
button.on_click = [this](auto) {
- auto path = GUI::FilePicker::get_open_filepath(window(), "Select wallpaper from file system", "/res/wallpapers"sv, false, GUI::Dialog::ScreenPosition::CenterWithinParent, { { GUI::FileTypeFilter::image_files(), GUI::FileTypeFilter::all_files() } });
- if (!path.has_value())
+ auto path_or_empty = GUI::FilePicker::get_open_filepath(window(), "Select wallpaper from file system", "/res/wallpapers"sv, false, GUI::Dialog::ScreenPosition::CenterWithinParent, { { GUI::FileTypeFilter::image_files(), GUI::FileTypeFilter::all_files() } });
+ if (!path_or_empty.has_value())
+ return;
+ auto path = String::from_deprecated_string(path_or_empty.value());
+ if (path.is_error()) {
+ GUI::MessageBox::show_error(window(), "Unable to set wallpaper"sv);
return;
+ }
m_wallpaper_view->selection().clear();
- m_monitor_widget->set_wallpaper(path.value());
+ m_monitor_widget->set_wallpaper(path.release_value());
m_background_settings_changed = true;
set_modified(true);
};
m_mode_combo = *find_descendant_of_type_named<GUI::ComboBox>("mode_combo");
m_mode_combo->set_only_allow_values_from_model(true);
- m_mode_combo->set_model(*GUI::ItemListModel<DeprecatedString>::create(m_modes));
+ m_mode_combo->set_model(*GUI::ItemListModel<String>::create(m_modes));
bool first_mode_change = true;
m_mode_combo->on_change = [this, first_mode_change](auto&, const GUI::ModelIndex& index) mutable {
m_monitor_widget->set_wallpaper_mode(m_modes.at(index.row()));
@@ -134,17 +143,17 @@ ErrorOr<void> BackgroundSettingsWidget::load_current_settings()
{
auto ws_config = TRY(Core::ConfigFile::open("/etc/WindowServer.ini"));
- auto selected_wallpaper = Config::read_string("WindowManager"sv, "Background"sv, "Wallpaper"sv, ""sv);
+ auto selected_wallpaper = TRY(String::from_deprecated_string(Config::read_string("WindowManager"sv, "Background"sv, "Wallpaper"sv, ""sv)));
if (!selected_wallpaper.is_empty()) {
- auto index = static_cast<GUI::FileSystemModel*>(m_wallpaper_view->model())->index(selected_wallpaper, m_wallpaper_view->model_column());
+ auto index = static_cast<GUI::FileSystemModel*>(m_wallpaper_view->model())->index(selected_wallpaper.to_deprecated_string(), m_wallpaper_view->model_column());
m_wallpaper_view->set_cursor(index, GUI::AbstractView::SelectionUpdate::Set);
m_monitor_widget->set_wallpaper(selected_wallpaper);
}
- auto mode = ws_config->read_entry("Background", "Mode", "Center");
+ auto mode = TRY(String::from_deprecated_string(ws_config->read_entry("Background", "Mode", "Center")));
if (!m_modes.contains_slow(mode)) {
warnln("Invalid background mode '{}' in WindowServer config, falling back to 'Center'", mode);
- mode = "Center";
+ mode = TRY(String::from_utf8("Center"sv));
}
m_monitor_widget->set_wallpaper_mode(mode);
m_mode_combo->set_selected_index(m_modes.find_first_index(mode).value_or(0), GUI::AllowCallback::No);
@@ -167,8 +176,19 @@ ErrorOr<void> BackgroundSettingsWidget::load_current_settings()
void BackgroundSettingsWidget::apply_settings()
{
- if (!GUI::Desktop::the().set_wallpaper(m_monitor_widget->wallpaper_bitmap(), m_monitor_widget->wallpaper()))
- GUI::MessageBox::show_error(window(), DeprecatedString::formatted("Unable to load file {} as wallpaper", m_monitor_widget->wallpaper()));
+ auto wallpaper_path_or_empty = m_monitor_widget->wallpaper();
+
+ if (!GUI::Desktop::the().set_wallpaper(m_monitor_widget->wallpaper_bitmap(), wallpaper_path_or_empty)) {
+ if (!wallpaper_path_or_empty.has_value()) {
+ GUI::MessageBox::show_error(window(), "Unable to load wallpaper"sv);
+ } else {
+ auto detailed_error_message = String::formatted("Unable to load file {} as wallpaper", wallpaper_path_or_empty.value());
+ if (!detailed_error_message.is_error())
+ GUI::MessageBox::show_error(window(), detailed_error_message.release_value());
+ else
+ GUI::MessageBox::show_error(window(), "Unable to load wallpaper"sv);
+ }
+ }
GUI::Desktop::the().set_background_color(m_color_input->text());
GUI::Desktop::the().set_wallpaper_mode(m_monitor_widget->wallpaper_mode());