diff options
author | Mael Dodin <mdodin@mandriva.org> | 2002-05-28 08:12:26 +0000 |
---|---|---|
committer | Mael Dodin <mdodin@mandriva.org> | 2002-05-28 08:12:26 +0000 |
commit | 96f0dedb1cce77dae4ab791dd7b875bfb2ca547b (patch) | |
tree | 91a0e752ac51b6e463b5eeb4fb780df66a2c13d1 /server_wizard.pl | |
parent | 91b42bc3d3416aea7f5ef49bad15ec45aa6f1063 (diff) | |
download | drakwizard-96f0dedb1cce77dae4ab791dd7b875bfb2ca547b.tar drakwizard-96f0dedb1cce77dae4ab791dd7b875bfb2ca547b.tar.gz drakwizard-96f0dedb1cce77dae4ab791dd7b875bfb2ca547b.tar.bz2 drakwizard-96f0dedb1cce77dae4ab791dd7b875bfb2ca547b.tar.xz drakwizard-96f0dedb1cce77dae4ab791dd7b875bfb2ca547b.zip |
-first commit
Diffstat (limited to 'server_wizard.pl')
-rw-r--r-- | server_wizard.pl | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/server_wizard.pl b/server_wizard.pl new file mode 100644 index 00000000..a0cf2c1d --- /dev/null +++ b/server_wizard.pl @@ -0,0 +1,124 @@ +#!/usr/bin/perl +# +# +# +# Copyright (c) 2002 ... +# + +use lib qw(/usr/lib/libDrakX); +use strict; +use vars qw($wizard_title $lib_script %variable $in); + +use XML::Parser; + +use standalone; +use interactive; + +sub member { my $e = shift; foreach (@_) { $e eq $_ and return 1 } 0 } + +sub get_parameter { + my ($tree, $tag) = @_; + my $page; + foreach my $leaf (@$tree) { + if (ref($leaf) eq 'ARRAY') { + get_parameter($leaf, $tag); + } elsif (ref($leaf) eq 'HASH') { + my $common_freetext_chooser; + my %actions = (Wizard => sub { + ($wizard_title, $lib_script) = @{$leaf}{qw(wizardTitle libScript)}; + }, + Variable => sub { + $variable{$leaf->{name}} = $leaf->{shellVariable}; + $ENV{$leaf->{shellVariable}} = $leaf->{defaultValue}; + }, + Page => sub { + my $old_page = $page; + $page = { %$leaf }; + $old_page->{next_page} = $page; + }, + Target => sub { + $page->{$leaf->{jumpIndex} > 3 ? 'targetOK' : 'targetNOK'} = $leaf->{targetName}; + }, + Info => sub { + $page->{info} = $leaf->{helpText} ? "$page->{info} $leaf->{helpText}" : "$page->{info}\n"; + }, + Freetext => $common_freetext_chooser = sub { + push @{$page->{freetext}}, { %$leaf, main_order => ($tag eq 'Chooser') ? 'combo' : 'entry' }; + }, + Chooser => \&$common_freetext_chooser); + $actions{$tag} and &{$actions{$tag}}; + undef $tag; + } else { + $tag = $leaf; + } + } +} + + +sub find_page { + my ($o, $name) = @_; + $_->{name} eq $name and return $_ foreach @$o; +} + +sub display { + my ($o, $page) = @_; + + if (member($page->{name}, qw(error_need_root done))) { + $in->ask_okcancel(translate($page->{name}), + translate($page->{info}), 1) or quit_global($in, 0); + exit 0; + } elsif (!$page->{main_order}) { + $in->ask_okcancel(translate($page->{name}), + translate($page->{info}), 1) or navigation($o, $page->{old_page}); + } else { + my @data = map { + for ($_->{fillScript}) { + m,^\s*echo|/, and system("source $lib_script ; $_"); + /^(\S*) (.*)$/ and system("source $lib_script ; $1($2)"); + } + { label => translate($_->{helpText}), + val => \$ENV{$variable{$_->{variableName}}}, type => $_->{main_order} }; + } @{$page->{freetext}}; + + $in->ask_from(translate($page->{name}), translate($page->{info}), \@data) + or navigation($o, $page->{old_page}); + } + undef $::Wizard_no_previous; +} + +sub navigation { + my ($o, $page, $previous_page) = @_; + $page->{old_page} ||= $previous_page; + if ($page->{jumpPage}) { + navigation($o, $page->{jumpPage}, $page->{old_page}); + } else { + display($o, $page); + + my ($next, $prev) = do { + if($page->{jumpScript}) { + system("source $lib_script ; $page->{jumpScript}"); + if ($page->{targetOK} && $page->{targetNOK}) { + find_name($o, $? == 256 ? $page->{targetNOK} : $page->{targetOK}), $page; + } else { + $page->{next_page}, $page->{old_page}; + } + } else { + $page->{next_page}, $page; + } + }; + navigation($o, $next, $prev); + } +} + +my $o = {}; +get_parameter($o, XML::Parser->new(Style => 'Tree')->parsefile("server.wiz")); + +$in = 'interactive'->vnew; + +!$::isEmbedded && $in->isa('interactive_gtk') and $::isWizard=1; +$::Wizard_title = translate($wizard_title); +$::Wizard_pix_up = "wiz_draknet.png"; +$::direct = /-direct/; +$::Wizard_no_previous = 1; + +navigation($o, $o->[0]{name}); |