mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 15:47:45 +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
7 changed files with 40 additions and 33 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue