From 8faeead7536321d4b7625615585e74db48108dd0 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 12 Aug 2019 11:56:30 +0200 Subject: [PATCH] ProcessManager: Hook the sort order for the file systems JSON model ..and install a GSortingProxyModel on the view. This allows you to sort the filesystems by used space etc *numerically*. :^) --- Applications/ProcessManager/main.cpp | 46 +++++++++++++++++++--------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/Applications/ProcessManager/main.cpp b/Applications/ProcessManager/main.cpp index c833486110..6361f342b6 100644 --- a/Applications/ProcessManager/main.cpp +++ b/Applications/ProcessManager/main.cpp @@ -1,10 +1,10 @@ #include "GraphWidget.h" #include "MemoryStatsWidget.h" +#include "NetworkStatisticsWidget.h" #include "ProcessFileDescriptorMapWidget.h" #include "ProcessMemoryMapWidget.h" #include "ProcessStacksWidget.h" #include "ProcessTableView.h" -#include "NetworkStatisticsWidget.h" #include #include #include @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -216,18 +217,35 @@ GWidget* build_file_systems_tab() Vector 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( + "Size", TextAlignment::CenterRight, + [](const JsonObject& object) { + return human_readable_size(object.get("total_block_count").to_u32() * object.get("block_size").to_u32()); + }, + [](const JsonObject& object) { + return 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()); }, + [](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 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()); + }, + [](const JsonObject& object) { + return 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"; }); @@ -236,7 +254,7 @@ GWidget* build_file_systems_tab() 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->set_model(GSortingProxyModel::create(GJsonArrayModel::create("/proc/df", move(df_fields)))); fs_table_view->model()->update(); return fs_widget; }