22 #include "kacleditwidget.h"
23 #include "kacleditwidget_p.h"
27 #include <tqpainter.h>
28 #include <tqptrlist.h>
31 #include <tqpushbutton.h>
32 #include <tqvbuttongroup.h>
33 #include <tqradiobutton.h>
34 #include <tqcombobox.h>
36 #include <tqcheckbox.h>
38 #include <tqwidgetstack.h>
41 #include <tdelocale.h>
42 #include <tdefileitem.h>
45 #include <kdialogbase.h>
47 #ifdef HAVE_ACL_LIBACL_H
48 # include <acl/libacl.h>
60 const char* pixmapName;
62 } s_itemAttributes[] = {
63 { I18N_NOOP(
"Owner" ),
"user-grey", 0 },
64 { I18N_NOOP(
"Owning Group" ),
"group-grey", 0 },
65 { I18N_NOOP(
"Others" ),
"others-grey", 0 },
66 { I18N_NOOP(
"Mask" ),
"mask", 0 },
67 { I18N_NOOP(
"Named User" ),
"user", 0 },
68 { I18N_NOOP(
"Named Group" ),
"group", 0 },
71 KACLEditWidget::KACLEditWidget( TQWidget *parent,
const char *name )
72 :TQWidget( parent, name )
74 TQHBox *hbox =
new TQHBox( parent );
75 hbox->setSpacing( KDialog::spacingHint() );
76 m_listView =
new KACLListView( hbox,
"acl_listview" );
77 connect( m_listView, TQ_SIGNAL( selectionChanged() ),
78 this, TQ_SLOT( slotUpdateButtons() ) );
79 TQVBox *vbox =
new TQVBox( hbox );
80 vbox->setSpacing( KDialog::spacingHint() );
81 m_AddBtn =
new TQPushButton( i18n(
"Add Entry..." ), vbox,
"add_entry_button" );
82 connect( m_AddBtn, TQ_SIGNAL( clicked() ), m_listView, TQ_SLOT( slotAddEntry() ) );
83 m_EditBtn =
new TQPushButton( i18n(
"Edit Entry..." ), vbox,
"edit_entry_button" );
84 connect( m_EditBtn, TQ_SIGNAL( clicked() ), m_listView, TQ_SLOT( slotEditEntry() ) );
85 m_DelBtn =
new TQPushButton( i18n(
"Delete Entry" ), vbox,
"delete_entry_button" );
86 connect( m_DelBtn, TQ_SIGNAL( clicked() ), m_listView, TQ_SLOT( slotRemoveEntry() ) );
87 TQWidget *spacer =
new TQWidget( vbox );
88 spacer->setSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Expanding );
92 void KACLEditWidget::slotUpdateButtons()
94 bool atLeastOneIsNotDeletable =
false;
95 bool atLeastOneIsNotAllowedToChangeType =
false;
96 int selectedCount = 0;
97 TQListViewItemIterator it( m_listView, TQListViewItemIterator::Selected );
98 while ( KACLListViewItem *item =
dynamic_cast<KACLListViewItem*
>( it.current() ) ) {
99 ++it; ++selectedCount;
100 if ( !item->isDeletable() )
101 atLeastOneIsNotDeletable =
true;
102 if ( !item->isAllowedToChangeType() )
103 atLeastOneIsNotAllowedToChangeType =
true;
105 m_EditBtn->setEnabled( selectedCount && !atLeastOneIsNotAllowedToChangeType );
106 m_DelBtn->setEnabled( selectedCount && !atLeastOneIsNotDeletable );
109 KACL KACLEditWidget::getACL()
const
111 return m_listView->getACL();
114 KACL KACLEditWidget::getDefaultACL()
const
116 return m_listView->getDefaultACL();
119 void KACLEditWidget::setACL(
const KACL &acl )
121 return m_listView->setACL( acl );
124 void KACLEditWidget::setDefaultACL(
const KACL &acl )
126 return m_listView->setDefaultACL( acl );
129 void KACLEditWidget::setAllowDefaults(
bool value )
131 m_listView->setAllowDefaults( value );
134 void KACLEditWidget::setReadOnly(
bool on )
136 m_listView->setEnabled( !on );
137 m_AddBtn->setEnabled( !on );
142 KACLListViewItem::KACLListViewItem( TQListView* parent,
143 KACLListView::EntryType _type,
144 unsigned short _value,
bool defaults,
145 const TQString& _qualifier )
146 : TDEListViewItem( parent, parent->lastItem() ),
147 type( _type ), value( _value ), isDefault( defaults ),
148 qualifier( _qualifier ), isPartial( false )
150 m_pACLListView =
dynamic_cast<KACLListView*
>( parent );
155 KACLListViewItem::~ KACLListViewItem()
160 TQString KACLListViewItem::key(
int,
bool )
const
169 case KACLListView::User:
172 case KACLListView::Group:
175 case KACLListView::Others:
178 case KACLListView::Mask:
181 case KACLListView::NamedUser:
182 key +=
"E" + text( 1 );
184 case KACLListView::NamedGroup:
185 key +=
"F" + text( 1 );
194 void KACLListViewItem::paintCell( TQPainter* p,
const TQColorGroup &cg,
195 int column,
int width,
int alignment )
197 TQColorGroup mycg = cg;
199 mycg.setColor( TQColorGroup::Text, TQColor( 0, 0, 255 ) );
202 TQFont font = p->font();
203 font.setItalic(
true );
204 mycg.setColor( TQColorGroup::Text, TQColor( 100, 100, 100 ) );
207 TDEListViewItem::paintCell( p, mycg, column, width, alignment );
209 KACLListViewItem *below =0;
211 below =
static_cast<KACLListViewItem*
>( itemBelow() );
212 const bool lastUser = type == KACLListView::NamedUser && below && below->type == KACLListView::NamedGroup;
213 const bool lastNonDefault = !isDefault && below && below->isDefault;
214 if ( type == KACLListView::Mask || lastUser || lastNonDefault )
216 p->setPen( TQPen( TQt::gray, 0, TQPen::DotLine ) );
217 if ( type == KACLListView::Mask )
218 p->drawLine( 0, 0, width - 1, 0 );
219 p->drawLine( 0, height() - 1, width - 1, height() - 1 );
224 void KACLListViewItem::updatePermPixmaps()
226 unsigned int partialPerms = value;
228 if ( value & ACL_READ )
229 setPixmap( 2, m_pACLListView->getYesPixmap() );
230 else if ( partialPerms & ACL_READ )
231 setPixmap( 2, m_pACLListView->getYesPartialPixmap() );
233 setPixmap( 2, TQPixmap() );
235 if ( value & ACL_WRITE )
236 setPixmap( 3, m_pACLListView->getYesPixmap() );
237 else if ( partialPerms & ACL_WRITE )
238 setPixmap( 3, m_pACLListView->getYesPartialPixmap() );
240 setPixmap( 3, TQPixmap() );
242 if ( value & ACL_EXECUTE )
243 setPixmap( 4, m_pACLListView->getYesPixmap() );
244 else if ( partialPerms & ACL_EXECUTE )
245 setPixmap( 4, m_pACLListView->getYesPartialPixmap() );
247 setPixmap( 4, TQPixmap() );
250 void KACLListViewItem::repaint()
255 case KACLListView::User:
256 idx = KACLListView::OWNER_IDX;
258 case KACLListView::Group:
259 idx = KACLListView::GROUP_IDX;
261 case KACLListView::Others:
262 idx = KACLListView::OTHERS_IDX;
264 case KACLListView::Mask:
265 idx = KACLListView::MASK_IDX;
267 case KACLListView::NamedUser:
268 idx = KACLListView::NAMED_USER_IDX;
270 case KACLListView::NamedGroup:
271 idx = KACLListView::NAMED_GROUP_IDX;
274 idx = KACLListView::OWNER_IDX;
277 setText( 0, i18n(s_itemAttributes[idx].label) );
278 setPixmap( 0, *s_itemAttributes[idx].pixmap );
280 setText( 0, text( 0 ) + i18n(
" (Default)" ) );
281 setText( 1, qualifier );
286 void KACLListViewItem::calcEffectiveRights()
288 TQString strEffective = TQString(
"---" );
292 if ( m_pACLListView->hasMaskEntry()
293 && ( type == KACLListView::NamedUser
294 || type == KACLListView::Group
295 || type == KACLListView::NamedGroup )
299 strEffective[0] = ( m_pACLListView->maskPermissions() & value & ACL_READ ) ?
'r' :
'-';
300 strEffective[1] = ( m_pACLListView->maskPermissions() & value & ACL_WRITE ) ?
'w' :
'-';
301 strEffective[2] = ( m_pACLListView->maskPermissions() & value & ACL_EXECUTE ) ?
'x' :
'-';
321 strEffective[0] = ( value & ACL_READ ) ?
'r' :
'-';
322 strEffective[1] = ( value & ACL_WRITE ) ?
'w' :
'-';
323 strEffective[2] = ( value & ACL_EXECUTE ) ?
'x' :
'-';
335 setText( 5, strEffective );
338 bool KACLListViewItem::isDeletable()
const
340 bool isMaskAndDeletable =
false;
341 if (type == KACLListView::Mask ) {
342 if ( !isDefault && m_pACLListView->maskCanBeDeleted() )
343 isMaskAndDeletable =
true;
344 else if ( isDefault && m_pACLListView->defaultMaskCanBeDeleted() )
345 isMaskAndDeletable =
true;
347 return type != KACLListView::User &&
348 type != KACLListView::Group &&
349 type != KACLListView::Others &&
350 ( type != KACLListView::Mask || isMaskAndDeletable );
353 bool KACLListViewItem::isAllowedToChangeType()
const
355 return type != KACLListView::User &&
356 type != KACLListView::Group &&
357 type != KACLListView::Others &&
358 type != KACLListView::Mask;
361 void KACLListViewItem::togglePerm( acl_perm_t perm )
364 if ( type == KACLListView::Mask && !isDefault ) {
365 m_pACLListView->setMaskPermissions( value );
367 calcEffectiveRights();
389 EditACLEntryDialog::EditACLEntryDialog( KACLListView *listView, KACLListViewItem *item,
390 const TQStringList &users,
391 const TQStringList &groups,
392 const TQStringList &defaultUsers,
393 const TQStringList &defaultGroups,
394 int allowedTypes,
int allowedDefaultTypes,
396 : KDialogBase( listView,
"edit_entry_dialog", true,
397 i18n(
"Edit ACL Entry" ), KDialogBase::Ok|KDialogBase::Cancel,
398 KDialogBase::Ok, false ),
399 m_listView( listView ), m_item( item ), m_users( users ), m_groups( groups ),
400 m_defaultUsers( defaultUsers ), m_defaultGroups( defaultGroups ),
401 m_allowedTypes( allowedTypes ), m_allowedDefaultTypes( allowedDefaultTypes ),
404 TQWidget *page =
new TQWidget(
this );
405 setMainWidget( page );
406 TQVBoxLayout *mainLayout =
new TQVBoxLayout( page, 0, spacingHint(),
"mainLayout" );
407 m_buttonGroup =
new TQVButtonGroup( i18n(
"Entry Type"), page,
"bg" );
409 if ( allowDefaults ) {
410 m_defaultCB =
new TQCheckBox( i18n(
"Default for new files in this folder"), page,
"defaultCB" );
411 mainLayout->addWidget( m_defaultCB );
412 connect( m_defaultCB, TQ_SIGNAL( toggled(
bool ) ),
413 this, TQ_SLOT( slotUpdateAllowedUsersAndGroups() ) );
414 connect( m_defaultCB, TQ_SIGNAL( toggled(
bool ) ),
415 this, TQ_SLOT( slotUpdateAllowedTypes() ) );
419 mainLayout->addWidget( m_buttonGroup );
421 TQRadioButton *ownerType =
new TQRadioButton( i18n(
"Owner"), m_buttonGroup,
"ownerType" );
422 m_buttonGroup->insert( ownerType, KACLListView::User );
423 TQRadioButton *owningGroupType =
new TQRadioButton( i18n(
"Owning Group"), m_buttonGroup,
"owningGroupType" );
424 m_buttonGroup->insert( owningGroupType, KACLListView::Group );
425 TQRadioButton *othersType =
new TQRadioButton( i18n(
"Others"), m_buttonGroup,
"othersType" );
426 m_buttonGroup->insert( othersType, KACLListView::Others );
427 TQRadioButton *maskType =
new TQRadioButton( i18n(
"Mask"), m_buttonGroup,
"maskType" );
428 m_buttonGroup->insert( maskType, KACLListView::Mask );
429 TQRadioButton *namedUserType =
new TQRadioButton( i18n(
"Named User"), m_buttonGroup,
"namesUserType" );
430 m_buttonGroup->insert( namedUserType, KACLListView::NamedUser );
431 TQRadioButton *namedGroupType =
new TQRadioButton( i18n(
"Named Group"), m_buttonGroup,
"namedGroupType" );
432 m_buttonGroup->insert( namedGroupType, KACLListView::NamedGroup );
434 connect( m_buttonGroup, TQ_SIGNAL( clicked(
int ) ),
435 this, TQ_SLOT( slotSelectionChanged(
int ) ) );
437 m_widgetStack =
new TQWidgetStack( page );
438 mainLayout->addWidget( m_widgetStack );
440 TQHBox *usersBox =
new TQHBox( m_widgetStack );
441 m_widgetStack->addWidget( usersBox, KACLListView::NamedUser );
443 TQHBox *groupsBox =
new TQHBox( m_widgetStack );
444 m_widgetStack->addWidget( groupsBox, KACLListView::NamedGroup );
446 TQLabel *usersLabel =
new TQLabel( i18n(
"User: " ), usersBox );
447 m_usersCombo =
new TQComboBox(
false, usersBox,
"users" );
448 usersLabel->setBuddy( m_usersCombo );
450 TQLabel *groupsLabel =
new TQLabel( i18n(
"Group: " ), groupsBox );
451 m_groupsCombo =
new TQComboBox(
false, groupsBox,
"groups" );
452 groupsLabel->setBuddy( m_groupsCombo );
455 m_buttonGroup->setButton( m_item->type );
457 m_defaultCB->setChecked( m_item->isDefault );
458 slotUpdateAllowedTypes();
459 slotSelectionChanged( m_item->type );
460 slotUpdateAllowedUsersAndGroups();
461 if ( m_item->type == KACLListView::NamedUser ) {
462 m_usersCombo->setCurrentText( m_item->qualifier );
463 }
else if ( m_item->type == KACLListView::NamedGroup ) {
464 m_groupsCombo->setCurrentText( m_item->qualifier );
468 m_buttonGroup->setButton( KACLListView::NamedUser );
469 slotUpdateAllowedTypes();
470 slotSelectionChanged( KACLListView::NamedUser );
471 slotUpdateAllowedUsersAndGroups();
473 incInitialSize( TQSize( 100, 0 ) );
476 void EditACLEntryDialog::slotUpdateAllowedTypes()
478 int allowedTypes = m_allowedTypes;
479 if ( m_defaultCB && m_defaultCB->isChecked() ) {
480 allowedTypes = m_allowedDefaultTypes;
482 for (
int i=1; i < KACLListView::AllTypes; i=i*2 ) {
483 if ( allowedTypes & i )
484 m_buttonGroup->find( i )->show();
486 m_buttonGroup->find( i )->hide();
490 void EditACLEntryDialog::slotUpdateAllowedUsersAndGroups()
492 const TQString oldUser = m_usersCombo->currentText();
493 const TQString oldGroup = m_groupsCombo->currentText();
494 m_usersCombo->clear();
495 m_groupsCombo->clear();
496 if ( m_defaultCB && m_defaultCB->isChecked() ) {
497 m_usersCombo->insertStringList( m_defaultUsers );
498 if ( m_defaultUsers.find( oldUser ) != m_defaultUsers.end() )
499 m_usersCombo->setCurrentText( oldUser );
500 m_groupsCombo->insertStringList( m_defaultGroups );
501 if ( m_defaultGroups.find( oldGroup ) != m_defaultGroups.end() )
502 m_groupsCombo->setCurrentText( oldGroup );
504 m_usersCombo->insertStringList( m_users );
505 if ( m_users.find( oldUser ) != m_users.end() )
506 m_usersCombo->setCurrentText( oldUser );
507 m_groupsCombo->insertStringList( m_groups );
508 if ( m_groups.find( oldGroup ) != m_groups.end() )
509 m_groupsCombo->setCurrentText( oldGroup );
512 void EditACLEntryDialog::slotOk()
514 KACLListView::EntryType type =
static_cast<KACLListView::EntryType
>( m_buttonGroup->selectedId() );
517 if ( type == KACLListView::NamedUser )
518 qualifier = m_usersCombo->currentText();
519 if ( type == KACLListView::NamedGroup )
520 qualifier = m_groupsCombo->currentText();
523 m_item =
new KACLListViewItem( m_listView, type, ACL_READ | ACL_WRITE | ACL_EXECUTE,
false, qualifier );
526 m_item->qualifier = qualifier;
529 m_item->isDefault = m_defaultCB->isChecked();
532 KDialogBase::slotOk();
535 void EditACLEntryDialog::slotSelectionChanged(
int id )
538 case KACLListView::User:
539 case KACLListView::Group:
540 case KACLListView::Others:
541 case KACLListView::Mask:
542 m_widgetStack->setEnabled(
false );
544 case KACLListView::NamedUser:
545 m_widgetStack->setEnabled(
true );
546 m_widgetStack->raiseWidget( KACLListView::NamedUser );
548 case KACLListView::NamedGroup:
549 m_widgetStack->setEnabled(
true );
550 m_widgetStack->raiseWidget( KACLListView::NamedGroup );
558 KACLListView::KACLListView( TQWidget* parent,
const char* name )
559 : TDEListView( parent, name ),
560 m_hasMask( false ), m_allowDefaults( false )
563 addColumn( i18n(
"Type" ) );
564 addColumn( i18n(
"Name" ) );
565 addColumn( i18n(
"read permission",
"r" ) );
566 addColumn( i18n(
"write permission",
"w" ) );
567 addColumn( i18n(
"execute permission",
"x" ) );
568 addColumn( i18n(
"Effective" ) );
570 header()->setClickEnabled(
false );
573 for (
int i=0; i < LAST_IDX; ++i ) {
574 s_itemAttributes[i].pixmap =
new TQPixmap( qembed_findImage( s_itemAttributes[i].pixmapName ) );
576 m_yesPixmap =
new TQPixmap( qembed_findImage(
"yes" ) );
577 m_yesPartialPixmap =
new TQPixmap( qembed_findImage(
"yespartial" ) );
579 setSelectionMode( TQListView::Extended );
582 struct passwd *user = 0;
584 while ( ( user = getpwent() ) != 0 ) {
585 m_allUsers << TQString::fromLatin1( user->pw_name );
589 struct group *gr = 0;
591 while ( ( gr = getgrent() ) != 0 ) {
592 m_allGroups << TQString::fromLatin1( gr->gr_name );
600 KACLListView::~KACLListView()
602 for (
int i=0; i < LAST_IDX; ++i ) {
603 delete s_itemAttributes[i].pixmap;
606 delete m_yesPartialPixmap;
609 TQStringList KACLListView::allowedUsers(
bool defaults, KACLListViewItem *allowedItem )
611 TQStringList allowedUsers = m_allUsers;
612 TQListViewItemIterator it(
this );
613 while ( it.current() ) {
614 const KACLListViewItem *item =
static_cast<const KACLListViewItem*
>( *it );
616 if ( !item->type == NamedUser || item->isDefault != defaults )
continue;
617 if ( allowedItem && item == allowedItem && allowedItem->isDefault == defaults )
continue;
618 allowedUsers.remove( item->qualifier );
623 TQStringList KACLListView::allowedGroups(
bool defaults, KACLListViewItem *allowedItem )
625 TQStringList allowedGroups = m_allGroups;
626 TQListViewItemIterator it(
this );
627 while ( it.current() ) {
628 const KACLListViewItem *item =
static_cast<const KACLListViewItem*
>( *it );
630 if ( !item->type == NamedGroup || item->isDefault != defaults )
continue;
631 if ( allowedItem && item == allowedItem && allowedItem->isDefault == defaults )
continue;
632 allowedGroups.remove( item->qualifier );
634 return allowedGroups;
637 void KACLListView::fillItemsFromACL(
const KACL &pACL,
bool defaults )
640 TQListViewItemIterator it(
this );
641 while ( KACLListViewItem *item =
static_cast<KACLListViewItem*
>( it.current() ) ) {
643 if ( item->isDefault == defaults )
646 KACLListViewItem *item =
647 new KACLListViewItem(
this, User, pACL.ownerPermissions(), defaults );
649 item =
new KACLListViewItem(
this, Group, pACL.owningGroupPermissions(), defaults );
651 item =
new KACLListViewItem(
this, Others, pACL.othersPermissions(), defaults );
653 bool hasMask =
false;
654 unsigned short mask = pACL.maskPermissions( hasMask );
656 item =
new KACLListViewItem(
this, Mask, mask, defaults );
660 const ACLUserPermissionsList &userList = pACL.allUserPermissions();
661 ACLUserPermissionsConstIterator itu = userList.begin();
662 while ( itu != userList.end() ) {
663 new KACLListViewItem(
this, NamedUser, (*itu).second, defaults, (*itu).first );
668 const ACLUserPermissionsList &groupList = pACL.allGroupPermissions();
669 ACLUserPermissionsConstIterator itg = groupList.begin();
670 while ( itg != groupList.end() ) {
671 new KACLListViewItem(
this, NamedGroup, (*itg).second, defaults, (*itg).first );
676 void KACLListView::setACL(
const KACL &acl )
678 if ( !acl.isValid() )
return;
681 fillItemsFromACL( m_ACL );
683 m_mask = acl.maskPermissions( m_hasMask );
684 calculateEffectiveRights();
687 void KACLListView::setDefaultACL(
const KACL &acl )
689 if ( !acl.isValid() )
return;
691 fillItemsFromACL( m_defaultACL,
true );
692 calculateEffectiveRights();
695 KACL KACLListView::itemsToACL(
bool defaults )
const
698 bool atLeastOneEntry =
false;
699 ACLUserPermissionsList users;
700 ACLGroupPermissionsList groups;
701 TQListViewItemIterator it(
const_cast<KACLListView*
>(
this ) );
702 while ( TQListViewItem* qlvi = it.current() ) {
704 const KACLListViewItem* item =
static_cast<KACLListViewItem*
>( qlvi );
705 if ( item->isDefault != defaults )
continue;
706 atLeastOneEntry =
true;
707 switch ( item->type ) {
709 newACL.setOwnerPermissions( item->value );
712 newACL.setOwningGroupPermissions( item->value );
715 newACL.setOthersPermissions( item->value );
718 newACL.setMaskPermissions( item->value );
721 users.append( qMakePair( item->text( 1 ), item->value ) );
724 groups.append( qMakePair( item->text( 1 ), item->value ) );
730 if ( atLeastOneEntry ) {
731 newACL.setAllUserPermissions( users );
732 newACL.setAllGroupPermissions( groups );
733 if ( newACL.isValid() )
739 KACL KACLListView::getACL()
741 return itemsToACL(
false );
745 KACL KACLListView::getDefaultACL()
747 return itemsToACL(
true );
750 void KACLListView::contentsMousePressEvent( TQMouseEvent * e )
752 TQListViewItem *clickedItem = itemAt( contentsToViewport( e->pos() ) );
753 if ( !clickedItem )
return;
755 if ( !clickedItem->isSelected() )
756 TDEListView::contentsMousePressEvent( e );
758 if ( !currentItem() )
return;
759 int column = header()->sectionAt( e->x() );
773 return TDEListView::contentsMousePressEvent( e );
775 KACLListViewItem* referenceItem =
static_cast<KACLListViewItem*
>( clickedItem );
776 unsigned short referenceHadItSet = referenceItem->value & perm;
777 TQListViewItemIterator it(
this );
778 while ( KACLListViewItem* item =
static_cast<KACLListViewItem*
>( it.current() ) ) {
780 if ( !item->isSelected() )
continue;
782 if ( referenceHadItSet == ( item->value & perm ) )
783 item->togglePerm( perm );
787 void KACLListView::entryClicked( TQListViewItem* pItem,
const TQPoint& ,
int col )
789 if ( !pItem )
return;
791 TQListViewItemIterator it(
this );
792 while ( KACLListViewItem* item =
static_cast<KACLListViewItem*
>( it.current() ) ) {
794 if ( !item->isSelected() )
continue;
798 item->togglePerm( ACL_READ );
801 item->togglePerm( ACL_WRITE );
804 item->togglePerm( ACL_EXECUTE );
836 void KACLListView::calculateEffectiveRights()
838 TQListViewItemIterator it(
this );
839 KACLListViewItem* pItem;
840 while ( ( pItem =
dynamic_cast<KACLListViewItem*
>( it.current() ) ) != 0 )
843 pItem->calcEffectiveRights();
848 unsigned short KACLListView::maskPermissions()
const
854 void KACLListView::setMaskPermissions(
unsigned short maskPerms )
857 calculateEffectiveRights();
861 acl_perm_t KACLListView::maskPartialPermissions()
const
868 void KACLListView::setMaskPartialPermissions( acl_perm_t )
871 calculateEffectiveRights();
874 bool KACLListView::hasDefaultEntries()
const
876 TQListViewItemIterator it(
const_cast<KACLListView*
>(
this ) );
877 while ( it.current() ) {
878 const KACLListViewItem *item =
static_cast<const KACLListViewItem*
>( it.current() );
880 if ( item->isDefault )
return true;
885 const KACLListViewItem* KACLListView::findDefaultItemByType( EntryType type )
const
887 return findItemByType( type,
true );
890 const KACLListViewItem* KACLListView::findItemByType( EntryType type,
bool defaults )
const
892 TQListViewItemIterator it(
const_cast<KACLListView*
>(
this ) );
893 while ( it.current() ) {
894 const KACLListViewItem *item =
static_cast<const KACLListViewItem*
>( it.current() );
896 if ( item->isDefault == defaults && item->type == type ) {
904 unsigned short KACLListView::calculateMaskValue(
bool defaults )
const
908 return itemsToACL( defaults ).maskPermissions( dummy );
911 void KACLListView::slotAddEntry()
913 int allowedTypes = NamedUser | NamedGroup;
915 allowedTypes |= Mask;
916 int allowedDefaultTypes = NamedUser | NamedGroup;
917 if ( !findDefaultItemByType( Mask ) )
918 allowedDefaultTypes |= Mask;
919 if ( !hasDefaultEntries() )
920 allowedDefaultTypes |= User | Group;
921 EditACLEntryDialog dlg(
this, 0,
922 allowedUsers(
false ), allowedGroups(
false ),
923 allowedUsers(
true ), allowedGroups(
true ),
924 allowedTypes, allowedDefaultTypes, m_allowDefaults );
926 KACLListViewItem *item = dlg.item();
928 if ( item->type == Mask && !item->isDefault ) {
930 m_mask = item->value;
932 if ( item->isDefault && !hasDefaultEntries() ) {
934 if ( item->type != User ) {
935 unsigned short v = findDefaultItemByType( User )->value;
936 new KACLListViewItem(
this, User, v,
true );
938 if ( item->type != Group ) {
939 unsigned short v = findDefaultItemByType( Group )->value;
940 new KACLListViewItem(
this, Group, v,
true );
942 if ( item->type != Others ) {
943 unsigned short v = findDefaultItemByType( Others )->value;
944 new KACLListViewItem(
this, Others, v,
true );
947 const KACLListViewItem *defaultMaskItem = findDefaultItemByType( Mask );
948 if ( item->isDefault && !defaultMaskItem ) {
949 unsigned short v = calculateMaskValue(
true );
950 new KACLListViewItem(
this, Mask, v,
true );
952 if ( !item->isDefault && !m_hasMask &&
953 ( item->type == Group
954 || item->type == NamedUser
955 || item->type == NamedGroup ) ) {
957 unsigned short v = calculateMaskValue(
false );
958 new KACLListViewItem(
this, Mask, v,
false );
962 calculateEffectiveRights();
964 setCurrentItem( item );
967 if ( childCount() == 1 )
968 emit currentChanged( item );
971 void KACLListView::slotEditEntry()
973 TQListViewItem * current = currentItem();
974 if ( !current )
return;
975 KACLListViewItem *item =
static_cast<KACLListViewItem*
>( current );
976 int allowedTypes = item->type | NamedUser | NamedGroup;
977 bool itemWasMask = item->type == Mask;
978 if ( !m_hasMask || itemWasMask )
979 allowedTypes |= Mask;
980 int allowedDefaultTypes = item->type | NamedUser | NamedGroup;
981 if ( !findDefaultItemByType( Mask ) )
982 allowedDefaultTypes |= Mask;
983 if ( !hasDefaultEntries() )
984 allowedDefaultTypes |= User | Group;
986 EditACLEntryDialog dlg(
this, item,
987 allowedUsers(
false, item ), allowedGroups(
false, item ),
988 allowedUsers(
true, item ), allowedGroups(
true, item ),
989 allowedTypes, allowedDefaultTypes, m_allowDefaults );
991 if ( itemWasMask && item->type != Mask ) {
995 if ( !itemWasMask && item->type == Mask ) {
996 m_mask = item->value;
999 calculateEffectiveRights();
1003 void KACLListView::slotRemoveEntry()
1005 TQListViewItemIterator it(
this, TQListViewItemIterator::Selected );
1006 while ( it.current() ) {
1007 KACLListViewItem *item =
static_cast<KACLListViewItem*
>( it.current() );
1012 if ( item->type == Mask ) {
1013 bool itemWasDefault = item->isDefault;
1014 if ( !itemWasDefault && maskCanBeDeleted() ) {
1018 }
else if ( itemWasDefault && defaultMaskCanBeDeleted() ) {
1024 if ( !itemWasDefault )
1025 calculateEffectiveRights();
1028 if ( !item->isDefault &&
1029 ( item->type == User
1030 || item->type == Group
1031 || item->type == Others ) ) {
1041 bool KACLListView::maskCanBeDeleted()
const
1043 return !findItemByType( NamedUser ) && !findItemByType( NamedGroup );
1046 bool KACLListView::defaultMaskCanBeDeleted()
const
1048 return !findDefaultItemByType( NamedUser ) && !findDefaultItemByType( NamedGroup );
1051 #include "kacleditwidget.moc"
1052 #include "kacleditwidget_p.moc"