package standalone; # $Id$ use c; use strict; use common qw(N N_ if_); use Config; #- for sanity (if a use standalone is made during install, MANY problems will happen) require 'log.pm'; #- "require log" causes some pb, perl thinking that "log" is the log() function if ($::isInstall) { log::l('ERROR: use standalone made during install :-('); log::l('backtrace: ' . backtrace()); } $::isStandalone = 1; $ENV{SHARE_PATH} ||= "/usr/share"; c::setlocale(); c::bindtextdomain('libDrakX', "/usr/share/locale"); $::license = N_("This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. "); my $progname = common::basename($0); my %usages = ( 'diskdrake' => "[--{" . join(",", qw(hd nfs smb dav removable fileshare)) . "}]", 'drakbackup' => N_("[--config-info] [--daemon] [--debug] [--default] [--show-conf] Backup and Restore application --default : save default directories. --debug : show all debug messages. --show-conf : list of files or directories to backup. --config-info : explain configuration file options (for non-X users). --daemon : use daemon configuration. --help : show this message. --version : show version number. "), 'drakbug' => N_("[OPTIONS] [PROGRAM_NAME] OPTIONS: --help - print this help message. --report - program should be one of mandrake tools --incident - program should be one of mandrake tools"), 'drakfont' => N_("Font Importation and monitoring application --windows_import : import from all available windows partitions. --xls_fonts : show all fonts that already exist from xls --strong : strong verification of font. --install : accept any font file and any directry. --uninstall : uninstall any font or any directory of font. --replace : replace all font if already exist --application : 0 none application. : 1 all application available supported. : name_of_application like so for staroffice : and gs for ghostscript for only this one."), 'draksec' => "[--debug] --debug: print debugging information", 'drakTermServ' => N_("[OPTIONS]... Mandrake Terminal Server Configurator --enable : enable MTS --disable : disable MTS --start : start MTS --stop : stop MTS --adduser : add an existing system user to MTS (requires username) --deluser : delete an existing system user from MTS (requires username) --addclient : add a client machine to MTS (requires MAC address, IP, nbi image name) --delclient : delete a client machine from MTS (requires MAC address, IP, nbi image name)"), 'drakxtv' => "[--no-guess]", 'drakupdate_fstab' => " [--add | --del] \n", 'keyboardrake' => N_("[keyboard]"), 'logdrake' => N_("[--file=myfile] [--word=myword] [--explain=regexp] [--alert]"), 'net_monitor' => N_("[OPTIONS] Network & Internet connection and monitoring application --defaultintf interface : show this interface by default --connect : connect to internet if not already connected --disconnect : disconnect to internet if already connected --force : used with (dis)connect : force (dis)connection. --status : returns 1 if connected 0 otherwise, then exit. --quiet : don't be interactive. To be used with (dis)connect."), 'printerdrake' => N_(" [--skiptest] [--cups] [--lprng] [--lpd] [--pdq]"), 'rpmdrake' => N_("[OPTION]... --no-confirmation don't ask first confirmation question in MandrakeUpdate mode --no-verify-rpm don't verify packages signatures --changelog-first display changelog before filelist in the description window --merge-all-rpmnew propose to merge all .rpmnew/.rpmsave files found"), 'scannerdrake' => N_("[--manual] [--device=dev] [--update-sane=sane_source_dir] [--update-usbtable] [--dynamic=dev]"), 'XFdrake' => N_(" [everything] XFdrake [--noauto] monitor XFdrake resolution"), ); $usages{$_} = $usages{rpmdrake} foreach qw(rpmdrake-remove MandrakeUpdate); $usages{Xdrakres} = $usages{XFdrake}; my ($i, @new_ARGV); foreach (@ARGV) { $i++; if (/^-(-help|h)$/) { version(); print STDERR N("\nUsage: %s [--auto] [--beginner] [--expert] [-h|--help] [--noauto] [--testing] [-v|--version] ", $progname), if_($usages{$progname}, $usages{$progname}), "\n"; # print N("\nUsage: "), $::usage, "\n" if $::usage; exit(0); } elsif (/^-(-version|v)$/) { version(); exit(0); } elsif (/^--embedded$/) { $::XID = splice @ARGV, $i, 1; $::isEmbedded = 1; } elsif (/^--expert$/) { $::expert = 1; } elsif (/^--noauto$/) { $::noauto = /-noauto/; } elsif (/^--auto$/) { $::auto = 1; } elsif (/^--testing$/) { $::testing = 1; } elsif (/^--beginner$/) { $::expert = 0; } else { push @new_ARGV, $_; } } @ARGV = @new_ARGV; sub version { print STDERR "Drakxtools version 9.1.0 Copyright (C) 1999-2002 MandrakeSoft by ", $::license, "\n"; } ################################################################################ package pkgs_interactive; use run_program; use common; require 'log.pm'; our @ISA = qw(); #- tell perl_checker this is a class sub interactive::do_pkgs { my ($in) = @_; bless { in => $in }, 'pkgs_interactive'; } sub install { my ($o, @l) = @_; return 1 if is_installed($o, @l); my $wait; if ($o->{in}->isa('interactive::newt')) { $o->{in}->suspend; } else { $wait = $o->{in}->wait_message('', N("Installing packages...")); } log::explanations("installed packages @l"); my $ret = system('urpmi', '--allow-medium-change', '--auto', '--best-output', '--no-verify-rpm', @l) == 0; if ($o->{in}->isa('interactive::newt')) { $o->{in}->resume; } else { undef $wait; } $ret; } sub ensure_is_installed { my ($o, $pkg, $file, $auto) = @_; if (! -e $file) { $o->{in}->ask_okcancel('', N("The package %s needs to be installed. Do you want to install it?", $pkg), 1) or return if !$auto; $o->{in}->do_pkgs->install($pkg); } if (! -e $file) { $o->{in}->ask_warn('', N("Mandatory package %s is missing", $pkg)); return; } 1; } sub check_kernel_module_packages { my ($do, $base_name, $ext_name) = @_; my $result; my (%list, %select); eval { local *_; require urpm; my $urpm = new urpm; $urpm->read_config(nocheck_access => 1); foreach (grep { !$_->{ignore} } @{$urpm->{media} || []}) { $urpm->parse_synthesis("$urpm->{statedir}/synthesis.$_->{hdlist}"); } foreach (@{$urpm->{depslist} || []}) { $_->name eq $ext_name and $list{$_->name} = 1; $_->name =~ /$base_name/ and $list{$_->name} = 1; } foreach (`rpm --qf '\%{NAME}\n' -qa`) { chomp; $_ eq $ext_name and $list{$_} = 0; /$base_name/ and $list{$_} = 0; } }; if (!$ext_name || exists $list{$ext_name}) { eval { my ($version_release, $ext); if (c::kernel_version() =~ /([^-]*)-([^-]*mdk)(\S*)/) { $version_release = "$1.$2"; $ext = $3 ? "-$3" : ""; exists $list{"$base_name$ext-$version_release"} or die "no $base_name for current kernel"; $list{"$base_name$ext-$version_release"} and $select{"$base_name$ext-$version_release"} = 1; } else { #- kernel version is not recognized, what to do ? } foreach (`rpm -qa`) { ($ext, $version_release) = /kernel[^\-]*(-smp|-enterprise|-secure)?(?:-([^\-]+))$/; $list{"$base_name$ext-$version_release"} and $select{"$base_name$ext-$version_release"} = 1; } $result = [ keys(%select), if_($ext_name, $ext_name) ]; } } return $result; } sub what_provides { my ($_o, $name) = @_; my ($what) = split '\n', `urpmq '$name' 2>/dev/null`; split '\|', $what; } sub is_installed { my ($_o, @l) = @_; run_program::run('/bin/rpm', '>', '/dev/null', '-q', @l); } sub are_installed { my ($_o, @l) = @_; my @l2; run_program::run('/bin/rpm', '>', \@l2, '-q', '--qf', "%{name}\n", @l); intersection(\@l, [ map { chomp_($_) } @l2 ]); } sub remove { my ($o, @l) = @_; $o->{in}->suspend; log::explanations("removed packages @l"); my $ret = system('rpm', '-e', @l) == 0; $o->{in}->resume; $ret; } sub remove_nodeps { my ($o, @l) = @_; $o->{in}->suspend; log::explanations("removed (with --nodeps) packages @l"); my $ret = system('rpm', '-e', '--nodeps', @l) == 0; $o->{in}->resume; $ret; } ################################################################################ package standalone; #- stuff will go to special /var/log/explanations file my $standalone_name; sub explanations { log::explanations("@_") } our @common_functs = qw(renamef linkf symlinkf output substInFile mkdir_p rm_rf cp_af touch setVarsInSh setExportedVarsInSh setExportedVarsInCsh update_gnomekderc); our @builtin_functs = qw(chmod chown unlink link symlink rename system); our @drakx_modules = qw(Xconfig::card Xconfig::default Xconfig::main Xconfig::monitor Xconfig::parse Xconfig::proprietary Xconfig::resolution_and_depth Xconfig::screen Xconfig::test Xconfig::various Xconfig::xfree Xconfig::xfree3 Xconfig::xfree4 Xconfig::xfreeX any bootloader bootlook c class_discard commands crypto detect_devices devices diskdrake diskdrake::hd_gtk diskdrake::interactive diskdrake::removable diskdrake::removable_gtk diskdrake::smbnfs_gtk fs fsedit http keyboard lang log loopback lvm modules::parameters modules mouse my_gtk network network::adsl network::ethernet network::isdn_consts network::isdn network::modem network::netconnect network::network network::nfs network::smb network::tools partition_table partition_table_bsd partition_table::dos partition_table::empty partition_table::gpt partition_table::mac partition_table::raw partition_table::sun printer printerdrake proxy raid run_program scanner services steps swap timezone network::drakfirewall network::shorewall); $SIG{SEGV} = sub { my $progname = $0; $progname =~ s|.*/||; exec("drakbug --incident $progname") }; sub import { ($standalone_name = $0) =~ s|.*/||; c::openlog($standalone_name."[$$]"); explanations('### Program is starting ###'); eval "*MDK::Common::$_ = *$_" foreach @common_functs; foreach my $f (@builtin_functs) { eval "*$_"."::$f = *$f" foreach @drakx_modules; eval "*".caller()."::$f = *$f"; } } sub renamef { explanations "moved file $_[0] to $_[1]"; goto &MDK::Common::File::renamef; } sub linkf { explanations "hard linked file $_[0] to $_[1]"; goto &MDK::Common::File::linkf; } sub symlinkf { explanations "symlinked file $_[0] to $_[1]"; goto &MDK::Common::File::symlinkf; } sub output { explanations "created file $_[0]"; goto &MDK::Common::File::output; } sub substInFile(&@) { explanations "modified file $_[1]"; goto &MDK::Common::File::substInFile; } sub mkdir_p { explanations "created directory $_[0] (and parents if necessary)"; goto &MDK::Common::File::mkdir_p; } sub rm_rf { explanations "removed files/directories (recursively) @_"; goto &MDK::Common::File::rm_rf; } sub cp_af { my $retval = MDK::Common::File::cp_af(@_); my $dest = pop @_; explanations "copied recursively @_ to $dest"; return $retval; } sub touch { explanations "touched file @_"; goto &MDK::Common::File::touch; } sub setVarsInSh { explanations "modified file $_[0]"; goto &MDK::Common::System::setVarsInSh; } sub setExportedVarsInSh { explanations "modified file $_[0]"; goto &MDK::Common::System::setExportedVarsInSh; } sub setExportedVarsInCsh { explanations "modified file $_[0]"; goto &MDK::Common::System::setExportedVarsInCsh; } sub update_gnomekderc { explanations "modified file $_[0]"; goto &MDK::Common::System::update_gnomekderc; } sub chmod { my $retval = CORE::chmod(@_); my $mode = shift @_; explanations sprintf("changed mode of %s to %o", $_, $mode) foreach @_; return $retval; } sub chown { my $retval = CORE::chown(@_); my $uid = shift @_; my $gid = shift @_; explanations sprintf("changed owner of $_ to $uid.$gid") foreach @_; return $retval; } sub unlink { explanations "removed files/directories @_"; CORE::unlink(@_); } sub link { explanations "hard linked file $_[0] to $_[1]"; CORE::link($_[0], $_[1]); } sub symlink { explanations "symlinked file $_[0] to $_[1]"; CORE::symlink($_[0], $_[1]); } sub rename { explanations "renamed file $_[0] to $_[1]"; CORE::rename($_[0], $_[1]); } sub system { explanations "launched command: @_"; CORE::system(@_); } 1; ' href='#n215'>215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703
package install_steps_gtk; # $Id$

