PropertiesWindow.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibCore/File.h>
  8. #include <LibGUI/Button.h>
  9. #include <LibGUI/Dialog.h>
  10. #include <LibGUI/FileSystemModel.h>
  11. #include <LibGUI/ImageWidget.h>
  12. #include <LibGUI/Label.h>
  13. #include <LibGUI/TextBox.h>
  14. class PropertiesWindow final : public GUI::Window {
  15. C_OBJECT(PropertiesWindow);
  16. public:
  17. virtual ~PropertiesWindow() override;
  18. private:
  19. PropertiesWindow(String const& path, bool disable_rename, Window* parent = nullptr);
  20. struct PropertyValuePair {
  21. String property;
  22. String value;
  23. Optional<URL> link = {};
  24. };
  25. struct PermissionMasks {
  26. mode_t read;
  27. mode_t write;
  28. mode_t execute;
  29. };
  30. static String const get_description(mode_t const mode)
  31. {
  32. if (S_ISREG(mode))
  33. return "File";
  34. if (S_ISDIR(mode))
  35. return "Directory";
  36. if (S_ISLNK(mode))
  37. return "Symbolic link";
  38. if (S_ISCHR(mode))
  39. return "Character device";
  40. if (S_ISBLK(mode))
  41. return "Block device";
  42. if (S_ISFIFO(mode))
  43. return "FIFO (named pipe)";
  44. if (S_ISSOCK(mode))
  45. return "Socket";
  46. if (mode & S_IXUSR)
  47. return "Executable";
  48. return "Unknown";
  49. }
  50. GUI::Button& make_button(String, GUI::Widget& parent);
  51. void setup_permission_checkboxes(GUI::CheckBox& box_read, GUI::CheckBox& box_write, GUI::CheckBox& box_execute, PermissionMasks masks, mode_t mode);
  52. void permission_changed(mode_t mask, bool set);
  53. bool apply_changes();
  54. void update();
  55. String make_full_path(String const& name);
  56. RefPtr<GUI::Button> m_apply_button;
  57. RefPtr<GUI::TextBox> m_name_box;
  58. RefPtr<GUI::ImageWidget> m_icon;
  59. String m_name;
  60. String m_parent_path;
  61. String m_path;
  62. mode_t m_mode { 0 };
  63. mode_t m_old_mode { 0 };
  64. bool m_permissions_dirty { false };
  65. bool m_name_dirty { false };
  66. };