1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 01:27:43 +00:00

Presenter: Replace uses of JsonObject::get_deprecated()/get_ptr()

This commit is contained in:
Sam Atkins 2022-12-21 19:34:59 +00:00 committed by Tim Flynn
parent c36de98223
commit 74452ffc50
3 changed files with 18 additions and 18 deletions

View file

@ -91,23 +91,23 @@ ErrorOr<NonnullOwnPtr<Presentation>> Presentation::load_from_file(StringView fil
if (!global_object.has_number("version"sv))
return Error::from_string_view("Presentation file is missing a version specification"sv);
auto const version = global_object.get_deprecated("version"sv).to_int(-1);
auto const version = global_object.get_integer<int>("version"sv).value_or(-1);
if (version != PRESENTATION_FORMAT_VERSION)
return Error::from_string_view("Presentation file has incompatible version"sv);
auto const& maybe_metadata = global_object.get_deprecated("metadata"sv);
auto const& maybe_slides = global_object.get_deprecated("slides"sv);
auto maybe_metadata = global_object.get_object("metadata"sv);
auto maybe_slides = global_object.get_array("slides"sv);
if (maybe_metadata.is_null() || !maybe_metadata.is_object() || maybe_slides.is_null() || !maybe_slides.is_array())
if (!maybe_metadata.has_value() || !maybe_slides.has_value())
return Error::from_string_view("Metadata or slides in incorrect format"sv);
auto const& raw_metadata = maybe_metadata.as_object();
auto const& raw_metadata = maybe_metadata.value();
auto metadata = parse_metadata(raw_metadata);
auto size = TRY(parse_presentation_size(raw_metadata));
auto presentation = Presentation::construct(size, metadata);
auto const& slides = maybe_slides.as_array();
auto const& slides = maybe_slides.value();
for (auto const& maybe_slide : slides.values()) {
if (!maybe_slide.is_object())
return Error::from_string_view("Slides must be objects"sv);
@ -133,15 +133,15 @@ HashMap<DeprecatedString, DeprecatedString> Presentation::parse_metadata(JsonObj
ErrorOr<Gfx::IntSize> Presentation::parse_presentation_size(JsonObject const& metadata_object)
{
auto const& maybe_width = metadata_object.get_deprecated("width"sv);
auto const& maybe_aspect = metadata_object.get_deprecated("aspect"sv);
auto const& maybe_width = metadata_object.get("width"sv);
auto const& maybe_aspect = metadata_object.get_deprecated_string("aspect"sv);
if (maybe_width.is_null() || !maybe_width.is_number() || maybe_aspect.is_null() || !maybe_aspect.is_string())
if (!maybe_width.has_value() || !maybe_width->is_number() || !maybe_aspect.has_value())
return Error::from_string_view("Width or aspect in incorrect format"sv);
// We intentionally discard floating-point data here. If you need more resolution, just use a larger width.
auto const width = maybe_width.to_int();
auto const aspect_parts = maybe_aspect.as_string().split_view(':');
auto const width = maybe_width->to_int();
auto const aspect_parts = maybe_aspect->split_view(':');
if (aspect_parts.size() != 2)
return Error::from_string_view("Aspect specification must have the exact format `width:height`"sv);
auto aspect_width = aspect_parts[0].to_int<int>();

View file

@ -18,13 +18,13 @@ Slide::Slide(NonnullRefPtrVector<SlideObject> slide_objects, DeprecatedString ti
ErrorOr<Slide> Slide::parse_slide(JsonObject const& slide_json)
{
// FIXME: Use the text with the "title" role for a title, if there is no title given.
auto title = slide_json.get_deprecated("title"sv).as_string_or("Untitled slide");
auto title = slide_json.get_deprecated_string("title"sv).value_or("Untitled slide");
auto const& maybe_slide_objects = slide_json.get_deprecated("objects"sv);
if (!maybe_slide_objects.is_array())
auto maybe_slide_objects = slide_json.get_array("objects"sv);
if (!maybe_slide_objects.has_value())
return Error::from_string_view("Slide objects must be an array"sv);
auto const& json_slide_objects = maybe_slide_objects.as_array();
auto const& json_slide_objects = maybe_slide_objects.value();
NonnullRefPtrVector<SlideObject> slide_objects;
for (auto const& maybe_slide_object_json : json_slide_objects.values()) {
if (!maybe_slide_object_json.is_object())

View file

@ -19,11 +19,11 @@ static DeprecatedString to_css_length(float design_value, Presentation const& pr
ErrorOr<NonnullRefPtr<SlideObject>> SlideObject::parse_slide_object(JsonObject const& slide_object_json)
{
auto const& maybe_type = slide_object_json.get_deprecated("type"sv);
if (!maybe_type.is_string())
auto maybe_type = slide_object_json.get_deprecated_string("type"sv);
if (!maybe_type.has_value())
return Error::from_string_view("Slide object must have a type"sv);
auto type = maybe_type.as_string();
auto type = maybe_type.value();
RefPtr<SlideObject> object;
if (type == "text"sv)
object = TRY(try_make_ref_counted<Text>());