Skip to content

Commit e46f08f

Browse files
creator1creeper1awesomekling
authored andcommitted
Applets/Network: Propagate errors using custom try_create
We now move-construct the bitmaps into the NetworkWidget.
1 parent f125d52 commit e46f08f

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

Userland/Applets/Network/main.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,20 @@
2020
#include <stdio.h>
2121

2222
class NetworkWidget final : public GUI::ImageWidget {
23-
C_OBJECT(NetworkWidget);
23+
C_OBJECT_ABSTRACT(NetworkWidget)
24+
25+
public:
26+
static ErrorOr<NonnullRefPtr<NetworkWidget>> try_create(bool notifications)
27+
{
28+
NonnullRefPtr<Gfx::Bitmap> connected_icon = TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/network.png"));
29+
NonnullRefPtr<Gfx::Bitmap> disconnected_icon = TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/network-disconnected.png"));
30+
return adopt_nonnull_ref_or_enomem(new (nothrow) NetworkWidget(notifications, move(connected_icon), move(disconnected_icon)));
31+
}
2432

2533
private:
26-
NetworkWidget(bool notifications)
34+
NetworkWidget(bool notifications, NonnullRefPtr<Gfx::Bitmap> connected_icon, NonnullRefPtr<Gfx::Bitmap> disconnected_icon)
35+
: m_connected_icon(move(connected_icon))
36+
, m_disconnected_icon(move(disconnected_icon))
2737
{
2838
m_notifications = notifications;
2939
update_widget();
@@ -153,8 +163,8 @@ class NetworkWidget final : public GUI::ImageWidget {
153163
String m_adapter_info;
154164
bool m_connected = false;
155165
bool m_notifications = true;
156-
RefPtr<Gfx::Bitmap> m_connected_icon = Gfx::Bitmap::try_load_from_file("/res/icons/16x16/network.png").release_value_but_fixme_should_propagate_errors();
157-
RefPtr<Gfx::Bitmap> m_disconnected_icon = Gfx::Bitmap::try_load_from_file("/res/icons/16x16/network-disconnected.png").release_value_but_fixme_should_propagate_errors();
166+
NonnullRefPtr<Gfx::Bitmap> m_connected_icon;
167+
NonnullRefPtr<Gfx::Bitmap> m_disconnected_icon;
158168
};
159169

160170
ErrorOr<int> serenity_main(Main::Arguments arguments)

0 commit comments

Comments
 (0)