mirror of
https://github.com/SerenityOS/serenity
synced 2024-09-06 17:06:31 +00:00
LibCore+LibGUI+About: Use String in Core::Version and GUI::AboutDialog
The Core::Version API now returns ErrorOr<String>, and the GUI::AboutDialog API was adjusted to accommodate this.
This commit is contained in:
parent
ad4b4046f4
commit
d0977ac566
|
@ -21,6 +21,6 @@ ErrorOr<int> 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();
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include <AK/Format.h>
|
||||
#include <AK/JsonObject.h>
|
||||
#include <AK/OptionParser.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/String.h>
|
||||
#include <LibCore/ArgsParser.h>
|
||||
#include <LibCore/Version.h>
|
||||
#include <limits.h>
|
||||
|
@ -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)
|
||||
|
|
|
@ -4,22 +4,20 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/DeprecatedString.h>
|
||||
#include <AK/String.h>
|
||||
#include <LibCore/System.h>
|
||||
#include <LibCore/Version.h>
|
||||
|
||||
namespace Core::Version {
|
||||
|
||||
DeprecatedString read_long_version_string()
|
||||
ErrorOr<String> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Mahmoud Mandour <ma.mandourr@gmail.com>
|
||||
* Copyright (c) 2023, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/StringView.h>
|
||||
#include <AK/Forward.h>
|
||||
|
||||
namespace Core::Version {
|
||||
|
||||
DeprecatedString read_long_version_string();
|
||||
ErrorOr<String> read_long_version_string();
|
||||
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
namespace GUI {
|
||||
|
||||
ErrorOr<NonnullRefPtr<AboutDialog>> AboutDialog::try_create(StringView name, StringView version, Gfx::Bitmap const* icon, Window* parent_window)
|
||||
ErrorOr<NonnullRefPtr<AboutDialog>> AboutDialog::try_create(String name, String version, RefPtr<Gfx::Bitmap const> 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<NonnullRefPtr<AboutDialog>> AboutDialog::try_create(StringView name, Str
|
|||
icon_wrapper->set_visible(false);
|
||||
}
|
||||
|
||||
widget->find_descendant_of_type_named<GUI::Label>("name")->set_text(name);
|
||||
widget->find_descendant_of_type_named<GUI::Label>("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<GUI::Label>("serenity_os")->set_visible(name != "SerenityOS");
|
||||
widget->find_descendant_of_type_named<GUI::Label>("version")->set_text(version);
|
||||
widget->find_descendant_of_type_named<GUI::Label>("version")->set_text(version.to_deprecated_string());
|
||||
|
||||
auto ok_button = widget->find_descendant_of_type_named<DialogButton>("ok_button");
|
||||
ok_button->on_click = [dialog](auto) {
|
||||
|
@ -49,11 +49,11 @@ ErrorOr<NonnullRefPtr<AboutDialog>> 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<Gfx::Bitmap const> 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<void> AboutDialog::show(String name, String version, RefPtr<Gfx::Bitmap const> icon, Window* parent_window, RefPtr<Gfx::Bitmap const> 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 {};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/String.h>
|
||||
#include <LibCore/Version.h>
|
||||
#include <LibGUI/Dialog.h>
|
||||
|
||||
|
@ -15,23 +16,16 @@ namespace GUI {
|
|||
class AboutDialog final : public Dialog {
|
||||
C_OBJECT_ABSTRACT(AboutDialog)
|
||||
public:
|
||||
static ErrorOr<NonnullRefPtr<AboutDialog>> try_create(StringView name, StringView version, Gfx::Bitmap const* icon = nullptr, Window* parent_window = nullptr);
|
||||
static ErrorOr<NonnullRefPtr<AboutDialog>> try_create(String name, String version, RefPtr<Gfx::Bitmap const> icon = nullptr, Window* parent_window = nullptr);
|
||||
virtual ~AboutDialog() override = default;
|
||||
|
||||
static ErrorOr<void> 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<void> show(String name, String version, RefPtr<Gfx::Bitmap const> icon = nullptr, Window* parent_window = nullptr, RefPtr<Gfx::Bitmap const> window_icon = nullptr);
|
||||
|
||||
private:
|
||||
AboutDialog(StringView name, StringView version, Gfx::Bitmap const* icon = nullptr, Window* parent_window = nullptr);
|
||||
AboutDialog(String name, String version, RefPtr<Gfx::Bitmap const> icon = nullptr, Window* parent_window = nullptr);
|
||||
|
||||
DeprecatedString m_name;
|
||||
String m_name;
|
||||
String m_version_string;
|
||||
RefPtr<Gfx::Bitmap const> m_icon;
|
||||
DeprecatedString m_version_string;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -21,7 +21,12 @@ NonnullRefPtr<Action> make_about_action(DeprecatedString const& app_name, Icon c
|
|||
{
|
||||
auto weak_parent = AK::make_weak_ptr_if_nonnull<Window>(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;
|
||||
|
|
Loading…
Reference in a new issue