diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-08-11 10:11:21 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-08-11 10:11:21 +0200 |
commit | b07a31573664ed574c0c8e807b197b8c2dd14ba2 (patch) | |
tree | dd06700b4aa946eb0cc74ed5c1b0f526d94d11ba /Applications | |
parent | c246f2db4ad072cfc444486b50382c8603f30dd7 (diff) | |
download | serenity-b07a31573664ed574c0c8e807b197b8c2dd14ba2.zip |
ProcessManager: Add "File systems" tab with info on mounted filesystems
This was rather nice and easy to add with the new GJsonArrayModel! :^)
Diffstat (limited to 'Applications')
-rw-r--r-- | Applications/ProcessManager/main.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/Applications/ProcessManager/main.cpp b/Applications/ProcessManager/main.cpp index 7d15ff37be..c833486110 100644 --- a/Applications/ProcessManager/main.cpp +++ b/Applications/ProcessManager/main.cpp @@ -11,6 +11,7 @@ #include <LibGUI/GApplication.h> #include <LibGUI/GBoxLayout.h> #include <LibGUI/GGroupBox.h> +#include <LibGUI/GJsonArrayModel.h> #include <LibGUI/GLabel.h> #include <LibGUI/GMenuBar.h> #include <LibGUI/GSplitter.h> @@ -22,6 +23,19 @@ #include <stdio.h> #include <unistd.h> +static String human_readable_size(u32 size) +{ + if (size < (64 * KB)) + return String::format("%u", size); + if (size < MB) + return String::format("%u KB", size / KB); + if (size < GB) + return String::format("%u MB", size / MB); + return String::format("%u GB", size / GB); +} + +static GWidget* build_file_systems_tab(); + int main(int argc, char** argv) { GApplication app(argc, argv); @@ -72,6 +86,8 @@ int main(int argc, char** argv) tabwidget->add_widget("Graphs", graphs_container); + tabwidget->add_widget("File systems", build_file_systems_tab()); + auto* network_stats_widget = new NetworkStatisticsWidget(nullptr); tabwidget->add_widget("Network", network_stats_widget); @@ -188,3 +204,39 @@ int main(int argc, char** argv) return app.exec(); } + +GWidget* build_file_systems_tab() +{ + auto* fs_widget = new GWidget(nullptr); + fs_widget->set_layout(make<GBoxLayout>(Orientation::Vertical)); + fs_widget->layout()->set_margins({ 4, 4, 4, 4 }); + auto* fs_table_view = new GTableView(fs_widget); + fs_table_view->set_size_columns_to_fit_content(true); + + Vector<GJsonArrayModel::FieldSpec> df_fields; + df_fields.empend("mount_point", "Mount point", TextAlignment::CenterLeft); + df_fields.empend("class_name", "Class", TextAlignment::CenterLeft); + df_fields.empend("Size", TextAlignment::CenterRight, [](const JsonObject& object) { + return human_readable_size(object.get("total_block_count").to_u32() * object.get("block_size").to_u32()); + }); + df_fields.empend("Used", TextAlignment::CenterRight, [](const JsonObject& object) { + auto total_blocks = object.get("total_block_count").to_u32(); + auto free_blocks = object.get("free_block_count").to_u32(); + auto used_blocks = total_blocks - free_blocks; + return human_readable_size(used_blocks * object.get("block_size").to_u32()); + }); + df_fields.empend("Available", TextAlignment::CenterRight, [](const JsonObject& object) { + return human_readable_size(object.get("free_block_count").to_u32() * object.get("block_size").to_u32()); + }); + df_fields.empend("Access", TextAlignment::CenterLeft, [](const JsonObject& object) { + return object.get("readonly").to_bool() ? "Read-only" : "Read/Write"; + }); + df_fields.empend("free_block_count", "Free blocks", TextAlignment::CenterRight); + df_fields.empend("total_block_count", "Total blocks", TextAlignment::CenterRight); + df_fields.empend("free_inode_count", "Free inodes", TextAlignment::CenterRight); + df_fields.empend("total_inode_count", "Total inodes", TextAlignment::CenterRight); + df_fields.empend("block_size", "Block size", TextAlignment::CenterRight); + fs_table_view->set_model(GJsonArrayModel::create("/proc/df", move(df_fields))); + fs_table_view->model()->update(); + return fs_widget; +} |