From 6ed6b5341362f87e3c70420f206a33f71c72a3de Mon Sep 17 00:00:00 2001 From: Thierry Vignaud Date: Tue, 23 Jul 2002 10:35:55 +0000 Subject: - Big Move 1: interactive::* hierarchy --- perl-install/Makefile | 6 +- perl-install/Makefile.config | 2 +- perl-install/Makefile.drakxtools | 4 +- perl-install/Xconfigurator.pm | 8 +- perl-install/diskdrake/interactive.pm | 2 +- perl-install/drakxtools.spec | 6 +- perl-install/install_any.pm | 2 +- perl-install/install_steps.pm | 2 +- perl-install/install_steps_gtk.pm | 6 +- perl-install/install_steps_interactive.pm | 4 +- perl-install/install_steps_newt.pm | 8 +- perl-install/install_steps_stdio.pm | 4 +- perl-install/interactive.pm | 12 +- perl-install/interactive/gtk.pm | 636 ++++++++++++++++++++++++++++++ perl-install/interactive/http.pm | 159 ++++++++ perl-install/interactive/newt.pm | 254 ++++++++++++ perl-install/interactive/stdio.pm | 171 ++++++++ perl-install/interactive_gtk.pm | 636 ------------------------------ perl-install/interactive_http.pm | 159 -------- perl-install/interactive_newt.pm | 254 ------------ perl-install/interactive_stdio.pm | 171 -------- perl-install/printerdrake.pm | 28 +- perl-install/services.pm | 2 +- perl-install/standalone/diskdrake | 2 +- perl-install/standalone/drakautoinst | 5 +- perl-install/standalone/drakboot | 2 +- perl-install/standalone/drakconnect | 2 +- perl-install/standalone/drakgw | 7 +- perl-install/standalone/drakxtv | 4 +- perl-install/standalone/mousedrake | 4 +- perl-install/standalone/tinyfirewall | 2 +- 31 files changed, 1279 insertions(+), 1285 deletions(-) create mode 100644 perl-install/interactive/gtk.pm create mode 100644 perl-install/interactive/http.pm create mode 100644 perl-install/interactive/newt.pm create mode 100644 perl-install/interactive/stdio.pm delete mode 100644 perl-install/interactive_gtk.pm delete mode 100644 perl-install/interactive_http.pm delete mode 100644 perl-install/interactive_newt.pm delete mode 100644 perl-install/interactive_stdio.pm (limited to 'perl-install') diff --git a/perl-install/Makefile b/perl-install/Makefile index 6011abac8..239c4248b 100644 --- a/perl-install/Makefile +++ b/perl-install/Makefile @@ -7,7 +7,7 @@ include Makefile.config POFILES = $(shell ls share/po/*.po) MOFILES = $(POFILES:%.po=%.mo) -DISTFILES = Makefile Makefile.config Newt apps.net_monitor diskdrake c ddcprobe drakxtools.spec pam.net_monitor serial_probe share/po sbus_probing resize_fat share/diskdrake.rc $(STANDALONEPMS) standalone/icons pixmaps network standalone/interactive_http rpcinfo-flushed.c *.pm security harddrake +DISTFILES = Makefile Makefile.config Newt apps.net_monitor diskdrake c ddcprobe drakxtools.spec pam.net_monitor serial_probe share/po sbus_probing resize_fat share/diskdrake.rc $(STANDALONEPMS) standalone/icons pixmaps network interactive standalone/interactive_http rpcinfo-flushed.c *.pm security harddrake OTHERS = $(OTHERDIRS) $(OTHERFILES) OTHERDIRS = tools/ddcprobe tools/serial_probe OTHERFILES = tools/rpcinfo-flushed.c @@ -23,7 +23,7 @@ TAGS: $(ALLPMS) @etags -o - $^ /usr/lib/perl5/*/*/MDK/Common/*.pm | ./perl2etags > $@ clean: - for i in $(DIRS) share/po; do $(MAKE) -C $$i clean; done + for i in $(DIRS) share/po; do $(MAKE) -C $$i clean; done;: rm -rf auto ../drakxtools.tar.bz2 find . -name "*~" -o -name ".#*" -o -name "TAGS" -o -name "*.old" | xargs rm -f @@ -34,7 +34,7 @@ check: localcopy: clean rm -rf standalone/pixmaps - $(MAKE) -C ../tools clean + $(MAKE) -C ../tools clean || : cd .. ; rm -rf $(PACKAGE)-$(PKGVERSION) ; cp -af perl-install $(PACKAGE)-$(PKGVERSION) ; cp -af $(OTHERS) $(PACKAGE)-$(PKGVERSION) cd find ../$(PACKAGE)-$(PKGVERSION) -name '*.pm' | xargs perl -pi -e 's/\s*use\s+(diagnostics|vars|strict)//g' diff --git a/perl-install/Makefile.config b/perl-install/Makefile.config index f7ce06dac..0081767ac 100644 --- a/perl-install/Makefile.config +++ b/perl-install/Makefile.config @@ -5,7 +5,7 @@ ARCH := $(patsubst sparc%,sparc,$(ARCH)) VERSION = 2.2.10-BOOT SUDO = sudo SO_FILES = c/blib/arch/auto/c/c.so -PMS = *.pm Newt/*.pm c/stuff.pm resize_fat/*.pm sbus_probing/*.pm network/*.pm diskdrake/*.pm harddrake/*.pm commands install2 g_auto_install live_install live_install2 share/advertising/*.pl +PMS = *.pm Newt/*.pm c/stuff.pm resize_fat/*.pm sbus_probing/*.pm network/*.pm interactive/*.pm diskdrake/*.pm harddrake/*.pm commands install2 g_auto_install live_install live_install2 share/advertising/*.pl STANDALONEPMS_ = diskdrake XFdrake mousedrake printerdrake logdrake keyboarddrake drakconnect drakbackup drakfont drakproxy localedrake net_monitor drakbug_report tinyfirewall drakxconf drakxservices draksec drakboot adduserdrake drakgw drakautoinst livedrake lsnetdrake scannerdrake fileshareset drakxtv drakfloppy harddrake2 drakTermServ service_harddrake service_harddrake.sh drakbug STANDALONEPMS = $(STANDALONEPMS_:%=standalone/%) ALLPMS = $(PMS) $(STANDALONEPMS) diff --git a/perl-install/Makefile.drakxtools b/perl-install/Makefile.drakxtools index 0801446f1..032556e50 100644 --- a/perl-install/Makefile.drakxtools +++ b/perl-install/Makefile.drakxtools @@ -26,7 +26,7 @@ $(DIRS): [ ! -e $@/Makefile ] || $(MAKE) -C $@ install: - mkdir -p $(BINDEST) $(ETCDEST) $(SBINDEST) $(DATADIR)/{harddrake,pixmaps} $(LIBDEST)/{network,security,harddrake} $(BINX11DEST) $(LIBX11DEST) $(PIXDIR) $(INITDIR) + mkdir -p $(BINDEST) $(ETCDEST) $(SBINDEST) $(DATADIR)/{harddrake,pixmaps} $(LIBDEST)/{network,security,harddrake,interactive} $(BINX11DEST) $(LIBX11DEST) $(PIXDIR) $(INITDIR) install -d $(INLIBDEST_DIRS:%=$(LIBDEST)/%) install $(STANDALONEPMS) $(SBINDEST) install -s rpcinfo-flushed ddcprobe/ddcxinfos serial_probe/serial_probe $(SBINDEST) @@ -35,7 +35,7 @@ install: mv -f $(SBINDEST)/lsnetdrake $(BINDEST)/lsnetdrake install -m 644 *.pm $(LIBDEST) - for i in network harddrake security; do install -m 644 $$i/*.pm $(LIBDEST)/$$i/;done + for i in network harddrake security interactive; do install -m 644 $$i/*.pm $(LIBDEST)/$$i/;done install -m 644 pixmaps/* $(PIXDIR) install -m 644 share/diskdrake.rc $(DATADIR)/$(NAME) diff --git a/perl-install/Xconfigurator.pm b/perl-install/Xconfigurator.pm index df67350e9..22864b6f5 100644 --- a/perl-install/Xconfigurator.pm +++ b/perl-install/Xconfigurator.pm @@ -638,7 +638,7 @@ sub testFinalConfig { print F "use lib qw(", join(' ', @INC), ");\n"; print F q{ require lang; - use interactive_gtk; + use interactive::gtk; use my_gtk qw(:wrappers); $::isStandalone = 1; @@ -664,7 +664,7 @@ sub testFinalConfig { -r "} . $::prefix . q{/$background" && -x "} . $::prefix . q{/$qiv" and system(($::testing ? "} . $::prefix . q{" : "chroot } . $::prefix . q{/ ") . "$qiv -y $background"); - my $in = interactive_gtk->new; + my $in = interactive::gtk->new; $in->exit($in->ask_yesorno('', [ _("Is this the correct setting?"), $text ], 0) ? 0 : 222); }; my $rc = close F; @@ -858,7 +858,7 @@ sub chooseResolutionsGtk { sub chooseResolutions { my ($in, $card, $chosen_depth, $chosen_w) = @_; - return chooseResolutionsGtk($card, $chosen_depth, $chosen_w) if $in->isa('interactive_gtk'); + return chooseResolutionsGtk($card, $chosen_depth, $chosen_w) if $in->isa('interactive::gtk'); my $best_w; my $allowed_depth = allowedDepth($card); @@ -1379,7 +1379,7 @@ _("I can setup your computer to automatically start the graphical interface (XFr Would you like XFree to start when you reboot?"), 1); any::runlevel($::prefix, $run ? 5 : 3) if !$::testing; } - if ($::isStandalone && $in->isa('interactive_gtk')) { + if ($::isStandalone && $in->isa('interactive::gtk')) { if (my $wm = any::running_window_manager()) { if ($in->ask_okcancel('', _("Please relog into %s to activate the changes", ucfirst (lc $wm)), 1)) { fork and $in->exit; diff --git a/perl-install/diskdrake/interactive.pm b/perl-install/diskdrake/interactive.pm index 8c49f9570..0cefc1d05 100644 --- a/perl-install/diskdrake/interactive.pm +++ b/perl-install/diskdrake/interactive.pm @@ -161,7 +161,7 @@ struct all_hds { sub main { my ($in, $all_hds) = @_; - if ($in->isa('interactive_gtk')) { + if ($in->isa('interactive::gtk')) { require diskdrake::hd_gtk; goto &diskdrake::hd_gtk::main; } diff --git a/perl-install/drakxtools.spec b/perl-install/drakxtools.spec index a682365c1..ebb084715 100644 --- a/perl-install/drakxtools.spec +++ b/perl-install/drakxtools.spec @@ -1,7 +1,7 @@ Summary: The drakxtools (XFdrake, diskdrake, keyboarddrake, mousedrake...) Name: drakxtools Version: 1.1.8 -Release: 8mdk +Release: 9mdk Url: http://www.linux-mandrake.com/en/drakx.php3 Source0: %name-%version.tar.bz2 License: GPL @@ -245,6 +245,10 @@ done %config(noreplace) %_sysconfdir/logrotate.d/drakxtools-http %changelog +* Tue Jul 23 2002 Thierry Vignaud 1.1.8-9mdk +- reorganization cleanup: + move interactive_* into interactive::* + * Sun Jul 21 2002 Pixel 1.1.8-8mdk - new snapshot (beware of XFdrake) diff --git a/perl-install/install_any.pm b/perl-install/install_any.pm index 4b701f5a8..2a93b2be1 100644 --- a/perl-install/install_any.pm +++ b/perl-install/install_any.pm @@ -1129,7 +1129,7 @@ sub check_prog { sub remove_unused { $::testing and return; - if ($::o->isa('interactive_gtk')) { + if ($::o->isa('interactive::gtk')) { unlink glob_("/lib/lib$_*") foreach qw(slang newt); unlink "/usr/bin/perl-install/auto/Newt/Newt.so"; } else { diff --git a/perl-install/install_steps.pm b/perl-install/install_steps.pm index c27787e38..53f32a45e 100644 --- a/perl-install/install_steps.pm +++ b/perl-install/install_steps.pm @@ -88,7 +88,7 @@ sub set_help { 1 } #------------------------------------------------------------------------------ sub selectLanguage { my ($o) = @_; - lang::set($o->{lang}, !$o->isa('interactive_gtk')); + lang::set($o->{lang}, !$o->isa('interactive::gtk')); $o->{langs} ||= { $o->{lang} => 1 }; log::l("selectLanguage: pack_langs ", lang::pack_langs($o->{langs})); diff --git a/perl-install/install_steps_gtk.pm b/perl-install/install_steps_gtk.pm index ef4c15d15..c2ec797cd 100644 --- a/perl-install/install_steps_gtk.pm +++ b/perl-install/install_steps_gtk.pm @@ -4,14 +4,14 @@ use diagnostics; use strict; use vars qw(@ISA); -@ISA = qw(install_steps_interactive interactive_gtk); +@ISA = qw(install_steps_interactive interactive::gtk); #-###################################################################################### #- misc imports #-###################################################################################### use pkgs; use install_steps_interactive; -use interactive_gtk; +use interactive::gtk; use common; use my_gtk qw(:helpers :wrappers); use Gtk; @@ -113,7 +113,7 @@ sub new($$) { $my_gtk::force_center = [ $::rootwidth - $::windowwidth, $::logoheight, $::windowwidth, $::windowheight ]; $o = (bless {}, ref $type || $type)->SUPER::new($o); - $o->interactive_gtk::new; + $o->interactive::gtk::new; $o; } diff --git a/perl-install/install_steps_interactive.pm b/perl-install/install_steps_interactive.pm index 069764f7d..4f04a8dcb 100644 --- a/perl-install/install_steps_interactive.pm +++ b/perl-install/install_steps_interactive.pm @@ -87,7 +87,7 @@ sub selectLanguage { $o->charsetChanged; - if ($o->isa('interactive_gtk')) { + if ($o->isa('interactive::gtk')) { $o->ask_warn('', formatAlaTeX( "If you see this message it is because you chose a language for which DrakX does not include a translation yet; however the fact @@ -406,7 +406,7 @@ Continue at your own risk!")); \&partition_table::description, \@l) or die "setstep exitInstall\n"; } install_any::use_root_part($o->{all_hds}, $p, $o->{prefix}); - } elsif ($::expert && $o->isa('interactive_gtk')) { + } elsif ($::expert && $o->isa('interactive::gtk')) { install_interactive::partition_with_diskdrake($o, $o->{all_hds}); } else { install_interactive::partitionWizard($o); diff --git a/perl-install/install_steps_newt.pm b/perl-install/install_steps_newt.pm index 2292094b0..1204c0729 100644 --- a/perl-install/install_steps_newt.pm +++ b/perl-install/install_steps_newt.pm @@ -4,13 +4,13 @@ use diagnostics; use strict; use vars qw(@ISA); -@ISA = qw(install_steps_interactive interactive_newt); +@ISA = qw(install_steps_interactive interactive::newt); #-###################################################################################### #- misc imports #-###################################################################################### use install_steps_interactive; -use interactive_newt; +use interactive::newt; use install_any; use devices; use lang; @@ -28,7 +28,7 @@ sub banner { sub new($$) { my ($type, $o) = @_; - interactive_newt->new; + interactive::newt->new; banner(''); Newt::PushHelpLine(_(" / between elements | selects | next screen ")); @@ -44,7 +44,7 @@ sub enteringStep { sub exitInstall { &install_steps_interactive::exitInstall; - interactive_newt::end; + interactive::newt::end; } #-###################################################################################### diff --git a/perl-install/install_steps_stdio.pm b/perl-install/install_steps_stdio.pm index 518640d29..1c0ea9abc 100644 --- a/perl-install/install_steps_stdio.pm +++ b/perl-install/install_steps_stdio.pm @@ -4,10 +4,10 @@ use diagnostics; use strict; use vars qw(@ISA); -@ISA = qw(install_steps_interactive interactive_stdio); +@ISA = qw(install_steps_interactive interactive::stdio); use common; -use interactive_stdio; +use interactive::stdio; use install_steps_interactive; use lang; diff --git a/perl-install/interactive.pm b/perl-install/interactive.pm index e978e9b6d..e217ecefb 100644 --- a/perl-install/interactive.pm +++ b/perl-install/interactive.pm @@ -73,8 +73,8 @@ sub vnew { my ($type, $su, $icon) = @_; $su = $su eq "su"; if ($ENV{INTERACTIVE_HTTP}) { - require interactive_http; - return interactive_http->new; + require interactive::http; + return interactive::http->new; } require c; if ($su) { @@ -89,9 +89,9 @@ sub vnew { exec {'consolehelper'} $0, @ARGV or die _("consolehelper missing"); } } - eval { require interactive_gtk }; + eval { require interactive::gtk }; if (!$@) { - my $o = interactive_gtk->new; + my $o = interactive::gtk->new; if ($icon && $icon ne 'default' && !$::isWizard) { $o->{icon} = $icon } else { undef $o->{icon} } return $o; } @@ -107,8 +107,8 @@ sub vnew { require 'log.pm'; undef *log::l; *log::l = sub {}; # otherwise, it will bother us :( - require interactive_newt; - interactive_newt->new; + require interactive::newt; + interactive::newt->new; } sub enter_console {} diff --git a/perl-install/interactive/gtk.pm b/perl-install/interactive/gtk.pm new file mode 100644 index 000000000..8c71711ef --- /dev/null +++ b/perl-install/interactive/gtk.pm @@ -0,0 +1,636 @@ +package interactive::gtk; # $Id$ + +use diagnostics; +use strict; +use vars qw(@ISA); + +@ISA = qw(interactive); + +use interactive; +use common; +use my_gtk qw(:helpers :wrappers); + +my $forgetTime = 1000; #- in milli-seconds + +sub new { + ($::windowheight, $::windowwidth) = my_gtk::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 { + gtkset_mousecursor_normal(); #- for restoring a normal in any case on standalone + my_gtk::flush(); + $::isEmbedded and kill 10, $::CCPID; #10 is USR1 + c::_exit($_[1]) #- workaround +} + +sub ask_warn { + local $my_gtk::pop_it = 1; + &interactive::ask_warn; +} + +sub ask_fileW { + my ($o, $title, $dir) = @_; + my $w = my_gtk->new($title); + $dir .= '/' if $dir !~ m|/$|; + my_gtk::_ask_file($w, $title, $dir); + $w->main; +} + +sub create_boxradio { + my ($e, $may_go_to_next, $changed, $double_click) = @_; + my @l = map { may_apply($e->{format}, $_) } @{$e->{list}}; + + my $boxradio = gtkpack2__(new Gtk::VBox(0, 0), + my @radios = gtkradio('', @l)); + $boxradio->show; + my $tips = new Gtk::Tooltips; + mapn { + my ($txt, $w) = @_; + $w->signal_connect(button_press_event => $double_click) if $double_click; + + $w->signal_connect(key_press_event => sub { + my ($w, $event) = @_; + $may_go_to_next->($w, $event, 'tab'); + 1; + }); + $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) = @_; + mapn { $_[0]->set_active($_[1] eq $v) } \@radios, $e->{list}; + }, $radios[0]; +} + +sub create_clist { + my ($e, $may_go_to_next, $changed, $double_click) = @_; + my $curr; + my @l = map { may_apply($e->{format}, $_) } @{$e->{list}}; + + my $list = new Gtk::CList(1); + $list->set_selection_mode('browse'); + $list->set_column_auto_resize(0, 1); + + my $select = sub { + $list->set_focus_row($_[0]); + $list->select_row($_[0], 0); + $list->moveto($_[0], 0, 0.5, 0) if $list->row_is_visible($_[0]) ne 'full'; + }; + +# ref $title && !@okcancel ? +# $list->signal_connect(button_release_event => $leave) : +# $list->signal_connect(button_press_event => sub { &$leave if $_[1]{type} =~ /^2/ }); + + my ($first_time, $starting_word, $start_reg) = (1, '', "^"); + my $timeout; + $list->signal_connect(key_press_event => sub { + my ($w, $event) = @_; + my $c = chr($event->{keyval} & 0xff); + + Gtk->timeout_remove($timeout) if $timeout; $timeout = ''; + + if ($event->{keyval} >= 0x100) { + &$may_go_to_next if $c eq "\r" || $c eq "\x8d"; + $starting_word = '' if $event->{keyval} != 0xffe4; # control + } else { + if ($event->{state} & 4) { + #- control pressed + $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 $word = quotemeta $starting_word; + my $j; for ($j = 0; $j < @l; $j++) { + $l[($j + $curr) % @l] =~ /$start_reg$word/i and last; + } + $j == @l ? + $starting_word = '' : + $select->(($j + $curr) % @l); + + $timeout = Gtk->timeout_add($forgetTime, sub { $timeout = $starting_word = ''; 0 } ); + } + 1; + }); + $list->show; + + $list->append($_) foreach @l; + + $list->signal_connect(select_row => sub { + my ($w, $row) = @_; + ${$e->{val}} = $e->{list}[$curr = $row]; + &$changed; + }); + $list->signal_connect(button_press_event => $double_click) if $double_click; + + $list, sub { + my ($v) = @_; + eval { + my $nb = find_index { $_ eq $v } @{$e->{list}}; + $select->($nb) if $nb != $list->focus_row; + }; + }; +} + +sub create_ctree { + my ($e, $may_go_to_next, $changed, $double_click, $tree_expanded) = @_; + my @l = map { may_apply($e->{format}, $_) } @{$e->{list}}; + + $tree_expanded = to_bool($tree_expanded); #- to reduce "Use of uninitialized value", especially when debugging + + my $sep = quotemeta $e->{separator}; + my $tree = Gtk::CTree->new(1, 0); + + 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->insert_node($s ? $parent->($s) : undef, undef, [$_], 5, (undef) x 4, 0, $tree_expanded); + $size++ if !$s; + $s .= "$_$e->{separator}"; + } + $wtree{$s}; + }; + foreach (@l) { + my ($root, $leaf) = /(.*)$sep(.+)/ ? ($1, $2) : ('', $_); + $wleaves{$_} = $tree->insert_node($parent->($root), undef, [$leaf], 5, (undef) x 4, 1, 0); + } + undef %wtree; + + my $select = sub { + my ($node) = @_; + for (my $c = $node; $c; $c = $c->row->parent) { + $tree->expand($c); + } + for (my $i = 0; $tree->node_nth($i); $i++) { + if ($tree->node_nth($i) == $node) { + $tree->set_focus_row($i); + last; + } + } + $tree->select($node); + $tree->node_moveto($node, 0, 0.5, 0) if $tree->node_is_visible($node) ne 'full'; + }; + + my $curr = $tree->node_nth(0); #- default value + $tree->set_column_auto_resize(0, 1); + $tree->set_selection_mode('browse'); + $tree->set_row_height($tree->style->font->ascent + $tree->style->font->descent + 1); + $tree->signal_connect(tree_select_row => sub { + $curr = $_[1]; + if ($curr->row->is_leaf) { + my @ll; for (my $c = $curr; $c; $c = $c->row->parent) { + unshift @ll, first $tree->node_get_pixtext($c, 0); + } + my $val = join $e->{separator}, @ll; + mapn { + ${$e->{val}} = $_[1] if $val eq $_[0] + } \@l, $e->{list}; + &$changed; + } else { + $tree->expand($curr) if $selected_via_click; + } + }); + my ($first_time, $starting_word, $start_reg) = (1, '', "^"); + my $timeout; + + my $toggle = sub { + $curr->row->is_leaf ? + &$may_go_to_next : + $tree->toggle_expansion($curr); + }; + $tree->signal_connect(key_press_event => sub { + my ($w, $event) = @_; + $selected_via_click = 0; + my $c = chr($event->{keyval} & 0xff); + $curr or return; + Gtk->timeout_remove($timeout) if $timeout; $timeout = ''; + + if ($event->{keyval} >= 0x100) { + &$toggle if $c eq "\r" || $c eq "\x8d"; + $starting_word = '' if $event->{keyval} != 0xffe4; # control + } else { + my $next; + if ($event->{state} & 4) { + #- control pressed + $c eq "s" or return 1; + $start_reg and $start_reg = '', return 1; + $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); + + $tree->pre_recursive(undef, sub { + my ($tree, $node) = @_; + $next &&= !$after; + $after ||= $node == $curr; + my ($t) = $tree->node_get_pixtext($node, 0); + + if ($t =~ /$start_reg$word/i) { + if ($after && !$next) { + ($best, $after) = ($node, 0); + } else { + $best ||= $node; + } + } + }); + if (defined $best) { + $select->($best); + } else { + $starting_word = ''; + } + $timeout = Gtk->timeout_add($forgetTime, sub { $timeout = $starting_word = ''; 0 }); + } + 1; + }); + $tree->signal_connect(button_press_event => sub { + $selected_via_click = 1; + &$double_click if $curr->row->is_leaf && $double_click; + }); + + $tree, sub { + my $v = may_apply($e->{format}, $_[0]); + $select->($wleaves{$v} || return) if $wleaves{$v} != $tree->selection; + }, $size; +} + +sub create_list { + my ($e, $may_go_to_next, $changed, $double_click) = @_; + my $l = $e->{list}; + my $list = new Gtk::List(); + $list->set_selection_mode('browse'); + + my $select = sub { + $list->select_item($_[0]); + }; + + my $tips = new Gtk::Tooltips; + my $toselect; + map_index { + my $item = new Gtk::ListItem(may_apply($e->{format}, $_)); + $item->signal_connect(key_press_event => sub { + my ($w, $event) = @_; + my $c = chr($event->{keyval} & 0xff); + $may_go_to_next->($event) if $event->{keyval} < 0x100 ? $c eq ' ' : $c eq "\r" || $c eq "\x8d"; + 1; + }); + $list->append_items($item); + $item->show; + 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); + }; + }; +} + +sub ask_fromW { + my ($o, $common, $l, $l2) = @_; + my $ignore = 0; #-to handle recursivity + + my $mainw = my_gtk->new($common->{title}, %$o); + $mainw->sync; # for XPM's creation + + #-the widgets + my (@widgets, @widgets_always, @widgets_advanced, $advanced, $advanced_pack, $has_horiz_scroll, $has_scroll, $total_size, $max_width); + my $tooltips = new Gtk::Tooltips; + + 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; + $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 $create_widget = sub { + my ($e, $ind) = @_; + + my $may_go_to_next = sub { + my ($w, $event, $kind) = @_; + if ($kind eq 'tab') { + if (($event->{keyval} & 0x7f) == 0x9) { + $w->signal_emit_stop("key_press_event"); + if ($ind == $#widgets) { + $mainw->{ok}->grab_focus; + } else { + $widgets[$ind+1]{focus_w}->grab_focus; + } + } + } else { + if (!$event || ($event->{keyval} & 0x7f) == 0xd) { + $w->signal_emit_stop("key_press_event") if $event; + if ($ind == $#widgets) { + @widgets == 1 ? $mainw->{ok}->clicked : $mainw->{ok}->grab_focus; + } else { + $widgets[$ind+1]{focus_w}->grab_focus; + } + } + } + }; + my $changed = sub { $update->(sub { $common->{callbacks}{changed}($ind) }) }; + + my ($w, $real_w, $focus_w, $set, $get, $expand, $size, $width); + if ($e->{type} eq 'iconlist') { + $w = new Gtk::Button; + $set = sub { + gtkdestroy($e->{icon}); + my $f = $e->{icon2f}->($_[0]); + $e->{icon} = -e $f ? + gtkpng($f) : + new Gtk::Label(may_apply($e->{format}, $_[0])); + $w->add($e->{icon}); + $e->{icon}->show; + }; + $w->signal_connect(clicked => sub { + $set->(${$e->{val}} = next_val_in_array(${$e->{val}}, $e->{list})); + $changed->(); + }); + $real_w = gtkpack_(new Gtk::HBox(0,10), 1, new Gtk::HBox(0,0), 0, $w, 1, new Gtk::HBox(0,0), ); + } elsif ($e->{type} eq 'bool') { + $w = Gtk::CheckButton->new($e->{text}); + $w->signal_connect(clicked => $changed); + $set = sub { $w->set_active($_[0]) }; + $get = sub { $w->get_active }; + $width = length $e->{text}; + } elsif ($e->{type} eq 'label') { + $w = Gtk::Label->new(${$e->{val}}); + $set = sub { $w->set($_[0]) }; + $width = length ${$e->{val}}; + } elsif ($e->{type} eq 'button') { + $w = Gtk::Button->new(''); + $w->signal_connect(clicked => sub { + $get_all->(); + if ($::isWizard) { + $mainw->{rwindow}->set_sensitive(0); + } else { + $mainw->{rwindow}->hide; + } + if (my $v = $e->{clicked_may_quit}()) { + $mainw->{retval} = $v; + Gtk->main_quit; + } + if ($::isWizard) { + $mainw->{rwindow}->set_sensitive(1); + } else { + $mainw->{rwindow}->show; + } + $set_all->(); + }); + $set = sub { $w->child->set(may_apply($e->{format}, $_[0])) }; + $width = length may_apply($e->{format}, ${$e->{val}}); + } elsif ($e->{type} eq 'range') { + my $adj = create_adjustment(${$e->{val}}, $e->{min}, $e->{max}); + $adj->signal_connect(value_changed => $changed); + $w = new Gtk::HScale($adj); + $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 }; + $size = 2; + } elsif ($e->{type} =~ /list/) { + + my $quit_if_double_click = + #- i'm the only one, double click means accepting + @$l == 1 || $e->{quit_if_double_click} ? + sub { if ($_[1]{type} =~ /^2/) { $mainw->{retval} = 1; Gtk->main_quit } } : ''; + + 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 (CList 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, $size) = create_ctree(@para, $e->{tree_expanded}); + } else { + ($w, $set, $focus_w) = $use_boxradio ? create_boxradio(@para) : create_clist(@para); + } + if (@{$e->{list}} > (@$l == 1 ? 10 : 4)) { + $has_scroll = 1; + $expand = 1; + $real_w = createScrolledWindow($w); + $size = (@$l == 1 ? 10 : 4); + } else { + $size ||= @{$e->{list}}; + } + $width = max(map { length } @{$e->{list}}); + } else { + if ($e->{type} eq "combo") { + $w = new Gtk::Combo; + $w->set_use_arrows_always(1); + $w->entry->set_editable(!$e->{not_edit}); + $w->set_popdown_strings(@{$e->{list}}); + $w->disable_activate; + ($real_w, $w) = ($w, $w->entry); + my @l = sort { $b <=> $a } map { length } @{$e->{list}}; + $has_horiz_scroll = 1; + $width = $l[@l / 16]; # take the third octile (think quartile) + } else { + $w = new Gtk::Entry; + $w->signal_connect(focus_in_event => sub { $w->select_region }); + $w->signal_connect(focus_out_event => sub { $w->select_region(0,0) }); + } + $w->signal_connect(key_press_event => $may_go_to_next); + $w->signal_connect(changed => $changed); + $w->set_visibility(0) if $e->{hidden}; + $set = sub { $w->set_text($_[0]) if $_[0] ne $w->get_text }; + $get = sub { $w->get_text }; + } + $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}); + + $max_width = max($max_width, $width); + $total_size += $size || 1; + + { e => $e, w => $w, real_w => $real_w || $w, focus_w => $focus_w || $w, expand => $expand, + get => $get || sub { ${$e->{val}} }, set => $set || sub {}, + icon_w => -e $e->{icon} ? gtkpng($e->{icon}) : '' }; + }; + @widgets_always = map_index { $create_widget->($_, $::i ) } @$l; + my $always_total_size = $total_size; + @widgets_advanced = map_index { $create_widget->($_, $::i + @$l) } @$l2; + my $advanced_total_size = $total_size - $always_total_size; + + + my $pack = create_box_with_title($mainw, @{$common->{messages}}); + my ($totalheight, $totalwidth) = ($mainw->{box_size}, 0); + + my $set_default_size = sub { + if (!$::isEmbedded && !$::isWizard || $my_gtk::pop_it) { + if ($has_scroll || $has_horiz_scroll) { + $mainw->{rwindow}->set_default_size($totalwidth+6+$my_gtk::shape_width, $has_scroll ? $totalheight+6+3+$my_gtk::shape_width : 0); + } + } + }; + + my $set_advanced = sub { + ($advanced) = @_; + $set_default_size->() if $advanced; + $advanced ? $advanced_pack->show : $advanced_pack->hide; + @widgets = (@widgets_always, $advanced ? @widgets_advanced : ()); + $mainw->sync; #- for $set_all below (mainly for the set of clist) + $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($advanced ? $common->{advanced_label_close} : $common->{advanced_label}); + } ]; + + my $create_widgets = sub { + my ($size, @widgets) = @_; + my $w = create_packtable({}, map { [($_->{icon_w}, $_->{e}{label}, $_->{real_w})]} @widgets); + + $size && $total_size or return $w; #- do not bother computing stupid/bad things + my $ratio = max($size / $total_size, 0.2); + + my ($possibleheight, $possiblewidth) = $::isEmbedded && !$my_gtk::pop_it ? (450, 380) : ($::windowheight * 0.8, $::windowwidth * 0.8); + $possibleheight -= $mainw->{box_size}; + + my $wantedwidth = max(250, $max_width * 5); + my $width = min($possiblewidth, $wantedwidth); + + my $wantedheight = my_gtk::n_line_size($size, 'various', $mainw->{rwindow}); + my $height = min($possibleheight * $ratio, max(200, $wantedheight)); + + $totalheight += $height; + $totalwidth = max($width, $totalwidth); + + my $has = $wantedwidth > $width || $wantedheight > $height; + $has_scroll ||= $has; + $has ? createScrolledWindow($w) : $w; + }; + + gtkpack_($pack, + 1, $create_widgets->($always_total_size, @widgets_always), + if_($common->{ok} || $::isWizard, + 0, $mainw->create_okcancel($common->{ok}, $common->{cancel}, '', if_(@$l2, $advanced_button)))); + my $has_scroll_always = $has_scroll; + my @adv = map { warp_text($_) } @{$common->{advanced_messages}}; + $advanced_pack = + gtkpack_(new Gtk::VBox(0,0), + 0, '', + (map {; 0, new Gtk::Label($_) } @adv), + 0, new Gtk::HSeparator, + 1, $create_widgets->($advanced_total_size, @widgets_advanced)); + + $pack->pack_start($advanced_pack, 1, 1, 0); + gtkadd($mainw->{window}, $pack); + $set_default_size->() if $has_scroll_always; + $set_advanced->(0); + (@widgets ? $widgets[0]{focus_w} : $common->{focus_cancel} ? $mainw->{cancel} : $mainw->{ok})->grab_focus(); + + my $check = sub { + my ($f) = @_; + sub { + $get_all->(); + my ($error, $focus) = $f->(); + + if ($error) { + $set_all->(); + $widgets[$focus || 0]{focus_w}->grab_focus(); + } + !$error; + } + }; + $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(@_) } }); + my_gtk::ask_browse_tree_info($common); +} + +sub wait_messageW($$$) { + my ($o, $title, $messages) = @_; + + local $my_gtk::pop_it = 1; + my $w = my_gtk->new($title, %$o, grab => 1); + gtkadd($w->{window}, my $hbox = new Gtk::HBox(0,0)); + $hbox->pack_start(my $box = new Gtk::VBox(0,0), 1, 1, 10); + $box->pack_start($_, 1, 1, 4) foreach my @l = map { new Gtk::Label(scalar warp_text($_)) } @$messages; + + ($w->{wait_messageW} = $l[$#l])->signal_connect(expose_event => sub { $w->{displayed} = 1 }); + $w->{rwindow}->set_position('center') if ($::isStandalone && (!$::isEmbedded && !$::isWizard || $my_gtk::pop_it)); + $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) = @_; + $o->{before_killing} ||= 0; + + while (my $e = shift @tempory::objects) { $e->destroy } + while (@interactive::objects > $o->{before_killing}) { + my $w = pop @interactive::objects; + $w->destroy; + } + $o->{before_killing} = @interactive::objects; +} + +1; diff --git a/perl-install/interactive/http.pm b/perl-install/interactive/http.pm new file mode 100644 index 000000000..785446c46 --- /dev/null +++ b/perl-install/interactive/http.pm @@ -0,0 +1,159 @@ +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 $uid; +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 ($title) = @_; + print CGI::start_html(-title => $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 "\n"; + + map_index { + my $e = $_; + + print "\n"; + } @$l; + + print "
$e->{label}\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 "
\n"; + print $q->p(); + print $q->submit(-name => 'ok_submit', -value => $common->{ok} || _("Ok")); + print $q->submit(-name => 'cancel_submit', -value => $common->{cancel}) if $common->{cancel}; + print $q->hidden('state'), $q->hidden('uid'); + print $q->end_form, $q->end_html; + + close STDOUT; # page terminated + + while (1) { + local *F; + open 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(_("Error")); + print $q->h1(_("Error")), $q->p("Sorry, you can't go back"); + goto redisplay; + } + map_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(_("Done")); + print "\n" . CGI::p(); +} + + + +1; diff --git a/perl-install/interactive/newt.pm b/perl-install/interactive/newt.pm new file mode 100644 index 000000000..da18c198a --- /dev/null +++ b/perl-install/interactive/newt.pm @@ -0,0 +1,254 @@ +package interactivew::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() { + Newt::Init; + 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 myTextbox { + my $allow_scroll = shift; + + my $width = $width - 9; + my @l = map { /(.{1,$width})/g } map { split "\n" } @_; + my $h = min($height - 13, int @l); + my $flag = 1 << 6; + if ($h < @l) { + if ($allow_scroll) { + $flag |= 1 << 2; #- NEWT_FLAG_SCROLL + } 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, $flag); + $mess->TextboxSetText(join("\n", @_)); + $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) = @_; + my $ignore; #-to handle recursivity + my $old_focus = -2; + + #-the widgets + my (@widgets, $total_size); + + 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} =~ /(icon|tree)list/; + + #- 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); + if ($e->{type} eq 'bool') { + $w = Newt::Component::Checkbox(-1, -1, $e->{text} || '', checkval(${$e->{val}}), " *"); + $set = sub { $w->CheckboxSetValue(checkval($_[0])) }; + $get = sub { $w->CheckboxGetValue == ord '*' }; + } elsif ($e->{type} eq 'button') { + $w = Newt::Component::Button(-1, -1, simplify_string(may_apply($e->{format}, ${$e->{val}}))); + } elsif ($e->{type} =~ /list/) { + my ($h, $wi) = (@$l == 1 && $height > 30 ? 10 : 5, 20); + my $scroll = @{$e->{list}} > $h ? 1 << 2 : 0; + $size = min(int @{$e->{list}}, $h); + + $w = Newt::Component::Listbox(-1, -1, $h, $scroll); #- NEWT_FLAG_SCROLL + foreach (@{$e->{list}}) { + my $t = simplify_string(may_apply($e->{format}, $_)); + $w->ListboxAddEntry($t, $_); + $wi = max($wi, length $t); + } + $w->ListboxSetWidth(min($wi + 3, $width - 7)); # 3 added for the scrollbar (?) + $get = sub { $w->ListboxGetCurrent }; + $set = sub { + my ($val) = @_; + map_index { + $w->ListboxSetCurrent($::i) if $val eq $_; + } @{$e->{list}}; + }; + } else { + $w = Newt::Component::Entry(-1, -1, '', 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 {} }; + }; + @widgets = map_index { $create_widget->($_, $::i) } @$l; + + $_->{w}->addCallback($_->{callback}) foreach @widgets; + + $set_all->(); + + my $grid = Newt::Grid::CreateGrid(3, max(1, int @$l)); + map_index { + $grid->GridSetField(0, $::i, 1, ${Newt::Component::Label(-1, -1, $_->{e}{label})}, 0, 0, 1, 0, 1, 0); + $grid->GridSetField(1, $::i, 1, ${$_->{real_w}}, 0, 0, 0, 0, 1, 0); + } @widgets; + + my $listg = do { + my $height = 18; + #- 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 ((((grep { $_->{type} eq 'bool' } @$l) > 6) || + ((@$l) > 3)) && $total_size > $height) { + $grid->GridPlace(1, 1); #- Uh?? otherwise the size allocated is bad + + my $scroll = Newt::Component::VerticalScrollbar(-1, -1, $height, 9, 10); + my $subf = $scroll->Form('', 0); + $subf->FormSetHeight($height); + $subf->FormAddGrid($grid, 0); + Newt::Grid::HCloseStacked($subf, separator(1, $height), $scroll); + } else { + $grid; + } + }; + my ($buttons, $ok, $cancel) = Newt::Grid::ButtonBar(simplify_string($common->{ok} || _("Ok")), + if_($common->{cancel}, simplify_string($common->{cancel}))); + + my $form = Newt::Component::Form(\undef, '', 0); + my $window = Newt::Grid::GridBasicWindow(first(myTextbox(@widgets == 0, @{$common->{messages}})), $listg, $buttons); + $window->GridWrappedWindow($common->{title} || ''); + $form->FormAddGrid($window, 1); + + my $check = sub { + my ($f) = @_; + + $get_all->(); + my ($error, $focus) = $f->(); + + if ($error) { + $set_all->(); + } + !$error; + }; + + my ($destroyed, $canceled); + do { + my $r = do { + local $::setstep = 1; + $form->RunForm; + }; + $canceled = $cancel && $$r == $$cancel; + + if (my ($button) = grep { $$r == ${$_->{w}} } @widgets) { + $get_all->(); + my $v = do { + local $::setstep = 1; + $button->{e}{clicked_may_quit}(); + }; + $form->FormDestroy; + Newt::PopWindow; + return $v || &ask_fromW; + } + } until ($check->($common->{callbacks}{$canceled ? 'canceled' : 'complete'})); + + $form->FormDestroy; + Newt::PopWindow; + !$canceled; +} + + +sub waitbox { + my ($title, $messages) = @_; + my ($t, $w, $h) = myTextbox(1, @$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) = @_; + $s =~ s/\n/ /g; + $s = substr($s, 0, 40); #- truncate if too long + $s; +} + +1; diff --git a/perl-install/interactive/stdio.pm b/perl-install/interactive/stdio.pm new file mode 100644 index 000000000..126e1d897 --- /dev/null +++ b/perl-install/interactive/stdio.pm @@ -0,0 +1,171 @@ +package interactivew::stdio; # $Id$ + +use diagnostics; +use strict; +use vars qw(@ISA); + +@ISA = qw(interactive); + +use interactive; +use common; + +$| = 1; + +sub readln { + my $l = ; + 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 _("Bad choice, try again\n"); + print _("Your choice? (default %s) ", $def_s); + $i = readln(); + } until (!$i || check_it($i, $max)); + $i; +} + +sub ask_fromW { + my ($o, $common, $l, $l2) = @_; + +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 _("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 "`${$e->{val}}' $e->{label} $e->{text}\n"; }; + my $do_widget = sub { + my ($e, $ind) = @_; + + if ($e->{type} eq 'bool') { + print "$e->{text} $e->{label}\n"; + print _("Your choice? (0/1, default `%s') ", ${$e->{val}} || '0'); + my $i = readln(); + if ($i ne '') { + 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; my $def_n = 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); + ${$e->{val}} eq $_ and $def_n = $n; + } + 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 _("Button `%s': %s", $e->{label}, may_apply($e->{format}, ${$e->{val}})), " $e->{text}\n"; + print _("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 _("Your choice? (default `%s'%s) ", ${$e->{val}}, ${$e->{val}} ne '' ? _(" 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 { + print "UNSUPPORTED WIDGET TYPE (type <$e->{type}> label <$e->{label}> text <$e->{text}> val <${$e->{val}}>\n"; + } + }; + + 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 _("=> There are many things to choose from (%s).\n", $ll); +ask_fromW_handle_verylonglist: + print _( +"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)) { + map_index { $do_widget->($_, $::i) } grep_index { $::i >= $i-1 && $::i < $i+9 } @$l; + goto ask_fromW_handle_verylonglist; + } + } else { + map_index { $do_widget->($_, $::i) } @$l; + } + + my $lab; + map_index { $labels[$::i] && (($lab = $format_label->($_)) ne $labels[$::i]) and print _("=> Notice, a label changed:\n%s", $lab); } + grep { $_->{type} eq 'label' } @$l; + + my $i; + if (listlength(@$l) != 1 || $common->{ok} ne _("Ok") || $common->{cancel} ne _("Cancel")) { + print "[1] ", $common->{ok} || _("Ok"); + $common->{cancel} and print " [2] $common->{cancel}"; + @$l and print " [9] ", _("Re-submit"); + print "\n"; + do { + defined $i and print _("Bad choice, try again\n"); + print _("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" } + +1; + diff --git a/perl-install/interactive_gtk.pm b/perl-install/interactive_gtk.pm deleted file mode 100644 index 4a4504997..000000000 --- a/perl-install/interactive_gtk.pm +++ /dev/null @@ -1,636 +0,0 @@ -package interactive_gtk; # $Id$ - -use diagnostics; -use strict; -use vars qw(@ISA); - -@ISA = qw(interactive); - -use interactive; -use common; -use my_gtk qw(:helpers :wrappers); - -my $forgetTime = 1000; #- in milli-seconds - -sub new { - ($::windowheight, $::windowwidth) = my_gtk::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 { - gtkset_mousecursor_normal(); #- for restoring a normal in any case on standalone - my_gtk::flush(); - $::isEmbedded and kill 10, $::CCPID; #10 is USR1 - c::_exit($_[1]) #- workaround -} - -sub ask_warn { - local $my_gtk::pop_it = 1; - &interactive::ask_warn; -} - -sub ask_fileW { - my ($o, $title, $dir) = @_; - my $w = my_gtk->new($title); - $dir .= '/' if $dir !~ m|/$|; - my_gtk::_ask_file($w, $title, $dir); - $w->main; -} - -sub create_boxradio { - my ($e, $may_go_to_next, $changed, $double_click) = @_; - my @l = map { may_apply($e->{format}, $_) } @{$e->{list}}; - - my $boxradio = gtkpack2__(new Gtk::VBox(0, 0), - my @radios = gtkradio('', @l)); - $boxradio->show; - my $tips = new Gtk::Tooltips; - mapn { - my ($txt, $w) = @_; - $w->signal_connect(button_press_event => $double_click) if $double_click; - - $w->signal_connect(key_press_event => sub { - my ($w, $event) = @_; - $may_go_to_next->($w, $event, 'tab'); - 1; - }); - $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) = @_; - mapn { $_[0]->set_active($_[1] eq $v) } \@radios, $e->{list}; - }, $radios[0]; -} - -sub create_clist { - my ($e, $may_go_to_next, $changed, $double_click) = @_; - my $curr; - my @l = map { may_apply($e->{format}, $_) } @{$e->{list}}; - - my $list = new Gtk::CList(1); - $list->set_selection_mode('browse'); - $list->set_column_auto_resize(0, 1); - - my $select = sub { - $list->set_focus_row($_[0]); - $list->select_row($_[0], 0); - $list->moveto($_[0], 0, 0.5, 0) if $list->row_is_visible($_[0]) ne 'full'; - }; - -# ref $title && !@okcancel ? -# $list->signal_connect(button_release_event => $leave) : -# $list->signal_connect(button_press_event => sub { &$leave if $_[1]{type} =~ /^2/ }); - - my ($first_time, $starting_word, $start_reg) = (1, '', "^"); - my $timeout; - $list->signal_connect(key_press_event => sub { - my ($w, $event) = @_; - my $c = chr($event->{keyval} & 0xff); - - Gtk->timeout_remove($timeout) if $timeout; $timeout = ''; - - if ($event->{keyval} >= 0x100) { - &$may_go_to_next if $c eq "\r" || $c eq "\x8d"; - $starting_word = '' if $event->{keyval} != 0xffe4; # control - } else { - if ($event->{state} & 4) { - #- control pressed - $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 $word = quotemeta $starting_word; - my $j; for ($j = 0; $j < @l; $j++) { - $l[($j + $curr) % @l] =~ /$start_reg$word/i and last; - } - $j == @l ? - $starting_word = '' : - $select->(($j + $curr) % @l); - - $timeout = Gtk->timeout_add($forgetTime, sub { $timeout = $starting_word = ''; 0 } ); - } - 1; - }); - $list->show; - - $list->append($_) foreach @l; - - $list->signal_connect(select_row => sub { - my ($w, $row) = @_; - ${$e->{val}} = $e->{list}[$curr = $row]; - &$changed; - }); - $list->signal_connect(button_press_event => $double_click) if $double_click; - - $list, sub { - my ($v) = @_; - eval { - my $nb = find_index { $_ eq $v } @{$e->{list}}; - $select->($nb) if $nb != $list->focus_row; - }; - }; -} - -sub create_ctree { - my ($e, $may_go_to_next, $changed, $double_click, $tree_expanded) = @_; - my @l = map { may_apply($e->{format}, $_) } @{$e->{list}}; - - $tree_expanded = to_bool($tree_expanded); #- to reduce "Use of uninitialized value", especially when debugging - - my $sep = quotemeta $e->{separator}; - my $tree = Gtk::CTree->new(1, 0); - - 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->insert_node($s ? $parent->($s) : undef, undef, [$_], 5, (undef) x 4, 0, $tree_expanded); - $size++ if !$s; - $s .= "$_$e->{separator}"; - } - $wtree{$s}; - }; - foreach (@l) { - my ($root, $leaf) = /(.*)$sep(.+)/ ? ($1, $2) : ('', $_); - $wleaves{$_} = $tree->insert_node($parent->($root), undef, [$leaf], 5, (undef) x 4, 1, 0); - } - undef %wtree; - - my $select = sub { - my ($node) = @_; - for (my $c = $node; $c; $c = $c->row->parent) { - $tree->expand($c); - } - for (my $i = 0; $tree->node_nth($i); $i++) { - if ($tree->node_nth($i) == $node) { - $tree->set_focus_row($i); - last; - } - } - $tree->select($node); - $tree->node_moveto($node, 0, 0.5, 0) if $tree->node_is_visible($node) ne 'full'; - }; - - my $curr = $tree->node_nth(0); #- default value - $tree->set_column_auto_resize(0, 1); - $tree->set_selection_mode('browse'); - $tree->set_row_height($tree->style->font->ascent + $tree->style->font->descent + 1); - $tree->signal_connect(tree_select_row => sub { - $curr = $_[1]; - if ($curr->row->is_leaf) { - my @ll; for (my $c = $curr; $c; $c = $c->row->parent) { - unshift @ll, first $tree->node_get_pixtext($c, 0); - } - my $val = join $e->{separator}, @ll; - mapn { - ${$e->{val}} = $_[1] if $val eq $_[0] - } \@l, $e->{list}; - &$changed; - } else { - $tree->expand($curr) if $selected_via_click; - } - }); - my ($first_time, $starting_word, $start_reg) = (1, '', "^"); - my $timeout; - - my $toggle = sub { - $curr->row->is_leaf ? - &$may_go_to_next : - $tree->toggle_expansion($curr); - }; - $tree->signal_connect(key_press_event => sub { - my ($w, $event) = @_; - $selected_via_click = 0; - my $c = chr($event->{keyval} & 0xff); - $curr or return; - Gtk->timeout_remove($timeout) if $timeout; $timeout = ''; - - if ($event->{keyval} >= 0x100) { - &$toggle if $c eq "\r" || $c eq "\x8d"; - $starting_word = '' if $event->{keyval} != 0xffe4; # control - } else { - my $next; - if ($event->{state} & 4) { - #- control pressed - $c eq "s" or return 1; - $start_reg and $start_reg = '', return 1; - $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); - - $tree->pre_recursive(undef, sub { - my ($tree, $node) = @_; - $next &&= !$after; - $after ||= $node == $curr; - my ($t) = $tree->node_get_pixtext($node, 0); - - if ($t =~ /$start_reg$word/i) { - if ($after && !$next) { - ($best, $after) = ($node, 0); - } else { - $best ||= $node; - } - } - }); - if (defined $best) { - $select->($best); - } else { - $starting_word = ''; - } - $timeout = Gtk->timeout_add($forgetTime, sub { $timeout = $starting_word = ''; 0 }); - } - 1; - }); - $tree->signal_connect(button_press_event => sub { - $selected_via_click = 1; - &$double_click if $curr->row->is_leaf && $double_click; - }); - - $tree, sub { - my $v = may_apply($e->{format}, $_[0]); - $select->($wleaves{$v} || return) if $wleaves{$v} != $tree->selection; - }, $size; -} - -sub create_list { - my ($e, $may_go_to_next, $changed, $double_click) = @_; - my $l = $e->{list}; - my $list = new Gtk::List(); - $list->set_selection_mode('browse'); - - my $select = sub { - $list->select_item($_[0]); - }; - - my $tips = new Gtk::Tooltips; - my $toselect; - map_index { - my $item = new Gtk::ListItem(may_apply($e->{format}, $_)); - $item->signal_connect(key_press_event => sub { - my ($w, $event) = @_; - my $c = chr($event->{keyval} & 0xff); - $may_go_to_next->($event) if $event->{keyval} < 0x100 ? $c eq ' ' : $c eq "\r" || $c eq "\x8d"; - 1; - }); - $list->append_items($item); - $item->show; - 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); - }; - }; -} - -sub ask_fromW { - my ($o, $common, $l, $l2) = @_; - my $ignore = 0; #-to handle recursivity - - my $mainw = my_gtk->new($common->{title}, %$o); - $mainw->sync; # for XPM's creation - - #-the widgets - my (@widgets, @widgets_always, @widgets_advanced, $advanced, $advanced_pack, $has_horiz_scroll, $has_scroll, $total_size, $max_width); - my $tooltips = new Gtk::Tooltips; - - 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; - $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 $create_widget = sub { - my ($e, $ind) = @_; - - my $may_go_to_next = sub { - my ($w, $event, $kind) = @_; - if ($kind eq 'tab') { - if (($event->{keyval} & 0x7f) == 0x9) { - $w->signal_emit_stop("key_press_event"); - if ($ind == $#widgets) { - $mainw->{ok}->grab_focus; - } else { - $widgets[$ind+1]{focus_w}->grab_focus; - } - } - } else { - if (!$event || ($event->{keyval} & 0x7f) == 0xd) { - $w->signal_emit_stop("key_press_event") if $event; - if ($ind == $#widgets) { - @widgets == 1 ? $mainw->{ok}->clicked : $mainw->{ok}->grab_focus; - } else { - $widgets[$ind+1]{focus_w}->grab_focus; - } - } - } - }; - my $changed = sub { $update->(sub { $common->{callbacks}{changed}($ind) }) }; - - my ($w, $real_w, $focus_w, $set, $get, $expand, $size, $width); - if ($e->{type} eq 'iconlist') { - $w = new Gtk::Button; - $set = sub { - gtkdestroy($e->{icon}); - my $f = $e->{icon2f}->($_[0]); - $e->{icon} = -e $f ? - gtkpng($f) : - new Gtk::Label(may_apply($e->{format}, $_[0])); - $w->add($e->{icon}); - $e->{icon}->show; - }; - $w->signal_connect(clicked => sub { - $set->(${$e->{val}} = next_val_in_array(${$e->{val}}, $e->{list})); - $changed->(); - }); - $real_w = gtkpack_(new Gtk::HBox(0,10), 1, new Gtk::HBox(0,0), 0, $w, 1, new Gtk::HBox(0,0), ); - } elsif ($e->{type} eq 'bool') { - $w = Gtk::CheckButton->new($e->{text}); - $w->signal_connect(clicked => $changed); - $set = sub { $w->set_active($_[0]) }; - $get = sub { $w->get_active }; - $width = length $e->{text}; - } elsif ($e->{type} eq 'label') { - $w = Gtk::Label->new(${$e->{val}}); - $set = sub { $w->set($_[0]) }; - $width = length ${$e->{val}}; - } elsif ($e->{type} eq 'button') { - $w = Gtk::Button->new(''); - $w->signal_connect(clicked => sub { - $get_all->(); - if ($::isWizard) { - $mainw->{rwindow}->set_sensitive(0); - } else { - $mainw->{rwindow}->hide; - } - if (my $v = $e->{clicked_may_quit}()) { - $mainw->{retval} = $v; - Gtk->main_quit; - } - if ($::isWizard) { - $mainw->{rwindow}->set_sensitive(1); - } else { - $mainw->{rwindow}->show; - } - $set_all->(); - }); - $set = sub { $w->child->set(may_apply($e->{format}, $_[0])) }; - $width = length may_apply($e->{format}, ${$e->{val}}); - } elsif ($e->{type} eq 'range') { - my $adj = create_adjustment(${$e->{val}}, $e->{min}, $e->{max}); - $adj->signal_connect(value_changed => $changed); - $w = new Gtk::HScale($adj); - $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 }; - $size = 2; - } elsif ($e->{type} =~ /list/) { - - my $quit_if_double_click = - #- i'm the only one, double click means accepting - @$l == 1 || $e->{quit_if_double_click} ? - sub { if ($_[1]{type} =~ /^2/) { $mainw->{retval} = 1; Gtk->main_quit } } : ''; - - 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 (CList 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, $size) = create_ctree(@para, $e->{tree_expanded}); - } else { - ($w, $set, $focus_w) = $use_boxradio ? create_boxradio(@para) : create_clist(@para); - } - if (@{$e->{list}} > (@$l == 1 ? 10 : 4)) { - $has_scroll = 1; - $expand = 1; - $real_w = createScrolledWindow($w); - $size = (@$l == 1 ? 10 : 4); - } else { - $size ||= @{$e->{list}}; - } - $width = max(map { length } @{$e->{list}}); - } else { - if ($e->{type} eq "combo") { - $w = new Gtk::Combo; - $w->set_use_arrows_always(1); - $w->entry->set_editable(!$e->{not_edit}); - $w->set_popdown_strings(@{$e->{list}}); - $w->disable_activate; - ($real_w, $w) = ($w, $w->entry); - my @l = sort { $b <=> $a } map { length } @{$e->{list}}; - $has_horiz_scroll = 1; - $width = $l[@l / 16]; # take the third octile (think quartile) - } else { - $w = new Gtk::Entry; - $w->signal_connect(focus_in_event => sub { $w->select_region }); - $w->signal_connect(focus_out_event => sub { $w->select_region(0,0) }); - } - $w->signal_connect(key_press_event => $may_go_to_next); - $w->signal_connect(changed => $changed); - $w->set_visibility(0) if $e->{hidden}; - $set = sub { $w->set_text($_[0]) if $_[0] ne $w->get_text }; - $get = sub { $w->get_text }; - } - $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}); - - $max_width = max($max_width, $width); - $total_size += $size || 1; - - { e => $e, w => $w, real_w => $real_w || $w, focus_w => $focus_w || $w, expand => $expand, - get => $get || sub { ${$e->{val}} }, set => $set || sub {}, - icon_w => -e $e->{icon} ? gtkpng($e->{icon}) : '' }; - }; - @widgets_always = map_index { $create_widget->($_, $::i ) } @$l; - my $always_total_size = $total_size; - @widgets_advanced = map_index { $create_widget->($_, $::i + @$l) } @$l2; - my $advanced_total_size = $total_size - $always_total_size; - - - my $pack = create_box_with_title($mainw, @{$common->{messages}}); - my ($totalheight, $totalwidth) = ($mainw->{box_size}, 0); - - my $set_default_size = sub { - if (!$::isEmbedded && !$::isWizard || $my_gtk::pop_it) { - if ($has_scroll || $has_horiz_scroll) { - $mainw->{rwindow}->set_default_size($totalwidth+6+$my_gtk::shape_width, $has_scroll ? $totalheight+6+3+$my_gtk::shape_width : 0); - } - } - }; - - my $set_advanced = sub { - ($advanced) = @_; - $set_default_size->() if $advanced; - $advanced ? $advanced_pack->show : $advanced_pack->hide; - @widgets = (@widgets_always, $advanced ? @widgets_advanced : ()); - $mainw->sync; #- for $set_all below (mainly for the set of clist) - $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($advanced ? $common->{advanced_label_close} : $common->{advanced_label}); - } ]; - - my $create_widgets = sub { - my ($size, @widgets) = @_; - my $w = create_packtable({}, map { [($_->{icon_w}, $_->{e}{label}, $_->{real_w})]} @widgets); - - $size && $total_size or return $w; #- do not bother computing stupid/bad things - my $ratio = max($size / $total_size, 0.2); - - my ($possibleheight, $possiblewidth) = $::isEmbedded && !$my_gtk::pop_it ? (450, 380) : ($::windowheight * 0.8, $::windowwidth * 0.8); - $possibleheight -= $mainw->{box_size}; - - my $wantedwidth = max(250, $max_width * 5); - my $width = min($possiblewidth, $wantedwidth); - - my $wantedheight = my_gtk::n_line_size($size, 'various', $mainw->{rwindow}); - my $height = min($possibleheight * $ratio, max(200, $wantedheight)); - - $totalheight += $height; - $totalwidth = max($width, $totalwidth); - - my $has = $wantedwidth > $width || $wantedheight > $height; - $has_scroll ||= $has; - $has ? createScrolledWindow($w) : $w; - }; - - gtkpack_($pack, - 1, $create_widgets->($always_total_size, @widgets_always), - if_($common->{ok} || $::isWizard, - 0, $mainw->create_okcancel($common->{ok}, $common->{cancel}, '', if_(@$l2, $advanced_button)))); - my $has_scroll_always = $has_scroll; - my @adv = map { warp_text($_) } @{$common->{advanced_messages}}; - $advanced_pack = - gtkpack_(new Gtk::VBox(0,0), - 0, '', - (map {; 0, new Gtk::Label($_) } @adv), - 0, new Gtk::HSeparator, - 1, $create_widgets->($advanced_total_size, @widgets_advanced)); - - $pack->pack_start($advanced_pack, 1, 1, 0); - gtkadd($mainw->{window}, $pack); - $set_default_size->() if $has_scroll_always; - $set_advanced->(0); - (@widgets ? $widgets[0]{focus_w} : $common->{focus_cancel} ? $mainw->{cancel} : $mainw->{ok})->grab_focus(); - - my $check = sub { - my ($f) = @_; - sub { - $get_all->(); - my ($error, $focus) = $f->(); - - if ($error) { - $set_all->(); - $widgets[$focus || 0]{focus_w}->grab_focus(); - } - !$error; - } - }; - $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(@_) } }); - my_gtk::ask_browse_tree_info($common); -} - -sub wait_messageW($$$) { - my ($o, $title, $messages) = @_; - - local $my_gtk::pop_it = 1; - my $w = my_gtk->new($title, %$o, grab => 1); - gtkadd($w->{window}, my $hbox = new Gtk::HBox(0,0)); - $hbox->pack_start(my $box = new Gtk::VBox(0,0), 1, 1, 10); - $box->pack_start($_, 1, 1, 4) foreach my @l = map { new Gtk::Label(scalar warp_text($_)) } @$messages; - - ($w->{wait_messageW} = $l[$#l])->signal_connect(expose_event => sub { $w->{displayed} = 1 }); - $w->{rwindow}->set_position('center') if ($::isStandalone && (!$::isEmbedded && !$::isWizard || $my_gtk::pop_it)); - $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) = @_; - $o->{before_killing} ||= 0; - - while (my $e = shift @tempory::objects) { $e->destroy } - while (@interactive::objects > $o->{before_killing}) { - my $w = pop @interactive::objects; - $w->destroy; - } - $o->{before_killing} = @interactive::objects; -} - -1; diff --git a/perl-install/interactive_http.pm b/perl-install/interactive_http.pm deleted file mode 100644 index 18bff77fe..000000000 --- a/perl-install/interactive_http.pm +++ /dev/null @@ -1,159 +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 $uid; -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 ($title) = @_; - print CGI::start_html(-title => $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 "\n"; - - map_index { - my $e = $_; - - print "\n"; - } @$l; - - print "
$e->{label}\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 "
\n"; - print $q->p(); - print $q->submit(-name => 'ok_submit', -value => $common->{ok} || _("Ok")); - print $q->submit(-name => 'cancel_submit', -value => $common->{cancel}) if $common->{cancel}; - print $q->hidden('state'), $q->hidden('uid'); - print $q->end_form, $q->end_html; - - close STDOUT; # page terminated - - while (1) { - local *F; - open 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(_("Error")); - print $q->h1(_("Error")), $q->p("Sorry, you can't go back"); - goto redisplay; - } - map_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(_("Done")); - print "\n" . CGI::p(); -} - - - -1; diff --git a/perl-install/interactive_newt.pm b/perl-install/interactive_newt.pm deleted file mode 100644 index d930b9f29..000000000 --- a/perl-install/interactive_newt.pm +++ /dev/null @@ -1,254 +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() { - Newt::Init; - 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 myTextbox { - my $allow_scroll = shift; - - my $width = $width - 9; - my @l = map { /(.{1,$width})/g } map { split "\n" } @_; - my $h = min($height - 13, int @l); - my $flag = 1 << 6; - if ($h < @l) { - if ($allow_scroll) { - $flag |= 1 << 2; #- NEWT_FLAG_SCROLL - } 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, $flag); - $mess->TextboxSetText(join("\n", @_)); - $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) = @_; - my $ignore; #-to handle recursivity - my $old_focus = -2; - - #-the widgets - my (@widgets, $total_size); - - 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} =~ /(icon|tree)list/; - - #- 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); - if ($e->{type} eq 'bool') { - $w = Newt::Component::Checkbox(-1, -1, $e->{text} || '', checkval(${$e->{val}}), " *"); - $set = sub { $w->CheckboxSetValue(checkval($_[0])) }; - $get = sub { $w->CheckboxGetValue == ord '*' }; - } elsif ($e->{type} eq 'button') { - $w = Newt::Component::Button(-1, -1, simplify_string(may_apply($e->{format}, ${$e->{val}}))); - } elsif ($e->{type} =~ /list/) { - my ($h, $wi) = (@$l == 1 && $height > 30 ? 10 : 5, 20); - my $scroll = @{$e->{list}} > $h ? 1 << 2 : 0; - $size = min(int @{$e->{list}}, $h); - - $w = Newt::Component::Listbox(-1, -1, $h, $scroll); #- NEWT_FLAG_SCROLL - foreach (@{$e->{list}}) { - my $t = simplify_string(may_apply($e->{format}, $_)); - $w->ListboxAddEntry($t, $_); - $wi = max($wi, length $t); - } - $w->ListboxSetWidth(min($wi + 3, $width - 7)); # 3 added for the scrollbar (?) - $get = sub { $w->ListboxGetCurrent }; - $set = sub { - my ($val) = @_; - map_index { - $w->ListboxSetCurrent($::i) if $val eq $_; - } @{$e->{list}}; - }; - } else { - $w = Newt::Component::Entry(-1, -1, '', 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 {} }; - }; - @widgets = map_index { $create_widget->($_, $::i) } @$l; - - $_->{w}->addCallback($_->{callback}) foreach @widgets; - - $set_all->(); - - my $grid = Newt::Grid::CreateGrid(3, max(1, int @$l)); - map_index { - $grid->GridSetField(0, $::i, 1, ${Newt::Component::Label(-1, -1, $_->{e}{label})}, 0, 0, 1, 0, 1, 0); - $grid->GridSetField(1, $::i, 1, ${$_->{real_w}}, 0, 0, 0, 0, 1, 0); - } @widgets; - - my $listg = do { - my $height = 18; - #- 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 ((((grep { $_->{type} eq 'bool' } @$l) > 6) || - ((@$l) > 3)) && $total_size > $height) { - $grid->GridPlace(1, 1); #- Uh?? otherwise the size allocated is bad - - my $scroll = Newt::Component::VerticalScrollbar(-1, -1, $height, 9, 10); - my $subf = $scroll->Form('', 0); - $subf->FormSetHeight($height); - $subf->FormAddGrid($grid, 0); - Newt::Grid::HCloseStacked($subf, separator(1, $height), $scroll); - } else { - $grid; - } - }; - my ($buttons, $ok, $cancel) = Newt::Grid::ButtonBar(simplify_string($common->{ok} || _("Ok")), - if_($common->{cancel}, simplify_string($common->{cancel}))); - - my $form = Newt::Component::Form(\undef, '', 0); - my $window = Newt::Grid::GridBasicWindow(first(myTextbox(@widgets == 0, @{$common->{messages}})), $listg, $buttons); - $window->GridWrappedWindow($common->{title} || ''); - $form->FormAddGrid($window, 1); - - my $check = sub { - my ($f) = @_; - - $get_all->(); - my ($error, $focus) = $f->(); - - if ($error) { - $set_all->(); - } - !$error; - }; - - my ($destroyed, $canceled); - do { - my $r = do { - local $::setstep = 1; - $form->RunForm; - }; - $canceled = $cancel && $$r == $$cancel; - - if (my ($button) = grep { $$r == ${$_->{w}} } @widgets) { - $get_all->(); - my $v = do { - local $::setstep = 1; - $button->{e}{clicked_may_quit}(); - }; - $form->FormDestroy; - Newt::PopWindow; - return $v || &ask_fromW; - } - } until ($check->($common->{callbacks}{$canceled ? 'canceled' : 'complete'})); - - $form->FormDestroy; - Newt::PopWindow; - !$canceled; -} - - -sub waitbox { - my ($title, $messages) = @_; - my ($t, $w, $h) = myTextbox(1, @$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) = @_; - $s =~ s/\n/ /g; - $s = substr($s, 0, 40); #- truncate if too long - $s; -} - -1; diff --git a/perl-install/interactive_stdio.pm b/perl-install/interactive_stdio.pm deleted file mode 100644 index 519f5ccbe..000000000 --- a/perl-install/interactive_stdio.pm +++ /dev/null @@ -1,171 +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 = ; - 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 _("Bad choice, try again\n"); - print _("Your choice? (default %s) ", $def_s); - $i = readln(); - } until (!$i || check_it($i, $max)); - $i; -} - -sub ask_fromW { - my ($o, $common, $l, $l2) = @_; - -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 _("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 "`${$e->{val}}' $e->{label} $e->{text}\n"; }; - my $do_widget = sub { - my ($e, $ind) = @_; - - if ($e->{type} eq 'bool') { - print "$e->{text} $e->{label}\n"; - print _("Your choice? (0/1, default `%s') ", ${$e->{val}} || '0'); - my $i = readln(); - if ($i ne '') { - 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; my $def_n = 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); - ${$e->{val}} eq $_ and $def_n = $n; - } - 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 _("Button `%s': %s", $e->{label}, may_apply($e->{format}, ${$e->{val}})), " $e->{text}\n"; - print _("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 _("Your choice? (default `%s'%s) ", ${$e->{val}}, ${$e->{val}} ne '' ? _(" 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 { - print "UNSUPPORTED WIDGET TYPE (type <$e->{type}> label <$e->{label}> text <$e->{text}> val <${$e->{val}}>\n"; - } - }; - - 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 _("=> There are many things to choose from (%s).\n", $ll); -ask_fromW_handle_verylonglist: - print _( -"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)) { - map_index { $do_widget->($_, $::i) } grep_index { $::i >= $i-1 && $::i < $i+9 } @$l; - goto ask_fromW_handle_verylonglist; - } - } else { - map_index { $do_widget->($_, $::i) } @$l; - } - - my $lab; - map_index { $labels[$::i] && (($lab = $format_label->($_)) ne $labels[$::i]) and print _("=> Notice, a label changed:\n%s", $lab); } - grep { $_->{type} eq 'label' } @$l; - - my $i; - if (listlength(@$l) != 1 || $common->{ok} ne _("Ok") || $common->{cancel} ne _("Cancel")) { - print "[1] ", $common->{ok} || _("Ok"); - $common->{cancel} and print " [2] $common->{cancel}"; - @$l and print " [9] ", _("Re-submit"); - print "\n"; - do { - defined $i and print _("Bad choice, try again\n"); - print _("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" } - -1; - diff --git a/perl-install/printerdrake.pm b/perl-install/printerdrake.pm index f158d5142..86541ffe1 100644 --- a/perl-install/printerdrake.pm +++ b/perl-install/printerdrake.pm @@ -2572,7 +2572,7 @@ sub main { #if ((!$::expert) && (!$::isEmbedded) && (!$::isInstall) && if ((!$::isEmbedded) && (!$::isInstall) && #if ((!$::isInstall) && - ($in->isa('interactive_gtk'))) { + ($in->isa('interactive::gtk'))) { $continue = 1; # Enter wizard mode $::Wizard_pix_up = "wiz_printerdrake.png"; @@ -2915,14 +2915,11 @@ What do you want to modify on this printer?", # Delete some variables $printer->{OLD_QUEUE} = ""; - $printer->{QUEUE} = ""; - $printer->{TYPE} = ""; - $printer->{str_type} = ""; + foreach (qw(QUEUE TYPE str_type DBENTRY ARGS OLD_CHOICE)) { + $printer->{$_} = ""; + } $printer->{currentqueue} = {}; - $printer->{DBENTRY} = ""; - $printer->{ARGS} = ""; $printer->{complete} = 0; - $printer->{OLD_CHOICE} = ""; } # Clean up the $printer data structure for auto-install log for my $queue (keys %{$printer->{configured}}) { @@ -2935,20 +2932,7 @@ What do you want to modify on this printer?", delete($printer->{configured}{$queue}{queuedata}{menuentry}); } } - delete($printer->{OLD_QUEUE}); - delete($printer->{QUEUE}); - delete($printer->{TYPE}); - delete($printer->{str_type}); - delete($printer->{currentqueue}); - delete($printer->{DBENTRY}); - delete($printer->{ARGS}); - delete($printer->{complete}); - delete($printer->{OLD_CHOICE}); - delete($printer->{NEW}); - delete($printer->{MORETHANONE}); - delete($printer->{MANUALMODEL}); - #use Data::Dumper; - #print "###############################################################################\n", Dumper($printer); - + foreach (qw(Old_queue QUEUE TYPE str_type currentqueue DBENTRY ARGS complete OLD_CHOICE NEW MORETHANONE MANUALMODEL)) + { delete $printer->{$_} }; } diff --git a/perl-install/services.pm b/perl-install/services.pm index 0ddaaf79a..a4dbc8e3a 100644 --- a/perl-install/services.pm +++ b/perl-install/services.pm @@ -252,7 +252,7 @@ sub ask_standalone_gtk { sub ask { my ($in, $prefix) = @_; - !$::isInstall && $in->isa('interactive_gtk') ? &ask_standalone_gtk : &ask_install; + !$::isInstall && $in->isa('interactive::gtk') ? &ask_standalone_gtk : &ask_install; } sub doit { diff --git a/perl-install/standalone/diskdrake b/perl-install/standalone/diskdrake index 69b84b0dc..97fca7bde 100755 --- a/perl-install/standalone/diskdrake +++ b/perl-install/standalone/diskdrake @@ -112,7 +112,7 @@ if ($type eq 'hd') { $in->ask_from_listf('', '', \&diskdrake::interactive::format_raw_hd_info, $all_hds->{raw_hds}) or $in->exit(0); diskdrake::removable::main($in, $all_hds, $raw_hd); } else { - $in->ask_warn('', "Sorry only a gtk frontend is available") if !$in->isa('interactive_gtk'); + $in->ask_warn('', "Sorry only a gtk frontend is available") if !$in->isa('interactive::gtk'); require diskdrake::smbnfs_gtk; diskdrake::smbnfs_gtk::main($in, $all_hds, $type); } diff --git a/perl-install/standalone/drakautoinst b/perl-install/standalone/drakautoinst index ae7ce1e9a..54e0fd139 100755 --- a/perl-install/standalone/drakautoinst +++ b/perl-install/standalone/drakautoinst @@ -89,7 +89,7 @@ my $cfgfile = "$mountdir/auto_inst.cfg"; eval(cat_($cfgfile)); my $o_old = $o; -if (!$::isEmbedded && $in->isa('interactive_gtk')) { +if (!$::isEmbedded && $in->isa('interactive::gtk')) { require Gtk; init Gtk; require my_gtk; @@ -368,6 +368,9 @@ sub control_buttons { #------------------------------------------------- #- $Log$ +#- Revision 1.19 2002/07/23 10:35:55 tvignaud +#- - Big Move 1: interactive::* hierarchy +#- #- Revision 1.18 2002/03/06 20:17:51 damien #- corrected HASH and ARRAY label #- diff --git a/perl-install/standalone/drakboot b/perl-install/standalone/drakboot index e7e283c0d..174a40847 100755 --- a/perl-install/standalone/drakboot +++ b/perl-install/standalone/drakboot @@ -25,7 +25,7 @@ my $in = 'interactive'->vnew('su', 'bootloader'); $::lilo_choice = \&lilo_choice; -if ($in->isa('interactive_gtk')) { +if ($in->isa('interactive::gtk')) { require 'bootlook.pm'; } else { lilo_choice(); diff --git a/perl-install/standalone/drakconnect b/perl-install/standalone/drakconnect index fdbe4bda4..aceef3f82 100755 --- a/perl-install/standalone/drakconnect +++ b/perl-install/standalone/drakconnect @@ -51,7 +51,7 @@ my @conx_type = ('modem', 'isdn_internal', 'isdn_external', 'adsl', 'cable', 'la #$::wizard_xpm = "/usr/share/pixmaps/internet.xpm"; my $in = 'interactive'->vnew('su', 'network'); -!$::isEmbedded && $in->isa('interactive_gtk') and $::isWizard=1; +!$::isEmbedded && $in->isa('interactive::gtk') and $::isWizard=1; $::Wizard_pix_up = "wiz_drakconnect.png"; $::Wizard_title = "Network & Internet Configuration"; diff --git a/perl-install/standalone/drakgw b/perl-install/standalone/drakgw index cc35a1dc2..08119a6a9 100755 --- a/perl-install/standalone/drakgw +++ b/perl-install/standalone/drakgw @@ -56,9 +56,9 @@ my $drakgw_setup = "/etc/sysconfig/inet_sharing"; my $in = 'interactive'->vnew('su', 'default'); -!$::isEmbedded && $in->isa('interactive_gtk') and $::isWizard=1; +!$::isEmbedded && $in->isa('interactive::gtk') and $::isWizard=1; -pur_gtk_mode() if $::isEmbedded && $in->isa('interactive_gtk'); +pur_gtk_mode() if $::isEmbedded && $in->isa('interactive::gtk'); sub sys { system(@_) == 0 or log::l("[drakgw] Warning, sys failed for $_[0]") } @@ -611,6 +611,9 @@ Click on Configure to launch the setup wizard.", $setup_state)); #------------------------------------------------- #- $Log$ +#- Revision 1.62 2002/07/23 10:35:55 tvignaud +#- - Big Move 1: interactive::* hierarchy +#- #- Revision 1.61 2002/04/09 08:50:36 gc #- time to remove ipchains/2.2 stuff since now ipchains and iptables #- packages conflict diff --git a/perl-install/standalone/drakxtv b/perl-install/standalone/drakxtv index 16b64ecec..7250ab5f8 100755 --- a/perl-install/standalone/drakxtv +++ b/perl-install/standalone/drakxtv @@ -120,8 +120,8 @@ You can install it by typing \"urpmi xawtv\" as root, in a console."))); # we provide scantv a bogus table (france) which will # will be ignored since "All" is selected (because of -a) $ftable_id = "france -a " if ($ftable_id eq -1); - # Note that this'll be broken if/when we implement interactive_qt - my $use_X =$in->isa('interactive_gtk') && -x "/usr/X11R6/bin/xvt"; + # Note that this'll be broken if/when we implement interactive::qt + my $use_X =$in->isa('interactive::gtk') && -x "/usr/X11R6/bin/xvt"; my $home = $ENV{HOME}; my $i=system ( (($use_X ) ? "xvt -T '"._("Scanning for TV channels")." ...' -e ":"") diff --git a/perl-install/standalone/mousedrake b/perl-install/standalone/mousedrake index 90cb8994c..f8bb9a02e 100755 --- a/perl-install/standalone/mousedrake +++ b/perl-install/standalone/mousedrake @@ -58,7 +58,7 @@ $mouse->{XMOUSETYPE} eq $curr_env->{mouse}{XMOUSETYPE} || $::isEmbedded and kill USR2, $::CCPID; if (!$mouse || !$::auto) { $mouse ||= mouse::fullname2mouse("serial|Generic 2 Button Mouse"); - if ($::isEmbedded && $in->isa('interactive_gtk')) { + if ($::isEmbedded && $in->isa('interactive::gtk')) { require my_gtk; my $time_tag = Gtk->timeout_add(100, sub { defined $::Plug && defined $::Plug->child or return 1; @@ -70,7 +70,7 @@ if (!$mouse || !$::auto) { sub { join '|', map { translate($_) } split '\|', $_[0] }, [ mouse::fullnames ], $mouse->{type} . '|' . $mouse->{name}); - Gtk->timeout_remove($time_tag2) if $::isEmbedded && $in->isa('interactive_gtk'); + Gtk->timeout_remove($time_tag2) if $::isEmbedded && $in->isa('interactive::gtk'); $name or $::isEmbedded ? do { kill(USR1, $::CCPID); goto begin } : $in->exit(0); my $mouse_chosen = mouse::fullname2mouse($name); $mouse->{type} eq $mouse_chosen->{type} && $mouse->{name} eq $mouse_chosen->{name} or $mouse = $mouse_chosen; diff --git a/perl-install/standalone/tinyfirewall b/perl-install/standalone/tinyfirewall index 3f91a0027..40dbd5f21 100755 --- a/perl-install/standalone/tinyfirewall +++ b/perl-install/standalone/tinyfirewall @@ -34,7 +34,7 @@ local $_ = join '', @ARGV; my $in = 'interactive'->vnew('su', 'default'); -$::isEmbedded && $in->isa('interactive_gtk') or goto dd; +$::isEmbedded && $in->isa('interactive::gtk') or goto dd; require Gtk; init Gtk; -- cgit v1.2.1