KIO
kacleditwidget_p.h
Go to the documentation of this file.
00001 /*************************************************************************** 00002 * Copyright (C) 2005 by Sean Harmer <sh@rama.homelinux.org> * 00003 * 2005 - 2007 Till Adam <adam@kde.org> * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU Library General Public License as * 00007 * published by the Free Software Foundation; either version 2 of the * 00008 * License, or (at your option) any later version. * 00009 * * 00010 * This program is distributed in the hope that it will be useful, * 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00013 * GNU General Public License for more details. * 00014 * * 00015 * You should have received a copy of the GNU General Public License * 00016 * along with this program; if not, write to the * 00017 * Free Software Foundation, Inc., * 00018 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 00019 ***************************************************************************/ 00020 #ifndef KACLEDITWIDGET_P_H 00021 #define KACLEDITWIDGET_P_H 00022 00023 #include <config-acl.h> 00024 00025 #if defined(HAVE_POSIX_ACL) || defined(Q_MOC_RUN) 00026 #include <sys/acl.h> 00027 #include <kacl.h> 00028 00029 #include <QPixmap> 00030 #include <QTreeWidget> 00031 #include <QtCore/QHash> 00032 00033 #include <kcombobox.h> 00034 #include <kdialog.h> 00035 #include <kfileitem.h> 00036 00037 class KACLListViewItem; 00038 class QButtonGroup; 00039 class KACLListView; 00040 class QStackedWidget; 00041 class QCheckBox; 00042 class QAbstractButton; 00043 class QColorGroup; 00044 00048 class KACLListView : public QTreeWidget 00049 { 00050 Q_OBJECT 00051 friend class KACLListViewItem; 00052 public: 00053 enum Types 00054 { 00055 OWNER_IDX = 0, 00056 GROUP_IDX, 00057 OTHERS_IDX, 00058 MASK_IDX, 00059 NAMED_USER_IDX, 00060 NAMED_GROUP_IDX, 00061 LAST_IDX 00062 }; 00063 enum EntryType { User = 1, 00064 Group = 2, 00065 Others = 4, 00066 Mask = 8, 00067 NamedUser = 16, 00068 NamedGroup = 32, 00069 AllTypes = 63 }; 00070 00071 KACLListView( QWidget* parent = 0 ); 00072 ~KACLListView(); 00073 00074 bool hasMaskEntry() const { return m_hasMask; } 00075 bool hasDefaultEntries() const; 00076 bool allowDefaults() const { return m_allowDefaults; } 00077 void setAllowDefaults( bool v ) { m_allowDefaults = v; } 00078 unsigned short maskPermissions() const; 00079 void setMaskPermissions( unsigned short maskPerms ); 00080 acl_perm_t maskPartialPermissions() const; 00081 void setMaskPartialPermissions( acl_perm_t maskPerms ); 00082 00083 bool maskCanBeDeleted() const; 00084 bool defaultMaskCanBeDeleted() const; 00085 00086 const KACLListViewItem* findDefaultItemByType( EntryType type ) const; 00087 const KACLListViewItem* findItemByType( EntryType type, 00088 bool defaults = false ) const; 00089 unsigned short calculateMaskValue( bool defaults ) const; 00090 void calculateEffectiveRights(); 00091 00092 QStringList allowedUsers( bool defaults, KACLListViewItem *allowedItem = 0 ); 00093 QStringList allowedGroups( bool defaults, KACLListViewItem *allowedItem = 0 ); 00094 00095 const KACL getACL() const { return getACL(); } 00096 KACL getACL(); 00097 00098 const KACL getDefaultACL() const { return getDefaultACL(); } 00099 KACL getDefaultACL(); 00100 00101 QPixmap getYesPixmap() const { return *m_yesPixmap; } 00102 QPixmap getYesPartialPixmap() const { return *m_yesPartialPixmap; } 00103 00104 public Q_SLOTS: 00105 void slotAddEntry(); 00106 void slotEditEntry(); 00107 void slotRemoveEntry(); 00108 void setACL( const KACL &anACL ); 00109 void setDefaultACL( const KACL &anACL ); 00110 00111 protected Q_SLOTS: 00112 void slotItemClicked( QTreeWidgetItem* pItem, int col ); 00113 protected: 00114 void contentsMousePressEvent( QMouseEvent * e ); 00115 00116 private: 00117 void fillItemsFromACL( const KACL &pACL, bool defaults = false ); 00118 KACL itemsToACL( bool defaults ) const; 00119 00120 KACL m_ACL; 00121 KACL m_defaultACL; 00122 unsigned short m_mask; 00123 bool m_hasMask; 00124 bool m_allowDefaults; 00125 QStringList m_allUsers; 00126 QStringList m_allGroups; 00127 QPixmap* m_yesPixmap; 00128 QPixmap* m_yesPartialPixmap; 00129 }; 00130 00131 class EditACLEntryDialog : public KDialog 00132 { 00133 Q_OBJECT 00134 public: 00135 EditACLEntryDialog( KACLListView *listView, KACLListViewItem *item, 00136 const QStringList &users, 00137 const QStringList &groups, 00138 const QStringList &defaultUsers, 00139 const QStringList &defaultGroups, 00140 int allowedTypes = KACLListView::AllTypes, 00141 int allowedDefaultTypes = KACLListView::AllTypes, 00142 bool allowDefault = false ); 00143 KACLListViewItem* item() const { return m_item; } 00144 public Q_SLOTS: 00145 void slotOk(); 00146 void slotSelectionChanged( QAbstractButton* ); 00147 private Q_SLOTS: 00148 void slotUpdateAllowedUsersAndGroups(); 00149 void slotUpdateAllowedTypes(); 00150 private: 00151 KACLListView *m_listView; 00152 KACLListViewItem *m_item; 00153 QStringList m_users; 00154 QStringList m_groups; 00155 QStringList m_defaultUsers; 00156 QStringList m_defaultGroups; 00157 int m_allowedTypes; 00158 int m_allowedDefaultTypes; 00159 QButtonGroup *m_buttonGroup; 00160 KComboBox *m_usersCombo; 00161 KComboBox *m_groupsCombo; 00162 QStackedWidget *m_widgetStack; 00163 QCheckBox *m_defaultCB; 00164 QHash<QAbstractButton*, int> m_buttonIds; 00165 }; 00166 00167 00168 class KACLListViewItem : public QTreeWidgetItem 00169 { 00170 public: 00171 KACLListViewItem( QTreeWidget* parent, KACLListView::EntryType type, 00172 unsigned short value, 00173 bool defaultEntry, 00174 const QString& qualifier = QString() ); 00175 virtual ~KACLListViewItem(); 00176 QString key() const; 00177 bool operator< ( const QTreeWidgetItem & other ) const; 00178 00179 void calcEffectiveRights(); 00180 00181 bool isDeletable() const; 00182 bool isAllowedToChangeType() const; 00183 00184 void togglePerm( acl_perm_t perm ); 00185 00186 #if 0 00187 virtual void paintCell( QPainter *p, const QColorGroup &cg, 00188 int column, int width, int alignment ); 00189 #endif 00190 00191 void updatePermPixmaps(); 00192 void repaint(); 00193 00194 KACLListView::EntryType type; 00195 unsigned short value; 00196 bool isDefault; 00197 QString qualifier; 00198 bool isPartial; 00199 00200 private: 00201 KACLListView* m_pACLListView; 00202 }; 00203 00204 00205 #endif 00206 #endif
KDE 4.6 API Reference