use diagnostics;
use strict;
use vars qw(@ISA);

@ISA = qw(install_steps_interactive interactive_gtk);

#-######################################################################################
#- misc imports
#-######################################################################################
use install_steps_interactive;
use interactive_gtk;
use common;
use my_gtk qw(:helpers :wrappers);
use Gtk;
use devices;
use modules;
use install_gtk;
use install_any;
use mouse;
use help;
use log;

#-######################################################################################
#- In/Out Steps Functions
#-######################################################################################
sub new($$) {
    my ($type, $o) = @_;

    my $old = $SIG{__DIE__};
    $SIG{__DIE__} = sub { $_[0] !~ /my_gtk\.pm/ and goto $old };

    $ENV{DISPLAY} ||= $o->{display} || ":0";
    unless ($::testing) {
	if ($ENV{DISPLAY} eq ":0" && !$::live) {
	    my $f = "/tmp/Xconf";
	    install_gtk::createXconf($f, @{$o->{mouse}}{"XMOUSETYPE", "device"}, $o->{wacom}[0]);
	    devices::make("/dev/kbd");

	    local (*T1, *T2);
	    open T1, ">/dev/tty5";
	    open T2, ">/dev/tty6";

	    my $launchX = sub {
		my $ok = 1;
		my $xpmac_opts = cat_("/proc/cmdline");
		unless (-d "/var/log" ) { mkdir("/var/log"); }
		local $SIG{CHLD} = sub { $ok = 0 if waitpid(-1, c::WNOHANG()) > 0 };
		unless (fork) {
		    exec $_[0], (arch() =~ /^sparc/ || arch() eq "ppc" ? () : ("-kb")), "-dpms","-s" ,"240",
		      ($_[0] =~ /Xpmac/ ? $xpmac_opts !~ /ofonly/ ? ("-mode", "17", "-depth", "32") : ("-mach64"):()),
		      ($_[0] =~ /Xsun/ || $_[0] =~ /Xpmac/ ? ("-fp", "/usr/X11R6/lib/X11/fonts:unscaled") :
		       ("-allowMouseOpenFail", "-xf86config", $f)) or exit 1;
		}
		foreach (1..60) {
		    sleep 1;
		    log::l("Server died"), return 0 if !$ok;
		    if (c::Xtest($ENV{DISPLAY})) {
			fork || exec("aewm-drakx") || exec("true");
			return 1;
		    }
		}
		log::l("Timeout!!");
		0;
	    };
	    my @servers = qw(FBDev VGA16); #-)
	    if (arch() eq "alpha") {
		require Xconfigurator;
		my $card = Xconfigurator::cardConfigurationAuto();
		Xconfigurator::updateCardAccordingName($card, $card->{type}) if $card && $card->{type};
		@servers = $card->{server} || "TGA";
		#-@servers = qw(SVGA 3DLabs TGA) 
	    } elsif (arch() =~ /^sparc/) {
		local $_ = cat_("/proc/fb");
		if (/Mach64/) { @servers = qw(Mach64) }
		elsif (/Permedia2/) { @servers = qw(3DLabs) }
		else { @servers = qw(Xsun24) }
	    } elsif (arch() =~ /ia64/) {
		@servers= 'XFree86';
	    } elsif (arch() eq "ppc") {
	    	@servers = qw(Xpmac);
            }

	    foreach (@servers) {
		log::l("Trying with server $_");
		my $dir = "/usr/X11R6/bin";
		my $prog = /Xsun|Xpmac|XFree86/ ? $_ : "XF86_$_";
		unless (-x "$dir/$prog") {
		    unlink $_ foreach glob_("$dir/X*");
		    install_any::getAndSaveFile("Mandrake/mdkinst$dir/$prog", "$dir/$prog") or die "failed to get server $prog: $!";
		    chmod 0755, "$dir/$prog";
		}
		if (/FB/) {
		    !$o->{vga16} && $o->{allowFB} or next;

		    $o->{allowFB} = &$launchX($prog) #- keep in mind FB is used.
		      and goto OK;
		} else {
		    $o->{vga16} = 1 if /VGA16/;
		    &$launchX($prog) and goto OK;
		}
	    }
	    return undef;
	}
    }
  OK:
    install_gtk::init_sizes();
    install_gtk::default_theme($o);
    install_gtk::create_logo_window($o);

    $my_gtk::force_center = [ $::rootwidth - $::windowwidth, $::logoheight, $::windowwidth, $::windowheight ];

    $o = (bless {}, ref $type || $type)->SUPER::new($o);
    $o->interactive_gtk::new;
    $o;
}

