summaryrefslogtreecommitdiffstats
path: root/perl-install/interactive
diff options
context:
space:
mode:
Diffstat (limited to 'perl-install/interactive')
-rw-r--r--perl-install/interactive/gtk.pm773
-rw-r--r--perl-install/interactive/http.pm164
-rw-r--r--perl-install/interactive/newt.pm426
-rw-r--r--perl-install/interactive/stdio.pm180
4 files changed, 0 insertions, 1543 deletions
diff --git a/perl-install/interactive/gtk.pm b/perl-install/interactive/gtk.pm
deleted file mode 100644
index 871541697..000000000
--- a/perl-install/interactive/gtk.pm
+++ /dev/null
@@ -1,773 +0,0 @@
-package interactive::gtk; # $Id$
-
-use diagnostics;
-use strict;
-use vars qw(@ISA);
-
-@ISA = qw(interactive);
-
-use interactive;
-use common;
-use ugtk2 qw(:helpers :wrappers :create);
-use Gtk2::Gdk::Keysyms;
-
-my $forgetTime = 1000; #- in milli-seconds
-
-sub new {
- ($::windowwidth, $::windowheight) = gtkroot()->get_size if !$::isInstall;
- goto &interactive::new;
-}
-sub enter_console { my ($o) = @_; $o->{suspended} = common::setVirtual(1) }
-sub leave_console { my ($o) = @_; common::setVirtual(delete $o->{suspended}) }
-
-sub exit { ugtk2::exit(@_) }
-
-sub ask_fileW {
- my ($_o, $title, $dir) = @_;
- my $w = ugtk2->new($title);
- $dir .= '/' if $dir !~ m|/$|;
- ugtk2::_ask_file($w, $title, $dir);
- $w->main;
-}
-
-sub create_boxradio {
- my ($e, $may_go_to_next, $changed, $double_click) = @_;
-
- my $boxradio = gtkshow(gtkpack2__(Gtk2::VBox->new(0, 0),
- my @radios = gtkradio('', @{$e->{formatted_list}})));
- my $tips = Gtk2::Tooltips->new;
- mapn {
- my ($txt, $w) = @_;
- $w->signal_connect(button_press_event => $double_click) if $double_click;
-
- $w->signal_connect(key_press_event => sub {
- &$may_go_to_next;
- });
- $w->signal_connect(clicked => sub {
- ${$e->{val}} = $txt;
- &$changed;
- });
- if ($e->{help}) {
- gtkset_tip($tips, $w,
- ref($e->{help}) eq 'HASH' ? $e->{help}{$txt} :
- ref($e->{help}) eq 'CODE' ? $e->{help}($txt) : $e->{help});
- }
- } $e->{list}, \@radios;
-
- $boxradio, sub {
- my ($v, $full_struct) = @_;
- mapn {
- $_[0]->set_active($_[1] eq $v);
- $full_struct->{focus_w} = $_[0] if $_[1] eq $v;
- } \@radios, $e->{list};
- }, $radios[0];
-}
-
-sub create_treeview_list {
- my ($e, $may_go_to_next, $changed, $double_click) = @_;
- my $curr;
-
- my $list = Gtk2::ListStore->new("Glib::String");
- my $list_tv = Gtk2::TreeView->new_with_model($list);
- $list_tv->set_headers_visible(0);
- $list_tv->get_selection->set_mode('browse');
- my $textcolumn = Gtk2::TreeViewColumn->new_with_attributes(undef, Gtk2::CellRendererText->new, 'text' => 0);
- $list_tv->append_column($textcolumn);
-
- my $select = sub {
- $list_tv->set_cursor($_[0], undef, 0);
- $list_tv->scroll_to_cell($_[0], undef, 1, 0.5, 0);
- };
-
- my ($starting_word, $start_reg) = ('', '^');
- my $timeout;
- $list_tv->set_enable_search(0);
- $list_tv->signal_connect(key_press_event => sub {
- my ($_w, $event) = @_;
- my $c = chr($event->keyval & 0xff);
-
- Glib::Source->remove($timeout) if $timeout; $timeout = '';
-
- if ($event->keyval >= 0x100) {
- &$may_go_to_next if member($event->keyval, ($Gtk2::Gdk::Keysyms{Return}, $Gtk2::Gdk::Keysyms{KP_Enter}));
- $starting_word = '' if !member($event->keyval, ($Gtk2::Gdk::Keysyms{Control_L}, $Gtk2::Gdk::Keysyms{Control_R}));
- } else {
- if (member('control-mask', @{$event->state})) {
- $c eq 's' or return 1;
- $start_reg and $start_reg = '', return 1;
- $curr++;
- } else {
- &$may_go_to_next if $c eq ' ';
-
- $curr++ if $starting_word eq '' || $starting_word eq $c;
- $starting_word .= $c unless $starting_word eq $c;
- }
- my @l = @{$e->{formatted_list}};
- my $word = quotemeta $starting_word;
- my $j; for ($j = 0; $j < @l; $j++) {
- $l[($j + $curr) % @l] =~ /$start_reg$word/i and last;
- }
- if ($j == @l) {
- $starting_word = '';
- } else {
- $select->(Gtk2::TreePath->new_from_string(($j + $curr) % @l));
- }
-
- $timeout = Glib::Timeout->add($forgetTime, sub { $timeout = $starting_word = ''; 0 });
- }
- 0;
- });
- $list_tv->show;
-
- $list->append_set([ 0 => $_ ]) foreach @{$e->{formatted_list}};
-
- $list_tv->get_selection->signal_connect(changed => sub {
- my ($model, $iter) = $_[0]->get_selected;
- $model && $iter or return;
- my $row = $model->get_path_str($iter);
- ${$e->{val}} = $e->{list}[$curr = $row];
- &$changed;
- });
- $list_tv->signal_connect(button_press_event => $double_click) if $double_click;
-
- $list_tv, sub {
- my ($v) = @_;
- eval {
- my $nb = find_index { $_ eq $v } @{$e->{list}};
- my ($old_path) = $list_tv->get_cursor;
- if (!$old_path || $nb != $old_path->to_string) {
- $select->(Gtk2::TreePath->new_from_string($nb));
- }
- undef $old_path if $old_path;
- };
- };
-}
-
-sub create_treeview_tree {
- my ($e, $may_go_to_next, $changed, $double_click, $tree_expanded) = @_;
-
- $tree_expanded = to_bool($tree_expanded); #- to reduce "Use of uninitialized value", especially when debugging
-
- my $sep = quotemeta $e->{separator};
- my $tree_model = Gtk2::TreeStore->new("Glib::String", "Gtk2::Gdk::Pixbuf", "Glib::String");
- my $tree = Gtk2::TreeView->new_with_model($tree_model);
- $tree->get_selection->set_mode('browse');
- $tree->append_column(Gtk2::TreeViewColumn->new_with_attributes(undef, Gtk2::CellRendererText->new, 'text' => 0));
- $tree->append_column(Gtk2::TreeViewColumn->new_with_attributes(undef, Gtk2::CellRendererPixbuf->new, 'pixbuf' => 1));
- $tree->append_column(Gtk2::TreeViewColumn->new_with_attributes(undef, Gtk2::CellRendererText->new, 'text' => 2));
- $tree->set_headers_visible(0);
-
- my ($build_value, $clean_image);
- if (exists $e->{image2f}) {
- my $to_unref;
- $build_value = sub {
- my ($text, $image) = $e->{image2f}->($_[0]);
- [ $text ? (0 => $text) : @{[]},
- $image ? (1 => $to_unref = gtkcreate_pixbuf($image)) : @{[]} ];
- };
- $clean_image = sub { undef $to_unref };
- } else {
- $build_value = sub { [ 0 => $_[0] ] };
- $clean_image = sub {};
- }
-
- my (%wtree, %wleaves, $size, $selected_via_click);
- my $parent; $parent = sub {
- if (my $w = $wtree{"$_[0]$e->{separator}"}) { return $w }
- my $s = '';
- foreach (split $sep, $_[0]) {
- $wtree{"$s$_$e->{separator}"} ||=
- $tree_model->append_set($s ? $parent->($s) : undef, $build_value->($_));
- $clean_image->();
- $size++ if !$s;
- $s .= "$_$e->{separator}";
- }
- $wtree{$s};
- };
-
- #- do some precomputing to not slowdown selection change and key press
- my (%precomp, @ordered_keys);
- mapn {
- my ($root, $leaf) = $_[0] =~ /(.*)$sep(.+)/ ? ($1, $2) : ('', $_[0]);
- my $iter = $tree_model->append_set($parent->($root), $build_value->($leaf));
- $clean_image->();
- my $pathstr = $tree_model->get_path_str($iter);
- $precomp{$pathstr} = { value => $leaf, fullvalue => $_[0], listvalue => $_[1] };
- push @ordered_keys, $pathstr;
- $wleaves{$_[0]} = $pathstr;
- } $e->{formatted_list}, $e->{list};
- undef $_ foreach values %wtree;
- undef %wtree;
-
- my $select = sub {
- my ($path_str) = @_;
- $tree->expand_to_path(Gtk2::TreePath->new_from_string($path_str));
- my $path = Gtk2::TreePath->new_from_string($path_str);
- $tree->set_cursor($path, undef, 0);
- gtkflush(); #- workaround gtk2 bug not honouring centering on the given row if node was closed
- $tree->scroll_to_cell($path, undef, 1, 0.5, 0);
- };
-
- my $curr = $tree_model->get_iter_first; #- default value
- $tree->expand_all if $tree_expanded;
-
- $tree->get_selection->signal_connect(changed => sub {
- my ($model, $iter) = $_[0]->get_selected;
- $model && $iter or return;
- undef $curr if ref $curr;
- my $path = $tree_model->get_path($curr = $iter);
- if (!$tree_model->iter_has_child($iter)) {
- ${$e->{val}} = $precomp{$path->to_string}{listvalue};
- &$changed;
- } else {
- $tree->expand_row($path, 0) if $selected_via_click;
- }
- });
- my ($starting_word, $start_reg) = ('', "^");
- my $timeout;
-
- my $toggle = sub {
- if ($tree_model->iter_has_child($curr)) {
- $tree->toggle_expansion($tree_model->get_path($curr), 0);
-
- } else {
- &$may_go_to_next;
- }
- };
-
- $tree->set_enable_search(0);
- $tree->signal_connect(key_press_event => sub {
- my ($_w, $event) = @_;
- $selected_via_click = 0;
- my $c = chr($event->keyval & 0xff);
- $curr or return 0;
- Glib::Source->remove($timeout) if $timeout; $timeout = '';
-
- if ($event->keyval >= 0x100) {
- &$toggle if member($event->keyval, ($Gtk2::Gdk::Keysyms{Return}, $Gtk2::Gdk::Keysyms{KP_Enter}));
- $starting_word = '' if !member($event->keyval, ($Gtk2::Gdk::Keysyms{Control_L}, $Gtk2::Gdk::Keysyms{Control_R}));
- } else {
- my $next;
- if (member('control-mask', @{$event->state})) {
- $c eq "s" or return 1;
- $start_reg and $start_reg = '', return 0;
- $next = 1;
- } else {
- &$toggle if $c eq ' ';
- $next = 1 if $starting_word eq '' || $starting_word eq $c;
- $starting_word .= $c unless $starting_word eq $c;
- }
- my $word = quotemeta $starting_word;
- my ($after, $best);
-
- my $currpath = $tree_model->get_path_str($curr);
- foreach my $v (@ordered_keys) {
- $next &&= !$after;
- $after ||= $v eq $currpath;
- if ($precomp{$v}{value} =~ /$start_reg$word/i) {
- if ($after && !$next) {
- ($best, $after) = ($v, 0);
- } else {
- $best ||= $v;
- }
- }
- }
-
- if (defined $best) {
- $select->($best);
- } else {
- $starting_word = '';
- }
-
- $timeout = Glib::Timeout->add($forgetTime, sub { $timeout = $starting_word = ''; 0 });
- }
- 0;
- });
- $tree->signal_connect(button_press_event => sub {
- $selected_via_click = 1;
- &$double_click if $curr && !$tree_model->iter_has_child($curr) && $double_click;
- });
-
- $tree, sub {
- my $v = may_apply($e->{format}, $_[0]);
- my ($model, $iter) = $tree->get_selection->get_selected;
- $select->($wleaves{$v} || return) if !$model || $wleaves{$v} ne $model->get_path_str($iter);
- undef $iter if ref $iter;
- };
-}
-
-sub create_list {
- my ($e, $may_go_to_next, $changed, $double_click) = @_;
- my $l = $e->{list};
- my $list = Gtk2::List->new;
- $list->set_selection_mode('browse');
-
- my $select = sub {
- $list->select_item($_[0]);
- };
-
- my $tips = Gtk2::Tooltips->new;
- each_index {
- my $item = Gtk2::ListItem->new(may_apply($e->{format}, $_));
- $item->signal_connect(key_press_event => sub {
- my ($_w, $event) = @_;
- my $c = chr($event->keyval & 0xff);
- &$may_go_to_next if $event->keyval < 0x100 ? $c eq ' ' : $c eq "\r" || $c eq "\x8d";
- 0;
- });
- $list->append_items(gtkshow($item));
- if ($e->{help}) {
- gtkset_tip($tips, $item,
- ref($e->{help}) eq 'HASH' ? $e->{help}{$_} :
- ref($e->{help}) eq 'CODE' ? $e->{help}($_) : $e->{help});
- }
- $item->grab_focus if ${$e->{val}} && $_ eq ${$e->{val}};
- } @$l;
-
- #- signal_connect'ed after append_items otherwise it is called and destroys the default value
- $list->signal_connect(select_child => sub {
- my ($_w, $row) = @_;
- ${$e->{val}} = $l->[$list->child_position($row)];
- &$changed;
- });
- $list->signal_connect(button_press_event => $double_click) if $double_click;
-
- $list, sub {
- my ($v) = @_;
- eval {
- $select->(find_index { $_ eq $v } @$l);
- };
- };
-}
-
-#- $actions is a ref list of $action
-#- $action is a { kind => $kind, action => sub { ... }, button => Gtk2::Button->new(...) }
-#- where $kind is one of '', 'modify', 'remove', 'add'
-sub add_modify_remove_action {
- my ($button, $buttons, $e, $treelist) = @_;
-
- if (member($button->{kind}, 'modify', 'remove')) {
- @{$e->{list}} or return;
- }
- my $r = $button->{action}->(${$e->{val}});
- defined $r or return;
-
- if ($button->{kind} eq 'add') {
- ${$e->{val}} = $r;
- } elsif ($button->{kind} eq 'remove') {
- ${$e->{val}} = $e->{list}[0];
- }
- ugtk2::gtk_set_treelist($treelist, [ map { may_apply($e->{format}, $_) } @{$e->{list}} ]);
-
- add_modify_remove_sensitive($buttons, $e);
- 1;
-}
-
-sub add_modify_remove_sensitive {
- my ($buttons, $e) = @_;
- $_->{button}->set_sensitive(@{$e->{list}} != ()) foreach
- grep { member($_->{kind}, 'modify', 'remove') } @$buttons;
-}
-
-sub ask_fromW {
- my ($o, $common, $l, $l2) = @_;
- my $ignore = 0; #-to handle recursivity
-
- my $mainw = ugtk2->new($common->{title}, %$o, modal => 1, if__($::main_window, transient => $::main_window));
-
- #-the widgets
- my (@widgets, @widgets_always, @widgets_advanced, $advanced);
- my $tooltips = Gtk2::Tooltips->new;
- my $ok_clicked = sub {
- !$mainw->{ok} || $mainw->{ok}->get_property('sensitive') or return;
- $mainw->{retval} = 1;
- Gtk2->main_quit;
- };
- my $set_all = sub {
- $ignore = 1;
- $_->{set}->(${$_->{e}{val}}, $_) foreach @widgets_always, @widgets_advanced;
- $_->{real_w}->set_sensitive(!$_->{e}{disabled}()) foreach @widgets_always, @widgets_advanced;
- $mainw->{ok}->set_sensitive(!$common->{callbacks}{ok_disabled}()) if $common->{callbacks}{ok_disabled};
- $ignore = 0;
- };
- my $get_all = sub {
- ${$_->{e}{val}} = $_->{get}->() foreach @widgets_always, @widgets_advanced;
- };
- my $update = sub {
- my ($f) = @_;
- return if $ignore;
- $get_all->();
- $f->();
- $set_all->();
- };
-
- my $label_sizegrp = Gtk2::SizeGroup->new('horizontal');
- my $realw_sizegrp = Gtk2::SizeGroup->new('horizontal');
-
- my $create_widget = sub {
- my ($e, $ind) = @_;
-
- my $may_go_to_next = sub {
- my (undef, $event) = @_;
- if (!$event || ($event->keyval & 0x7f) == 0xd) {
- if ($ind == $#widgets) {
- @widgets == 1 ? $ok_clicked->() : $mainw->{ok}->grab_focus;
- } else {
- $widgets[$ind+1]{focus_w}->grab_focus;
- }
- return 1; #- prevent an action on the just grabbed focus
- }
- };
- my $changed = sub { $update->(sub { $common->{callbacks}{changed}($ind) }) };
-
- my ($w, $real_w, $focus_w, $set, $get, $grow);
- if ($e->{type} eq 'iconlist') {
- $w = Gtk2::Button->new;
- $set = sub {
- gtkdestroy($e->{icon});
- my $f = $e->{icon2f}->($_[0]);
- $e->{icon} = -e $f ?
- gtkcreate_img($f) :
- Gtk2::WrappedLabel->new(may_apply($e->{format}, $_[0]));
- $w->add(gtkshow($e->{icon}));
- };
- $w->signal_connect(clicked => sub {
- $set->(${$e->{val}} = next_val_in_array(${$e->{val}}, $e->{list}));
- $changed->();
- });
- $real_w = gtkpack_(Gtk2::HBox->new(0,10), 1, Gtk2::HBox->new(0,0), 0, $w, 1, Gtk2::HBox->new(0,0));
- } elsif ($e->{type} eq 'bool') {
- if ($e->{image}) {
- $w = gtkadd(Gtk2::CheckButton->new, gtkshow(gtkcreate_img($e->{image})));
- } else {
-#- warn "\"text\" member should have been used instead of \"label\" one at:\n", common::backtrace(), "\n" if $e->{label} && !$e->{text};
- $w = Gtk2::CheckButton->new_with_label($e->{text});
- }
- $w->signal_connect(clicked => $changed);
- $set = sub { $w->set_active($_[0]) };
- $get = sub { $w->get_active };
- } elsif ($e->{type} eq 'label') {
- $w = Gtk2::WrappedLabel->new(${$e->{val}});
- $set = sub { $w->set($_[0]) };
- } elsif ($e->{type} eq 'button') {
- $w = Gtk2::Button->new_with_label('');
- $w->signal_connect(clicked => sub {
- $get_all->();
- $mainw->{rwindow}->hide;
- if (my $v = $e->{clicked_may_quit}()) {
- $mainw->{retval} = $v;
- Gtk2->main_quit;
- }
- $mainw->{rwindow}->show;
- $set_all->();
- });
- $set = sub { $w->child->set_label(may_apply($e->{format}, $_[0])) };
- } elsif ($e->{type} eq 'range') {
- my $want_scale = !$::expert;
- my $adj = Gtk2::Adjustment->new(${$e->{val}}, $e->{min}, $e->{max} + ($want_scale ? 1 : 0), 1, ($e->{max} - $e->{min}) / 10, 1);
- $adj->signal_connect(value_changed => $changed);
- $w = $want_scale ? Gtk2::HScale->new($adj) : Gtk2::SpinButton->new($adj, 10, 0);
- $w->set_size_request($want_scale ? 200 : 100, -1);
- $w->set_digits(0);
- $w->signal_connect(key_press_event => $may_go_to_next);
- $set = sub { $adj->set_value($_[0]) };
- $get = sub { $adj->get_value };
- } elsif ($e->{type} =~ /list/) {
-
- $e->{formatted_list} = [ map { may_apply($e->{format}, $_) } @{$e->{list}} ];
-
- if (my $actions = $e->{add_modify_remove}) {
- my @buttons = map {
- { kind => lc $_, action => $actions->{$_}, button => Gtk2::Button->new(translate($_)) };
- } N_("Add"), N_("Modify"), N_("Remove");
- my $modify = find { $_->{kind} eq 'modify' } @buttons;
-
- my $do_action = sub {
- my ($button) = @_;
- add_modify_remove_action($button, \@buttons, $e, $w) and $changed->();
- };
-
- ($w, $set, $focus_w) = create_treeview_list($e, $may_go_to_next, $changed,
- sub { $do_action->($modify) if $_[1]->type =~ /^2/ });
- $e->{saved_default_val} = ${$e->{val}};
-
- foreach my $button (@buttons) {
- $button->{button}->signal_connect(clicked => sub { $do_action->($button) });
- }
- add_modify_remove_sensitive(\@buttons, $e);
-
- $real_w = gtkpack_(Gtk2::HBox->new(0,0),
- 1, create_scrolled_window($w),
- 0, gtkpack__(Gtk2::VBox->new(0,0), map { $_->{button} } @buttons));
- $grow = 1;
- } else {
-
- my $quit_if_double_click =
- #- i'm the only one, double click means accepting
- @$l == 1 || $e->{quit_if_double_click} ?
- sub { $_[1]->type =~ /^2/ && $ok_clicked->() } : '';
-
- my @para = ($e, $may_go_to_next, $changed, $quit_if_double_click);
- my $use_boxradio = exists $e->{gtk}{use_boxradio} ? $e->{gtk}{use_boxradio} : @{$e->{list}} <= 8;
-
- if ($e->{help}) {
- #- used only when needed, as key bindings are dropped by List (ListStore does not seems to accepts Tooltips).
- ($w, $set, $focus_w) = $use_boxradio ? create_boxradio(@para) : create_list(@para);
- } elsif ($e->{type} eq 'treelist') {
- ($w, $set) = create_treeview_tree(@para, $e->{tree_expanded});
- $e->{saved_default_val} = ${$e->{val}}; #- during realization, signals will mess up the default val :(
- } else {
- if ($use_boxradio) {
- ($w, $set, $focus_w) = create_boxradio(@para);
- } else {
- ($w, $set, $focus_w) = create_treeview_list(@para);
- $e->{saved_default_val} = ${$e->{val}};
- }
- }
- if (@{$e->{list}} > 10) {
- $real_w = create_scrolled_window($w);
- $grow = 1;
- }
- }
- } else {
- if ($e->{type} eq "combo") {
-
- my @formatted_list = map { may_apply($e->{format}, $_) } @{$e->{list}};
-
- my @l = sort { $b <=> $a } map { length } @formatted_list;
- my $width = $l[@l / 16]; # take the third octile (think quartile)
-
- if ($e->{not_edit} && $width < 160) { #- ComboBoxes do not have an horizontal scroll-bar. This can cause havoc for long strings (eg: diskdrake Create dialog box in expert mode)
- $w = Gtk2::ComboBox->new_text;
- } else {
- $w = Gtk2::Combo->new;
- $w->set_use_arrows_always(1);
- $w->entry->set_editable(!$e->{not_edit});
- $w->disable_activate;
- }
-
- $w->set_popdown_strings(@formatted_list);
- $w->set_text(ref($e->{val}) ? may_apply($e->{format}, ${$e->{val}}) : $formatted_list[0]) if $w->isa('Gtk2::ComboBox');
- ($real_w, $w) = ($w, $w->entry);
-
- #- FIXME workaround gtk suckiness (set_text generates two 'change' signals, one when removing the whole, one for inserting the replacement..)
- my $idle;
- $w->signal_connect(changed => sub {
- $idle ||= Glib::Idle->add(sub { undef $idle; $changed->(); 0 });
- });
-
- $set = sub {
- my $s = may_apply($e->{format}, $_[0]);
- $w->set_text($s) if $s ne $w->get_text && $_[0] ne $w->get_text;
- };
- $get = sub {
- my $s = $w->get_text;
- my $i = eval { find_index { $s eq $_ } @formatted_list };
- defined $i ? $e->{list}[$i] : $s;
- };
- } else {
- $w = Gtk2::Entry->new;
- $w->signal_connect(changed => $changed);
- $w->signal_connect(focus_in_event => sub { $w->select_region(0, -1) });
- $w->signal_connect(focus_out_event => sub { $w->select_region(0, 0) });
- $set = sub { $w->set_text($_[0]) if $_[0] ne $w->get_text };
- $get = sub { $w->get_text };
- }
- $w->signal_connect(key_press_event => $may_go_to_next);
- $w->set_visibility(0) if $e->{hidden};
- }
- $w->signal_connect(focus_out_event => sub {
- $update->(sub { $common->{callbacks}{focus_out}($ind) });
- });
- $tooltips->set_tip($w, $e->{help}) if $e->{help} && !ref($e->{help});
-
- $real_w ||= $w;
- $real_w = gtkpack_(Gtk2::HBox->new,
- if_($e->{icon}, 0, eval { gtkcreate_img($e->{icon}) }),
- 0, gtkadd_widget($label_sizegrp, $e->{label}),
- 1, gtkadd_widget($realw_sizegrp, $real_w),
- ) if !$real_w->isa("Gtk2::CheckButton") || $e->{icon} || $e->{label};
-
- { e => $e, w => $w, real_w => $real_w, focus_w => $focus_w || $w,
- get => $get || sub { ${$e->{val}} }, set => $set || sub {}, grow => $grow };
- };
- @widgets_always = map_index { $create_widget->($_, $::i) } @$l;
- @widgets_advanced = map_index { $create_widget->($_, $::i + @$l) } @$l2;
-
- $mainw->{box_allow_grow} = !@$l;
- my $pack = create_box_with_title($mainw, @{$common->{messages}});
- ugtk2::set_main_window_size($mainw) if $mainw->{pop_it} && (@$l || $mainw->{box_size} == 200);
-
- my @before_widgets_advanced = (
- (map { { grow => 0, real_w => Gtk2::WrappedLabel->new($_) } } @{$common->{advanced_messages}}),
- { grow => 0, real_w => Gtk2::HSeparator->new },
- );
-
- my $first_time = 1;
- my $set_advanced = sub {
- ($advanced) = @_;
- $update->($common->{callbacks}{advanced}) if $advanced && !$first_time;
- foreach (@before_widgets_advanced, @widgets_advanced) {
- my $w = $_->{embed_scroll} || $_->{real_w};
- $advanced ? $w->show : $w->hide;
- }
- @widgets = (@widgets_always, if_($advanced, @widgets_advanced));
- $mainw->sync; #- for $set_all below (mainly for the set of clist)
- $first_time = 0;
- $set_all->(); #- must be done when showing advanced lists (to center selected value)
- };
- my $advanced_button = [ $common->{advanced_label},
- sub {
- my ($w) = @_;
- $set_advanced->(!$advanced);
- $w->child->set_label($advanced ? $common->{advanced_label_close} : $common->{advanced_label});
- } ];
-
- my @more_buttons = (
- if_($common->{interactive_help},
- [ N("Help"), sub {
- my $message = $common->{interactive_help}->() or return;
- $o->ask_warn(N("Help"), $message);
- }, 1 ]),
- if_($common->{more_buttons}, @{$common->{more_buttons}}),
- );
- if ($::expert && @$l2) {
- $common->{advanced_state} = 1;
- $advanced_button->[0] = $common->{advanced_label_close};
- }
- my $buttons_pack = ($common->{ok} || !exists $common->{ok}) && $mainw->create_okcancel($common->{ok}, $common->{cancel}, '', @more_buttons, if_(@$l2, $advanced_button));
-
- my @widgets_to_pack;
- foreach my $l (\@widgets_always, if_(@widgets_advanced, [ @before_widgets_advanced, @widgets_advanced ])) {
- my @grouped;
- my $add_grouped = sub {
- if (@grouped == 0) {
- push @widgets_to_pack, 1 => Gtk2::VBox->new(0,0) if @$l == 0;
- } elsif (@grouped == 1 && @$l > 1) {
- push @widgets_to_pack, 0 => $grouped[0]{real_w};
- } else {
- my $scroll = create_scrolled_window(gtkpack__(Gtk2::VBox->new(0,0), map { $_->{real_w} } @grouped),
- [ 'automatic', 'automatic' ], 'none');
- $_->{embed_scroll} = $scroll foreach @grouped;
- push @widgets_to_pack, 1 => $scroll;
- }
- @grouped = ();
- };
- foreach (@$l) {
- if ($_->{grow}) {
- $add_grouped->();
- push @widgets_to_pack, 1 => $_->{real_w};
- } else {
- push @grouped, $_;
- }
- }
- $add_grouped->();
- }
-
- gtkpack_($pack, @widgets_to_pack);
-
- if ($buttons_pack) {
- if ($::isWizard && !$mainw->{pop_it} && $::isInstall) {
- #- is this still needed?
- $buttons_pack->set_size_request($::real_windowwidth - 20, -1);
- $buttons_pack = gtkpack__(Gtk2::HBox->new(0,0), $buttons_pack);
- }
- $pack->pack_start(gtkshow($buttons_pack), 0, 0, 0);
- }
- gtkadd($mainw->{window}, $pack);
- $set_advanced->($common->{advanced_state});
-
- my $widget_to_focus =
- $common->{focus_cancel} ? $mainw->{cancel} :
- @widgets && ($common->{focus_first} || !$mainw->{ok} || @widgets == 1 && member(ref($widgets[0]{focus_w}), "Gtk2::TreeView", "Gtk2::RadioButton")) ?
- $widgets[0]{focus_w} :
- $mainw->{ok};
- $widget_to_focus->grab_focus if $widget_to_focus;
-
- my $check = sub {
- my ($f) = @_;
- sub {
- $get_all->();
- my ($error, $focus) = $f->();
-
- if ($error) {
- $set_all->();
- if (my $to_focus = $widgets[$focus || 0]) {
- $to_focus->{focus_w}->grab_focus;
- } else {
- log::l("ERROR: bad entry number given to focus " . backtrace());
- }
- }
- !$error;
- }
- };
-
- $_->{set}->($_->{e}{saved_default_val} || next) foreach @widgets_always, @widgets_advanced;
- $mainw->main(map { $check->($common->{callbacks}{$_}) } 'complete', 'canceled');
-}
-
-
-sub ask_browse_tree_info_refW {
- my ($o, $common) = @_;
- add2hash($common, { wait_message => sub { $o->wait_message(@_) } });
- ugtk2::ask_browse_tree_info($common);
-}
-
-
-sub ask_from__add_modify_removeW {
- my ($o, $title, $message, $l, %callback) = @_;
-
- my $e = $l->[0];
- my $chosen_element;
- put_in_hash($e, { allow_empty_list => 1, gtk => { use_boxradio => 0 }, sort => 0,
- val => \$chosen_element, type => 'list', add_modify_remove => \%callback });
-
- $o->ask_from($title, $message, $l, %callback);
-}
-
-sub wait_messageW($$$) {
- my ($o, $title, $messages) = @_;
- local $::isEmbedded = 0; # to prevent sub window embedding
- local $::isWizard = 0 if !$::isInstall; # to prevent sub window embedding
-
- my @l = map { Gtk2::Label->new(scalar warp_text($_)) } @$messages;
- my $w = ugtk2->new($title, %$o, grab => 1, if__($::main_window, transient => $::main_window));
- gtkadd($w->{window}, my $hbox = Gtk2::HBox->new(0,0));
- $hbox->pack_start(my $box = Gtk2::VBox->new(0,0), 1, 1, 10);
- $box->pack_start(shift @l, 0, 0, 4);
- $box->pack_start($_, 1, 1, 4) foreach @l;
-
- ($w->{wait_messageW} = $l[-1])->signal_connect(expose_event => sub { $w->{displayed} = 1; 0 });
- $w->{rwindow}->set_position('center') if $::isStandalone && !$w->{isEmbedded} && !$w->{isWizard};
- $w->{window}->show_all;
- $w->sync until $w->{displayed};
- $w;
-}
-sub wait_message_nextW {
- my ($_o, $messages, $w) = @_;
- my $msg = warp_text(join "\n", @$messages);
- return if $msg eq $w->{wait_messageW}->get; #- needed otherwise no expose_event :(
- $w->{displayed} = 0;
- $w->{wait_messageW}->set($msg);
- $w->flush until $w->{displayed};
-}
-sub wait_message_endW {
- my ($_o, $w) = @_;
- $w->destroy;
-}
-
-sub kill {
- my ($_o) = @_;
- $_->destroy foreach $::WizardTable ? $::WizardTable->get_children : (), @tempory::objects;
- @tempory::objects = ();
-}
-
-sub ok {
- N("Ok");
-}
-
-sub cancel {
- N("Cancel");
-}
-
-1;
diff --git a/perl-install/interactive/http.pm b/perl-install/interactive/http.pm
deleted file mode 100644
index 8a453616f..000000000
--- a/perl-install/interactive/http.pm
+++ /dev/null
@@ -1,164 +0,0 @@
-package interactive::http; # $Id$
-
-use diagnostics;
-use strict;
-use vars qw(@ISA);
-
-@ISA = qw(interactive);
-
-use CGI;
-use interactive;
-use common;
-use log;
-
-my $script_name = $ENV{INTERACTIVE_HTTP};
-my $no_header;
-my $pipe_r = "/tmp/interactive_http_r";
-my $pipe_w = "/tmp/interactive_http_w";
-
-sub open_stdout() {
- open STDOUT, ">$pipe_w" or die;
- $| = 1;
- print CGI::header();
- $no_header = 1;
-}
-
-# cont_stdout must be called after open_stdout and before the first print
-sub cont_stdout {
- my ($o_title) = @_;
- print CGI::start_html('-title' => $o_title) if $no_header;
- $no_header = 0;
-}
-
-sub new_uid() {
- my ($s, $ms) = gettimeofday();
- $s * 256 + $ms % 256;
-}
-
-sub new {
- open_stdout();
- bless {}, $_[0];
-}
-
-sub end {
- -e $pipe_r or return; # don't run this twice
- my $q = CGI->new;
- cont_stdout("Exit");
- print "It's done, thanks for playing", $q->end_html;
- close STDOUT;
- unlink $pipe_r, $pipe_w;
-}
-sub exit { end(); exit($_[1]) }
-END { end() }
-
-sub ask_fromW {
- my ($o, $common, $l, $_l2) = @_;
-
- redisplay:
- my $uid = new_uid();
- my $q = CGI->new;
- $q->param(state => 'next_step');
- $q->param(uid => $uid);
- cont_stdout($common->{title});
-
-# print $q->img({ -src => "/icons/$o->{icon}" }) if $o->{icon};
- print @{$common->{messages}};
- print $q->start_form('-name' => 'form', '-action' => $script_name, '-method' => 'post');
-
- print "<table>\n";
-
- each_index {
- my $e = $_;
-
- print "<tr><td>$e->{label}</td><td>\n";
-
- $e->{type} = 'list' if $e->{type} =~ /(icon|tree)list/;
-
- #- combo doesn't exist, fallback to a sensible default
- $e->{type} = $e->{not_edit} ? 'list' : 'entry' if $e->{type} eq 'combo';
-
- if ($e->{type} eq 'bool') {
- print $q->checkbox('-name' => "w$::i", '-checked' => ${$e->{val}} && 'on', '-label' => $e->{text} || " ");
- } elsif ($e->{type} eq 'button') {
- print "nobuttonyet";
- } elsif ($e->{type} =~ /list/) {
- my %t;
- $t{$_} = may_apply($e->{format}, $_) foreach @{$e->{list}};
-
- print $q->scrolling_list('-name' => "w$::i",
- '-values' => $e->{list},
- '-default' => [ ${$e->{val}} ],
- '-size' => 5, '-multiple' => '', '-labels' => \%t);
- } else {
- print $e->{hidden} ?
- $q->password_field('-name' => "w$::i", '-default' => ${$e->{val}}) :
- $q->textfield('-name' => "w$::i", '-default' => ${$e->{val}});
- }
-
- print "</td></tr>\n";
- } @$l;
-
- print "</table>\n";
- print $q->p;
- print $q->submit('-name' => 'ok_submit', '-value' => $common->{ok} || N("Ok"));
- print $q->submit('-name' => 'cancel_submit', '-value' => $common->{cancel} || N("Cancel")) if $common->{cancel} || !exists $common->{ok};
- print $q->hidden('state'), $q->hidden('uid');
- print $q->end_form, $q->end_html;
-
- close STDOUT; # page terminated
-
- while (1) {
- open(my $F, "<$pipe_r") or die;
- $q = CGI->new($F);
- $q->param('force_exit_dead_prog') and $o->exit;
- last if $q->param('uid') == $uid;
-
- open_stdout(); # re-open for writing
- cont_stdout(N("Error"));
- print $q->h1(N("Error")), $q->p("Sorry, you can't go back");
- goto redisplay;
- }
- each_index {
- my $e = $_;
- my $v = $q->param("w$::i");
- if ($e->{type} eq 'bool') {
- $v = $v eq 'on';
- }
- ${$e->{val}} = $v;
- } @$l;
-
- open_stdout(); # re-open for writing
- $q->param('ok_submit');
-}
-
-sub p {
- print "\n" . CGI::br($_) foreach @_;
-}
-
-sub wait_messageW {
- my ($_o, $_title, $messages) = @_;
- cont_stdout();
- print "\n" . CGI::p();
- p(@$messages);
-}
-
-sub wait_message_nextW {
- my ($_o, $messages, $_w) = @_;
- p(@$messages);
-}
-sub wait_message_endW {
- my ($_o, $_w) = @_;
- p(N("Done"));
- print "\n" . CGI::p();
-}
-
-sub ok {
- N("Ok");
-}
-
-sub cancel {
- N("Cancel");
-}
-
-
-1;
diff --git a/perl-install/interactive/newt.pm b/perl-install/interactive/newt.pm
deleted file mode 100644
index c9da9c92a..000000000
--- a/perl-install/interactive/newt.pm
+++ /dev/null
@@ -1,426 +0,0 @@
-package interactive::newt; # $Id$
-
-use diagnostics;
-use strict;
-use vars qw(@ISA);
-
-@ISA = qw(interactive);
-
-use interactive;
-use common;
-use log;
-use Newt::Newt; #- !! provides Newt and not Newt::Newt
-
-my ($width, $height) = (80, 25);
-my @wait_messages;
-
-sub new {
- if ($::isInstall) {
- system('unicode_start'); #- don't use run_program, we must do it on current console
- {
- local $ENV{LC_CTYPE} = "en_US.UTF-8";
- Newt::Init(1);
- }
- c::setlocale();
- } else {
- Newt::Init(0);
- }
- Newt::Cls();
- Newt::SetSuspendCallback();
- ($width, $height) = Newt::GetScreenSize();
- open STDERR, ">/dev/null" if $::isStandalone && !$::testing;
- bless {}, $_[0];
-}
-
-sub enter_console { Newt::Suspend() }
-sub leave_console { Newt::Resume() }
-sub suspend { Newt::Suspend() }
-sub resume { Newt::Resume() }
-sub end { Newt::Finished() }
-sub exit { end(); exit($_[1]) }
-END { end() }
-
-sub messages {
- my ($width, @messages) = @_;
- warp_text(join("\n", @messages), $width - 9);
-}
-
-sub myTextbox {
- my ($allow_scroll, $free_height, @messages) = @_;
-
- my @l = messages($width, @messages);
- my $h = min($free_height - 13, int @l);
-
- my $want_scroll;
- if ($h < @l) {
- if ($allow_scroll) {
- $want_scroll = 1;
- } else {
- # remove the text, no other way!
- @l = @l[0 .. $h-1];
- }
- }
-
- my $mess = Newt::Component::Textbox(1, 0, my $w = max(map { length } @l) + 1, $h, $want_scroll);
- $mess->TextboxSetText(join("\n", @l));
- $mess, $w + 1, $h;
-}
-
-sub separator {
- my $blank = Newt::Component::Form(\undef, '', 0);
- $blank->FormSetWidth($_[0]);
- $blank->FormSetHeight($_[1]);
- $blank;
-}
-sub checkval { $_[0] && $_[0] ne ' ' ? '*' : ' ' }
-
-sub ask_fromW {
- my ($o, $common, $l, $l2) = @_;
-
- if (@$l == 1 && $l->[0]{list} && @{$l->[0]{list}} == 2 && listlength(map { split "\n" } @{$common->{messages}}) > 20) {
- #- special ugly case, esp. for license agreement
- my $e = $l->[0];
- my $ok_disabled = $common->{callbacks} && delete $common->{callbacks}{ok_disabled};
- ($common->{ok}, $common->{cancel}) = map { may_apply($e->{format}, $_) } @{$e->{list}};
- do {
- ${$e->{val}} = ask_fromW_real($o, $common, [], $l2) ? $e->{list}[0] : $e->{list}[1];
- } while $ok_disabled && $ok_disabled->();
- 1;
- } elsif ((any { $_->{type} ne 'button' } @$l) || @$l < 5) {
- &ask_fromW_real;
- } else {
- $common->{cancel} = N("Do") if $common->{cancel} eq '';
- my $r;
- do {
- my @choices = map {
- my $s = simplify_string(may_apply($_->{format}, ${$_->{val}}));
- $s = "$_->{label}: $s" if $_->{label};
- { label => $s, clicked_may_quit => $_->{clicked_may_quit} }
- } @$l;
- #- replace many buttons with a list
- my $new_l = [ { val => \$r, type => 'list', list => \@choices, format => sub { $_[0]{label} }, sort => 0 } ];
- ask_fromW_real($o, $common, $new_l, $l2) and return;
- } until $r->{clicked_may_quit}->();
- 1;
- }
-}
-
-sub ask_fromW_real {
- my ($o, $common, $l, $l2) = @_;
- my $ignore; #-to handle recursivity
- my $old_focus = -2;
-
- my @l = $common->{advanced_state} ? @$l2 : @$l;
- my @messages = (@{$common->{messages}}, if_($common->{advanced_state}, @{$common->{advanced_messages}}));
-
- #-the widgets
- my (@widgets, $total_size, $has_scroll);
-
- my $label_width;
- my $get_label_width = sub {
- $label_width ||= max(map { length($_->{label}) } @l);
- };
-
- my $set_all = sub {
- $ignore = 1;
- $_->{set}->(${$_->{e}{val}}) foreach @widgets;
-# $_->{w}->set_sensitive(!$_->{e}{disabled}()) foreach @widgets;
- $ignore = 0;
- };
- my $get_all = sub {
- ${$_->{e}{val}} = $_->{get}->() foreach @widgets;
- };
- my $create_widget = sub {
- my ($e, $ind) = @_;
-
- $e->{type} = 'list' if $e->{type} =~ /iconlist/;
-
- #- combo doesn't exist, fallback to a sensible default
- $e->{type} = $e->{not_edit} ? 'list' : 'entry' if $e->{type} eq 'combo';
-
- my $changed = sub {
- return if $ignore;
- return $old_focus++ if $old_focus == -2; #- handle special first case
- $get_all->();
-
- #- TODO: this is very rough :(
- $common->{callbacks}{$old_focus == $ind ? 'changed' : 'focus_out'}->($ind);
-
- $set_all->();
- $old_focus = $ind;
- };
-
- my ($w, $real_w, $set, $get, $expand, $size, $invalid_choice, $extra_text);
- if ($e->{type} eq 'bool') {
- my $subwidth = $width - $get_label_width->() - 9;
- my @text = messages($subwidth, $e->{text} || '');
- $size = @text;
- $w = Newt::Component::Checkbox(shift(@text), checkval(${$e->{val}}), " *");
- if (@text) {
- $extra_text = Newt::Component::Textbox(-1, -1, $subwidth, $size - 1, 0);
- $extra_text->TextboxSetText(join("\n", @text));
- }
- $set = sub { $w->CheckboxSetValue(checkval($_[0])) };
- $get = sub { $w->CheckboxGetValue == ord '*' };
- } elsif ($e->{type} eq 'button') {
- $w = Newt::Component::Button(simplify_string(may_apply($e->{format}, ${$e->{val}})));
- } elsif ($e->{type} eq 'treelist') {
- $e->{formatted_list} = [ map { may_apply($e->{format}, $_) } @{$e->{list}} ];
- my $data_tree = interactive::helper_separator_tree_to_tree($e->{separator}, $e->{list}, $e->{formatted_list});
-
- my $count; $count = sub {
- my ($t) = @_;
- 1 + ($t->{_leaves_} ? int @{$t->{_leaves_}} : 0)
- + ($t->{_order_} ? sum(map { $count->($t->{$_}) } @{$t->{_order_}}) : 0);
- };
- $size = $count->($data_tree);
-
- my $prefered_size = @l == 1 && $height > 30 ? 10 : 5;
- my $scroll;
- if ($size > $prefered_size && !$o->{no_individual_scroll}) {
- $has_scroll = $scroll = 1;
- $size = $prefered_size;
- }
-
- $w = Newt::Component::Tree($size, $scroll);
-
- my $wi;
- my $add_item = sub {
- my ($text, $index, $parents) = @_;
- $text = simplify_string($text, $width - 10);
- $wi = max($wi, length($text) + 3 * @$parents + 4);
- $w->TreeAdd($text, $index, $parents);
- };
-
- my @data = '';
- my $populate; $populate = sub {
- my ($node, $parents) = @_;
- if (my $l = $node->{_order_}) {
- each_index {
- $add_item->($_, 0, $parents);
- $populate->($node->{$_}, [ @$parents, $::i ]);
- } @$l;
- }
- if (my $l = $node->{_leaves_}) {
- foreach (@$l) {
- my ($leaf, $data) = @$_;
- $add_item->($leaf, int(@data), $parents);
- push @data, $data;
- }
- }
- };
- $populate->($data_tree, []);
-
- $w->TreeSetWidth($wi + 1);
- $get = sub {
- my $i = $w->TreeGetCurrent;
- $invalid_choice = $i == 0;
- $data[$i];
- };
- $set = sub {
- my ($data) = @_;
- eval {
- my $i = find_index { $_ eq $data } @data;
- $w->TreeSetCurrent($i);
- } if $data;
- 1;
- };
- } elsif ($e->{type} =~ /list/) {
- $size = @{$e->{list}};
- my $prefered_size = @l == 1 && $height > 30 ? 10 : 5;
- my $scroll;
- if ($size > $prefered_size && !$o->{no_individual_scroll}) {
- $has_scroll = $scroll = 1;
- $size = $prefered_size;
- }
-
- $w = Newt::Component::Listbox($size, $scroll ? 1 << 2 : 0); #- NEWT_FLAG_SCROLL
-
- my @l = map {
- my $t = simplify_string(may_apply($e->{format}, $_), $width - 10);
- $w->ListboxAddEntry($t, $_);
- $t;
- } @{$e->{list}};
-
- $w->ListboxSetWidth(max(map { length($_) } @l) + 3); # 3 added for the scrollbar (?)
- $get = sub { $w->ListboxGetCurrent };
- $set = sub {
- my ($val) = @_;
- each_index {
- $w->ListboxSetCurrent($::i) if $val eq $_;
- } @{$e->{list}};
- };
- } else {
- $w = Newt::Component::Entry('', 20, ($e->{hidden} && 1 << 11) | (1 << 2));
- $get = sub { $w->EntryGetValue };
- $set = sub { $w->EntrySet($_[0], 1) };
- }
- $total_size += $size || 1;
-
- #- !! callbacks must be kept otherwise perl will free them !!
- #- (better handling of addCallback needed)
-
- { e => $e, w => $w, real_w => $real_w || $w, expand => $expand, callback => $changed,
- get => $get || sub { ${$e->{val}} }, set => $set || sub {},
- extra_text => $extra_text, invalid_choice => \$invalid_choice };
- };
- @widgets = map_index { $create_widget->($_, $::i) } @l;
-
- $_->{w}->addCallback($_->{callback}) foreach @widgets;
-
- $set_all->();
-
- my $grid = Newt::Grid::CreateGrid(3, max(1, sum(map { $_->{extra_text} ? 2 : 1 } @widgets)));
- my $i;
- foreach (@widgets) {
- $grid->GridSetField(0, $i, 1, ${Newt::Component::Label($_->{e}{label})}, 0, 0, 1, 0, 1, 0);
- $grid->GridSetField(1, $i, 1, ${$_->{real_w}}, 0, 0, 0, 0, 1, 0);
- $i++;
- if ($_->{extra_text}) {
- $grid->GridSetField(0, $i, 1, ${Newt::Component::Label('')}, 0, 0, 1, 0, 1, 0);
- $grid->GridSetField(1, $i, 1, ${$_->{extra_text}}, 0, 0, 0, 0, 1, 0);
- $i++;
- }
- }
-
- my $listg = do {
- my $wanted_header_height = min(8, listlength(messages($width, @messages)));
- my $height_avail = $height - $wanted_header_height - 13;
- #- use a scrolled window if there is a lot of checkboxes (aka
- #- ask_many_from_list) or a lot of widgets in general (aka
- #- options of a native PostScript printer in printerdrake)
- #- !! works badly together with list's (lists are one widget, so a
- #- big list window will not switch to scrollbar mode) :-(
- if (@l > 3 && $total_size > $height_avail) {
- $grid->GridPlace(1, 1); #- Uh?? otherwise the size allocated is bad
- if ($has_scroll) {
- #- trying again with no_individual_scroll set
- $o->{no_individual_scroll} and internal_error('no_individual_scroll already set, argh...');
- $o->{no_individual_scroll} = 1;
- goto &ask_fromW_real; #- same player shoot again!
- }
- $has_scroll = 1;
- $total_size = $height_avail;
-
- my $scroll = Newt::Component::VerticalScrollbar($height_avail, 9, 10); # 9=NEWT_COLORSET_CHECKBOX, 10=NEWT_COLORSET_ACTCHECKBOX
- my $subf = $scroll->Form('', 0);
- $subf->FormSetHeight($height_avail);
- $subf->FormAddGrid($grid, 0);
- Newt::Grid::HCloseStacked3($subf, separator(1, $height_avail-1), $scroll);
- } else {
- $grid;
- }
- };
-
- my ($ok, $cancel) = ($common->{ok}, $common->{cancel});
- $cancel = $::isWizard && !$::Wizard_no_previous ? N("Previous") : N("Cancel") if !defined $cancel && !defined $ok;
- $ok ||= $::isWizard ? ($::Wizard_finished ? N("Finish") : N("Next")) : N("Ok");
-
- my @okcancel = grep { $_ } $ok, $cancel;
- @okcancel = reverse(@okcancel) if $::isWizard;
- my @buttons_text = (if_(@$l2, $common->{advanced_state} ? $common->{advanced_label_close} : $common->{advanced_label}), @okcancel);
- my ($buttonbar, @buttons) = Newt::Grid::ButtonBar(map { simplify_string($_) } @buttons_text);
- my $advanced_button = @$l2 && shift @buttons;
- @buttons = reverse(@buttons) if $::isWizard;
- my ($ok_button, $cancel_button) = @buttons;
-
- my $form = Newt::Component::Form(\undef, '', 0);
- my $window = Newt::Grid::GridBasicWindow(first(myTextbox(!$has_scroll, $height - $total_size, @messages)), $listg, $buttonbar);
- $window->GridWrappedWindow($common->{title} || '');
- $form->FormAddGrid($window, 1);
-
- my $check = sub {
- my ($f) = @_;
-
- my ($error, $_focus) = $f->();
-
- if ($error) {
- $set_all->();
- }
- !$error;
- };
-
- my ($blocked, $canceled);
- while (1) {
- my $r = $form->RunForm;
-
- $get_all->();
-
- if ($advanced_button && $$r == $$advanced_button) {
- invbool(\$common->{advanced_state});
- $form->FormDestroy;
- Newt::PopWindow();
- return &ask_fromW_real;
- }
-
- $canceled = $cancel_button && $$r == $$cancel_button;
-
- next if !$canceled && any { ${$_->{invalid_choice}} } @widgets;
-
- $blocked =
- $$r == $$ok_button &&
- $common->{callbacks}{ok_disabled} &&
- do { $common->{callbacks}{ok_disabled}() };
-
- if (my $button = find { $$r == ${$_->{w}} } @widgets) {
- my $v = $button->{e}{clicked_may_quit}();
- $form->FormDestroy;
- Newt::PopWindow();
- return $v || &ask_fromW;
- }
- last if !$blocked && $check->($common->{callbacks}{$canceled ? 'canceled' : 'complete'});
- }
-
- $form->FormDestroy;
- Newt::PopWindow();
- !$canceled;
-}
-
-
-sub waitbox {
- my ($title, $messages) = @_;
- my ($t, $w, $h) = myTextbox(1, $height, @$messages);
- my $f = Newt::Component::Form(\undef, '', 0);
- Newt::CenteredWindow($w, $h, $title);
- $f->FormAddComponent($t);
- $f->DrawForm;
- Newt::Refresh();
- $f->FormDestroy;
- push @wait_messages, $f;
- $f;
-}
-
-
-sub wait_messageW {
- my ($_o, $title, $messages) = @_;
- { form => waitbox($title, $messages), title => $title };
-}
-
-sub wait_message_nextW {
- my ($o, $messages, $w) = @_;
- $o->wait_message_endW($w);
- $o->wait_messageW($w->{title}, $messages);
-}
-sub wait_message_endW {
- my ($_o, $_w) = @_;
- my $_wait = pop @wait_messages;
-# log::l("interactive_newt does not handle none stacked wait-messages") if $w->{form} != $wait;
- Newt::PopWindow();
-}
-
-sub simplify_string {
- my ($s, $o_width) = @_;
- $s =~ s/\n/ /g;
- $s = substr($s, 0, $o_width || 40); #- truncate if too long
- $s;
-}
-
-sub ok {
- N("Ok");
-}
-
-sub cancel {
- N("Cancel");
-}
-
-1;
diff --git a/perl-install/interactive/stdio.pm b/perl-install/interactive/stdio.pm
deleted file mode 100644
index 8fd7a43ef..000000000
--- a/perl-install/interactive/stdio.pm
+++ /dev/null
@@ -1,180 +0,0 @@
-package interactive::stdio; # $Id$
-
-use diagnostics;
-use strict;
-use vars qw(@ISA);
-
-@ISA = qw(interactive);
-
-use interactive;
-use common;
-
-$| = 1;
-
-sub readln() {
- my $l = <STDIN>;
- chomp $l;
- $l;
-}
-
-sub check_it {
- my ($i, $n) = @_;
- $i =~ /^\s*\d+\s*$/ && 1 <= $i && $i <= $n
-}
-
-sub good_choice {
- my ($def_s, $max) = @_;
- my $i;
- do {
- defined $i and print N("Bad choice, try again\n");
- print N("Your choice? (default %s) ", $def_s);
- $i = readln();
- } until !$i || check_it($i, $max);
- $i;
-}
-
-sub ask_fromW {
- my ($_o, $common, $l, $_l2) = @_;
-
- add2hash_($common, { ok => N("Ok"), cancel => N("Cancel") }) if !exists $common->{ok};
-
-ask_fromW_begin:
-
- my $already_entries = 0;
- my $predo_widget = sub {
- my ($e) = @_;
-
- $e->{type} = 'list' if $e->{type} =~ /(icon|tree)list/;
- #- combo doesn't exist, fallback to a sensible default
- $e->{type} = $e->{not_edit} ? 'list' : 'entry' if $e->{type} eq 'combo';
-
- if ($e->{type} eq 'entry') {
- my $t = "\t$e->{label} $e->{text}\n";
- if ($already_entries) {
- length($already_entries) > 1 and print N("Entries you'll have to fill:\n%s", $already_entries);
- $already_entries = 1;
- print $t;
- } else {
- $already_entries = $t;
- }
- }
- };
-
- my @labels;
- my $format_label = sub { my ($e) = @_; return sprintf("`%s' %s %s\n", ${$e->{val}}, $e->{label}, $e->{text}) };
- my $do_widget = sub {
- my ($e, $ind) = @_;
-
- if ($e->{type} eq 'bool') {
- print "$e->{text} $e->{label}\n";
- print N("Your choice? (0/1, default `%s') ", ${$e->{val}} || '0');
- my $i = readln();
- if ($i) {
- to_bool($i) != to_bool(${$e->{val}}) and $common->{callbacks}{changed}->($ind);
- ${$e->{val}} = $i;
- }
- } elsif ($e->{type} =~ /list/) {
- $e->{text} || $e->{label} and print "=> $e->{label} $e->{text}\n";
- my $n = 0; my $size = 0;
- foreach (@{$e->{list}}) {
- $n++;
- my $t = "$n: " . may_apply($e->{format}, $_) . "\t";
- if ($size + length($t) >= 80) {
- print "\n";
- $size = 0;
- }
- print $t;
- $size += length($t);
- }
- print "\n";
- my $i = good_choice(may_apply($e->{format}, ${$e->{val}}), $n);
- print "Setting to <", $i ? ${$e->{list}}[$i-1] : ${$e->{val}}, ">\n";
- $i and ${$e->{val}} = ${$e->{list}}[$i-1], $common->{callbacks}{changed}->($ind);
- } elsif ($e->{type} eq 'button') {
- print N("Button `%s': %s", $e->{label}, may_apply($e->{format}, ${$e->{val}})), " $e->{text}\n";
- print N("Do you want to click on this button?");
- my $i = readln();
- $i && $i !~ /^n/i and $e->{clicked_may_quit}(), $common->{callbacks}{changed}->($ind);
- } elsif ($e->{type} eq 'label') {
- my $t = $format_label->($e);
- push @labels, $t;
- print $t;
- } elsif ($e->{type} eq 'entry') {
- print "$e->{label} $e->{text}\n";
- print N("Your choice? (default `%s'%s) ", ${$e->{val}}, ${$e->{val}} ? N(" enter `void' for void entry") : '');
- my $i = readln();
- ${$e->{val}} = $i || ${$e->{val}};
- ${$e->{val}} = '' if ${$e->{val}} eq 'void';
- print "Setting to <", ${$e->{val}}, ">\n";
- $i and $common->{callbacks}{changed}->($ind);
- } else {
- printf "UNSUPPORTED WIDGET TYPE (type <%s> label <%s> text <%s> val <%s>\n", $e->{type}, $e->{label}, $e->{text}, ${$e->{val}};
- }
- };
-
- print "* ";
- $common->{title} and print "$common->{title}\n";
- print(map { "$_\n" } @{$common->{messages}});
-
- $predo_widget->($_) foreach @$l;
- if (listlength(@$l) > 30) {
- my $ll = listlength(@$l);
- print N("=> There are many things to choose from (%s).\n", $ll);
-ask_fromW_handle_verylonglist:
- print
-N("Please choose the first number of the 10-range you wish to edit,
-or just hit Enter to proceed.
-Your choice? ");
- my $i = readln();
- if (check_it($i, $ll)) {
- each_index { $do_widget->($_, $::i) } grep_index { $::i >= $i-1 && $::i < $i+9 } @$l;
- goto ask_fromW_handle_verylonglist;
- }
- } else {
- each_index { $do_widget->($_, $::i) } @$l;
- }
-
- my $lab;
- each_index { $labels[$::i] && (($lab = $format_label->($_)) ne $labels[$::i]) and print N("=> Notice, a label changed:\n%s", $lab) }
- grep { $_->{type} eq 'label' } @$l;
-
- my $i;
- if (listlength(@$l) != 1 || $common->{ok} ne N("Ok") || $common->{cancel} ne N("Cancel")) {
- print "[1] ", $common->{ok} || N("Ok");
- $common->{cancel} and print " [2] $common->{cancel}";
- @$l and print " [9] ", N("Re-submit");
- print "\n";
- do {
- defined $i and print N("Bad choice, try again\n");
- print N("Your choice? (default %s) ", $common->{focus_cancel} ? $common->{cancel} : $common->{ok});
- $i = readln() || ($common->{focus_cancel} ? "2" : "1");
- } until check_it($i, 9);
- $i == 9 and goto ask_fromW_begin;
- } else {
- $i = 1;
- }
- my ($callback_error) = $common->{callbacks}{$i == 2 ? 'canceled' : 'complete'}->();
- $callback_error and goto ask_fromW_begin;
- return $i != 2;
-}
-
-sub wait_messageW {
- my ($_o, $_title, $message) = @_;
- print join "\n", @$message;
-}
-sub wait_message_nextW {
- my $m = join "\n", @{$_[1]};
- print "\r$m", ' ' x (60 - length $m);
-}
-sub wait_message_endW { print "\nDone\n" }
-
-sub ok {
- N("Ok");
-}
-
-sub cancel {
- N("Cancel");
-}
-
-1;
-