From 74452ffc5041c744291abe46562c13d7b0711caa Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Wed, 21 Dec 2022 19:34:59 +0000 Subject: [PATCH] Presenter: Replace uses of JsonObject::get_deprecated()/get_ptr() --- .../Applications/Presenter/Presentation.cpp | 22 +++++++++---------- Userland/Applications/Presenter/Slide.cpp | 8 +++---- .../Applications/Presenter/SlideObject.cpp | 6 ++--- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Userland/Applications/Presenter/Presentation.cpp b/Userland/Applications/Presenter/Presentation.cpp index 9861d41ad1..2959022f10 100644 --- a/Userland/Applications/Presenter/Presentation.cpp +++ b/Userland/Applications/Presenter/Presentation.cpp @@ -91,23 +91,23 @@ ErrorOr> 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("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 Presentation::parse_metadata(JsonObj ErrorOr 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(); diff --git a/Userland/Applications/Presenter/Slide.cpp b/Userland/Applications/Presenter/Slide.cpp index 5322fea7f8..fcbed85419 100644 --- a/Userland/Applications/Presenter/Slide.cpp +++ b/Userland/Applications/Presenter/Slide.cpp @@ -18,13 +18,13 @@ Slide::Slide(NonnullRefPtrVector slide_objects, DeprecatedString ti ErrorOr 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 slide_objects; for (auto const& maybe_slide_object_json : json_slide_objects.values()) { if (!maybe_slide_object_json.is_object()) diff --git a/Userland/Applications/Presenter/SlideObject.cpp b/Userland/Applications/Presenter/SlideObject.cpp index 85eda49ca8..eee1ef8ee8 100644 --- a/Userland/Applications/Presenter/SlideObject.cpp +++ b/Userland/Applications/Presenter/SlideObject.cpp @@ -19,11 +19,11 @@ static DeprecatedString to_css_length(float design_value, Presentation const& pr ErrorOr> 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 object; if (type == "text"sv) object = TRY(try_make_ref_counted());