GamesSettings+LibCards: Get rid of DeprecatedString

This commit is contained in:
kleines Filmröllchen 2023-06-26 20:49:32 +02:00 committed by Linus Groh
parent afaea38be2
commit bd13cc0732
5 changed files with 14 additions and 13 deletions

View file

@ -93,7 +93,7 @@ ErrorOr<void> CardSettingsWidget::initialize()
m_card_back_image_view = find_descendant_of_type_named<GUI::IconView>("cards_back_image");
m_card_back_image_view->set_model(GUI::FileSystemModel::create("/res/graphics/cards/backs"));
m_card_back_image_view->set_model_column(GUI::FileSystemModel::Column::Name);
if (!set_card_back_image_path(Config::read_string("Games"sv, "Cards"sv, "CardBackImage"sv)))
if (!set_card_back_image_path(TRY(String::from_deprecated_string(Config::read_string("Games"sv, "Cards"sv, "CardBackImage"sv)))))
set_card_back_image_path(default_card_back_image_path);
m_card_back_image_view->on_selection_change = [&]() {
auto& card_back_selection = m_card_back_image_view->selection();
@ -122,9 +122,9 @@ void CardSettingsWidget::reset_default_values()
set_card_back_image_path(default_card_back_image_path);
}
bool CardSettingsWidget::set_card_back_image_path(DeprecatedString const& path)
bool CardSettingsWidget::set_card_back_image_path(StringView path)
{
auto index = static_cast<GUI::FileSystemModel*>(m_card_back_image_view->model())->index(path, m_card_back_image_view->model_column());
auto index = static_cast<GUI::FileSystemModel*>(m_card_back_image_view->model())->index(path.to_deprecated_string(), m_card_back_image_view->model_column());
if (index.is_valid()) {
m_card_back_image_view->set_cursor(index, GUI::AbstractView::SelectionUpdate::Set);
Cards::CardPainter::the().set_background_image_path(path);
@ -134,13 +134,13 @@ bool CardSettingsWidget::set_card_back_image_path(DeprecatedString const& path)
return false;
}
DeprecatedString CardSettingsWidget::card_back_image_path() const
String CardSettingsWidget::card_back_image_path() const
{
auto& card_back_selection = m_card_back_image_view->selection();
GUI::ModelIndex card_back_image_index = m_last_selected_card_back;
if (!card_back_selection.is_empty())
card_back_image_index = card_back_selection.first();
return static_cast<GUI::FileSystemModel const*>(m_card_back_image_view->model())->full_path(card_back_image_index);
return String::from_deprecated_string(static_cast<GUI::FileSystemModel const*>(m_card_back_image_view->model())->full_path(card_back_image_index)).release_value_but_fixme_should_propagate_errors();
}
}

View file

@ -30,8 +30,8 @@ private:
CardSettingsWidget() = default;
ErrorOr<void> initialize();
bool set_card_back_image_path(DeprecatedString const&);
DeprecatedString card_back_image_path() const;
bool set_card_back_image_path(StringView);
String card_back_image_path() const;
RefPtr<CardGamePreview> m_preview_frame;
RefPtr<GUI::ColorInput> m_background_color_input;

View file

@ -121,7 +121,7 @@ void CardGame::config_string_did_change(StringView domain, StringView group, Str
return;
}
if (key == "CardBackImage") {
CardPainter::the().set_background_image_path(value);
CardPainter::the().set_background_image_path(String::from_utf8(value).release_value_but_fixme_should_propagate_errors());
update();
return;
}

View file

@ -21,7 +21,7 @@ CardPainter& CardPainter::the()
CardPainter::CardPainter()
{
m_background_image_path = Config::read_string("Games"sv, "Cards"sv, "CardBackImage"sv, "/res/graphics/cards/backs/buggie-deck.png"sv);
m_background_image_path = MUST(String::from_deprecated_string(Config::read_string("Games"sv, "Cards"sv, "CardBackImage"sv, "/res/graphics/cards/backs/buggie-deck.png"sv)));
}
static constexpr Gfx::CharacterBitmap s_diamond {
@ -143,12 +143,12 @@ NonnullRefPtr<Gfx::Bitmap> CardPainter::card_back_inverted()
return *m_card_back_inverted;
}
void CardPainter::set_background_image_path(DeprecatedString path)
void CardPainter::set_background_image_path(StringView path)
{
if (m_background_image_path == path)
return;
m_background_image_path = path;
m_background_image_path = MUST(String::from_utf8(path));
if (!m_card_back.is_null())
paint_card_back(*m_card_back);
if (!m_card_back_inverted.is_null())

View file

@ -7,6 +7,7 @@
#pragma once
#include <AK/Array.h>
#include <AK/String.h>
#include <LibCards/Card.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/Color.h>
@ -23,7 +24,7 @@ public:
NonnullRefPtr<Gfx::Bitmap> card_back_inverted();
NonnullRefPtr<Gfx::Bitmap> card_front_highlighted(Suit, Rank);
void set_background_image_path(DeprecatedString path);
void set_background_image_path(StringView path);
void set_background_color(Color);
private:
@ -40,7 +41,7 @@ private:
RefPtr<Gfx::Bitmap> m_card_back;
RefPtr<Gfx::Bitmap> m_card_back_inverted;
DeprecatedString m_background_image_path;
String m_background_image_path;
Color m_background_color;
};