Gtk2-Net-LDAP-Widgets

 view release on metacpan or  search on metacpan

Widgets/LdapTreeSelector.pm  view on Meta::CPAN

# by OLO
# czw mar 17 14:10:53 CET 2005
# LdapTreeSelector: wielokrotna selekca elementow z drzewa LDAP

package Gtk2::Net::LDAP::Widgets::LdapTreeSelector;
#---[ pod head ]---{{{

=head1 NAME

Gtk2::Net::LDAP::Widgets::LdapTreeSelector - LDAP entry tree selection window

=head1 SYNOPSIS

    use Gtk2::Net::LDAP::Widgets;

    my $entryPopup = Gtk2::Net::LDAP::Widgets::LdapTreeSelector->new ($parent_window,
      $ldap_source,
      'o=People,dc=example,dc=com',
      '(|(objectClass=inetorgperson)(objectClass=organization))',
      'interactive_filter_type' => 'none',
      'single_selection' => 1
    );
    # expand entries below top-level tree entry:
    $entryPopup->{ldapTreeView}->expand_row(Gtk2::TreePath->new_from_string('0'), 0);
    $entryPopup->signal_connect (response => sub {
      my ($popup, $response) = @_;
      if($response =~ 'accept') {
        print "Selected entry DN: ".$entryPopup->get_dn;
      }
      $_[0]->destroy;
    });
    $entryPopup->show_all;

=head1 ABSTRACT

Gtk2::Net::LDAP::Widgets::LdapTreeSelector is a child class to L<Gtk2::Dialog> 
and is used to create a Gtk2 dialog which lets the user select LDAP entry/entries
displayed in a tree-like structure.

The dialog may be equipped with a search/filter box, although there might be 
problems with displaying search results when an interactive filter is set since 
there may be problems building the tree if all ancestors for an entry aren't 
included in the search result.

So it's advised to use this component without displaying a search/filter box 
('interactive_filter_type' => 'none').

=cut

#---}}}
use utf8;
use strict;
use vars qw(@ISA $VERSION);

use Net::LDAP;
use Net::LDAP::Util;
use Gtk2 -init;
use Data::Dumper;
use Gtk2::Net::LDAP::Widgets::DistinguishedName;

@ISA = qw(Gtk2::Dialog);

our $VERSION = "2.0.1";


use overload
q{""} => 'to_string';

# determine the filter (internal utility method)
sub _get_filter {
  my $self  = shift;
  if ($self->{interactive_filter_type} eq 'ldap') {
    return($self->{entryInteractiveFilter}->get_text);
  } elsif ($self->{interactive_filter_type} eq 'none') {
    return('');
  } elsif ($self->{interactive_filter_type} eq 'simple') {
    return('cn=*'.$self->{entryInteractiveFilter}->get_text.'*');
  }
  return('');
}

#---[ sub new ]---{{{

=head1 CONSTRUCTOR

=over 4



( run in 0.605 second using v1.01-cache-2.11-cpan-364913b4093 )