Gtk2-Net-LDAP-Widgets

 view release on metacpan or  search on metacpan

Widgets/LdapTreeView.pm  view on Meta::CPAN

  my $prev_dn = undef;
  my $child; 
  my $entry;
  my @ancestors_stack = ();
  my %dn_iters;
  #push @parents, $toplevel;
  foreach $entry (@entries) {
    my $dn = Gtk2::Net::LDAP::Widgets::DistinguishedName->new($entry->dn);
    my $rdn;
    my $parent = $ancestors_stack[$#ancestors_stack];
    if (defined($prev_dn) && $dn->isDescendant($prev_dn)) {
      # it's a child of the previous dn
      # print "$dn is a child of $prev_dn\n";
      # TODO: assert length($entry->dn) =okolo (rindex($entry->dn, $prev_dn) + length($prev_dn))
      # TODO: push the previous DN onto a stack

      # Push the parent to stack:
      push(@ancestors_stack, $prev_dn);
      $parent = $ancestors_stack[$#ancestors_stack];
      
    } else {
      # it might not be a descendant of the parent anymore. Search for the youngest ancestor:
      while(scalar(@ancestors_stack)) {
        $parent = pop(@ancestors_stack);
        if ($dn->isDescendant($parent)) {
          push(@ancestors_stack, $parent);
          last;
        }
      }
      #$rdn = $dn->getRdn($parent);
    }
    # determine the RDN:
    $rdn = $dn->getRdn($parent);
    #print " ...so its RDN is $rdn\n";
    #print "number of components:".$dn->getLength."\n";

    # Determine the Iter-a of the super element in the tree model (if there's 
		# no parent, then iter is undefined and tree's top level is created):
    my $iter = undef;
    if (defined($parent)) {
      $iter = $dn_iters{$parent->{dn}};
    }

    $child = $tree_model->append($iter);

    $tree_model->set($child,
        0 => $rdn,
        1 => 0,
        2 => ($dn->{dntext})
        );
    $dn_iters{$dn->{dn}} = $child;
    $prev_dn = $dn;
  }

  $self->set_model($tree_model);

}
#---}}}

# by OLO
# czw mar 17 17:51:20 CET 2005
# Conversion of self to string:
sub to_string {
  my $self  = shift;
  return $self->{class}.' "'.\$self.'"';
}

#---[ sub get_dn ]---{{{

=head2 get_dn

Return the list of selected entries' Distinguished Names.

The list has at most one entry if single_selection is set to 1.

=cut
sub get_dn {
  my $self  = shift;
  my @dn_list;
  
  if ($self->{single_selection}) {
    push @dn_list, $self->{selectedDN};
  } else {
    my $model = $self->get_model;
    $model->foreach( sub {
      my $model = shift;
      my $path = shift;
      my $iter = shift;
      if ($model->get ($iter, $bool_column) > 0) {
        # The entry is selected:
        push(@dn_list, $model->get ($iter, $dn_column));
      }
      return 0;
    });
  }
  
  #print "Selected:\n";
  #print Dumper(\@dn_list);
  #print "\n";
  return @dn_list;
}
#---}}}

#---[ sub set_dn ]---{{{

=head2 set_dn

=over 4

=item set_dn( dn_list )

Sets the state of entries specified by DNs in dn_list to "selected" and unselects all other entries.

C<dn_list> list of Distinguished Names of entries to select

=back

=cut
sub set_dn(@) {
  my $self  = shift;
  my @dn_list = @_;



( run in 0.874 second using v1.01-cache-2.11-cpan-39bf76dae61 )