summaryrefslogtreecommitdiffstats
path: root/kio/kfile/kacleditwidget_p.h
blob: 3ad77930c50c6165f8242f1db5836413fbca2888 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/***************************************************************************
 *   Copyright (C) 2005 by Sean Harmer <sh@rama.homelinux.org>             *
 *                         Till Adam <adam@kde.org>                        *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by  the Free Software Foundation; either version 2 of the   *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.             *
 ***************************************************************************/
#ifndef KACLEDITWIDGET_P_H
#define KACLEDITWIDGET_P_H

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#ifdef USE_POSIX_ACL
#include <klistview.h>
#include <sys/acl.h>
#include <kacl.h>
#include <kfileitem.h>
#include <kdialogbase.h>
#include <tqpixmap.h>
#include <tqcombobox.h>

class KACLListViewItem;
class QPushButton;
class QVButtonGroup;
class KACLListView;
class QWidgetStack;
class QCheckBox;

/**
@author Sean Harmer
*/
class KACLListView : public KListView
{
Q_OBJECT
    friend class KACLListViewItem;
public:
    enum Types
    {
        OWNER_IDX = 0,
        GROUP_IDX,
        OTHERS_IDX,
        MASK_IDX,
        NAMED_USER_IDX,
        NAMED_GROUP_IDX,
        LAST_IDX
    };
    enum EntryType { User = 1,
                     Group = 2,
                     Others = 4,
                     Mask = 8,
                     NamedUser = 16,
                     NamedGroup = 32,
                     AllTypes = 63 };

    KACLListView( TQWidget* parent = 0, const char* name = 0 );
    ~KACLListView();

    bool hasMaskEntry() const { return m_hasMask; }
    bool hasDefaultEntries() const;
    bool allowDefaults() const { return m_allowDefaults; }
    void setAllowDefaults( bool v ) { m_allowDefaults = v; }
    unsigned short maskPermissions() const;
    void setMaskPermissions( unsigned short maskPerms );
    acl_perm_t maskPartialPermissions() const;
    void setMaskPartialPermissions( acl_perm_t maskPerms );

    bool maskCanBeDeleted() const;
    bool defaultMaskCanBeDeleted() const;

    const KACLListViewItem* findDefaultItemByType( EntryType type ) const;
    const KACLListViewItem* findItemByType( EntryType type,
                                            bool defaults = false ) const;
    unsigned short calculateMaskValue( bool defaults ) const;
    void calculateEffectiveRights();

    TQStringList allowedUsers( bool defaults, KACLListViewItem *allowedItem = 0 );
    TQStringList allowedGroups( bool defaults, KACLListViewItem *allowedItem = 0 );

    const KACL getACL() const { return getACL(); }
    KACL getACL();

    const KACL getDefaultACL() const { return getDefaultACL(); }
    KACL getDefaultACL();

    TQPixmap getYesPixmap() const { return *m_yesPixmap; }
    TQPixmap getYesPartialPixmap() const { return *m_yesPartialPixmap; }

public slots:
    void slotAddEntry();
    void slotEditEntry();
    void slotRemoveEntry();
    void setACL( const KACL &anACL );
    void setDefaultACL( const KACL &anACL );

protected slots:
    void entryClicked( TQListViewItem* pItem, const TQPoint& pt, int col );
protected:
    void contentsMousePressEvent( TQMouseEvent * e );

private:
    void fillItemsFromACL( const KACL &pACL, bool defaults = false );
    KACL itemsToACL( bool defaults ) const;

    KACL m_ACL;
    KACL m_defaultACL;
    unsigned short m_mask;
    bool m_hasMask;
    bool m_allowDefaults;
    TQStringList m_allUsers;
    TQStringList m_allGroups;
    TQPixmap* m_yesPixmap;
    TQPixmap* m_yesPartialPixmap;
};

class EditACLEntryDialog : public KDialogBase
{
    Q_OBJECT
public:
    EditACLEntryDialog( KACLListView *listView, KACLListViewItem *item,
                        const TQStringList &users,
                        const TQStringList &groups,
                        const TQStringList &defaultUsers,
                        const TQStringList &defaultGroups,
                        int allowedTypes = KACLListView::AllTypes,
                        int allowedDefaultTypes = KACLListView::AllTypes,
                        bool allowDefault = false );
    KACLListViewItem* item() const { return m_item; }
public slots:
     void slotOk();
     void slotSelectionChanged( int id );
private slots:
     void slotUpdateAllowedUsersAndGroups();
     void slotUpdateAllowedTypes();
private:
     KACLListView *m_listView;
     KACLListViewItem *m_item;
     TQStringList m_users;
     TQStringList m_groups;
     TQStringList m_defaultUsers;
     TQStringList m_defaultGroups;
     int m_allowedTypes;
     int m_allowedDefaultTypes;
     TQVButtonGroup *m_buttonGroup;
     TQComboBox *m_usersCombo;
     TQComboBox *m_groupsCombo;
     TQWidgetStack *m_widgetStack;
     TQCheckBox *m_defaultCB;
};


class KACLListViewItem : public KListViewItem
{
public:
    KACLListViewItem( TQListView* parent, KACLListView::EntryType type,
                      unsigned short value,
                      bool defaultEntry,
                      const TQString& qualifier = TQString::null );
    virtual ~KACLListViewItem();
    virtual TQString key( int column, bool ascending ) const;

    void calcEffectiveRights();

    bool isDeletable() const;
    bool isAllowedToChangeType() const;

    void togglePerm( acl_perm_t perm );

    virtual void paintCell( TQPainter *p, const TQColorGroup &cg,
                            int column, int width, int alignment );

    void updatePermPixmaps();
    void repaint();

    KACLListView::EntryType type;
    unsigned short value;
    bool isDefault;
    TQString qualifier;
    bool isPartial;

private:
    KACLListView* m_pACLListView;
};


#endif
#endif