package install_gtk; # $Id$
use diagnostics;
use strict;
use ugtk2;
use mygtk2;
use common;
use lang;
use devices;
#-#####################################################################################
#-INTERN CONSTANT
#-#####################################################################################
#- if we're running for the doc team, we want screenshots with
#- a good B&W contrast: we'll override values of our theme
my $theme_overriding_for_doc = q(style "galaxy-default"
{
base[SELECTED] = "#E0E0FF"
base[ACTIVE] = "#E0E0FF"
base[PRELIGHT] = "#E0E0FF"
bg[SELECTED] = "#E0E0FF"
bg[ACTIVE] = "#E0E0FF"
bg[PRELIGHT] = "#E0E0FF"
text[ACTIVE] = "#000000"
text[PRELIGHT] = "#000000"
text[SELECTED] = "#000000"
fg[SELECTED] = "#000000"
}
style "white-on-blue"
{
base[NORMAL] = { 0.93, 0.93, 0.93 }
bg[NORMAL] = { 0.93, 0.93, 0.93 }
text[NORMAL] = "#000000"
fg[NORMAL] = "#000000"
}
style "background"
{
bg[NORMAL] = { 0.93, 0.93, 0.93 }
}
style "background-logo"
{
bg[NORMAL] = { 0.70, 0.70, 0.70 }
}
widget "*logo*" style "background-logo"
);
#------------------------------------------------------------------------------
sub load_rc {
my ($o, $name) = @_;
my $f = $name;
-r $name or $f = find { -r $_ } map { "$_/themes-$name.rc" } ("share", $ENV{SHARE_PATH}, dirname(__FILE__));
if ($f) {
Gtk2::Rc->parse_string($o->{doc} ? $theme_overriding_for_doc : scalar cat_($f));
}
if ($::move) {
#- override selection color since we will not do inverse-video on the text when it's images
Gtk2::Rc->parse_string(q(
style "galaxy-default"
{
base[ACTIVE] = "#CECECE"
base[SELECTED] = "#CECECE"
text[ACTIVE] = "#000000"
text[PRELIGHT] = "#000000"
text[SELECTED] = "#000000"
}
));
}
}
#------------------------------------------------------------------------------
sub load_font {
my ($o) = @_;
if (lang::text_direction_rtl()) {
Gtk2::Widget->set_default_direction('rtl');
my ($x, $y) = $::WizardWindow->get_position;
my ($width) = $::WizardWindow->get_size;
$::WizardWindow->move($::rootwidth - $width - $x, $y);
}
Gtk2::Rc->parse_string(q(
style "default-font"
{
font_name = ") . lang::l2pango_font($o->{locale}{lang}) . q("
}
widget "*" style "default-font"
));
}
#------------------------------------------------------------------------------
sub default_theme {
my ($o) = @_;
$::move ? '' :
$o->{simple_themes} || $o->{vga16} ? 'blue' : 'galaxy';
}
sub install_theme {
my ($o) = @_;
load_rc($o, $o->{theme} ||= default_theme($o));
load_font($o);
if (!$::move) {
my $win = gtknew('Window', widget_name => 'background');
$win->realize;
mygtk2::set_root_window_background_with_gc($win->style->bg_gc('normal'));
}
}
#------------------------------------------------------------------------------
my %steps;
sub create_steps_window {
my ($o) = @_;
return if $::stepswidth == 0;
$o->{steps_window} and $o->{steps_window}->destroy;
$steps{$_} ||= gtknew('Pixbuf', file => "steps_$_") foreach qw(on off);
my $category = sub {
gtknew('HBox', children_tight => [
gtknew('Label', text => $_[0], widget_name => 'Step-categories')
]);
};
my @l = $category->(N("System installation"));
foreach (grep { !eval $o->{steps}{$_}{hidden} } @{$o->{orderedSteps}}) {
if ($_ eq 'setRootPassword') {
push @l, '', $category->(N("System configuration"));
}
my $img = gtknew('Image', file => 'steps_off.png');
$steps{steps}{$_}{img} = $img;
push @l, gtknew('HBox', spacing => 7, children_tight => [ '', '', $img, translate($o->{steps}{$_}{text}) ]);
}
my $offset = 20;
$o->{steps_window} =
gtknew('Window', width => ($::stepswidth - $offset), widget_name => 'Steps',
position => [ lang::text_direction_rtl() ? $::rootwidth - $::stepswidth : $offset, 150 ],
child => gtknew('VBox', spacing => 6, children_tight => \@l));
$o->{steps_window}->show;
}
sub update_steps_position {
my ($o) = @_;
return if !$steps{steps};
my $last_step;
foreach (@{$o->{orderedSteps}}) {
exists $steps{steps}{$_} or next;
if ($o->{steps}{$_}{entered} && !$o->{steps}{$_}{done}) {
$steps{steps}{$_}{img}->set_from_pixbuf($steps{on});
$last_step and $steps{steps}{$last_step}{img}->set_from_pixbuf($steps{off});
return;
}
$last_step = $_;
}
}
#------------------------------------------------------------------------------
sub create_logo_window {
my ($o) = @_;
return if $::logowidth == 0 || $::move;
mygtk2::may_destroy($o->{logo_window});
my $file = $o->{meta_class} eq 'firewall' ? "logo-mandrake-Firewall.png" : "logo-mandrake.png";
$o->{logo_window} =
gtknew('Window',
width => $::logowidth, height => $::logoheight,
widget_name => 'logo',
child => gtknew('Image', file => $file),
);
$o->{logo_window}->show;
}
#------------------------------------------------------------------------------
sub init_gtk {
my ($o) = @_;
symlink("/tmp/stage2/etc/$_", "/etc/$_") foreach qw(gtk-2.0 pango fonts);
if ($o->{vga16}) {
#- inactivate antialias in VGA16 because it makes fonts look worse
output('/tmp/fonts.conf',
q(
package install_steps;
use diagnostics;
use strict;
use vars qw(@filesToSaveForUpgrade);
#-######################################################################################
#- misc imports
#-######################################################################################
use common qw(:file :system :common :functional);
use install_any qw(:all);
use partition_table qw(:types);
use detect_devices;
use modules;
use run_program;
use lang;
use raid;
use keyboard;
use log;
use fsedit;
use loopback;
use commands;
use network;
use any;
use fs;
@filesToSaveForUpgrade = qw(
/etc/ld.so.conf /etc/fstab /etc/hosts /etc/conf.modules
);
#-######################################################################################
#- OO Stuff
#-######################################################################################
sub new($$) {
my ($type, $o) = @_;
bless $o, ref $type || $type;
return $o;
}
#-######################################################################################
#- In/Out Steps Functions
#-######################################################################################
sub enteringStep {
my ($o, $step) = @_;
log::l("starting step `$step'");
}
sub leavingStep {
my ($o, $step) = @_;
log::l("step `$step' finished");
if (-d "$o->{prefix}/root") {
eval { commands::cp('-f', "/tmp/ddebug.log", "$o->{prefix}/root") };
install_any::g_auto_install();
}
for (my $s = $o->{steps}{first}; $s; $s = $o->{steps}{$s}{next}) {
#- the reachability property must be recomputed each time to take
#- into account failed step.
next if $o->{steps}{$s}{done} && !$o->{steps}{$s}{redoable};
my $reachable = 1;
if (my $needs = $o->{steps}{$s}{needs}) {
my @l = ref $needs ? @$needs : $needs;
$reachable = min(map { $o->{steps}{$_}{done} || 0 } @l);
}
$o->{steps}{$s}{reachable} = 1 if $reachable;
}
$o->{steps}{$step}{reachable} = $o->{steps}{$step}{redoable};
while (my $f = shift @{$o->{steps}{$step}{toBeDone} || []}) {
eval { &$f() };
$o->ask_warn(_("Error"), [
_("An error occurred, but I don't know how to handle it nicely.
Continue at your own risk."), $@ ]) if $@;
}
}
sub errorInStep($$) { print "error :(\n"; c::_exit(1) }
sub kill_action {}
sub set_help { 1 }
#-######################################################################################
#- Steps Functions
#-######################################################################################
#------------------------------------------------------------------------------
sub selectLanguage {
my ($o) = @_;
lang::set($o->{lang});
$o->{langs} ||= [ $o->{lang} ];
if ($o->{keyboard_unsafe} || !$o->{keyboard}) {
$o->{keyboard_unsafe} = 1;
$o->{keyboard} = keyboard::lang2keyboard($o->{lang});
selectKeyboard($o);
}
}
#------------------------------------------------------------------------------
sub selectKeyboard {
my ($o) = @_;
keyboard::setup($o->{keyboard});
lang::set_langs($o->{langs});
}
#------------------------------------------------------------------------------
sub selectPath {}
#------------------------------------------------------------------------------
sub selectInstallClass($@) {
my ($o) = @_;
$o->{installClass} ||= $::corporate ? "corporate" : "normal";
$o->{security} ||= ${{
normal => 2,
developer => 3,
corporate => 3,
server => 4,
}}{$o->{installClass}};
}
#------------------------------------------------------------------------------
sub setupSCSI {
modules::load_ide();
modules::load_thiskind('scsi');
}
#------------------------------------------------------------------------------
sub doPartitionDisks {
my ($o, $hds) = @_;
if ($o->{lnx4win}) {
my @l = sort { $a->{device_windobe} cmp $b->{device_windobe} }
grep { isFat($_) } fsedit::get_fstab(@{$o->{hds}}) or die "wow, lnx4win with no fat partitions! hard times :(";
my $real_part = @l > 1 && $o->doPartitionDisksLnx4winDev(\@l) || $l[0];
my $handle = loopback::inspect($real_part, '', 'rw') or die _("This partition can't be used for loopback");
my $size = loopback::getFree($handle->{dir}, $real_part);
my $max_linux = 1000 << 11; $max_linux *= 10 if $::expert;
my $min_linux = 300 << 11; $min_linux /= 3 if $::expert;