Serenity Operating System
1/*
2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice, this
9 * list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#pragma once
28
29#include <AK/FileSystemPath.h>
30#include <LibCore/File.h>
31#include <LibGUI/Button.h>
32#include <LibGUI/Dialog.h>
33#include <LibGUI/FileSystemModel.h>
34#include <LibGUI/Label.h>
35#include <LibGUI/TextBox.h>
36
37class PropertiesDialog final : public GUI::Dialog {
38 C_OBJECT(PropertiesDialog)
39public:
40 virtual ~PropertiesDialog() override;
41
42private:
43 PropertiesDialog(GUI::FileSystemModel&, String, bool disable_rename, Window* parent = nullptr);
44
45 struct PropertyValuePair {
46 String property;
47 String value;
48 };
49
50 struct PermissionMasks {
51 mode_t read;
52 mode_t write;
53 mode_t execute;
54 };
55
56 static const String get_description(const mode_t mode)
57 {
58 if (S_ISREG(mode))
59 return "File";
60 if (S_ISDIR(mode))
61 return "Directory";
62 if (S_ISLNK(mode))
63 return "Symbolic link";
64 if (S_ISCHR(mode))
65 return "Character device";
66 if (S_ISBLK(mode))
67 return "Block device";
68 if (S_ISFIFO(mode))
69 return "FIFO (named pipe)";
70 if (S_ISSOCK(mode))
71 return "Socket";
72 if (mode & S_IXUSR)
73 return "Executable";
74
75 return "Unknown";
76 }
77
78 GUI::Button& make_button(String, GUI::Widget& parent);
79 void make_divider(GUI::Widget& parent);
80 void make_property_value_pairs(const Vector<PropertyValuePair>& pairs, GUI::Widget& parent);
81 void make_permission_checkboxes(GUI::Widget& parent, PermissionMasks, String label_string, mode_t mode);
82 void permission_changed(mode_t mask, bool set);
83 bool apply_changes();
84 void update();
85 String make_full_path(String name);
86
87 GUI::FileSystemModel& m_model;
88 RefPtr<GUI::Button> m_apply_button;
89 RefPtr<GUI::TextBox> m_name_box;
90 RefPtr<GUI::Label> m_icon;
91 String m_name;
92 String m_path;
93 mode_t m_mode;
94 bool m_permissions_dirty { false };
95 bool m_name_dirty { false };
96};