sub enteringStep {
    my ($o, $step) = @_;

    printf "Entering step `%s'\n", $o->{steps}{$step}{text};
    $o->SUPER::enteringStep($step);
    install_gtk::create_steps_window($o);
    install_gtk::create_help_window($o);
}
sub leavingStep {
    my ($o, $step) = @_;
    $o->SUPER::leavingStep($step);
}


sub charsetChanged {
    my ($o) = @_;
    Gtk->set_locale;
    install_gtk::install_theme($o);
    install_gtk::create_steps_window($o);
}

#-######################################################################################
#- Steps Functions
#-######################################################################################
sub selectLanguage {
    my ($o, $first_time) = @_;
    $o->SUPER::selectLanguage;
  
    $o->ask_warn('',
_("Your system is low on resources. You may have some problem installing
Mandrake Linux. If that occurs, you can try a text install instead. For this,
press `F1' when booting on CDROM, then enter `text'.")) if $first_time && availableRamMB() < 60; # 60MB

}

#------------------------------------------------------------------------------
sub selectInstallClass1 {
    my ($o, $verif, $l, $def, $l2, $def2) = @_;
    $::live || @$l == 1 and return $o->SUPER::selectInstallClass1($verif, $l, $def, $l2, $def2);

    my $w = my_gtk->new(_("Install Class"));
    my $focused;
    gtkadd($w->{window},
	   gtkpack($w->create_box_with_title(_("Please choose one of the following classes of installation:")),
		   (my @radios = gtkradio($def, @$l)),
		   gtkadd(create_vbox(),
			  map { my $v = $_; 
				my $b = new Gtk::Button(translate($_));
				$focused = $b if $_ eq $def2;
				gtksignal_connect($b, "clicked" => sub { $w->{retval} = $v; Gtk->main_quit });
			    } @$l2)
		  ));
    $focused->grab_focus if $focused;
    $w->main;

    mapn { $verif->($_[1]) if $_[0]->active } \@radios, $l;
    install_gtk::create_steps_window($o);

    $w->{retval};
}

#------------------------------------------------------------------------------
sub selectMouse {
    my ($o, $force) = @_;
    my %old = %{$o->{mouse}};
    $o->SUPER::selectMouse($force) or return;
    my $mouse = $o->{mouse};
    $mouse->{type} eq 'none' ||
      $old{type}   eq $mouse->{type}   && 
      $old{name}   eq $mouse->{name}   &&
      $old{device} eq $mouse->{device} && !$force and return;

    local $my_gtk::grab = 1; #- unsure a crazy mouse don't go wild clicking everywhere

    while (1) {
	log::l("telling X server to use another mouse");
	eval { modules::load('serial') } if $mouse->{device} =~ /ttyS/;

	if (!$::testing) {
	    devices::make($mouse->{device});
	    symlinkf($mouse->{device}, "/dev/mouse");
	    c::setMouseLive($ENV{DISPLAY}, mouse::xmouse2xId($mouse->{XMOUSETYPE}), $mouse->{nbuttons} < 3);
	}
	mouse::test_mouse_install($mouse) and return;
	$o->SUPER::selectMouse(1);
	$mouse = $o->{mouse};
    } 
}

#------------------------------------------------------------------------------
sub chooseSizeToInstall {
    my ($o, $packages, $min_size, $def_size, $max_size_, $availableC, $individual) = @_;
    my $max_size = min($max_size_, $availableC);
    my $enough = $max_size == $max_size_;
    my $percentage = int 100 * $max_size / $max_size_;

    #- don't ask anything if the difference between min and max is too small
    log::l("chooseSizeToInstall: min_size=$min_size, def_size=$def_size, max_size=$max_size_, available=$availableC");
    return $max_size if $min_size && $max_size / $min_size < 1.05;

    log::l("choosing size to install between $min_size and $max_size");
    my $w = my_gtk->new('');
    my $adj = create_adjustment(int(100 * $def_size / $max_size_), $min_size * 100 / $max_size_, $percentage);
    my $spin = gtkset_usize(new Gtk::SpinButton($adj, 0, 0), 20, 0);
    my $val;

    require pkgs;
    gtkadd($w->{window},
	  gtkpack(new Gtk::VBox(0,20),
		  _("The total size for the groups you have selected is approximately %d MB.\n", pkgs::correctSize($max_size_ / sqr(1024))) .
		  ($enough ?
_("If you wish to install less than this size,
select the percentage of packages that you want to install.

A low percentage will install only the most important packages;
a percentage of 100%% will install all selected packages.") : 
_("You have space on your disk for only %d%% of these packages.

If you wish to install less than this,
select the percentage of packages that you want to install.
A low percentage will install only the most important packages;
a percentage of %d%% will install as many packages as possible.", $percentage, $percentage))
. ($individual ? "\n\n" . _("You will be able to choose them more specifically in the next step.") : ''),
		 create_packtable({},
				  [ _("Percentage of packages to install") . '  ', $spin, "%", my $mb = new Gtk::Label ],
				  [ undef, new Gtk::HScrollbar($adj) ],
			       ),
		 create_okcancel($w)
		)
	 );
    $spin->signal_connect(changed => my $changed = sub { 
	$val = $spin->get_value_as_int / 100 * $max_size_;
	$mb->set(sprintf("(%dMB)", pkgs::correctSize($val / sqr(1024)))); 
    }); &$changed();
    $spin->signal_connect(activate => sub { $w->{retval} = 1; Gtk->main_quit });
    $spin->grab_focus();
    $w->main and $val + 1; #- add a single byte (hack?) to make selection of 0 bytes ok.
}

sub reallyChooseGroups {
    my ($o, $size_to_display, $individual, $val) = @_;

    my $w = my_gtk->new('');
    my $tips = new Gtk::Tooltips;
    my $w_size = new Gtk::Label(&$size_to_display);

    my $entry = sub {
	my ($e) = @_;
	my $text = translate($o->{compssUsers}{$e}{label});
	my $help = translate($o->{compssUsers}{$e}{descr});

	my $file = do {
	    my $f = "$ENV{SHARE_PATH}/icons/" . ($o->{compssUsers}{$e}{icons} || 'default');
	    -e "$f.png" or $f .= "_section";
	    -e "$f.png" or $f = "$ENV{SHARE_PATH}/icons/default_section";
	    "$f.png";
	};
	my $check = Gtk::CheckButton->new($text);
	$check->set_active($val->{$e});
	$check->signal_connect(clicked => sub { 
	    $val->{$e} = $check->get_active;
	    $w_size->set(&$size_to_display);
	});
	gtkset_tip($tips, $check, $help);
	gtkpack_(new Gtk::HBox(0,0), 0, gtkpng($file), 1, $check);
	#$check;
    };
    my $entries_in_path = sub {
	my ($path) = @_;
	translate($path), map { $entry->($_) } grep { $o->{compssUsers}{$_}{path} eq $path } @{$o->{compssUsersSorted}};
    };
    gtkadd($w->{window},
	   gtkpack($w->create_box_with_title(_("Package Group Selection")),
		   gtkpack_(new Gtk::VBox(0,0),
			   1, gtkpack_(new Gtk::HBox(0,0),
			        $o->{meta_class} eq 'server' ? (
				   1, gtkpack(new Gtk::VBox(0,0), 
					   $entries_in_path->('Server'),
					  ),
				   1, gtkpack(new Gtk::VBox(0,0), 
					   $entries_in_path->('Graphical Environment'),
					   '',
					   $entries_in_path->('Development'),
					   '',
					   $entries_in_path->('Utilities'),
					  ),
				) : (
				   1, gtkpack(new Gtk::VBox(0,0), 
					   $entries_in_path->('Workstation'),
					   '',
					   $entry->('Development|Development'),
					   $entry->('Development|Documentation'),
					  ),
				   0, gtkpack(new Gtk::VBox(0,0), 
					   $entries_in_path->('Server'),
					   '',
					   $entries_in_path->('Graphical Environment'),
					  ),
				),
			   )),
		   '',
		   gtkadd(new Gtk::HBox(0,0),
			  $w_size,
			  if_($individual, do {
			      my $check = Gtk::CheckButton->new(_("Individual package selection"));
			      $check->set_active($$individual);
			      $check->signal_connect(clicked => sub { $$individual = $check->get_active });
			      $check;
			  }),
			  gtksignal_connect(new Gtk::Button(_("Ok")), clicked => sub { Gtk->main_quit }),
			 ),
		  ),
	  );
    $w->{rwindow}->set_default_size($::windowwidth * 0.8, $::windowheight * 0.8);
    $w->main;
    1;    
}


sub choosePackagesTree {
    my ($o, $packages, $limit_to_medium) = @_;

    my $available = install_any::getAvailableSpace($o);
    my $availableCorrected = pkgs::invCorrectSize($available / sqr(1024)) * sqr(1024);

    my $common; $common = { get_status => sub {
				my $size = pkgs::selectedSize($packages);
				_("Total size: %d / %d MB", pkgs::correctSize($size / sqr(1024)), $available / sqr(1024));
			    },
			    node_state => sub {
				my $p = pkgs::packageByName($packages,$_[0]) or return;
				pkgs::packageMedium($packages, $p)->{selected} or return;
				pkgs::packageFlagBase($p) and return 'base';
				pkgs::packageFlagInstalled($p) and return 'installed';
				pkgs::packageFlagSelected($p) and return 'selected';
				return 'unselected';
			    },
			    build_tree => sub {
				my ($add_node, $flat) = @_;
				if ($flat) {
				    foreach (sort keys %{$packages->{names}}) {
					!$limit_to_medium ||
					  pkgs::packageMedium($packages, $packages->{names}{$_}) == $limit_to_medium or next;
					$add_node->($_, undef);
				    }
				} else {
				    foreach my $root (@{$o->{compssUsersSorted}}) {
					my (%fl, @firstchoice, @others);
					#$fl{$_} = $o->{compssUsersChoice}{$_} foreach @{$o->{compssUsers}{$root}{flags}}; #- FEATURE:improve choce of packages...
					$fl{$_} = 1 foreach @{$o->{compssUsers}{$root}{flags}};
					foreach my $p (values %{$packages->{names}}) {
					    !$limit_to_medium || pkgs::packageMedium($packages, $p) == $limit_to_medium or next;
					    my ($rate, @flags) = pkgs::packageRateRFlags($p);
					    next if !($rate && grep { grep { !/^!/ && $fl{$_} } split('\|\|') } @flags);
					    $rate >= 3 ?
					      push(@firstchoice, pkgs::packageName($p)) :
						push(@others,      pkgs::packageName($p));
					}
					my $root2 = join('|', map { translate($_) } split('\|', $root));
					$add_node->($_, $root2                   ) foreach sort @firstchoice;
					$add_node->($_, $root2 . '|' . _("Other")) foreach sort @others;
				    }
				}
			    },
			    get_info => sub {
				my $p = pkgs::packageByName($packages, $_[0]) or return '';
				pkgs::extractHeaders($o->{prefix}, [$p], $packages->{mediums});
				pkgs::packageHeader($p) or die;

				my $imp = translate($pkgs::compssListDesc{pkgs::packageFlagBase($p) ?
									  5 : pkgs::packageRate($p)});

				my $info = $@ ? _("Bad package") :
				  (_("Name: %s\n", pkgs::packageName($p)) .
				   _("Version: %s\n", pkgs::packageVersion($p) . '-' . pkgs::packageRelease($p)) .
				   _("Size: %d KB\n", pkgs::packageSize($p) / 1024) .
				   ($imp && _("Importance: %s\n", $imp)) . "\n" .
				   formatLines(c::headerGetEntry(pkgs::packageHeader($p), 'description')));
				pkgs::packageFreeHeader($p);
				return $info;
			    },
			    toggle_nodes => sub {
				my $set_state = shift @_;
				my @n = map { pkgs::packageByName($packages, $_) } @_;
				my %l;
				my $isSelection = !pkgs::packageFlagSelected($n[0]);
				foreach (@n) {
				    pkgs::togglePackageSelection($packages, $_, my $l = {});
				    @l{grep {$l->{$_}} keys %$l} = ();
				}
				if (my @l = keys %l) {
				    #- check for size before trying to select.
				    my $size = pkgs::selectedSize($packages);
				    foreach (@l) {
					my $p = $packages->{names}{$_};
					pkgs::packageFlagSelected($p) or $size += pkgs::packageSize($p);
				    }
				    if (pkgs::correctSize($size / sqr(1024)) > $available / sqr(1024)) {
					return $o->ask_warn('', _("You can't select this package as there is not enough space left to install it"));
				    }

				    @l > @n && $common->{state}{auto_deps} and
				      $o->ask_okcancel('', [ $isSelection ? 
							     _("The following packages are going to be installed") :
							     _("The following packages are going to be removed"),
							     common::formatList(20, sort @l) ], 1) || return;
				    if ($isSelection) {
					pkgs::selectPackage($packages, $_) foreach @n;
				    } else {
					pkgs::unselectPackage($packages, $_) foreach @n;
				    }
				    foreach (@l) {
					my $p = pkgs::packageByName($packages, $_);
					$set_state->($_, pkgs::packageFlagSelected($p) ? 'selected' : 'unselected');
				    }
				} else {
				    $o->ask_warn('', _("You can't select/unselect this package"));
				}
			    },
			    grep_allowed_to_toggle => sub {
				grep { $_ ne _("Other") && !pkgs::packageFlagBase(pkgs::packageByName($packages, $_)) } @_;
			    },
			    grep_unselected => sub {
				grep { !pkgs::packageFlagSelected(pkgs::packageByName($packages, $_)) } @_;
			    },
			    check_interactive_to_toggle => sub {
				my $p = pkgs::packageByName($packages, $_[0]) or return;
				if (pkgs::packageFlagBase($p)) {
				    $o->ask_warn('', _("This is a mandatory package, it can't be unselected"));
				} elsif (pkgs::packageFlagInstalled($p)) {
				    $o->ask_warn('', _("You can't unselect this package. It is already installed"));
				} elsif (pkgs::packageFlagUpgrade($p)) {
				    if ($::expert) {
					if (pkgs::packageFlagSelected($p)) {
					    $o->ask_yesorno('', _("This package must be upgraded.\nAre you sure you want to deselect it?")) or return;
					}
					return 1;
				    } else {
					$o->ask_warn('', _("You can't unselect this package. It must be upgraded"));
				    }
				} else { return 1; }
				return;
			    },
			    auto_deps => _("Show automatically selected packages"),
			    ok => _("Install"),
			    cancel => $limit_to_medium && _("Cancel"),
			    icons => [ { icon         => 'floppy',
					 help         => _("Load/Save on floppy"),
					 wait_message => _("Updating package selection"),
					 code         => sub { $o->loadSavePackagesOnFloppy($packages); 1; },
				       }, 
				       if_(0,