Widgets/LdapTreeSelector.pm

filter: Statementstmt 88.8% 16 / 18 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 91.6% 22 / 24 CC 1 SCAR 0.5
CC
1
Cov
89%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Widgets.pm ↑ Summary Widgets/LdapTreeView.pm »
1 # by OLO
2 # czw mar 17 14:10:53 CET 2005
3 # LdapTreeSelector: wielokrotna selekca elementow z drzewa LDAP
4  
5 package Gtk2::Net::LDAP::Widgets::LdapTreeSelector;
6 #---[ pod head ]---{{{
7  
8 =head1 NAME
9  
10 Gtk2::Net::LDAP::Widgets::LdapTreeSelector - LDAP entry tree selection window
11  
12 =head1 SYNOPSIS
13  
14 use Gtk2::Net::LDAP::Widgets;
15  
16 my $entryPopup = Gtk2::Net::LDAP::Widgets::LdapTreeSelector->new ($parent_window,
17 $ldap_source,
18 'o=People,dc=example,dc=com',
19 '(|(objectClass=inetorgperson)(objectClass=organization))',
20 'interactive_filter_type' => 'none',
21 'single_selection' => 1
22 );
23 # expand entries below top-level tree entry:
24 $entryPopup->{ldapTreeView}->expand_row(Gtk2::TreePath->new_from_string('0'), 0);
25 $entryPopup->signal_connect (response => sub {
26 my ($popup, $response) = @_;
27 if($response =~ 'accept') {
28 print "Selected entry DN: ".$entryPopup->get_dn;
29 }
30 $_[0]->destroy;
31 });
32 $entryPopup->show_all;
33  
34 =head1 ABSTRACT
35  
36 Gtk2::Net::LDAP::Widgets::LdapTreeSelector is a child class to L<Gtk2::Dialog>
37 and is used to create a Gtk2 dialog which lets the user select LDAP entry/entries
38 displayed in a tree-like structure.
39  
40 The dialog may be equipped with a search/filter box, although there might be
41 problems with displaying search results when an interactive filter is set since
42 there may be problems building the tree if all ancestors for an entry aren't
43 included in the search result.
44  
45 So it's advised to use this component without displaying a search/filter box
46 ('interactive_filter_type' => 'none').
47  
48 =cut
49  
50 #---}}}
51 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
52 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
53 1 ▶use vars qw(@ISA $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
54  
55 1 ▶use Net::LDAP;
Subroutine BEGIN: called CC=1 SCAR=0.0
56 1 ▶use Net::LDAP::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
57 0 ▶use Gtk2 -init;
Subroutine BEGIN: called CC=1 SCAR=2.6
58 use Data::Dumper;
59 use Gtk2::Net::LDAP::Widgets::DistinguishedName;
60  
61 @ISA = qw(Gtk2::Dialog);
62  
63 our $VERSION = "2.0.1";
64  
65  
66 use overload
67 q{""} => 'to_string';
68  
69 # determine the filter (internal utility method)
70 sub _get_filter {
71 my $self = shift;
72 if ($self->{interactive_filter_type} eq 'ldap') {
73 return($self->{entryInteractiveFilter}->get_text);
74 } elsif ($self->{interactive_filter_type} eq 'none') {
75 return('');
76 } elsif ($self->{interactive_filter_type} eq 'simple') {
77 return('cn=*'.$self->{entryInteractiveFilter}->get_text.'*');
78 }
79 return('');
80 }
81  
82 #---[ sub new ]---{{{
83  
84 =head1 CONSTRUCTOR
85  
86 =over 4
87  
88 =item new ( parent, ldap_source, base_dn, static_filter, named parameters )
89  
90 Creates a new Gtk2::Net::LDAP::Widgets::LdapTreeSelector object.
91  
92 C<parent> the L<Gtk2::Window> which will be parent of this L<Gtk2::Dialog>
93  
94 C<ldap_source> the L<Net::LDAP> object which is an active connection to an LDAP server
95  
96 C<base_dn> the base DN of LDAP search operations
97  
98 C<static_filter> the static filter that will be logically AND-ed with all filters executed by this selector
99  
100 =back
101  
102 =head2 named parameters
103  
104 =over 4
105  
106 =item init_interactive_filter =E<gt> 'some ldap filter'
107  
108 The string to be initially put in the filter box
109  
110 =item single_selection =E<gt> 0 | 1
111  
112 Whether to use single selection mode (otherwise multiple selection is posible)
113  
114  
115 =item interactive_filter_type =E<gt> 'ldap' | 'simple' | 'none'
116  
117 The type of filter box: 'ldap' supports full LDAP filter syntax, 'simple' does a substring search against the "cn" attribute, 'none' disables the search/filter box.
118  
119 =back
120  
121 =cut
122 sub new {
123 my $class = shift;
124 my $self = $class->SUPER::new('Wybierz wpis(y) LDAP', shift, 'destroy-with-parent',
125 'gtk-ok' => 'accept', 'gtk-cancel' => 'reject');
126 $self->set_modal(1);
127 $self->{ldap_source} = shift;
128 $self->{base_dn} = shift;
129 $self->{static_filter} = shift;
130  
131 my %named_params = @_;
132 $self->{init_interactive_filter} = $named_params{'init_interactive_filter'};
133 $self->{single_selection} = $named_params{'single_selection'};
134 $self->{interactive_filter_type} = $named_params{'interactive_filter_type'};
135 # possible values: 'ldap', 'simple', 'none':
136 if (! $self->{interactive_filter_type}) {
137 $self->{interactive_filter_type} = 'ldap';
138 }
139  
140 my $btnFiltruj = Gtk2::Button->new_with_mnemonic ('_Filtruj');
141 if ($self->{interactive_filter_type} ne 'none') {
142 # The filter horizontal box:
143 my $hboxFilter = Gtk2::HBox->new;
144 my $labelFilter = Gtk2::Label->new;
145 if ($self->{interactive_filter_type} eq 'ldap') {
146 $labelFilter->set_markup("Wpisz <b>filtr LDAP</b>:");
147 } elsif ($self->{interactive_filter_type} eq 'simple') {
148 $labelFilter->set_markup("Wyszukaj:");
149 } else {
150 $labelFilter->set_markup("Wpisz <b>filtr</b>:");
151 }
152 $hboxFilter->pack_start ($labelFilter, 0, 0, 5);
153 my $entryInteractiveFilter = Gtk2::Entry->new;
154 $entryInteractiveFilter->set_text($self->{init_interactive_filter});
155 $hboxFilter->pack_start ($entryInteractiveFilter, 1, 1, 5);
156  
157 $hboxFilter->pack_start ($btnFiltruj, 1, 1, 5);
158  
159 $self->{entryInteractiveFilter} = $entryInteractiveFilter;
160 $self->vbox->pack_start ($hboxFilter, 0, 0, 5);
161 }
162  
163 # Results list component:
164 bless $self, $class;
165 $self->{ldapTreeView} = Gtk2::Net::LDAP::Widgets::LdapTreeView->new($self->{ldap_source}, $self->{base_dn}, $self->{static_filter},
166 $self->_get_filter, $self->{single_selection});
167
168 my $scrollwin = Gtk2::ScrolledWindow->new;
169 $scrollwin->set_policy ('never', 'automatic');
170 $scrollwin->set_shadow_type ('in');
171 $scrollwin->add($self->{ldapTreeView});
172 $self->vbox->pack_start ($scrollwin, 1, 1, 5);
173  
174 $self->set_default_size(640, 480);
175  
176 $btnFiltruj->signal_connect (clicked => sub {
177 $self->refresh_list;
178 });
179  
180 bless $self, $class;
181  
182 }
183 #---}}}
184  
185 # by OLO
186 # czw mar 17 17:51:20 CET 2005
187 # Conversion of self to string:
188 sub to_string {
189 my $self = shift;
190 return $self->{class}.' "'.\$self.'"';
191 }
192  
193 #---[ sub refresh_list ]---{{{
194 =head2 refresh_list
195  
196 Refresh the entries list - re-execute the search with the filter determined by
197 the search/filter box.
198  
199 =cut
200 sub refresh_list {
201 my $self = shift;
202 my $newfilter = $self->_get_filter;
203 #print "LdapTreeSelector nowy filtr: $newfilter\n";
204 $self->{listEntriesView}->set_interactive_filter($newfilter);
205 }
206 #---}}}
207  
208 #---[ sub get_dn ]---{{{
209  
210 =head2 get_dn
211  
212 Return the list of selected entries' Distinguished Names.
213  
214 The list has at most one entry if single_selection is set to 1.
215  
216 =cut
217 sub get_dn {
218 my $self = shift;
219 return $self->{ldapTreeView}->get_dn;
220 }
221 #---}}}
222  
223 1;
224  
225 __END__
« Widgets.pm ↑ Summary Widgets/LdapTreeView.pm »