Serenity Operating System
at master 100 lines 3.2 kB view raw
1/* 2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> 3 * Copyright (c) 2022-2023, the SerenityOS developers. 4 * 5 * SPDX-License-Identifier: BSD-2-Clause 6 */ 7 8#pragma once 9 10#include <AK/Queue.h> 11#include <LibGUI/Button.h> 12#include <LibGUI/Dialog.h> 13#include <LibGUI/FileSystemModel.h> 14#include <LibGUI/ImageWidget.h> 15#include <LibGUI/Label.h> 16#include <LibGUI/TextBox.h> 17#include <LibThreading/BackgroundAction.h> 18 19class PropertiesWindow final : public GUI::Window { 20 C_OBJECT(PropertiesWindow); 21 22public: 23 static ErrorOr<NonnullRefPtr<PropertiesWindow>> try_create(DeprecatedString const& path, bool disable_rename, Window* parent = nullptr); 24 virtual ~PropertiesWindow() override = default; 25 26 virtual void close() final; 27 28private: 29 PropertiesWindow(DeprecatedString const& path, Window* parent = nullptr); 30 ErrorOr<void> create_widgets(bool disable_rename); 31 32 struct PropertyValuePair { 33 DeprecatedString property; 34 DeprecatedString value; 35 Optional<URL> link = {}; 36 }; 37 38 struct PermissionMasks { 39 mode_t read; 40 mode_t write; 41 mode_t execute; 42 }; 43 44 class DirectoryStatisticsCalculator final : public RefCounted<DirectoryStatisticsCalculator> { 45 public: 46 DirectoryStatisticsCalculator(DeprecatedString path); 47 void start(); 48 void stop(); 49 Function<void(off_t total_size_in_bytes, size_t file_count, size_t directory_count)> on_update; 50 51 private: 52 off_t m_total_size_in_bytes { 0 }; 53 size_t m_file_count { 0 }; 54 size_t m_directory_count { 0 }; 55 RefPtr<Threading::BackgroundAction<int>> m_background_action; 56 Queue<DeprecatedString> m_work_queue; 57 }; 58 59 static DeprecatedString const get_description(mode_t const mode) 60 { 61 if (S_ISREG(mode)) 62 return "File"; 63 if (S_ISDIR(mode)) 64 return "Directory"; 65 if (S_ISLNK(mode)) 66 return "Symbolic link"; 67 if (S_ISCHR(mode)) 68 return "Character device"; 69 if (S_ISBLK(mode)) 70 return "Block device"; 71 if (S_ISFIFO(mode)) 72 return "FIFO (named pipe)"; 73 if (S_ISSOCK(mode)) 74 return "Socket"; 75 if (mode & S_IXUSR) 76 return "Executable"; 77 78 return "Unknown"; 79 } 80 81 static ErrorOr<NonnullRefPtr<GUI::Button>> make_button(String, GUI::Widget& parent); 82 ErrorOr<void> setup_permission_checkboxes(GUI::CheckBox& box_read, GUI::CheckBox& box_write, GUI::CheckBox& box_execute, PermissionMasks masks, mode_t mode); 83 void permission_changed(mode_t mask, bool set); 84 bool apply_changes(); 85 void update(); 86 DeprecatedString make_full_path(DeprecatedString const& name); 87 88 RefPtr<GUI::Button> m_apply_button; 89 RefPtr<GUI::TextBox> m_name_box; 90 RefPtr<GUI::ImageWidget> m_icon; 91 RefPtr<GUI::Label> m_size_label; 92 RefPtr<DirectoryStatisticsCalculator> m_directory_statistics_calculator; 93 DeprecatedString m_name; 94 DeprecatedString m_parent_path; 95 DeprecatedString m_path; 96 mode_t m_mode { 0 }; 97 mode_t m_old_mode { 0 }; 98 bool m_permissions_dirty { false }; 99 bool m_name_dirty { false }; 100};