/* * Copyright (c) 2018-2020, Andreas Kling * Copyright (c) 2022-2023, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include #include class PropertiesWindow final : public GUI::Window { C_OBJECT(PropertiesWindow); public: static ErrorOr> 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 create_widgets(bool disable_rename); ErrorOr create_general_tab(GUI::TabWidget&, bool disable_rename); ErrorOr create_file_type_specific_tabs(GUI::TabWidget&); ErrorOr create_archive_tab(GUI::TabWidget&, NonnullRefPtr); ErrorOr create_audio_tab(GUI::TabWidget&, NonnullRefPtr); ErrorOr create_font_tab(GUI::TabWidget&, NonnullRefPtr, StringView mime_type); ErrorOr create_image_tab(GUI::TabWidget&, NonnullRefPtr, StringView mime_type); ErrorOr create_pdf_tab(GUI::TabWidget&, NonnullRefPtr); struct PermissionMasks { mode_t read; mode_t write; mode_t execute; }; class DirectoryStatisticsCalculator final : public RefCounted { public: DirectoryStatisticsCalculator(DeprecatedString path); void start(); void stop(); Function on_update; private: off_t m_total_size_in_bytes { 0 }; size_t m_file_count { 0 }; size_t m_directory_count { 0 }; RefPtr> m_background_action; Queue m_work_queue; }; static StringView const get_description(mode_t const mode) { if (S_ISREG(mode)) return "File"sv; if (S_ISDIR(mode)) return "Directory"sv; if (S_ISLNK(mode)) return "Symbolic link"sv; if (S_ISCHR(mode)) return "Character device"sv; if (S_ISBLK(mode)) return "Block device"sv; if (S_ISFIFO(mode)) return "FIFO (named pipe)"sv; if (S_ISSOCK(mode)) return "Socket"sv; if (mode & S_IXUSR) return "Executable"sv; return "Unknown"sv; } static ErrorOr> make_button(String, GUI::Widget& parent); ErrorOr setup_permission_checkboxes(GUI::CheckBox& box_read, GUI::CheckBox& box_write, GUI::CheckBox& box_execute, PermissionMasks masks, mode_t mode); void permission_changed(mode_t mask, bool set); bool apply_changes(); void update(); DeprecatedString make_full_path(DeprecatedString const& name); RefPtr m_apply_button; RefPtr m_name_box; RefPtr m_icon; RefPtr m_size_label; RefPtr m_directory_statistics_calculator; RefPtr m_on_escape; DeprecatedString m_name; DeprecatedString m_parent_path; DeprecatedString m_path; mode_t m_mode { 0 }; mode_t m_old_mode { 0 }; bool m_permissions_dirty { false }; bool m_name_dirty { false }; };