1/*
2 SPDX-FileCopyrightText: 2005 Sean Harmer <sh@rama.homelinux.org>
3 SPDX-FileCopyrightText: 2005-2007 Till Adam <adam@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#ifndef KACLEDITWIDGET_P_H
9#define KACLEDITWIDGET_P_H
10
11#include <config-kiowidgets.h>
12
13#if HAVE_POSIX_ACL || defined(Q_MOC_RUN)
14#include <kacl.h>
15#include <sys/acl.h>
16
17#include <QDialog>
18#include <QHash>
19#include <QTreeWidget>
20
21#include <QComboBox>
22#include <kfileitem.h>
23
24class KACLListViewItem;
25class QButtonGroup;
26class KACLListView;
27class QStackedWidget;
28class QCheckBox;
29class QAbstractButton;
30class QColorGroup;
31
32/**
33@author Sean Harmer
34*/
35class KACLListView : public QTreeWidget
36{
37 Q_OBJECT
38 friend class KACLListViewItem;
39
40public:
41 enum Types {
42 OWNER_IDX = 0,
43 GROUP_IDX,
44 OTHERS_IDX,
45 MASK_IDX,
46 NAMED_USER_IDX,
47 NAMED_GROUP_IDX,
48 LAST_IDX,
49 };
50 enum EntryType {
51 User = 1,
52 Group = 2,
53 Others = 4,
54 Mask = 8,
55 NamedUser = 16,
56 NamedGroup = 32,
57 AllTypes = 63,
58 };
59
60 explicit KACLListView(QWidget *parent = nullptr);
61 ~KACLListView() override;
62
63 bool hasMaskEntry() const
64 {
65 return m_hasMask;
66 }
67 bool hasDefaultEntries() const;
68 bool allowDefaults() const
69 {
70 return m_allowDefaults;
71 }
72 void setAllowDefaults(bool v)
73 {
74 m_allowDefaults = v;
75 }
76 unsigned short maskPermissions() const;
77 void setMaskPermissions(unsigned short maskPerms);
78 acl_perm_t maskPartialPermissions() const;
79 void setMaskPartialPermissions(acl_perm_t maskPerms);
80
81 bool maskCanBeDeleted() const;
82 bool defaultMaskCanBeDeleted() const;
83
84 const KACLListViewItem *findDefaultItemByType(EntryType type) const;
85 const KACLListViewItem *findItemByType(EntryType type, bool defaults = false) const;
86 unsigned short calculateMaskValue(bool defaults) const;
87 void calculateEffectiveRights();
88
89 QStringList allowedUsers(bool defaults, KACLListViewItem *allowedItem = nullptr);
90 QStringList allowedGroups(bool defaults, KACLListViewItem *allowedItem = nullptr);
91
92 KACL getACL();
93 KACL getDefaultACL();
94
95public Q_SLOTS:
96 void slotAddEntry();
97 void slotEditEntry();
98 void slotRemoveEntry();
99 void setACL(const KACL &anACL);
100 void setDefaultACL(const KACL &anACL);
101
102 QSize sizeHint() const override;
103
104protected Q_SLOTS:
105 void slotItemClicked(QTreeWidgetItem *pItem, int col);
106 void slotItemDoubleClicked(QTreeWidgetItem *item, int col);
107
108protected:
109 void contentsMousePressEvent(QMouseEvent *e);
110
111private:
112 void fillItemsFromACL(const KACL &pACL, bool defaults = false);
113 KACL itemsToACL(bool defaults) const;
114
115 KACL m_ACL;
116 KACL m_defaultACL;
117 unsigned short m_mask;
118 bool m_hasMask;
119 bool m_allowDefaults;
120 QStringList m_allUsers;
121 QStringList m_allGroups;
122};
123
124class EditACLEntryDialog : public QDialog
125{
126 Q_OBJECT
127public:
128 EditACLEntryDialog(KACLListView *listView,
129 KACLListViewItem *item,
130 const QStringList &users,
131 const QStringList &groups,
132 const QStringList &defaultUsers,
133 const QStringList &defaultGroups,
134 int allowedTypes = KACLListView::AllTypes,
135 int allowedDefaultTypes = KACLListView::AllTypes,
136 bool allowDefault = false);
137 KACLListViewItem *item() const
138 {
139 return m_item;
140 }
141public Q_SLOTS:
142 void slotOk();
143 void slotSelectionChanged(QAbstractButton *);
144private Q_SLOTS:
145 void slotUpdateAllowedUsersAndGroups();
146 void slotUpdateAllowedTypes();
147
148private:
149 KACLListView *m_listView;
150 KACLListViewItem *m_item;
151 QStringList m_users;
152 QStringList m_groups;
153 QStringList m_defaultUsers;
154 QStringList m_defaultGroups;
155 int m_allowedTypes;
156 int m_allowedDefaultTypes;
157 QButtonGroup *m_buttonGroup;
158 QComboBox *m_usersCombo;
159 QComboBox *m_groupsCombo;
160 QStackedWidget *m_widgetStack;
161 QCheckBox *m_defaultCB;
162 QHash<QAbstractButton *, int> m_buttonIds;
163};
164
165class KACLListViewItem : public QTreeWidgetItem
166{
167public:
168 KACLListViewItem(QTreeWidget *parent, KACLListView::EntryType type, unsigned short value, bool defaultEntry, const QString &qualifier = QString());
169 ~KACLListViewItem() override;
170 QString key() const;
171 bool operator<(const QTreeWidgetItem &other) const override;
172
173 void calcEffectiveRights();
174
175 bool isDeletable() const;
176 bool isAllowedToChangeType() const;
177
178 void togglePerm(acl_perm_t perm);
179
180 void updatePermissionIcons();
181 void repaint();
182
183 KACLListView::EntryType type;
184 unsigned short value;
185 bool isDefault;
186 QString qualifier;
187 bool isPartial;
188
189private:
190 KACLListView *m_pACLListView;
191};
192
193#endif
194#endif
195

source code of kio/src/widgets/kacleditwidget_p.h