You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1055 lines
35 KiB
1055 lines
35 KiB
15 years ago
|
/***************************************************************************
|
||
|
* 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. *
|
||
|
***************************************************************************/
|
||
|
|
||
|
|
||
|
#include "kacleditwidget.h"
|
||
|
#include "kacleditwidget_p.h"
|
||
|
|
||
|
#ifdef USE_POSIX_ACL
|
||
|
|
||
15 years ago
|
#include <tqpainter.h>
|
||
|
#include <tqptrlist.h>
|
||
|
#include <tqvbox.h>
|
||
|
#include <tqhbox.h>
|
||
|
#include <tqpushbutton.h>
|
||
|
#include <tqvbuttongroup.h>
|
||
|
#include <tqradiobutton.h>
|
||
|
#include <tqcombobox.h>
|
||
|
#include <tqlabel.h>
|
||
|
#include <tqcheckbox.h>
|
||
13 years ago
|
#include <tqlayout.h>
|
||
15 years ago
|
#include <tqwidgetstack.h>
|
||
|
#include <tqheader.h>
|
||
15 years ago
|
|
||
|
#include <klocale.h>
|
||
12 years ago
|
#include <tdefileitem.h>
|
||
15 years ago
|
#include <kdebug.h>
|
||
|
#include <kdialog.h>
|
||
|
#include <kdialogbase.h>
|
||
|
|
||
|
#ifdef HAVE_ACL_LIBACL_H
|
||
|
# include <acl/libacl.h>
|
||
|
#endif
|
||
|
extern "C" {
|
||
|
#include <pwd.h>
|
||
|
#include <grp.h>
|
||
|
}
|
||
|
#include <assert.h>
|
||
|
|
||
|
#include "images.h"
|
||
|
|
||
|
static struct {
|
||
|
const char* label;
|
||
|
const char* pixmapName;
|
||
15 years ago
|
TQPixmap* pixmap;
|
||
15 years ago
|
} s_itemAttributes[] = {
|
||
|
{ I18N_NOOP( "Owner" ), "user-grey", 0 },
|
||
|
{ I18N_NOOP( "Owning Group" ), "group-grey", 0 },
|
||
|
{ I18N_NOOP( "Others" ), "others-grey", 0 },
|
||
14 years ago
|
{ I18N_NOOP( "Mask" ), "mask", 0 },
|
||
15 years ago
|
{ I18N_NOOP( "Named User" ), "user", 0 },
|
||
|
{ I18N_NOOP( "Named Group" ), "group", 0 },
|
||
|
};
|
||
|
|
||
15 years ago
|
KACLEditWidget::KACLEditWidget( TQWidget *parent, const char *name )
|
||
|
:TQWidget( parent, name )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQHBox *hbox = new TQHBox( parent );
|
||
15 years ago
|
hbox->setSpacing( KDialog::spacingHint() );
|
||
|
m_listView = new KACLListView( hbox, "acl_listview" );
|
||
15 years ago
|
connect( m_listView, TQT_SIGNAL( selectionChanged() ),
|
||
|
this, TQT_SLOT( slotUpdateButtons() ) );
|
||
|
TQVBox *vbox = new TQVBox( hbox );
|
||
15 years ago
|
vbox->setSpacing( KDialog::spacingHint() );
|
||
15 years ago
|
m_AddBtn = new TQPushButton( i18n( "Add Entry..." ), vbox, "add_entry_button" );
|
||
|
connect( m_AddBtn, TQT_SIGNAL( clicked() ), m_listView, TQT_SLOT( slotAddEntry() ) );
|
||
|
m_EditBtn = new TQPushButton( i18n( "Edit Entry..." ), vbox, "edit_entry_button" );
|
||
|
connect( m_EditBtn, TQT_SIGNAL( clicked() ), m_listView, TQT_SLOT( slotEditEntry() ) );
|
||
|
m_DelBtn = new TQPushButton( i18n( "Delete Entry" ), vbox, "delete_entry_button" );
|
||
|
connect( m_DelBtn, TQT_SIGNAL( clicked() ), m_listView, TQT_SLOT( slotRemoveEntry() ) );
|
||
|
TQWidget *spacer = new TQWidget( vbox );
|
||
13 years ago
|
spacer->setSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Expanding );
|
||
15 years ago
|
slotUpdateButtons();
|
||
|
}
|
||
|
|
||
|
void KACLEditWidget::slotUpdateButtons()
|
||
|
{
|
||
|
bool atLeastOneIsNotDeletable = false;
|
||
|
bool atLeastOneIsNotAllowedToChangeType = false;
|
||
|
int selectedCount = 0;
|
||
15 years ago
|
TQListViewItemIterator it( m_listView, TQListViewItemIterator::Selected );
|
||
15 years ago
|
while ( KACLListViewItem *item = dynamic_cast<KACLListViewItem*>( it.current() ) ) {
|
||
|
++it; ++selectedCount;
|
||
|
if ( !item->isDeletable() )
|
||
|
atLeastOneIsNotDeletable = true;
|
||
|
if ( !item->isAllowedToChangeType() )
|
||
|
atLeastOneIsNotAllowedToChangeType = true;
|
||
|
}
|
||
|
m_EditBtn->setEnabled( selectedCount && !atLeastOneIsNotAllowedToChangeType );
|
||
|
m_DelBtn->setEnabled( selectedCount && !atLeastOneIsNotDeletable );
|
||
|
}
|
||
|
|
||
|
KACL KACLEditWidget::getACL() const
|
||
|
{
|
||
|
return m_listView->getACL();
|
||
|
}
|
||
|
|
||
|
KACL KACLEditWidget::getDefaultACL() const
|
||
|
{
|
||
|
return m_listView->getDefaultACL();
|
||
|
}
|
||
|
|
||
|
void KACLEditWidget::setACL( const KACL &acl )
|
||
|
{
|
||
|
return m_listView->setACL( acl );
|
||
|
}
|
||
|
|
||
|
void KACLEditWidget::setDefaultACL( const KACL &acl )
|
||
|
{
|
||
|
return m_listView->setDefaultACL( acl );
|
||
|
}
|
||
|
|
||
|
void KACLEditWidget::setAllowDefaults( bool value )
|
||
|
{
|
||
|
m_listView->setAllowDefaults( value );
|
||
|
}
|
||
|
|
||
|
void KACLEditWidget::setReadOnly( bool on )
|
||
|
{
|
||
|
m_listView->setEnabled( !on );
|
||
|
m_AddBtn->setEnabled( !on );
|
||
|
if ( !on )
|
||
|
slotUpdateButtons();
|
||
|
}
|
||
|
|
||
15 years ago
|
KACLListViewItem::KACLListViewItem( TQListView* parent,
|
||
15 years ago
|
KACLListView::EntryType _type,
|
||
|
unsigned short _value, bool defaults,
|
||
15 years ago
|
const TQString& _qualifier )
|
||
15 years ago
|
: KListViewItem( parent, parent->lastItem() ), // we want to append
|
||
|
type( _type ), value( _value ), isDefault( defaults ),
|
||
|
qualifier( _qualifier ), isPartial( false )
|
||
|
{
|
||
|
m_pACLListView = dynamic_cast<KACLListView*>( parent );
|
||
13 years ago
|
repaint();
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
|
KACLListViewItem::~ KACLListViewItem()
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString KACLListViewItem::key( int, bool ) const
|
||
15 years ago
|
{
|
||
15 years ago
|
TQString key;
|
||
15 years ago
|
if ( !isDefault )
|
||
|
key = "A";
|
||
|
else
|
||
|
key = "B";
|
||
|
switch ( type )
|
||
|
{
|
||
|
case KACLListView::User:
|
||
|
key += "A";
|
||
|
break;
|
||
|
case KACLListView::Group:
|
||
|
key += "B";
|
||
|
break;
|
||
|
case KACLListView::Others:
|
||
|
key += "C";
|
||
|
break;
|
||
|
case KACLListView::Mask:
|
||
|
key += "D";
|
||
|
break;
|
||
|
case KACLListView::NamedUser:
|
||
|
key += "E" + text( 1 );
|
||
|
break;
|
||
|
case KACLListView::NamedGroup:
|
||
|
key += "F" + text( 1 );
|
||
|
break;
|
||
|
default:
|
||
|
key += text( 0 );
|
||
|
break;
|
||
|
}
|
||
|
return key;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KACLListViewItem::paintCell( TQPainter* p, const TQColorGroup &cg,
|
||
13 years ago
|
int column, int width, int alignment )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQColorGroup mycg = cg;
|
||
15 years ago
|
if ( isDefault ) {
|
||
15 years ago
|
mycg.setColor( TQColorGroup::Text, TQColor( 0, 0, 255 ) );
|
||
15 years ago
|
}
|
||
|
if ( isPartial ) {
|
||
15 years ago
|
TQFont font = p->font();
|
||
15 years ago
|
font.setItalic( true );
|
||
15 years ago
|
mycg.setColor( TQColorGroup::Text, TQColor( 100, 100, 100 ) );
|
||
15 years ago
|
p->setFont( font );
|
||
|
}
|
||
13 years ago
|
KListViewItem::paintCell( p, mycg, column, width, alignment );
|
||
15 years ago
|
|
||
|
KACLListViewItem *below =0;
|
||
|
if ( itemBelow() )
|
||
|
below = static_cast<KACLListViewItem*>( itemBelow() );
|
||
|
const bool lastUser = type == KACLListView::NamedUser && below && below->type == KACLListView::NamedGroup;
|
||
|
const bool lastNonDefault = !isDefault && below && below->isDefault;
|
||
|
if ( type == KACLListView::Mask || lastUser || lastNonDefault )
|
||
|
{
|
||
15 years ago
|
p->setPen( TQPen( Qt::gray, 0, TQPen::DotLine ) );
|
||
15 years ago
|
if ( type == KACLListView::Mask )
|
||
|
p->drawLine( 0, 0, width - 1, 0 );
|
||
|
p->drawLine( 0, height() - 1, width - 1, height() - 1 );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
void KACLListViewItem::updatePermPixmaps()
|
||
|
{
|
||
|
unsigned int partialPerms = value;
|
||
|
|
||
|
if ( value & ACL_READ )
|
||
|
setPixmap( 2, m_pACLListView->getYesPixmap() );
|
||
|
else if ( partialPerms & ACL_READ )
|
||
|
setPixmap( 2, m_pACLListView->getYesPartialPixmap() );
|
||
|
else
|
||
15 years ago
|
setPixmap( 2, TQPixmap() );
|
||
15 years ago
|
|
||
|
if ( value & ACL_WRITE )
|
||
|
setPixmap( 3, m_pACLListView->getYesPixmap() );
|
||
|
else if ( partialPerms & ACL_WRITE )
|
||
|
setPixmap( 3, m_pACLListView->getYesPartialPixmap() );
|
||
|
else
|
||
15 years ago
|
setPixmap( 3, TQPixmap() );
|
||
15 years ago
|
|
||
|
if ( value & ACL_EXECUTE )
|
||
|
setPixmap( 4, m_pACLListView->getYesPixmap() );
|
||
|
else if ( partialPerms & ACL_EXECUTE )
|
||
|
setPixmap( 4, m_pACLListView->getYesPartialPixmap() );
|
||
|
else
|
||
15 years ago
|
setPixmap( 4, TQPixmap() );
|
||
15 years ago
|
}
|
||
|
|
||
13 years ago
|
void KACLListViewItem::repaint()
|
||
15 years ago
|
{
|
||
|
int idx = 0;
|
||
|
switch ( type )
|
||
|
{
|
||
|
case KACLListView::User:
|
||
|
idx = KACLListView::OWNER_IDX;
|
||
|
break;
|
||
|
case KACLListView::Group:
|
||
|
idx = KACLListView::GROUP_IDX;
|
||
|
break;
|
||
|
case KACLListView::Others:
|
||
|
idx = KACLListView::OTHERS_IDX;
|
||
|
break;
|
||
|
case KACLListView::Mask:
|
||
|
idx = KACLListView::MASK_IDX;
|
||
|
break;
|
||
|
case KACLListView::NamedUser:
|
||
|
idx = KACLListView::NAMED_USER_IDX;
|
||
|
break;
|
||
|
case KACLListView::NamedGroup:
|
||
|
idx = KACLListView::NAMED_GROUP_IDX;
|
||
|
break;
|
||
|
default:
|
||
|
idx = KACLListView::OWNER_IDX;
|
||
|
break;
|
||
|
}
|
||
|
setText( 0, i18n(s_itemAttributes[idx].label) );
|
||
|
setPixmap( 0, *s_itemAttributes[idx].pixmap );
|
||
|
if ( isDefault )
|
||
|
setText( 0, text( 0 ) + i18n( " (Default)" ) );
|
||
|
setText( 1, qualifier );
|
||
|
// Set the pixmaps for which of the perms are set
|
||
|
updatePermPixmaps();
|
||
|
}
|
||
|
|
||
|
void KACLListViewItem::calcEffectiveRights()
|
||
|
{
|
||
15 years ago
|
TQString strEffective = TQString( "---" );
|
||
15 years ago
|
|
||
14 years ago
|
// Do we need to worry about the mask entry? It applies to named users,
|
||
15 years ago
|
// owning group, and named groups
|
||
|
if ( m_pACLListView->hasMaskEntry()
|
||
|
&& ( type == KACLListView::NamedUser
|
||
|
|| type == KACLListView::Group
|
||
|
|| type == KACLListView::NamedGroup )
|
||
|
&& !isDefault )
|
||
|
{
|
||
|
|
||
14 years ago
|
strEffective[0] = ( m_pACLListView->maskPermissions() & value & ACL_READ ) ? 'r' : '-';
|
||
|
strEffective[1] = ( m_pACLListView->maskPermissions() & value & ACL_WRITE ) ? 'w' : '-';
|
||
|
strEffective[2] = ( m_pACLListView->maskPermissions() & value & ACL_EXECUTE ) ? 'x' : '-';
|
||
15 years ago
|
/*
|
||
|
// What about any partial perms?
|
||
14 years ago
|
if ( maskPerms & partialPerms & ACL_READ || // Partial perms on entry
|
||
|
maskPartialPerms & perms & ACL_READ || // Partial perms on mask
|
||
|
maskPartialPerms & partialPerms & ACL_READ ) // Partial perms on mask and entry
|
||
15 years ago
|
strEffective[0] = 'R';
|
||
14 years ago
|
if ( maskPerms & partialPerms & ACL_WRITE || // Partial perms on entry
|
||
|
maskPartialPerms & perms & ACL_WRITE || // Partial perms on mask
|
||
|
maskPartialPerms & partialPerms & ACL_WRITE ) // Partial perms on mask and entry
|
||
15 years ago
|
strEffective[1] = 'W';
|
||
14 years ago
|
if ( maskPerms & partialPerms & ACL_EXECUTE || // Partial perms on entry
|
||
|
maskPartialPerms & perms & ACL_EXECUTE || // Partial perms on mask
|
||
|
maskPartialPerms & partialPerms & ACL_EXECUTE ) // Partial perms on mask and entry
|
||
15 years ago
|
strEffective[2] = 'X';
|
||
|
*/
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
// No, the effective value are just the value in this entry
|
||
|
strEffective[0] = ( value & ACL_READ ) ? 'r' : '-';
|
||
|
strEffective[1] = ( value & ACL_WRITE ) ? 'w' : '-';
|
||
|
strEffective[2] = ( value & ACL_EXECUTE ) ? 'x' : '-';
|
||
|
|
||
|
/*
|
||
|
// What about any partial perms?
|
||
|
if ( partialPerms & ACL_READ )
|
||
|
strEffective[0] = 'R';
|
||
|
if ( partialPerms & ACL_WRITE )
|
||
|
strEffective[1] = 'W';
|
||
|
if ( partialPerms & ACL_EXECUTE )
|
||
|
strEffective[2] = 'X';
|
||
|
*/
|
||
|
}
|
||
|
setText( 5, strEffective );
|
||
|
}
|
||
|
|
||
|
bool KACLListViewItem::isDeletable() const
|
||
|
{
|
||
|
bool isMaskAndDeletable = false;
|
||
|
if (type == KACLListView::Mask ) {
|
||
14 years ago
|
if ( !isDefault && m_pACLListView->maskCanBeDeleted() )
|
||
15 years ago
|
isMaskAndDeletable = true;
|
||
|
else if ( isDefault && m_pACLListView->defaultMaskCanBeDeleted() )
|
||
|
isMaskAndDeletable = true;
|
||
|
}
|
||
|
return type != KACLListView::User &&
|
||
|
type != KACLListView::Group &&
|
||
|
type != KACLListView::Others &&
|
||
|
( type != KACLListView::Mask || isMaskAndDeletable );
|
||
|
}
|
||
|
|
||
|
bool KACLListViewItem::isAllowedToChangeType() const
|
||
|
{
|
||
|
return type != KACLListView::User &&
|
||
|
type != KACLListView::Group &&
|
||
|
type != KACLListView::Others &&
|
||
|
type != KACLListView::Mask;
|
||
|
}
|
||
|
|
||
|
void KACLListViewItem::togglePerm( acl_perm_t perm )
|
||
|
{
|
||
|
value ^= perm; // Toggle the perm
|
||
|
if ( type == KACLListView::Mask && !isDefault ) {
|
||
|
m_pACLListView->setMaskPermissions( value );
|
||
|
}
|
||
|
calcEffectiveRights();
|
||
|
updatePermPixmaps();
|
||
|
/*
|
||
|
// If the perm is in the partial perms then remove it. i.e. Once
|
||
|
// a user changes a partial perm it then applies to all selected files.
|
||
|
if ( m_pEntry->m_partialPerms & perm )
|
||
|
m_pEntry->m_partialPerms ^= perm;
|
||
|
|
||
|
m_pEntry->setPartialEntry( false );
|
||
|
// Make sure that all entries have their effective rights calculated if
|
||
|
// we are changing the ACL_MASK entry.
|
||
|
if ( type == Mask )
|
||
|
{
|
||
|
m_pACLListView->setMaskPartialPermissions( m_pEntry->m_partialPerms );
|
||
|
m_pACLListView->setMaskPermissions( value );
|
||
|
m_pACLListView->calculateEffectiveRights();
|
||
|
}
|
||
|
*/
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
EditACLEntryDialog::EditACLEntryDialog( KACLListView *listView, KACLListViewItem *item,
|
||
15 years ago
|
const TQStringList &users,
|
||
|
const TQStringList &groups,
|
||
|
const TQStringList &defaultUsers,
|
||
|
const TQStringList &defaultGroups,
|
||
15 years ago
|
int allowedTypes, int allowedDefaultTypes,
|
||
|
bool allowDefaults )
|
||
|
: KDialogBase( listView, "edit_entry_dialog", true,
|
||
|
i18n( "Edit ACL Entry" ), KDialogBase::Ok|KDialogBase::Cancel,
|
||
|
KDialogBase::Ok, false ),
|
||
|
m_listView( listView ), m_item( item ), m_users( users ), m_groups( groups ),
|
||
|
m_defaultUsers( defaultUsers ), m_defaultGroups( defaultGroups ),
|
||
|
m_allowedTypes( allowedTypes ), m_allowedDefaultTypes( allowedDefaultTypes ),
|
||
|
m_defaultCB( 0 )
|
||
|
{
|
||
15 years ago
|
TQWidget *page = new TQWidget( this );
|
||
15 years ago
|
setMainWidget( page );
|
||
15 years ago
|
TQVBoxLayout *mainLayout = new TQVBoxLayout( page, 0, spacingHint(), "mainLayout" );
|
||
|
m_buttonGroup = new TQVButtonGroup( i18n("Entry Type"), page, "bg" );
|
||
15 years ago
|
|
||
|
if ( allowDefaults ) {
|
||
15 years ago
|
m_defaultCB = new TQCheckBox( i18n("Default for new files in this folder"), page, "defaultCB" );
|
||
15 years ago
|
mainLayout->addWidget( m_defaultCB );
|
||
15 years ago
|
connect( m_defaultCB, TQT_SIGNAL( toggled( bool ) ),
|
||
|
this, TQT_SLOT( slotUpdateAllowedUsersAndGroups() ) );
|
||
|
connect( m_defaultCB, TQT_SIGNAL( toggled( bool ) ),
|
||
|
this, TQT_SLOT( slotUpdateAllowedTypes() ) );
|
||
15 years ago
|
|
||
|
}
|
||
|
|
||
|
mainLayout->addWidget( m_buttonGroup );
|
||
|
|
||
15 years ago
|
TQRadioButton *ownerType = new TQRadioButton( i18n("Owner"), m_buttonGroup, "ownerType" );
|
||
15 years ago
|
m_buttonGroup->insert( ownerType, KACLListView::User );
|
||
15 years ago
|
TQRadioButton *owningGroupType = new TQRadioButton( i18n("Owning Group"), m_buttonGroup, "owningGroupType" );
|
||
15 years ago
|
m_buttonGroup->insert( owningGroupType, KACLListView::Group );
|
||
15 years ago
|
TQRadioButton *othersType = new TQRadioButton( i18n("Others"), m_buttonGroup, "othersType" );
|
||
15 years ago
|
m_buttonGroup->insert( othersType, KACLListView::Others );
|
||
14 years ago
|
TQRadioButton *maskType = new TQRadioButton( i18n("Mask"), m_buttonGroup, "maskType" );
|
||
|
m_buttonGroup->insert( maskType, KACLListView::Mask );
|
||
15 years ago
|
TQRadioButton *namedUserType = new TQRadioButton( i18n("Named User"), m_buttonGroup, "namesUserType" );
|
||
15 years ago
|
m_buttonGroup->insert( namedUserType, KACLListView::NamedUser );
|
||
15 years ago
|
TQRadioButton *namedGroupType = new TQRadioButton( i18n("Named Group"), m_buttonGroup, "namedGroupType" );
|
||
15 years ago
|
m_buttonGroup->insert( namedGroupType, KACLListView::NamedGroup );
|
||
|
|
||
15 years ago
|
connect( m_buttonGroup, TQT_SIGNAL( clicked( int ) ),
|
||
|
this, TQT_SLOT( slotSelectionChanged( int ) ) );
|
||
15 years ago
|
|
||
15 years ago
|
m_widgetStack = new TQWidgetStack( page );
|
||
15 years ago
|
mainLayout->addWidget( m_widgetStack );
|
||
|
|
||
15 years ago
|
TQHBox *usersBox = new TQHBox( m_widgetStack );
|
||
15 years ago
|
m_widgetStack->addWidget( usersBox, KACLListView::NamedUser );
|
||
|
|
||
15 years ago
|
TQHBox *groupsBox = new TQHBox( m_widgetStack );
|
||
15 years ago
|
m_widgetStack->addWidget( groupsBox, KACLListView::NamedGroup );
|
||
|
|
||
15 years ago
|
TQLabel *usersLabel = new TQLabel( i18n( "User: " ), usersBox );
|
||
|
m_usersCombo = new TQComboBox( false, usersBox, "users" );
|
||
15 years ago
|
usersLabel->setBuddy( m_usersCombo );
|
||
|
|
||
15 years ago
|
TQLabel *groupsLabel = new TQLabel( i18n( "Group: " ), groupsBox );
|
||
|
m_groupsCombo = new TQComboBox( false, groupsBox, "groups" );
|
||
15 years ago
|
groupsLabel->setBuddy( m_groupsCombo );
|
||
|
|
||
|
if ( m_item ) {
|
||
|
m_buttonGroup->setButton( m_item->type );
|
||
|
if ( m_defaultCB )
|
||
|
m_defaultCB->setChecked( m_item->isDefault );
|
||
|
slotUpdateAllowedTypes();
|
||
|
slotSelectionChanged( m_item->type );
|
||
|
slotUpdateAllowedUsersAndGroups();
|
||
|
if ( m_item->type == KACLListView::NamedUser ) {
|
||
|
m_usersCombo->setCurrentText( m_item->qualifier );
|
||
|
} else if ( m_item->type == KACLListView::NamedGroup ) {
|
||
|
m_groupsCombo->setCurrentText( m_item->qualifier );
|
||
|
}
|
||
|
} else {
|
||
|
// new entry, preselect "named user", arguably the most common one
|
||
|
m_buttonGroup->setButton( KACLListView::NamedUser );
|
||
|
slotUpdateAllowedTypes();
|
||
|
slotSelectionChanged( KACLListView::NamedUser );
|
||
|
slotUpdateAllowedUsersAndGroups();
|
||
|
}
|
||
15 years ago
|
incInitialSize( TQSize( 100, 0 ) );
|
||
15 years ago
|
}
|
||
|
|
||
|
void EditACLEntryDialog::slotUpdateAllowedTypes()
|
||
|
{
|
||
|
int allowedTypes = m_allowedTypes;
|
||
|
if ( m_defaultCB && m_defaultCB->isChecked() ) {
|
||
|
allowedTypes = m_allowedDefaultTypes;
|
||
|
}
|
||
|
for ( int i=1; i < KACLListView::AllTypes; i=i*2 ) {
|
||
|
if ( allowedTypes & i )
|
||
14 years ago
|
m_buttonGroup->find( i )->show();
|
||
15 years ago
|
else
|
||
14 years ago
|
m_buttonGroup->find( i )->hide();
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
|
void EditACLEntryDialog::slotUpdateAllowedUsersAndGroups()
|
||
|
{
|
||
15 years ago
|
const TQString oldUser = m_usersCombo->currentText();
|
||
|
const TQString oldGroup = m_groupsCombo->currentText();
|
||
15 years ago
|
m_usersCombo->clear();
|
||
|
m_groupsCombo->clear();
|
||
|
if ( m_defaultCB && m_defaultCB->isChecked() ) {
|
||
|
m_usersCombo->insertStringList( m_defaultUsers );
|
||
13 years ago
|
if ( m_defaultUsers.find( oldUser ) != m_defaultUsers.end() )
|
||
15 years ago
|
m_usersCombo->setCurrentText( oldUser );
|
||
|
m_groupsCombo->insertStringList( m_defaultGroups );
|
||
13 years ago
|
if ( m_defaultGroups.find( oldGroup ) != m_defaultGroups.end() )
|
||
15 years ago
|
m_groupsCombo->setCurrentText( oldGroup );
|
||
|
} else {
|
||
|
m_usersCombo->insertStringList( m_users );
|
||
13 years ago
|
if ( m_users.find( oldUser ) != m_users.end() )
|
||
15 years ago
|
m_usersCombo->setCurrentText( oldUser );
|
||
|
m_groupsCombo->insertStringList( m_groups );
|
||
13 years ago
|
if ( m_groups.find( oldGroup ) != m_groups.end() )
|
||
15 years ago
|
m_groupsCombo->setCurrentText( oldGroup );
|
||
|
}
|
||
|
}
|
||
|
void EditACLEntryDialog::slotOk()
|
||
|
{
|
||
|
KACLListView::EntryType type = static_cast<KACLListView::EntryType>( m_buttonGroup->selectedId() );
|
||
|
|
||
15 years ago
|
TQString qualifier;
|
||
15 years ago
|
if ( type == KACLListView::NamedUser )
|
||
|
qualifier = m_usersCombo->currentText();
|
||
|
if ( type == KACLListView::NamedGroup )
|
||
|
qualifier = m_groupsCombo->currentText();
|
||
|
|
||
|
if ( !m_item ) {
|
||
|
m_item = new KACLListViewItem( m_listView, type, ACL_READ | ACL_WRITE | ACL_EXECUTE, false, qualifier );
|
||
|
} else {
|
||
|
m_item->type = type;
|
||
|
m_item->qualifier = qualifier;
|
||
|
}
|
||
|
if ( m_defaultCB )
|
||
|
m_item->isDefault = m_defaultCB->isChecked();
|
||
13 years ago
|
m_item->repaint();
|
||
15 years ago
|
|
||
|
KDialogBase::slotOk();
|
||
|
}
|
||
|
|
||
|
void EditACLEntryDialog::slotSelectionChanged( int id )
|
||
|
{
|
||
|
switch ( id ) {
|
||
|
case KACLListView::User:
|
||
|
case KACLListView::Group:
|
||
|
case KACLListView::Others:
|
||
|
case KACLListView::Mask:
|
||
|
m_widgetStack->setEnabled( false );
|
||
|
break;
|
||
|
case KACLListView::NamedUser:
|
||
|
m_widgetStack->setEnabled( true );
|
||
|
m_widgetStack->raiseWidget( KACLListView::NamedUser );
|
||
|
break;
|
||
|
case KACLListView::NamedGroup:
|
||
|
m_widgetStack->setEnabled( true );
|
||
|
m_widgetStack->raiseWidget( KACLListView::NamedGroup );
|
||
|
break;
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
KACLListView::KACLListView( TQWidget* parent, const char* name )
|
||
15 years ago
|
: KListView( parent, name ),
|
||
|
m_hasMask( false ), m_allowDefaults( false )
|
||
|
{
|
||
|
// Add the columns
|
||
|
addColumn( i18n( "Type" ) );
|
||
|
addColumn( i18n( "Name" ) );
|
||
|
addColumn( i18n( "read permission", "r" ) );
|
||
|
addColumn( i18n( "write permission", "w" ) );
|
||
|
addColumn( i18n( "execute permission", "x" ) );
|
||
|
addColumn( i18n( "Effective" ) );
|
||
|
|
||
|
header()->setClickEnabled( false );
|
||
|
|
||
|
// Load the avatars
|
||
|
for ( int i=0; i < LAST_IDX; ++i ) {
|
||
14 years ago
|
s_itemAttributes[i].pixmap = new TQPixmap( qembed_findImage( s_itemAttributes[i].pixmapName ) );
|
||
15 years ago
|
}
|
||
14 years ago
|
m_yesPixmap = new TQPixmap( qembed_findImage( "yes" ) );
|
||
|
m_yesPartialPixmap = new TQPixmap( qembed_findImage( "yespartial" ) );
|
||
15 years ago
|
|
||
15 years ago
|
setSelectionMode( TQListView::Extended );
|
||
15 years ago
|
|
||
|
// fill the lists of all legal users and groups
|
||
|
struct passwd *user = 0;
|
||
|
setpwent();
|
||
|
while ( ( user = getpwent() ) != 0 ) {
|
||
13 years ago
|
m_allUsers << TQString::fromLatin1( user->pw_name );
|
||
15 years ago
|
}
|
||
|
endpwent();
|
||
|
|
||
|
struct group *gr = 0;
|
||
|
setgrent();
|
||
|
while ( ( gr = getgrent() ) != 0 ) {
|
||
13 years ago
|
m_allGroups << TQString::fromLatin1( gr->gr_name );
|
||
15 years ago
|
}
|
||
|
endgrent();
|
||
|
m_allUsers.sort();
|
||
|
m_allGroups.sort();
|
||
|
}
|
||
|
|
||
|
|
||
|
KACLListView::~KACLListView()
|
||
|
{
|
||
|
for ( int i=0; i < LAST_IDX; ++i ) {
|
||
|
delete s_itemAttributes[i].pixmap;
|
||
|
}
|
||
|
delete m_yesPixmap;
|
||
|
delete m_yesPartialPixmap;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQStringList KACLListView::allowedUsers( bool defaults, KACLListViewItem *allowedItem )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQStringList allowedUsers = m_allUsers;
|
||
|
TQListViewItemIterator it( this );
|
||
15 years ago
|
while ( it.current() ) {
|
||
|
const KACLListViewItem *item = static_cast<const KACLListViewItem*>( *it );
|
||
|
++it;
|
||
|
if ( !item->type == NamedUser || item->isDefault != defaults ) continue;
|
||
|
if ( allowedItem && item == allowedItem && allowedItem->isDefault == defaults ) continue;
|
||
|
allowedUsers.remove( item->qualifier );
|
||
|
}
|
||
|
return allowedUsers;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQStringList KACLListView::allowedGroups( bool defaults, KACLListViewItem *allowedItem )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQStringList allowedGroups = m_allGroups;
|
||
|
TQListViewItemIterator it( this );
|
||
15 years ago
|
while ( it.current() ) {
|
||
|
const KACLListViewItem *item = static_cast<const KACLListViewItem*>( *it );
|
||
|
++it;
|
||
|
if ( !item->type == NamedGroup || item->isDefault != defaults ) continue;
|
||
|
if ( allowedItem && item == allowedItem && allowedItem->isDefault == defaults ) continue;
|
||
|
allowedGroups.remove( item->qualifier );
|
||
|
}
|
||
|
return allowedGroups;
|
||
|
}
|
||
|
|
||
|
void KACLListView::fillItemsFromACL( const KACL &pACL, bool defaults )
|
||
|
{
|
||
|
// clear out old entries of that ilk
|
||
15 years ago
|
TQListViewItemIterator it( this );
|
||
15 years ago
|
while ( KACLListViewItem *item = static_cast<KACLListViewItem*>( it.current() ) ) {
|
||
|
++it;
|
||
|
if ( item->isDefault == defaults )
|
||
|
delete item;
|
||
|
}
|
||
|
KACLListViewItem *item =
|
||
|
new KACLListViewItem( this, User, pACL.ownerPermissions(), defaults );
|
||
|
|
||
|
item = new KACLListViewItem( this, Group, pACL.owningGroupPermissions(), defaults );
|
||
|
|
||
|
item = new KACLListViewItem( this, Others, pACL.othersPermissions(), defaults );
|
||
|
|
||
|
bool hasMask = false;
|
||
14 years ago
|
unsigned short mask = pACL.maskPermissions( hasMask );
|
||
15 years ago
|
if ( hasMask ) {
|
||
14 years ago
|
item = new KACLListViewItem( this, Mask, mask, defaults );
|
||
15 years ago
|
}
|
||
|
|
||
|
// read all named user entries
|
||
|
const ACLUserPermissionsList &userList = pACL.allUserPermissions();
|
||
|
ACLUserPermissionsConstIterator itu = userList.begin();
|
||
|
while ( itu != userList.end() ) {
|
||
|
new KACLListViewItem( this, NamedUser, (*itu).second, defaults, (*itu).first );
|
||
|
++itu;
|
||
|
}
|
||
|
|
||
|
// and now all named groups
|
||
|
const ACLUserPermissionsList &groupList = pACL.allGroupPermissions();
|
||
|
ACLUserPermissionsConstIterator itg = groupList.begin();
|
||
|
while ( itg != groupList.end() ) {
|
||
|
new KACLListViewItem( this, NamedGroup, (*itg).second, defaults, (*itg).first );
|
||
|
++itg;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KACLListView::setACL( const KACL &acl )
|
||
|
{
|
||
|
if ( !acl.isValid() ) return;
|
||
|
// Remove any entries left over from displaying a previous ACL
|
||
|
m_ACL = acl;
|
||
|
fillItemsFromACL( m_ACL );
|
||
|
|
||
14 years ago
|
m_mask = acl.maskPermissions( m_hasMask );
|
||
15 years ago
|
calculateEffectiveRights();
|
||
|
}
|
||
|
|
||
|
void KACLListView::setDefaultACL( const KACL &acl )
|
||
|
{
|
||
|
if ( !acl.isValid() ) return;
|
||
|
m_defaultACL = acl;
|
||
|
fillItemsFromACL( m_defaultACL, true );
|
||
|
calculateEffectiveRights();
|
||
|
}
|
||
|
|
||
|
KACL KACLListView::itemsToACL( bool defaults ) const
|
||
|
{
|
||
|
KACL newACL( 0 );
|
||
|
bool atLeastOneEntry = false;
|
||
|
ACLUserPermissionsList users;
|
||
|
ACLGroupPermissionsList groups;
|
||
15 years ago
|
TQListViewItemIterator it( const_cast<KACLListView*>( this ) );
|
||
|
while ( TQListViewItem* qlvi = it.current() ) {
|
||
15 years ago
|
++it;
|
||
|
const KACLListViewItem* item = static_cast<KACLListViewItem*>( qlvi );
|
||
|
if ( item->isDefault != defaults ) continue;
|
||
|
atLeastOneEntry = true;
|
||
|
switch ( item->type ) {
|
||
|
case User:
|
||
|
newACL.setOwnerPermissions( item->value );
|
||
|
break;
|
||
|
case Group:
|
||
|
newACL.setOwningGroupPermissions( item->value );
|
||
|
break;
|
||
|
case Others:
|
||
|
newACL.setOthersPermissions( item->value );
|
||
|
break;
|
||
|
case Mask:
|
||
|
newACL.setMaskPermissions( item->value );
|
||
|
break;
|
||
|
case NamedUser:
|
||
|
users.append( qMakePair( item->text( 1 ), item->value ) );
|
||
|
break;
|
||
|
case NamedGroup:
|
||
|
groups.append( qMakePair( item->text( 1 ), item->value ) );
|
||
|
break;
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if ( atLeastOneEntry ) {
|
||
|
newACL.setAllUserPermissions( users );
|
||
|
newACL.setAllGroupPermissions( groups );
|
||
|
if ( newACL.isValid() )
|
||
|
return newACL;
|
||
|
}
|
||
|
return KACL();
|
||
|
}
|
||
|
|
||
|
KACL KACLListView::getACL()
|
||
|
{
|
||
|
return itemsToACL( false );
|
||
|
}
|
||
|
|
||
|
|
||
|
KACL KACLListView::getDefaultACL()
|
||
|
{
|
||
|
return itemsToACL( true );
|
||
|
}
|
||
|
|
||
15 years ago
|
void KACLListView::contentsMousePressEvent( TQMouseEvent * e )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQListViewItem *clickedItem = itemAt( contentsToViewport( e->pos() ) );
|
||
15 years ago
|
if ( !clickedItem ) return;
|
||
|
// if the click is on an as yet unselected item, select it first
|
||
|
if ( !clickedItem->isSelected() )
|
||
|
KListView::contentsMousePressEvent( e );
|
||
|
|
||
|
if ( !currentItem() ) return;
|
||
|
int column = header()->sectionAt( e->x() );
|
||
|
acl_perm_t perm;
|
||
|
switch ( column )
|
||
|
{
|
||
|
case 2:
|
||
|
perm = ACL_READ;
|
||
|
break;
|
||
|
case 3:
|
||
|
perm = ACL_WRITE;
|
||
|
break;
|
||
|
case 4:
|
||
|
perm = ACL_EXECUTE;
|
||
|
break;
|
||
|
default:
|
||
|
return KListView::contentsMousePressEvent( e );
|
||
|
}
|
||
|
KACLListViewItem* referenceItem = static_cast<KACLListViewItem*>( clickedItem );
|
||
|
unsigned short referenceHadItSet = referenceItem->value & perm;
|
||
15 years ago
|
TQListViewItemIterator it( this );
|
||
15 years ago
|
while ( KACLListViewItem* item = static_cast<KACLListViewItem*>( it.current() ) ) {
|
||
|
++it;
|
||
|
if ( !item->isSelected() ) continue;
|
||
|
// toggle those with the same value as the clicked item, leave the others
|
||
|
if ( referenceHadItSet == ( item->value & perm ) )
|
||
|
item->togglePerm( perm );
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
void KACLListView::entryClicked( TQListViewItem* pItem, const TQPoint& /*pt*/, int col )
|
||
15 years ago
|
{
|
||
|
if ( !pItem ) return;
|
||
|
|
||
15 years ago
|
TQListViewItemIterator it( this );
|
||
15 years ago
|
while ( KACLListViewItem* item = static_cast<KACLListViewItem*>( it.current() ) ) {
|
||
|
++it;
|
||
|
if ( !item->isSelected() ) continue;
|
||
|
switch ( col )
|
||
|
{
|
||
|
case 2:
|
||
|
item->togglePerm( ACL_READ );
|
||
|
break;
|
||
|
case 3:
|
||
|
item->togglePerm( ACL_WRITE );
|
||
|
break;
|
||
|
case 4:
|
||
|
item->togglePerm( ACL_EXECUTE );
|
||
|
break;
|
||
|
|
||
|
default:
|
||
|
; // Do nothing
|
||
|
}
|
||
|
}
|
||
|
/*
|
||
|
// Has the user changed one of the required entries in a default ACL?
|
||
|
if ( m_pACL->aclType() == ACL_TYPE_DEFAULT &&
|
||
|
( col == 2 || col == 3 || col == 4 ) &&
|
||
|
( pACLItem->entryType() == ACL_USER_OBJ ||
|
||
|
pACLItem->entryType() == ACL_GROUP_OBJ ||
|
||
|
pACLItem->entryType() == ACL_OTHER ) )
|
||
|
{
|
||
|
// Mark the required entries as no longer being partial entries.
|
||
|
// That is, they will get applied to all selected directories.
|
||
14 years ago
|
KACLListViewItem* pUserObj = findACLEntryByType( this, ACL_USER_OBJ );
|
||
15 years ago
|
pUserObj->entry()->setPartialEntry( false );
|
||
|
|
||
14 years ago
|
KACLListViewItem* pGroupObj = findACLEntryByType( this, ACL_GROUP_OBJ );
|
||
15 years ago
|
pGroupObj->entry()->setPartialEntry( false );
|
||
|
|
||
14 years ago
|
KACLListViewItem* pOther = findACLEntryByType( this, ACL_OTHER );
|
||
15 years ago
|
pOther->entry()->setPartialEntry( false );
|
||
|
|
||
|
update();
|
||
|
}
|
||
|
*/
|
||
|
}
|
||
|
|
||
|
|
||
|
void KACLListView::calculateEffectiveRights()
|
||
|
{
|
||
15 years ago
|
TQListViewItemIterator it( this );
|
||
15 years ago
|
KACLListViewItem* pItem;
|
||
|
while ( ( pItem = dynamic_cast<KACLListViewItem*>( it.current() ) ) != 0 )
|
||
|
{
|
||
|
++it;
|
||
|
pItem->calcEffectiveRights();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
unsigned short KACLListView::maskPermissions() const
|
||
15 years ago
|
{
|
||
14 years ago
|
return m_mask;
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
14 years ago
|
void KACLListView::setMaskPermissions( unsigned short maskPerms )
|
||
15 years ago
|
{
|
||
14 years ago
|
m_mask = maskPerms;
|
||
15 years ago
|
calculateEffectiveRights();
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
acl_perm_t KACLListView::maskPartialPermissions() const
|
||
15 years ago
|
{
|
||
|
// return m_pMaskEntry->m_partialPerms;
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
void KACLListView::setMaskPartialPermissions( acl_perm_t /*maskPartialPerms*/ )
|
||
15 years ago
|
{
|
||
14 years ago
|
//m_pMaskEntry->m_partialPerms = maskPartialPerms;
|
||
15 years ago
|
calculateEffectiveRights();
|
||
|
}
|
||
|
|
||
|
bool KACLListView::hasDefaultEntries() const
|
||
|
{
|
||
15 years ago
|
TQListViewItemIterator it( const_cast<KACLListView*>( this ) );
|
||
15 years ago
|
while ( it.current() ) {
|
||
|
const KACLListViewItem *item = static_cast<const KACLListViewItem*>( it.current() );
|
||
|
++it;
|
||
|
if ( item->isDefault ) return true;
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
14 years ago
|
const KACLListViewItem* KACLListView::findDefaultItemByType( EntryType type ) const
|
||
15 years ago
|
{
|
||
14 years ago
|
return findItemByType( type, true );
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
const KACLListViewItem* KACLListView::findItemByType( EntryType type, bool defaults ) const
|
||
15 years ago
|
{
|
||
15 years ago
|
TQListViewItemIterator it( const_cast<KACLListView*>( this ) );
|
||
15 years ago
|
while ( it.current() ) {
|
||
|
const KACLListViewItem *item = static_cast<const KACLListViewItem*>( it.current() );
|
||
|
++it;
|
||
|
if ( item->isDefault == defaults && item->type == type ) {
|
||
|
return item;
|
||
|
}
|
||
|
}
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
|
||
|
unsigned short KACLListView::calculateMaskValue( bool defaults ) const
|
||
|
{
|
||
|
// KACL auto-adds the relevant maks entries, so we can simply query
|
||
|
bool dummy;
|
||
14 years ago
|
return itemsToACL( defaults ).maskPermissions( dummy );
|
||
15 years ago
|
}
|
||
|
|
||
|
void KACLListView::slotAddEntry()
|
||
|
{
|
||
|
int allowedTypes = NamedUser | NamedGroup;
|
||
|
if ( !m_hasMask )
|
||
|
allowedTypes |= Mask;
|
||
|
int allowedDefaultTypes = NamedUser | NamedGroup;
|
||
14 years ago
|
if ( !findDefaultItemByType( Mask ) )
|
||
15 years ago
|
allowedDefaultTypes |= Mask;
|
||
|
if ( !hasDefaultEntries() )
|
||
|
allowedDefaultTypes |= User | Group;
|
||
|
EditACLEntryDialog dlg( this, 0,
|
||
|
allowedUsers( false ), allowedGroups( false ),
|
||
|
allowedUsers( true ), allowedGroups( true ),
|
||
|
allowedTypes, allowedDefaultTypes, m_allowDefaults );
|
||
|
dlg.exec();
|
||
|
KACLListViewItem *item = dlg.item();
|
||
|
if ( !item ) return; // canceled
|
||
|
if ( item->type == Mask && !item->isDefault ) {
|
||
|
m_hasMask = true;
|
||
14 years ago
|
m_mask = item->value;
|
||
15 years ago
|
}
|
||
|
if ( item->isDefault && !hasDefaultEntries() ) {
|
||
|
// first default entry, fill in what is needed
|
||
|
if ( item->type != User ) {
|
||
14 years ago
|
unsigned short v = findDefaultItemByType( User )->value;
|
||
15 years ago
|
new KACLListViewItem( this, User, v, true );
|
||
|
}
|
||
|
if ( item->type != Group ) {
|
||
14 years ago
|
unsigned short v = findDefaultItemByType( Group )->value;
|
||
15 years ago
|
new KACLListViewItem( this, Group, v, true );
|
||
|
}
|
||
|
if ( item->type != Others ) {
|
||
14 years ago
|
unsigned short v = findDefaultItemByType( Others )->value;
|
||
15 years ago
|
new KACLListViewItem( this, Others, v, true );
|
||
|
}
|
||
|
}
|
||
14 years ago
|
const KACLListViewItem *defaultMaskItem = findDefaultItemByType( Mask );
|
||
15 years ago
|
if ( item->isDefault && !defaultMaskItem ) {
|
||
|
unsigned short v = calculateMaskValue( true );
|
||
|
new KACLListViewItem( this, Mask, v, true );
|
||
|
}
|
||
|
if ( !item->isDefault && !m_hasMask &&
|
||
|
( item->type == Group
|
||
|
|| item->type == NamedUser
|
||
|
|| item->type == NamedGroup ) ) {
|
||
14 years ago
|
// auto-add a mask entry
|
||
15 years ago
|
unsigned short v = calculateMaskValue( false );
|
||
|
new KACLListViewItem( this, Mask, v, false );
|
||
|
m_hasMask = true;
|
||
14 years ago
|
m_mask = v;
|
||
15 years ago
|
}
|
||
|
calculateEffectiveRights();
|
||
|
sort();
|
||
|
setCurrentItem( item );
|
||
15 years ago
|
// TQListView doesn't seem to emit, in this case, and we need to update
|
||
15 years ago
|
// the buttons...
|
||
|
if ( childCount() == 1 )
|
||
|
emit currentChanged( item );
|
||
|
}
|
||
|
|
||
|
void KACLListView::slotEditEntry()
|
||
|
{
|
||
15 years ago
|
TQListViewItem * current = currentItem();
|
||
15 years ago
|
if ( !current ) return;
|
||
|
KACLListViewItem *item = static_cast<KACLListViewItem*>( current );
|
||
|
int allowedTypes = item->type | NamedUser | NamedGroup;
|
||
|
bool itemWasMask = item->type == Mask;
|
||
|
if ( !m_hasMask || itemWasMask )
|
||
|
allowedTypes |= Mask;
|
||
|
int allowedDefaultTypes = item->type | NamedUser | NamedGroup;
|
||
14 years ago
|
if ( !findDefaultItemByType( Mask ) )
|
||
15 years ago
|
allowedDefaultTypes |= Mask;
|
||
|
if ( !hasDefaultEntries() )
|
||
|
allowedDefaultTypes |= User | Group;
|
||
|
|
||
|
EditACLEntryDialog dlg( this, item,
|
||
|
allowedUsers( false, item ), allowedGroups( false, item ),
|
||
|
allowedUsers( true, item ), allowedGroups( true, item ),
|
||
|
allowedTypes, allowedDefaultTypes, m_allowDefaults );
|
||
|
dlg.exec();
|
||
|
if ( itemWasMask && item->type != Mask ) {
|
||
|
m_hasMask = false;
|
||
14 years ago
|
m_mask = 0;
|
||
15 years ago
|
}
|
||
|
if ( !itemWasMask && item->type == Mask ) {
|
||
14 years ago
|
m_mask = item->value;
|
||
15 years ago
|
m_hasMask = true;
|
||
|
}
|
||
|
calculateEffectiveRights();
|
||
|
sort();
|
||
|
}
|
||
|
|
||
|
void KACLListView::slotRemoveEntry()
|
||
|
{
|
||
15 years ago
|
TQListViewItemIterator it( this, TQListViewItemIterator::Selected );
|
||
15 years ago
|
while ( it.current() ) {
|
||
|
KACLListViewItem *item = static_cast<KACLListViewItem*>( it.current() );
|
||
|
++it;
|
||
14 years ago
|
/* First check if it's a mask entry and if so, make sure that there is
|
||
|
* either no name user or group entry, which means the mask can be
|
||
15 years ago
|
* removed, or don't remove it, but reset it. That is allowed. */
|
||
|
if ( item->type == Mask ) {
|
||
|
bool itemWasDefault = item->isDefault;
|
||
14 years ago
|
if ( !itemWasDefault && maskCanBeDeleted() ) {
|
||
15 years ago
|
m_hasMask= false;
|
||
14 years ago
|
m_mask = 0;
|
||
15 years ago
|
delete item;
|
||
|
} else if ( itemWasDefault && defaultMaskCanBeDeleted() ) {
|
||
|
delete item;
|
||
|
} else {
|
||
|
item->value = 0;
|
||
13 years ago
|
item->repaint();
|
||
15 years ago
|
}
|
||
|
if ( !itemWasDefault )
|
||
|
calculateEffectiveRights();
|
||
|
} else {
|
||
|
// for the base permissions, disable them, which is what libacl does
|
||
|
if ( !item->isDefault &&
|
||
|
( item->type == User
|
||
|
|| item->type == Group
|
||
|
|| item->type == Others ) ) {
|
||
|
item->value = 0;
|
||
13 years ago
|
item->repaint();
|
||
15 years ago
|
} else {
|
||
|
delete item;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
bool KACLListView::maskCanBeDeleted() const
|
||
15 years ago
|
{
|
||
14 years ago
|
return !findItemByType( NamedUser ) && !findItemByType( NamedGroup );
|
||
15 years ago
|
}
|
||
|
|
||
|
bool KACLListView::defaultMaskCanBeDeleted() const
|
||
|
{
|
||
14 years ago
|
return !findDefaultItemByType( NamedUser ) && !findDefaultItemByType( NamedGroup );
|
||
15 years ago
|
}
|
||
|
|
||
|
#include "kacleditwidget.moc"
|
||
|
#include "kacleditwidget_p.moc"
|
||
|
#endif
|
||
|
// vim:set ts=8 sw=4:
|