| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
=head1 NAME |
| 4 |
|
| 5 |
Debconf::Element::Multiselect - Base multiselect input element |
| 6 |
|
| 7 |
=cut |
| 8 |
|
| 9 |
package Debconf::Element::Multiselect; |
| 10 |
use warnings; |
| 11 |
use strict; |
| 12 |
use base qw(Debconf::Element::Select); |
| 13 |
|
| 14 |
=head1 DESCRIPTION |
| 15 |
|
| 16 |
This is a base Multiselect input element. It inherits from the base Select |
| 17 |
input element. |
| 18 |
|
| 19 |
=head1 METHODS |
| 20 |
|
| 21 |
=item order_values |
| 22 |
|
| 23 |
Given a set of values, reorders then to be in the same order as the choices |
| 24 |
field of the question's template, and returns them. |
| 25 |
|
| 26 |
=cut |
| 27 |
|
| 28 |
sub order_values { |
| 29 |
my $this=shift; |
| 30 |
my %vals=map { $_ => 1 } @_; |
| 31 |
# Make sure that the choices are in the C locale, like the values |
| 32 |
# are. |
| 33 |
$this->question->template->i18n(''); |
| 34 |
my @ret=grep { $vals{$_} } $this->question->choices_split; |
| 35 |
$this->question->template->i18n(1); |
| 36 |
return @ret; |
| 37 |
} |
| 38 |
|
| 39 |
=item show |
| 40 |
|
| 41 |
Unlike select lists, multiselect questions are visible if there is just one |
| 42 |
choice. |
| 43 |
|
| 44 |
=cut |
| 45 |
|
| 46 |
sub visible { |
| 47 |
my $this=shift; |
| 48 |
|
| 49 |
my @choices=$this->question->choices_split; |
| 50 |
return ($#choices >= 0); |
| 51 |
} |
| 52 |
|
| 53 |
=item translate_default |
| 54 |
|
| 55 |
This method returns default value(s), in the user's language, suitable for |
| 56 |
displaying to the user. Defaults are stored internally in the C locale; |
| 57 |
this method does any necessary translation to the current locale. |
| 58 |
|
| 59 |
=cut |
| 60 |
|
| 61 |
sub translate_default { |
| 62 |
my $this=shift; |
| 63 |
|
| 64 |
# I need both the translated and the non-translated choices. |
| 65 |
my @choices=$this->question->choices_split; |
| 66 |
$this->question->template->i18n(''); |
| 67 |
my @choices_c=$this->question->choices_split; |
| 68 |
$this->question->template->i18n(1); |
| 69 |
|
| 70 |
my @ret; |
| 71 |
# Translate each default. |
| 72 |
foreach my $c_default ($this->question->value_split) { |
| 73 |
foreach (my $x=0; $x <= $#choices; $x++) { |
| 74 |
push @ret, $choices[$x] |
| 75 |
if $choices_c[$x] eq $c_default; |
| 76 |
} |
| 77 |
} |
| 78 |
return @ret; |
| 79 |
} |
| 80 |
|
| 81 |
=back |
| 82 |
|
| 83 |
=head1 AUTHOR |
| 84 |
|
| 85 |
Joey Hess <[email protected]> |
| 86 |
|
| 87 |
=cut |
| 88 |
|
| 89 |
1 |