1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:17:35 +00:00

FileManager: Show directory size and file count in PropertiesWindow

When displaying properties for a directory, the PropertiesWindow now
shows: the total number of files, the total number of subdirectories,
and the total size of all files, in bytes.

These numbers are calculated on a background thread, and current
progress is displayed to the user every 100ms.
This commit is contained in:
Tim Ledbetter 2023-02-01 17:30:35 +00:00 committed by Sam Atkins
parent d2e1f6ff57
commit baaf97787b
4 changed files with 105 additions and 6 deletions

View file

@ -7,6 +7,7 @@
#pragma once
#include <AK/Queue.h>
#include <LibCore/File.h>
#include <LibGUI/Button.h>
#include <LibGUI/Dialog.h>
@ -14,6 +15,7 @@
#include <LibGUI/ImageWidget.h>
#include <LibGUI/Label.h>
#include <LibGUI/TextBox.h>
#include <LibThreading/BackgroundAction.h>
class PropertiesWindow final : public GUI::Window {
C_OBJECT(PropertiesWindow);
@ -22,6 +24,8 @@ public:
static ErrorOr<NonnullRefPtr<PropertiesWindow>> try_create(DeprecatedString const& path, bool disable_rename, Window* parent = nullptr);
virtual ~PropertiesWindow() override = default;
virtual void close() final;
private:
PropertiesWindow(DeprecatedString const& path, Window* parent = nullptr);
ErrorOr<void> create_widgets(bool disable_rename);
@ -38,6 +42,21 @@ private:
mode_t execute;
};
class DirectoryStatisticsCalculator final : public RefCounted<DirectoryStatisticsCalculator> {
public:
DirectoryStatisticsCalculator(DeprecatedString path);
void start();
void stop();
Function<void(off_t total_size_in_bytes, size_t file_count, size_t directory_count)> on_update;
private:
off_t m_total_size_in_bytes { 0 };
size_t m_file_count { 0 };
size_t m_directory_count { 0 };
RefPtr<Threading::BackgroundAction<int>> m_background_action;
Queue<DeprecatedString> m_work_queue;
};
static DeprecatedString const get_description(mode_t const mode)
{
if (S_ISREG(mode))
@ -70,6 +89,8 @@ private:
RefPtr<GUI::Button> m_apply_button;
RefPtr<GUI::TextBox> m_name_box;
RefPtr<GUI::ImageWidget> m_icon;
RefPtr<GUI::Label> m_size_label;
RefPtr<DirectoryStatisticsCalculator> m_directory_statistics_calculator;
DeprecatedString m_name;
DeprecatedString m_parent_path;
DeprecatedString m_path;