diff options
Diffstat (limited to 'perl-install/wizards.pm')
| -rw-r--r-- | perl-install/wizards.pm | 67 |
1 files changed, 37 insertions, 30 deletions
diff --git a/perl-install/wizards.pm b/perl-install/wizards.pm index 9fdc33a1e..b1c9c4516 100644 --- a/perl-install/wizards.pm +++ b/perl-install/wizards.pm @@ -1,22 +1,20 @@ package wizards; -# $Id$ use strict; use c; use common; +# perl_checker: require interactive =head1 NAME -wizards - a layer on top of interactive that ensure proper stepping +wizards - a layer on top of L<interactive> that ensure proper stepping =head1 SYNOPSIS - use wizards - # global wizard options: - use wizards; use interactive; - my $wiz = { + + my $wiz = wizards->new({ allow_user => "", # do we need root defaultimage => "", # wizard icon @@ -31,6 +29,7 @@ wizards - a layer on top of interactive that ensure proper stepping post => sub { }, # code executing when stepping forward; # returned value is next step name (it overrides "next" field) end => , # is it the last step ? + default => , # default answer for yes/no or when data does not conatains any fields no_cancel => , # do not display the cancel button (eg for first step) no_back => , # do not display the back button (eg for first step) ignore => , # do not stack this step for back stepping (eg for warnings and the like steps) @@ -43,7 +42,7 @@ wizards - a layer on top of interactive that ensure proper stepping { # usual interactive fields: label => N("Banner:"), - val => \$o->{var}{wiz_banner} + val => \$o->{var}{wiz_banner}, list => [] , # wizard layer variables: boolean_list => "", # provide default status for booleans list @@ -51,10 +50,9 @@ wizards - a layer on top of interactive that ensure proper stepping ], }, }, - }; - - my $w => wizards->new - $w->process($wiz, $in); + }); + my $in = 'interactive'->vnew; + $wiz->process($in); =head1 DESCRIPTION @@ -84,14 +82,17 @@ extra exception managment such as destroying the wizard window and the like. =cut -sub new { bless {}, $_[0] } +sub new { + my ($class, $o) = @_; + bless $o, $class; +} sub check_rpm { - my ($in, $rpms) = @_; + my ($in, $rpms) = @_; # perl_checker: $in = interactive->new foreach my $rpm (@$rpms) { - next if !$in->do_pkgs->is_installed($rpm); - if ($in->ask_okcancel(N("Error"), N("%s is not installed\nClick \"Next\" to install or \"Cancel\" to quit", c::from_utf8($rpm)))) { + next if $in->do_pkgs->is_installed($rpm); + if ($in->ask_okcancel(N("Error"), N("%s is not installed\nClick \"Next\" to install or \"Cancel\" to quit", $rpm))) { $::testing and next; if (!$in->do_pkgs->install($rpm)) { local $::Wizard_finished = 1; @@ -104,11 +105,11 @@ sub check_rpm { # sync me with interactive::ask_from_normalize() if needed: -my %default_callback = (changed => sub {}, focus_out => sub {}, complete => sub { 0 }, canceled => sub { 0 }, advanced => sub {}); +my %default_callback = (complete => sub { 0 }); sub process { - my ($_w, $o, $in) = @_; + my ($o, $in) = @_; local $::isWizard = 1; local $::Wizard_title = $o->{name} || $::Wizard_title; local $::Wizard_pix_up = $o->{defaultimage} || $::Wizard_pix_up; @@ -118,7 +119,7 @@ sub process { my ($res, $msg) = &{$o->{init}}; if (!$res) { $in->ask_okcancel(N("Error"), $msg); - die "wizard failled" if !$::testing + die "wizard failed" if !$::testing; } } @@ -135,7 +136,7 @@ sub process { die qq(inexistant "$next" wizard step) if is_empty_hash_ref($page); # FIXME or the displaying fails - my $data = defined $page->{data} ? (ref($page->{data}) eq 'CODE' ? $page->{data}->() : $page->{data}) : [ { label => '' } ]; + my $data = defined $page->{data} ? (ref($page->{data}) eq 'CODE' ? $page->{data}->() : $page->{data}) : []; my $data2; foreach my $d (@$data) { $d->{val} = ${$d->{val_ref}} if $d->{val_ref}; @@ -145,28 +146,34 @@ sub process { my $i; foreach (@{$d->{boolean_list}}) { push @$data2, { text => $_, type => 'bool', val => \${$d->{val}}->[$i], disabled => $d->{disabled} }; - $i++ + $i++; } } else { - push @$data2, $d + push @$data2, $d; } } my $name = ref($page->{name}) ? $page->{name}->() : $page->{name}; my %yesno = (yes => N("Yes"), no => N("No")); - my $yes; - $data2 = [ { val => \$yes, type => 'list', list => [ values %yesno ], gtk => { use_boxradio => 1 } } ] if $page->{type} eq "yesorno"; - my $a = $in->ask_from_({ title => $o->{name}, + my $yes = ref($page->{default}) eq 'CODE' ? $page->{default}->() : $page->{default}; + $data2 = [ { val => \$yes, type => 'list', list => [ keys %yesno ], format => sub { $yesno{$_[0]} }, + gtk => { use_boxradio => 1 } } ] if $page->{type} eq "yesorno"; + my $a; + if (ref $data2 eq 'ARRAY' && @$data2) { + $a = $in->ask_from_({ title => $o->{name}, messages => $name, - callbacks => { map { $_ => $page->{$_} || $default_callback{$_} } qw(focus_out complete) }, + (map { $_ => $page->{$_} || $default_callback{$_} } qw(complete)), if_($page->{interactive_help_id}, interactive_help_id => $page->{interactive_help_id}), }, $data2); + } else { + $a = $in->ask_okcancel($o->{name}, $name, $yes || 'ok'); + } # interactive->ask_yesorno does not support stepping forward or backward: $a = $yes if $a && $page->{type} eq "yesorno"; if ($a) { # step forward: push @steps, $next if !$page->{ignore} && $steps[-1] ne $next; my $current = $next; - $next = defined $page->{post} ? $page->{post}($page->{type} eq "yesorno" ? $yes eq $yesno{yes} : $a) : 0; + $next = defined $page->{post} ? $page->{post}($page->{type} eq "yesorno" ? $yes eq 'yes' : $a) : 0; return if $page->{end}; if (!$next) { if (!defined $o->{pages}{$next}) { @@ -178,16 +185,16 @@ sub process { die qq(Step "$current": inexistant "$next" page) if !exists $o->{pages}{$next}; } else { # step back: - $next = pop @steps + $next = pop @steps; } - $page = $o->{pages}{$next} + $page = $o->{pages}{$next}; } } sub safe_process { - my ($w, $wiz, $in) = @_; - eval { $w->process($wiz, $in) }; + my ($o, $in) = @_; + eval { $o->process($in) }; my $err = $@; if ($err =~ /wizcancel/) { $in->exit(0); |
