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 resource. 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 { !/Utilities/ && $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), $entry->('Development|Development'), $entry->('Development|Documentation'), '', $entries_in_path->('Graphical Environment'), ), ) : ( 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::pack