diff --git a/Userland/Applications/About/main.cpp b/Userland/Applications/About/main.cpp index cf84fbb3ba4..ea3ee7c03a0 100644 --- a/Userland/Applications/About/main.cpp +++ b/Userland/Applications/About/main.cpp @@ -21,6 +21,6 @@ ErrorOr serenity_main(Main::Arguments arguments) TRY(Core::System::unveil(nullptr, nullptr)); auto app_icon = TRY(GUI::Icon::try_create_default_icon("ladyball"sv)); - TRY(GUI::AboutDialog::show("SerenityOS"sv, Core::Version::read_long_version_string(), app_icon.bitmap_for_size(32), nullptr, app_icon.bitmap_for_size(16))); + TRY(GUI::AboutDialog::show(TRY("SerenityOS"_string), TRY(Core::Version::read_long_version_string()), app_icon.bitmap_for_size(32), nullptr, app_icon.bitmap_for_size(16))); return app->exec(); } diff --git a/Userland/Libraries/LibCore/ArgsParser.cpp b/Userland/Libraries/LibCore/ArgsParser.cpp index 62c1190b82d..4f1f6f4a0cb 100644 --- a/Userland/Libraries/LibCore/ArgsParser.cpp +++ b/Userland/Libraries/LibCore/ArgsParser.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include #include @@ -364,7 +364,7 @@ void ArgsParser::print_usage_markdown(FILE* file, StringView argv0) void ArgsParser::print_version(FILE* file) { - outln(file, Core::Version::read_long_version_string()); + outln(file, Core::Version::read_long_version_string().release_value_but_fixme_should_propagate_errors()); } void ArgsParser::add_option(Option&& option) diff --git a/Userland/Libraries/LibCore/Version.cpp b/Userland/Libraries/LibCore/Version.cpp index 3e84917b0f2..202b59d2cc6 100644 --- a/Userland/Libraries/LibCore/Version.cpp +++ b/Userland/Libraries/LibCore/Version.cpp @@ -4,22 +4,20 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include +#include #include #include namespace Core::Version { -DeprecatedString read_long_version_string() +ErrorOr read_long_version_string() { - auto result = Core::System::uname(); - if (result.is_error()) - return {}; + auto uname = TRY(Core::System::uname()); - auto version = result.value().release; - auto git_hash = result.value().version; + auto const* version = uname.release; + auto const* git_hash = uname.version; - return DeprecatedString::formatted("Version {} revision {}", version, git_hash); + return String::formatted("Version {} revision {}", version, git_hash); } } diff --git a/Userland/Libraries/LibCore/Version.h b/Userland/Libraries/LibCore/Version.h index 35f54ad0fd7..9cda59f5ba9 100644 --- a/Userland/Libraries/LibCore/Version.h +++ b/Userland/Libraries/LibCore/Version.h @@ -1,15 +1,16 @@ /* * Copyright (c) 2021, Mahmoud Mandour + * Copyright (c) 2023, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once -#include +#include namespace Core::Version { -DeprecatedString read_long_version_string(); +ErrorOr read_long_version_string(); } diff --git a/Userland/Libraries/LibGUI/AboutDialog.cpp b/Userland/Libraries/LibGUI/AboutDialog.cpp index 5d57775221a..b15802218cc 100644 --- a/Userland/Libraries/LibGUI/AboutDialog.cpp +++ b/Userland/Libraries/LibGUI/AboutDialog.cpp @@ -19,7 +19,7 @@ namespace GUI { -ErrorOr> AboutDialog::try_create(StringView name, StringView version, Gfx::Bitmap const* icon, Window* parent_window) +ErrorOr> AboutDialog::try_create(String name, String version, RefPtr icon, Window* parent_window) { auto dialog = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) AboutDialog(name, version, icon, parent_window))); dialog->set_title(DeprecatedString::formatted("About {}", name)); @@ -36,10 +36,10 @@ ErrorOr> AboutDialog::try_create(StringView name, Str icon_wrapper->set_visible(false); } - widget->find_descendant_of_type_named("name")->set_text(name); + widget->find_descendant_of_type_named("name")->set_text(name.to_deprecated_string()); // If we are displaying a dialog for an application, insert 'SerenityOS' below the application name widget->find_descendant_of_type_named("serenity_os")->set_visible(name != "SerenityOS"); - widget->find_descendant_of_type_named("version")->set_text(version); + widget->find_descendant_of_type_named("version")->set_text(version.to_deprecated_string()); auto ok_button = widget->find_descendant_of_type_named("ok_button"); ok_button->on_click = [dialog](auto) { @@ -49,11 +49,11 @@ ErrorOr> AboutDialog::try_create(StringView name, Str return dialog; } -AboutDialog::AboutDialog(StringView name, StringView version, Gfx::Bitmap const* icon, Window* parent_window) +AboutDialog::AboutDialog(String name, String version, RefPtr icon, Window* parent_window) : Dialog(parent_window) - , m_name(name) - , m_icon(icon) - , m_version_string(version) + , m_name(move(name)) + , m_version_string(move(version)) + , m_icon(move(icon)) { resize(413, 204); set_resizable(false); @@ -62,4 +62,13 @@ AboutDialog::AboutDialog(StringView name, StringView version, Gfx::Bitmap const* set_icon(parent_window->icon()); } +ErrorOr AboutDialog::show(String name, String version, RefPtr icon, Window* parent_window, RefPtr window_icon) +{ + auto dialog = TRY(AboutDialog::try_create(move(name), move(version), move(icon), parent_window)); + if (window_icon) + dialog->set_icon(window_icon); + dialog->exec(); + return {}; +} + } diff --git a/Userland/Libraries/LibGUI/AboutDialog.h b/Userland/Libraries/LibGUI/AboutDialog.h index 93290749b14..13949c6a9b1 100644 --- a/Userland/Libraries/LibGUI/AboutDialog.h +++ b/Userland/Libraries/LibGUI/AboutDialog.h @@ -7,6 +7,7 @@ #pragma once +#include #include #include @@ -15,23 +16,16 @@ namespace GUI { class AboutDialog final : public Dialog { C_OBJECT_ABSTRACT(AboutDialog) public: - static ErrorOr> try_create(StringView name, StringView version, Gfx::Bitmap const* icon = nullptr, Window* parent_window = nullptr); + static ErrorOr> try_create(String name, String version, RefPtr icon = nullptr, Window* parent_window = nullptr); virtual ~AboutDialog() override = default; - static ErrorOr show(StringView name, StringView version, Gfx::Bitmap const* icon = nullptr, Window* parent_window = nullptr, Gfx::Bitmap const* window_icon = nullptr) - { - auto dialog = TRY(AboutDialog::try_create(name, version, icon, parent_window)); - if (window_icon) - dialog->set_icon(window_icon); - dialog->exec(); - return {}; - } + static ErrorOr show(String name, String version, RefPtr icon = nullptr, Window* parent_window = nullptr, RefPtr window_icon = nullptr); private: - AboutDialog(StringView name, StringView version, Gfx::Bitmap const* icon = nullptr, Window* parent_window = nullptr); + AboutDialog(String name, String version, RefPtr icon = nullptr, Window* parent_window = nullptr); - DeprecatedString m_name; + String m_name; + String m_version_string; RefPtr m_icon; - DeprecatedString m_version_string; }; } diff --git a/Userland/Libraries/LibGUI/CommonActions.cpp b/Userland/Libraries/LibGUI/CommonActions.cpp index 437de549ce4..8e3a7b4270c 100644 --- a/Userland/Libraries/LibGUI/CommonActions.cpp +++ b/Userland/Libraries/LibGUI/CommonActions.cpp @@ -21,7 +21,12 @@ NonnullRefPtr make_about_action(DeprecatedString const& app_name, Icon c { auto weak_parent = AK::make_weak_ptr_if_nonnull(parent); auto action = Action::create(DeprecatedString::formatted("&About {}", app_name), app_icon.bitmap_for_size(16), [=](auto&) { - AboutDialog::show(app_name, Core::Version::read_long_version_string(), app_icon.bitmap_for_size(32), weak_parent.ptr()).release_value_but_fixme_should_propagate_errors(); + AboutDialog::show( + String::from_utf8(app_name).release_value_but_fixme_should_propagate_errors(), + Core::Version::read_long_version_string().release_value_but_fixme_should_propagate_errors(), + app_icon.bitmap_for_size(32), + weak_parent) + .release_value_but_fixme_should_propagate_errors(); }); action->set_status_tip("Show application about box"); return action;