diff options
author | Karol Kosek <krkk@serenityos.org> | 2023-05-14 19:38:08 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-05-15 06:42:10 +0200 |
commit | b7558a5ce43c62efb357863f709d942daf9aa218 (patch) | |
tree | 6ee78cf24bf91569189b3383814dd99a454ece95 /Userland/Applications/SystemMonitor | |
parent | 945f05ed76b23e8b201ce0a758d5318723440d36 (diff) | |
download | serenity-b7558a5ce43c62efb357863f709d942daf9aa218.zip |
LibGUI+Userland: Store column names in JsonArrayModel as String
Diffstat (limited to 'Userland/Applications/SystemMonitor')
5 files changed, 59 insertions, 59 deletions
diff --git a/Userland/Applications/SystemMonitor/NetworkStatisticsWidget.cpp b/Userland/Applications/SystemMonitor/NetworkStatisticsWidget.cpp index 218c261c35..be4f56355a 100644 --- a/Userland/Applications/SystemMonitor/NetworkStatisticsWidget.cpp +++ b/Userland/Applications/SystemMonitor/NetworkStatisticsWidget.cpp @@ -43,17 +43,17 @@ NetworkStatisticsWidget::NetworkStatisticsWidget() m_adapter_table_view = adapters_group_box.add<GUI::TableView>(); Vector<GUI::JsonArrayModel::FieldSpec> net_adapters_fields; - net_adapters_fields.empend("", Gfx::TextAlignment::CenterLeft, + net_adapters_fields.empend(String(), Gfx::TextAlignment::CenterLeft, [this](JsonObject const& object) -> GUI::Variant { if (!object.get_bool("link_up"sv).value_or(false)) return *m_network_link_down_bitmap; else return object.get_deprecated_string("ipv4_address"sv).value_or("").is_empty() ? *m_network_disconnected_bitmap : *m_network_connected_bitmap; }); - net_adapters_fields.empend("name", "Name", Gfx::TextAlignment::CenterLeft); - net_adapters_fields.empend("class_name", "Class", Gfx::TextAlignment::CenterLeft); - net_adapters_fields.empend("mac_address", "MAC", Gfx::TextAlignment::CenterLeft); - net_adapters_fields.empend("Link status", Gfx::TextAlignment::CenterLeft, + net_adapters_fields.empend("name", "Name"_short_string, Gfx::TextAlignment::CenterLeft); + net_adapters_fields.empend("class_name", "Class"_short_string, Gfx::TextAlignment::CenterLeft); + net_adapters_fields.empend("mac_address", "MAC"_short_string, Gfx::TextAlignment::CenterLeft); + net_adapters_fields.empend("Link status"_string.release_value_but_fixme_should_propagate_errors(), Gfx::TextAlignment::CenterLeft, [](JsonObject const& object) -> DeprecatedString { if (!object.get_bool("link_up"sv).value_or(false)) return "Down"; @@ -61,14 +61,14 @@ NetworkStatisticsWidget::NetworkStatisticsWidget() return DeprecatedString::formatted("{} Mb/s {}-duplex", object.get_i32("link_speed"sv).value_or(0), object.get_bool("link_full_duplex"sv).value_or(false) ? "full"sv : "half"sv); }); - net_adapters_fields.empend("IPv4", Gfx::TextAlignment::CenterLeft, + net_adapters_fields.empend("IPv4"_short_string, Gfx::TextAlignment::CenterLeft, [](JsonObject const& object) -> DeprecatedString { return object.get_deprecated_string("ipv4_address"sv).value_or(""sv); }); - net_adapters_fields.empend("packets_in", "Pkt In", Gfx::TextAlignment::CenterRight); - net_adapters_fields.empend("packets_out", "Pkt Out", Gfx::TextAlignment::CenterRight); - net_adapters_fields.empend("bytes_in", "Bytes In", Gfx::TextAlignment::CenterRight); - net_adapters_fields.empend("bytes_out", "Bytes Out", Gfx::TextAlignment::CenterRight); + net_adapters_fields.empend("packets_in", "Pkt In"_short_string, Gfx::TextAlignment::CenterRight); + net_adapters_fields.empend("packets_out", "Pkt Out"_short_string, Gfx::TextAlignment::CenterRight); + net_adapters_fields.empend("bytes_in", "Bytes In"_string.release_value_but_fixme_should_propagate_errors(), Gfx::TextAlignment::CenterRight); + net_adapters_fields.empend("bytes_out", "Bytes Out"_string.release_value_but_fixme_should_propagate_errors(), Gfx::TextAlignment::CenterRight); m_adapter_model = GUI::JsonArrayModel::create("/sys/kernel/net/adapters", move(net_adapters_fields)); m_adapter_table_view->set_model(MUST(GUI::SortingProxyModel::create(*m_adapter_model))); m_adapter_context_menu = MUST(GUI::Menu::try_create()); @@ -97,17 +97,17 @@ NetworkStatisticsWidget::NetworkStatisticsWidget() m_tcp_socket_table_view = tcp_sockets_group_box.add<GUI::TableView>(); Vector<GUI::JsonArrayModel::FieldSpec> net_tcp_fields; - net_tcp_fields.empend("peer_address", "Peer", Gfx::TextAlignment::CenterLeft); - net_tcp_fields.empend("peer_port", "Port", Gfx::TextAlignment::CenterRight); - net_tcp_fields.empend("local_address", "Local", Gfx::TextAlignment::CenterLeft); - net_tcp_fields.empend("local_port", "Port", Gfx::TextAlignment::CenterRight); - net_tcp_fields.empend("state", "State", Gfx::TextAlignment::CenterLeft); - net_tcp_fields.empend("ack_number", "Ack#", Gfx::TextAlignment::CenterRight); - net_tcp_fields.empend("sequence_number", "Seq#", Gfx::TextAlignment::CenterRight); - net_tcp_fields.empend("packets_in", "Pkt In", Gfx::TextAlignment::CenterRight); - net_tcp_fields.empend("packets_out", "Pkt Out", Gfx::TextAlignment::CenterRight); - net_tcp_fields.empend("bytes_in", "Bytes In", Gfx::TextAlignment::CenterRight); - net_tcp_fields.empend("bytes_out", "Bytes Out", Gfx::TextAlignment::CenterRight); + net_tcp_fields.empend("peer_address", "Peer"_short_string, Gfx::TextAlignment::CenterLeft); + net_tcp_fields.empend("peer_port", "Port"_short_string, Gfx::TextAlignment::CenterRight); + net_tcp_fields.empend("local_address", "Local"_short_string, Gfx::TextAlignment::CenterLeft); + net_tcp_fields.empend("local_port", "Port"_short_string, Gfx::TextAlignment::CenterRight); + net_tcp_fields.empend("state", "State"_short_string, Gfx::TextAlignment::CenterLeft); + net_tcp_fields.empend("ack_number", "Ack#"_short_string, Gfx::TextAlignment::CenterRight); + net_tcp_fields.empend("sequence_number", "Seq#"_short_string, Gfx::TextAlignment::CenterRight); + net_tcp_fields.empend("packets_in", "Pkt In"_short_string, Gfx::TextAlignment::CenterRight); + net_tcp_fields.empend("packets_out", "Pkt Out"_short_string, Gfx::TextAlignment::CenterRight); + net_tcp_fields.empend("bytes_in", "Bytes In"_string.release_value_but_fixme_should_propagate_errors(), Gfx::TextAlignment::CenterRight); + net_tcp_fields.empend("bytes_out", "Bytes Out"_string.release_value_but_fixme_should_propagate_errors(), Gfx::TextAlignment::CenterRight); m_tcp_socket_model = GUI::JsonArrayModel::create("/sys/kernel/net/tcp", move(net_tcp_fields)); m_tcp_socket_table_view->set_model(MUST(GUI::SortingProxyModel::create(*m_tcp_socket_model))); @@ -117,10 +117,10 @@ NetworkStatisticsWidget::NetworkStatisticsWidget() m_udp_socket_table_view = udp_sockets_group_box.add<GUI::TableView>(); Vector<GUI::JsonArrayModel::FieldSpec> net_udp_fields; - net_udp_fields.empend("peer_address", "Peer", Gfx::TextAlignment::CenterLeft); - net_udp_fields.empend("peer_port", "Port", Gfx::TextAlignment::CenterRight); - net_udp_fields.empend("local_address", "Local", Gfx::TextAlignment::CenterLeft); - net_udp_fields.empend("local_port", "Port", Gfx::TextAlignment::CenterRight); + net_udp_fields.empend("peer_address", "Peer"_short_string, Gfx::TextAlignment::CenterLeft); + net_udp_fields.empend("peer_port", "Port"_short_string, Gfx::TextAlignment::CenterRight); + net_udp_fields.empend("local_address", "Local"_short_string, Gfx::TextAlignment::CenterLeft); + net_udp_fields.empend("local_port", "Port"_short_string, Gfx::TextAlignment::CenterRight); m_udp_socket_model = GUI::JsonArrayModel::create("/sys/kernel/net/udp", move(net_udp_fields)); m_udp_socket_table_view->set_model(MUST(GUI::SortingProxyModel::create(*m_udp_socket_model))); diff --git a/Userland/Applications/SystemMonitor/ProcessFileDescriptorMapWidget.cpp b/Userland/Applications/SystemMonitor/ProcessFileDescriptorMapWidget.cpp index c1a5db07c5..83941126a2 100644 --- a/Userland/Applications/SystemMonitor/ProcessFileDescriptorMapWidget.cpp +++ b/Userland/Applications/SystemMonitor/ProcessFileDescriptorMapWidget.cpp @@ -21,23 +21,23 @@ ProcessFileDescriptorMapWidget::ProcessFileDescriptorMapWidget() m_table_view = add<GUI::TableView>(); Vector<GUI::JsonArrayModel::FieldSpec> pid_fds_fields; - pid_fds_fields.empend("fd", "FD", Gfx::TextAlignment::CenterRight); - pid_fds_fields.empend("class", "Class", Gfx::TextAlignment::CenterLeft); - pid_fds_fields.empend("offset", "Offset", Gfx::TextAlignment::CenterRight); - pid_fds_fields.empend("absolute_path", "Path", Gfx::TextAlignment::CenterLeft); - pid_fds_fields.empend("Access", Gfx::TextAlignment::CenterLeft, [](auto& object) { + pid_fds_fields.empend("fd", "FD"_short_string, Gfx::TextAlignment::CenterRight); + pid_fds_fields.empend("class", "Class"_short_string, Gfx::TextAlignment::CenterLeft); + pid_fds_fields.empend("offset", "Offset"_short_string, Gfx::TextAlignment::CenterRight); + pid_fds_fields.empend("absolute_path", "Path"_short_string, Gfx::TextAlignment::CenterLeft); + pid_fds_fields.empend("Access"_short_string, Gfx::TextAlignment::CenterLeft, [](auto& object) { return object.get_bool("seekable"sv).value_or(false) ? "Seekable" : "Sequential"; }); - pid_fds_fields.empend("Blocking", Gfx::TextAlignment::CenterLeft, [](auto& object) { + pid_fds_fields.empend("Blocking"_string.release_value_but_fixme_should_propagate_errors(), Gfx::TextAlignment::CenterLeft, [](auto& object) { return object.get_bool("blocking"sv).value_or(false) ? "Blocking" : "Nonblocking"; }); - pid_fds_fields.empend("On exec", Gfx::TextAlignment::CenterLeft, [](auto& object) { + pid_fds_fields.empend("On exec"_short_string, Gfx::TextAlignment::CenterLeft, [](auto& object) { return object.get_bool("cloexec"sv).value_or(false) ? "Close" : "Keep"; }); - pid_fds_fields.empend("Can read", Gfx::TextAlignment::CenterLeft, [](auto& object) { + pid_fds_fields.empend("Can read"_string.release_value_but_fixme_should_propagate_errors(), Gfx::TextAlignment::CenterLeft, [](auto& object) { return object.get_bool("can_read"sv).value_or(false) ? "Yes" : "No"; }); - pid_fds_fields.empend("Can write", Gfx::TextAlignment::CenterLeft, [](auto& object) { + pid_fds_fields.empend("Can write"_string.release_value_but_fixme_should_propagate_errors(), Gfx::TextAlignment::CenterLeft, [](auto& object) { return object.get_bool("can_write"sv).value_or(false) ? "Yes" : "No"; }); diff --git a/Userland/Applications/SystemMonitor/ProcessMemoryMapWidget.cpp b/Userland/Applications/SystemMonitor/ProcessMemoryMapWidget.cpp index 2feabf542c..a669a0a2f1 100644 --- a/Userland/Applications/SystemMonitor/ProcessMemoryMapWidget.cpp +++ b/Userland/Applications/SystemMonitor/ProcessMemoryMapWidget.cpp @@ -55,13 +55,13 @@ ProcessMemoryMapWidget::ProcessMemoryMapWidget() m_table_view = add<GUI::TableView>(); Vector<GUI::JsonArrayModel::FieldSpec> pid_vm_fields; pid_vm_fields.empend( - "Address", Gfx::TextAlignment::CenterLeft, + "Address"_short_string, Gfx::TextAlignment::CenterLeft, [](auto& object) { return DeprecatedString::formatted("{:p}", object.get_u64("address"sv).value_or(0)); }, [](auto& object) { return object.get_u64("address"sv).value_or(0); }); - pid_vm_fields.empend("size", "Size", Gfx::TextAlignment::CenterRight); - pid_vm_fields.empend("amount_resident", "Resident", Gfx::TextAlignment::CenterRight); - pid_vm_fields.empend("amount_dirty", "Dirty", Gfx::TextAlignment::CenterRight); - pid_vm_fields.empend("Access", Gfx::TextAlignment::CenterLeft, [](auto& object) { + pid_vm_fields.empend("size", "Size"_short_string, Gfx::TextAlignment::CenterRight); + pid_vm_fields.empend("amount_resident", "Resident"_string.release_value_but_fixme_should_propagate_errors(), Gfx::TextAlignment::CenterRight); + pid_vm_fields.empend("amount_dirty", "Dirty"_short_string, Gfx::TextAlignment::CenterRight); + pid_vm_fields.empend("Access"_short_string, Gfx::TextAlignment::CenterLeft, [](auto& object) { StringBuilder builder; if (object.get_bool("readable"sv).value_or(false)) builder.append('R'); @@ -77,19 +77,19 @@ ProcessMemoryMapWidget::ProcessMemoryMapWidget() builder.append('T'); return builder.to_deprecated_string(); }); - pid_vm_fields.empend("VMObject type", Gfx::TextAlignment::CenterLeft, [](auto& object) { + pid_vm_fields.empend("VMObject type"_string.release_value_but_fixme_should_propagate_errors(), Gfx::TextAlignment::CenterLeft, [](auto& object) { auto type = object.get_deprecated_string("vmobject"sv).value_or({}); if (type.ends_with("VMObject"sv)) type = type.substring(0, type.length() - 8); return type; }); - pid_vm_fields.empend("Purgeable", Gfx::TextAlignment::CenterLeft, [](auto& object) { + pid_vm_fields.empend("Purgeable"_string.release_value_but_fixme_should_propagate_errors(), Gfx::TextAlignment::CenterLeft, [](auto& object) { if (object.get_bool("volatile"sv).value_or(false)) return "Volatile"; return "Non-volatile"; }); pid_vm_fields.empend( - "Page map", Gfx::TextAlignment::CenterLeft, + "Page map"_string.release_value_but_fixme_should_propagate_errors(), Gfx::TextAlignment::CenterLeft, [](auto&) { return GUI::Variant(); }, @@ -100,8 +100,8 @@ ProcessMemoryMapWidget::ProcessMemoryMapWidget() auto pagemap = object.get_deprecated_string("pagemap"sv).value_or({}); return pagemap; }); - pid_vm_fields.empend("cow_pages", "# CoW", Gfx::TextAlignment::CenterRight); - pid_vm_fields.empend("name", "Name", Gfx::TextAlignment::CenterLeft); + pid_vm_fields.empend("cow_pages", "# CoW"_short_string, Gfx::TextAlignment::CenterRight); + pid_vm_fields.empend("name", "Name"_short_string, Gfx::TextAlignment::CenterLeft); m_json_model = GUI::JsonArrayModel::create({}, move(pid_vm_fields)); m_table_view->set_model(MUST(GUI::SortingProxyModel::create(*m_json_model))); diff --git a/Userland/Applications/SystemMonitor/ProcessUnveiledPathsWidget.cpp b/Userland/Applications/SystemMonitor/ProcessUnveiledPathsWidget.cpp index e064543976..e6bf6a41e1 100644 --- a/Userland/Applications/SystemMonitor/ProcessUnveiledPathsWidget.cpp +++ b/Userland/Applications/SystemMonitor/ProcessUnveiledPathsWidget.cpp @@ -22,8 +22,8 @@ ProcessUnveiledPathsWidget::ProcessUnveiledPathsWidget() m_table_view = add<GUI::TableView>(); Vector<GUI::JsonArrayModel::FieldSpec> pid_unveil_fields; - pid_unveil_fields.empend("path", "Path", Gfx::TextAlignment::CenterLeft); - pid_unveil_fields.empend("permissions", "Permissions", Gfx::TextAlignment::CenterLeft); + pid_unveil_fields.empend("path", "Path"_short_string, Gfx::TextAlignment::CenterLeft); + pid_unveil_fields.empend("permissions", "Permissions"_string.release_value_but_fixme_should_propagate_errors(), Gfx::TextAlignment::CenterLeft); m_model = GUI::JsonArrayModel::create({}, move(pid_unveil_fields)); m_table_view->set_model(MUST(GUI::SortingProxyModel::create(*m_model))); diff --git a/Userland/Applications/SystemMonitor/main.cpp b/Userland/Applications/SystemMonitor/main.cpp index b3fa16a137..9875fbd9bd 100644 --- a/Userland/Applications/SystemMonitor/main.cpp +++ b/Userland/Applications/SystemMonitor/main.cpp @@ -123,11 +123,11 @@ public: auto& fs_table_view = *self.find_child_of_type_named<GUI::TableView>("storage_table"); Vector<GUI::JsonArrayModel::FieldSpec> df_fields; - df_fields.empend("mount_point", "Mount point", Gfx::TextAlignment::CenterLeft); - df_fields.empend("class_name", "Class", Gfx::TextAlignment::CenterLeft); - df_fields.empend("source", "Source", Gfx::TextAlignment::CenterLeft); + df_fields.empend("mount_point", "Mount point"_string.release_value_but_fixme_should_propagate_errors(), Gfx::TextAlignment::CenterLeft); + df_fields.empend("class_name", "Class"_short_string, Gfx::TextAlignment::CenterLeft); + df_fields.empend("source", "Source"_short_string, Gfx::TextAlignment::CenterLeft); df_fields.empend( - "Size", Gfx::TextAlignment::CenterRight, + "Size"_short_string, Gfx::TextAlignment::CenterRight, [](JsonObject const& object) { StringBuilder size_builder; size_builder.append(' '); @@ -148,7 +148,7 @@ public: return percentage; }); df_fields.empend( - "Used", Gfx::TextAlignment::CenterRight, + "Used"_short_string, Gfx::TextAlignment::CenterRight, [](JsonObject const& object) { auto total_blocks = object.get_u64("total_block_count"sv).value_or(0); auto free_blocks = object.get_u64("free_block_count"sv).value_or(0); @@ -161,19 +161,19 @@ public: return used_blocks * object.get_u64("block_size"sv).value_or(0); }); df_fields.empend( - "Available", Gfx::TextAlignment::CenterRight, + "Available"_string.release_value_but_fixme_should_propagate_errors(), Gfx::TextAlignment::CenterRight, [](JsonObject const& object) { return human_readable_size(object.get_u64("free_block_count"sv).value_or(0) * object.get_u64("block_size"sv).value_or(0)); }, [](JsonObject const& object) { return object.get_u64("free_block_count"sv).value_or(0) * object.get_u64("block_size"sv).value_or(0); }); - df_fields.empend("Access", Gfx::TextAlignment::CenterLeft, [](JsonObject const& object) { + df_fields.empend("Access"_short_string, Gfx::TextAlignment::CenterLeft, [](JsonObject const& object) { bool readonly = object.get_bool("readonly"sv).value_or(false); int mount_flags = object.get_i32("mount_flags"sv).value_or(0); return readonly || (mount_flags & MS_RDONLY) ? "Read-only" : "Read/Write"; }); - df_fields.empend("Mount flags", Gfx::TextAlignment::CenterLeft, [](JsonObject const& object) { + df_fields.empend("Mount flags"_string.release_value_but_fixme_should_propagate_errors(), Gfx::TextAlignment::CenterLeft, [](JsonObject const& object) { int mount_flags = object.get_i32("mount_flags"sv).value_or(0); StringBuilder builder; bool first = true; @@ -197,11 +197,11 @@ public: return DeprecatedString("defaults"); return builder.to_deprecated_string(); }); - df_fields.empend("free_block_count", "Free blocks", Gfx::TextAlignment::CenterRight); - df_fields.empend("total_block_count", "Total blocks", Gfx::TextAlignment::CenterRight); - df_fields.empend("free_inode_count", "Free inodes", Gfx::TextAlignment::CenterRight); - df_fields.empend("total_inode_count", "Total inodes", Gfx::TextAlignment::CenterRight); - df_fields.empend("block_size", "Block size", Gfx::TextAlignment::CenterRight); + df_fields.empend("free_block_count", "Free blocks"_string.release_value_but_fixme_should_propagate_errors(), Gfx::TextAlignment::CenterRight); + df_fields.empend("total_block_count", "Total blocks"_string.release_value_but_fixme_should_propagate_errors(), Gfx::TextAlignment::CenterRight); + df_fields.empend("free_inode_count", "Free inodes"_string.release_value_but_fixme_should_propagate_errors(), Gfx::TextAlignment::CenterRight); + df_fields.empend("total_inode_count", "Total inodes"_string.release_value_but_fixme_should_propagate_errors(), Gfx::TextAlignment::CenterRight); + df_fields.empend("block_size", "Block size"_string.release_value_but_fixme_should_propagate_errors(), Gfx::TextAlignment::CenterRight); fs_table_view.set_model(MUST(GUI::SortingProxyModel::create(GUI::JsonArrayModel::create("/sys/kernel/df", move(df_fields))))); |