From e46f08ff33c4b75acc6d3f54b25d2b462ac60e9f Mon Sep 17 00:00:00 2001 From: creator1creeper1 Date: Sat, 25 Dec 2021 13:50:43 +0100 Subject: [PATCH] Applets/Network: Propagate errors using custom try_create We now move-construct the bitmaps into the NetworkWidget. --- Userland/Applets/Network/main.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Userland/Applets/Network/main.cpp b/Userland/Applets/Network/main.cpp index 9e3d38085f..35fcbf6695 100644 --- a/Userland/Applets/Network/main.cpp +++ b/Userland/Applets/Network/main.cpp @@ -20,10 +20,20 @@ #include class NetworkWidget final : public GUI::ImageWidget { - C_OBJECT(NetworkWidget); + C_OBJECT_ABSTRACT(NetworkWidget) + +public: + static ErrorOr> try_create(bool notifications) + { + NonnullRefPtr connected_icon = TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/network.png")); + NonnullRefPtr disconnected_icon = TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/network-disconnected.png")); + return adopt_nonnull_ref_or_enomem(new (nothrow) NetworkWidget(notifications, move(connected_icon), move(disconnected_icon))); + } private: - NetworkWidget(bool notifications) + NetworkWidget(bool notifications, NonnullRefPtr connected_icon, NonnullRefPtr disconnected_icon) + : m_connected_icon(move(connected_icon)) + , m_disconnected_icon(move(disconnected_icon)) { m_notifications = notifications; update_widget(); @@ -153,8 +163,8 @@ private: String m_adapter_info; bool m_connected = false; bool m_notifications = true; - RefPtr m_connected_icon = Gfx::Bitmap::try_load_from_file("/res/icons/16x16/network.png").release_value_but_fixme_should_propagate_errors(); - RefPtr m_disconnected_icon = Gfx::Bitmap::try_load_from_file("/res/icons/16x16/network-disconnected.png").release_value_but_fixme_should_propagate_errors(); + NonnullRefPtr m_connected_icon; + NonnullRefPtr m_disconnected_icon; }; ErrorOr serenity_main(Main::Arguments arguments)