line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Gtk2::Net::LDAP::Widgets::LdapEntryView; |
2
|
|
|
|
|
|
|
#---[ pod head ]---{{{ |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 NAME |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
Gtk2::Net::LDAP::Widgets::LdapEntryView - LDAP entry viewport |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 SYNOPSIS |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
This component is mostly used by other components and isn't meant to be |
11
|
|
|
|
|
|
|
used directly. Read the source in case of any needs to do that. |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=cut |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
#---}}} |
16
|
1
|
|
|
1
|
|
33405
|
use utf8; |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
4
|
|
17
|
1
|
|
|
1
|
|
34
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
43
|
|
18
|
1
|
|
|
1
|
|
6
|
use vars qw(@ISA $VERSION); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
64
|
|
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
1
|
|
6
|
use Carp qw(cluck); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
74
|
|
21
|
1
|
|
|
1
|
|
1592
|
use Net::LDAP; |
|
1
|
|
|
|
|
219865
|
|
|
1
|
|
|
|
|
9
|
|
22
|
1
|
|
|
1
|
|
3824
|
use Net::LDAP::Util; |
|
1
|
|
|
|
|
69
|
|
|
1
|
|
|
|
|
65
|
|
23
|
1
|
|
|
1
|
|
485
|
use Gtk2 -init; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
use Data::Dumper; |
25
|
|
|
|
|
|
|
use Gtk2::Net::LDAP::Widgets::Util; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
@ISA = qw(Gtk2::TreeView); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
our $VERSION = "2.0.1"; |
30
|
|
|
|
|
|
|
our $dn_column = 0; |
31
|
|
|
|
|
|
|
our $bool_column = 1; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
use overload |
35
|
|
|
|
|
|
|
q{""} => 'to_string'; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# by OLO |
38
|
|
|
|
|
|
|
# czw mar 17 17:51:34 CET 2005 |
39
|
|
|
|
|
|
|
# Constructor: |
40
|
|
|
|
|
|
|
sub new { |
41
|
|
|
|
|
|
|
my $class = shift; |
42
|
|
|
|
|
|
|
my $self = $class->SUPER::new; |
43
|
|
|
|
|
|
|
$self->{ldap_source} = shift; |
44
|
|
|
|
|
|
|
$self->{base_dn} = shift; |
45
|
|
|
|
|
|
|
$self->{static_filter} = shift; |
46
|
|
|
|
|
|
|
$self->{interactive_filter} = shift; |
47
|
|
|
|
|
|
|
$self->{single_selection} = shift; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
$self->{selectedDN} = undef; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
### |
52
|
|
|
|
|
|
|
# 1st column |
53
|
|
|
|
|
|
|
my $renderer = Gtk2::CellRendererText->new; |
54
|
|
|
|
|
|
|
my $col_offset = $self->insert_column_with_attributes |
55
|
|
|
|
|
|
|
(-1, "DN", $renderer, |
56
|
|
|
|
|
|
|
text => 0); |
57
|
|
|
|
|
|
|
my $column = $self->get_column ($col_offset - 1); |
58
|
|
|
|
|
|
|
$column->set_clickable (1); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
### |
61
|
|
|
|
|
|
|
# 2nd column |
62
|
|
|
|
|
|
|
$renderer = Gtk2::CellRendererToggle->new; |
63
|
|
|
|
|
|
|
$renderer->set (xalign => 0.0); |
64
|
|
|
|
|
|
|
$renderer->set_data (column => 1); |
65
|
|
|
|
|
|
|
if ($self->{single_selection}) { |
66
|
|
|
|
|
|
|
$renderer->set_radio (1); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
$renderer->signal_connect (toggled => \&LdapEntryView_item_toggled, $self); |
69
|
|
|
|
|
|
|
$col_offset = $self->insert_column_with_attributes |
70
|
|
|
|
|
|
|
(-1, "Y/N", $renderer, |
71
|
|
|
|
|
|
|
active => 1 |
72
|
|
|
|
|
|
|
); |
73
|
|
|
|
|
|
|
$column = $self->get_column ($col_offset - 1); |
74
|
|
|
|
|
|
|
$column->set_clickable (1); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
bless $self, $class; |
77
|
|
|
|
|
|
|
$self->refresh_model; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
bless $self, $class; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# by OLO |
83
|
|
|
|
|
|
|
# czw mar 17 17:51:20 CET 2005 |
84
|
|
|
|
|
|
|
# Conversion of self to string: |
85
|
|
|
|
|
|
|
sub to_string { |
86
|
|
|
|
|
|
|
my $self = shift; |
87
|
|
|
|
|
|
|
return $self->{class}.' "'.\$self.'"'; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# by OLO |
91
|
|
|
|
|
|
|
# wto kwi 19 12:15:31 CEST 2005 |
92
|
|
|
|
|
|
|
# Returns the list of selected entries' Distinguished Names. |
93
|
|
|
|
|
|
|
sub get_dn { |
94
|
|
|
|
|
|
|
my $self = shift; |
95
|
|
|
|
|
|
|
my @dn_list; |
96
|
|
|
|
|
|
|
if ($self->{single_selection}) { |
97
|
|
|
|
|
|
|
push @dn_list, $self->{selectedDN}; |
98
|
|
|
|
|
|
|
} else { |
99
|
|
|
|
|
|
|
#TODO: multiple |
100
|
|
|
|
|
|
|
my $model = $self->get_model; |
101
|
|
|
|
|
|
|
$model->foreach( sub { |
102
|
|
|
|
|
|
|
my $model = shift; |
103
|
|
|
|
|
|
|
my $path = shift; |
104
|
|
|
|
|
|
|
my $iter = shift; |
105
|
|
|
|
|
|
|
if ($model->get ($iter, $bool_column) > 0) { |
106
|
|
|
|
|
|
|
# Wpis jest zaznaczony: |
107
|
|
|
|
|
|
|
push(@dn_list, $model->get ($iter, $dn_column)); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
return 0; |
110
|
|
|
|
|
|
|
}); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
#print "Selected:\n"; |
114
|
|
|
|
|
|
|
#print Dumper(\@dn_list); |
115
|
|
|
|
|
|
|
#print "\n"; |
116
|
|
|
|
|
|
|
return @dn_list; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub LdapEntryView_item_toggled { |
120
|
|
|
|
|
|
|
my ($cell, $path_str, $self) = @_; |
121
|
|
|
|
|
|
|
my $model = $self->get_model; |
122
|
|
|
|
|
|
|
my $path = Gtk2::TreePath->new_from_string ($path_str); |
123
|
|
|
|
|
|
|
my $column = $cell->get_data ("column"); |
124
|
|
|
|
|
|
|
# get toggled iter |
125
|
|
|
|
|
|
|
my $iter = $model->get_iter ($path); |
126
|
|
|
|
|
|
|
#print Dumper($iter); |
127
|
|
|
|
|
|
|
my ($toggle_item) = $model->get ($iter, $column); |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# do something with the value |
130
|
|
|
|
|
|
|
my $selectedDN = $model->get($iter, $dn_column); |
131
|
|
|
|
|
|
|
#print "val: ".$model->get($iter, $column)."\n"; |
132
|
|
|
|
|
|
|
#print "toggle_item before: $toggle_item\n"; |
133
|
|
|
|
|
|
|
#$toggle_item ^= 1; |
134
|
|
|
|
|
|
|
#print "toggle_item after: $toggle_item\n"; |
135
|
|
|
|
|
|
|
#$model->set ($iter, $column, $toggle_item); |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
# set new value |
138
|
|
|
|
|
|
|
if ($self->{single_selection}) { |
139
|
|
|
|
|
|
|
$model->foreach( sub { my $model = shift; my $path = shift; my $iter = shift; $model->set ($iter, $column, 0); return 0; } ); |
140
|
|
|
|
|
|
|
$model->set ($iter, $column, 1); |
141
|
|
|
|
|
|
|
$self->{selectedDN} = $selectedDN; |
142
|
|
|
|
|
|
|
} else { |
143
|
|
|
|
|
|
|
$toggle_item ^= 1; |
144
|
|
|
|
|
|
|
$model->set ($iter, $column, $toggle_item); |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
# by OLO |
150
|
|
|
|
|
|
|
# wto kwi 19 13:19:38 CEST 2005 |
151
|
|
|
|
|
|
|
# Changes the interactive filter and refreshes data model |
152
|
|
|
|
|
|
|
sub set_interactive_filter($) { |
153
|
|
|
|
|
|
|
my $self = shift; |
154
|
|
|
|
|
|
|
$self->{interactive_filter} = shift; |
155
|
|
|
|
|
|
|
$self->refresh_model; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub refresh_model { |
159
|
|
|
|
|
|
|
my $self = shift; |
160
|
|
|
|
|
|
|
my $static_filter = $self->{static_filter}; |
161
|
|
|
|
|
|
|
my $interactive_filter = $self->{interactive_filter}; |
162
|
|
|
|
|
|
|
# Remove superfluous pairs of parentheses: |
163
|
|
|
|
|
|
|
$interactive_filter = filter_trim_outer_parens($interactive_filter); |
164
|
|
|
|
|
|
|
$static_filter = filter_trim_outer_parens($static_filter); |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
my $compositeFilter; |
167
|
|
|
|
|
|
|
if (length($interactive_filter) > 3) { |
168
|
|
|
|
|
|
|
$compositeFilter = '(&('.$static_filter.')('.$interactive_filter.'))'; |
169
|
|
|
|
|
|
|
} else { |
170
|
|
|
|
|
|
|
$compositeFilter = '('.$static_filter.')'; |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
#print "LdapTreeView composite filter: $compositeFilter\n"; |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
my $result = $self->{ldap_source}->search(filter => $compositeFilter, base => $self->{base_dn}, attrs => ['dn']); |
175
|
|
|
|
|
|
|
my @entries = $result->sorted; |
176
|
|
|
|
|
|
|
my $newModel = Gtk2::ListStore->new (qw/Glib::String Glib::Boolean/); |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
foreach my $entry (@entries) { |
179
|
|
|
|
|
|
|
#print "Entry: ".$entry->dn."\n"; |
180
|
|
|
|
|
|
|
my $value = $newModel->set ($newModel->append, $dn_column => $entry->dn, $bool_column => 0); |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
$self->set_model($newModel); |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
1; |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
__END__ |