From 11a1b9567c53c489e6cd4a9f30528b0c39938c59 Mon Sep 17 00:00:00 2001 From: Yves Duret Date: Tue, 13 Mar 2001 17:06:00 +0000 Subject: bootlook.pm updated --- perl-install/bootlook.pm | 269 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 188 insertions(+), 81 deletions(-) (limited to 'perl-install/bootlook.pm') diff --git a/perl-install/bootlook.pm b/perl-install/bootlook.pm index 9b25fd1f6..1956eadcb 100644 --- a/perl-install/bootlook.pm +++ b/perl-install/bootlook.pm @@ -21,17 +21,20 @@ use Gtk; -use my_gtk qw(:helpers :wrappers); -use common; use Config; init Gtk; use POSIX; use Locale::GetText; +use lib qw(/usr/lib/libDrakX); +use interactive; +use common qw(:common :file :functional :system); +use my_gtk qw(:helpers :wrappers); use any; my $path_to_pixmaps = "/usr/share/libDrakX/pixmaps"; +#my $path_to_pixmaps = "."; setlocale (LC_ALL, ""); -Locale::GetText::textdomain ("Drakboot"); +Locale::GetText::textdomain ("Bootlookdrake"); import Locale::GetText I_; *_ = *I_; @@ -39,38 +42,40 @@ import Locale::GetText I_; $::isEmbedded = ($::XID, $::CCPID) = "@ARGV" =~/--embedded (\S*) (\S*)/; if ($::isEmbedded) { print "EMBED\n"; - print "XID: $::XID\n"; - print "CCPID: $::CCPID\n"; + print "XID : $::XID\n"; + print "CCPID : $::CCPID\n"; +# $path_to_pixmaps = "./pixmaps/"; } +my $in = vnew interactive('su'); local $_ = join '', @ARGV; /-h/ and die _("no help implemented yet.\n"); -my $x_mode = any::runlevel('') == 5; +my @winm; +my @usernames; +parse_etc_passwd(); + +my $x_mode = isXlaunched(); my $a_mode = (-e "/etc/aurora/Monitor") ? 1 : 0; my $l_mode = isAutologin(); +my %auto_mode = get_autologin(""); +my $inmain = 0; my $window = $::isEmbedded ? new Gtk::Plug ($::XID) : new Gtk::Window ("toplevel"); $window->signal_connect(delete_event => sub { $::isEmbedded ? kill(USR1, $::CCPID) : Gtk->exit(0) }); -$window->set_title(_("Boot Style Configuration")); -#$window->set_policy('automatic', 'automatic'); -#$window->set_policy(0, 0, 0); -$window->border_width (10); +$window->set_title(_("Boot Style Configuration") ); +$window->border_width(10); $window->realize; -# now for the pixmap from gdk - +# drakX mode my ($t_pixmap, $t_mask) = gtkcreate_xpm($window, "$path_to_pixmaps/tradi.xpm"); my ($h_pixmap, $h_mask) = gtkcreate_xpm($window, "$path_to_pixmaps/hori.xpm"); my ($v_pixmap, $v_mask) = gtkcreate_xpm($window, "$path_to_pixmaps/verti.xpm"); +my ($g_pixmap, $g_mask) = gtkcreate_xpm($window, "$path_to_pixmaps/gmon.xpm"); # a pixmap widget to contain the pixmap my $pixmap = new Gtk::Pixmap( $h_pixmap, $h_mask ); -#my $h_pixmapwid = new Gtk::Pixmap( $h_pixmap, $h_mask ); -#my $v_pixmapwid = new Gtk::Pixmap( $v_pixmap, $v_mask ); -#my $t_pixmapwid = new Gtk::Pixmap( $t_pixmap, $t_mask ); - ### menus definition # the menus are not shown @@ -92,56 +97,57 @@ my @menu_items = ( { path => _("/_File"), { path => _("/File/_Quit"), accelerator => _("Q"), callback => sub { $::isEmbedded ? kill(USR1, $::CCPID) : Gtk->exit(0) } }, - { path => _("/_Options"), type => '' }, - { path => _("/Options/Test") }, - + { path => _("/Options/Test")}, { path => _("/_Help"), type => '' }, - { path => _("/Help/_About...") } ); + { path => _("/Help/_About...")} ); my $menubar = get_main_menu( $window ); ######### menus end my $global_vbox = new Gtk::VBox(); - $global_vbox->pack_start (new Gtk::Label(_("Boot style configuration")), 0, 0, 0); - ######## aurora part -my $a_dedans = new Gtk::VBox( 0, 10 ); -$a_dedans->border_width (5); -my $a_box = new Gtk::VBox(0, 0 ); -my $a_button = new Gtk::CheckButton(_("Launch Aurora at boot time")); -$a_button->signal_connect( clicked => sub { - $a_box->set_sensitive(!$a_mode); - $pixmap->set($a_mode ? ($t_pixmap, $t_mask) : ($h_pixmap, $h_mask)); - $a_mode = !$a_mode; - }); -$a_dedans->pack_start ($a_button, 0, 0, 0); - +my $a_dedans = new Gtk::VBox(0, 10); +$a_dedans->border_width(5); +my $a_box = new Gtk::VBox(0, 0); my $a_h_button = new Gtk::RadioButton _("horizontal nice looking aurora"); -$a_h_button->signal_connect( clicked => sub { $pixmap->set($h_pixmap, $h_mask) }); -$a_h_button->set_active(1); +$a_h_button->signal_connect(clicked => sub { $pixmap->set($h_pixmap, $h_mask) }); $a_box->pack_start($a_h_button, 0, 0, 0); my $a_v_button = new Gtk::RadioButton _("vertical traditional aurora"), $a_h_button; -$a_v_button->signal_connect( clicked => sub { $pixmap->set($v_pixmap, $v_mask) }); +$a_v_button->signal_connect(clicked => sub { $pixmap->set($v_pixmap, $v_mask) }); $a_box->pack_start($a_v_button, 0, 0, 0); my $a_g_button = new Gtk::RadioButton _("gMonitor"), $a_h_button; +$a_g_button->signal_connect(clicked => sub { $pixmap->set($g_pixmap, $g_mask) }); $a_box->pack_start($a_g_button, 0, 0, 0); +my $a_button = new Gtk::CheckButton(_("Launch Aurora at boot time") ); +$a_button->signal_connect(clicked => sub { + if ($inmain) { + $a_box->set_sensitive(!$a_mode); + $a_mode = !$a_mode; + if ($a_mode) { + $pixmap->set($h_pixmap, $h_mask) if $a_h_button->get_active(); + $pixmap->set($v_pixmap, $v_mask) if $a_v_button->get_active(); + $pixmap->set($g_pixmap, $g_mask) if $a_g_button->get_active(); + } else { + $pixmap->set($t_pixmap, $t_mask); + } + } + }); +$a_dedans->pack_start($a_button, 0, 0, 0); $a_dedans->pack_start ($a_box, 0, 0, 0); my $a_main_hbox = new Gtk::HBox; $a_main_hbox->pack_start ($a_dedans, 0, 0, 0); my $a_pix_hbox = new Gtk::HBox; $a_pix_hbox->border_width(10); - $a_pix_hbox->pack_start ($pixmap, 0, 0, 0); - $a_main_hbox->pack_end ($a_pix_hbox, 0, 0, 0); my $aurora_frame = new Gtk::Frame _("Boot mode"); @@ -149,36 +155,41 @@ $aurora_frame->add($a_main_hbox); $global_vbox->pack_start ($aurora_frame, 0, 0, 0); ### X mode -my $x_dedans = new Gtk::VBox( 0, 10 ); +my $x_dedans = new Gtk::VBox(0, 10); $x_dedans->border_width (5); -my $x_box = new Gtk::VBox(0, 0 ); +my $x_box = new Gtk::VBox(0, 0); $x_box->border_width (10); my $x_button = new Gtk::CheckButton _("Launch the X-Window system at start"); $x_button->set_active($x_mode); -$x_button->signal_connect( clicked => sub { +$x_button->signal_connect(clicked => sub { $x_box->set_sensitive(!$x_mode); $x_mode = !$x_mode; }); $x_dedans->pack_start ($x_button, 0, 0, 0); -my $x_no_button = new Gtk::RadioButton _("no, I don't want autologin"); +my $x_no_button = new Gtk::RadioButton _("No, I don't want autologin"); $x_no_button->set_active(!$l_mode); $x_box->pack_start($x_no_button, 0, 0, 0); -my $user_dedans = new Gtk::HBox( 0, 10 ); +my $user_dedans = new Gtk::HBox(0, 10); $user_dedans->border_width (0); -my $x_yes_button = new Gtk::RadioButton _("yes, I want autologin with this (user, desktop)"), $x_no_button; +my $x_yes_button = new Gtk::RadioButton _("Yes, I want autologin with this (user , desktop)"), $x_no_button; $x_yes_button->set_active($l_mode); +my $x_combo_vbox = new Gtk::VBox(0, 10); my $user_combo = new Gtk::Combo; -$user_combo->set_popdown_strings(parse_etc_passwd()); -my $desktop_combo = new Gtk::Combo; +$user_combo->set_popdown_strings(@usernames); +$user_combo->entry->set_text($auto_mode{autologin}) if ($auto_mode{autologin}); + +my $desktop_combo =new Gtk::Combo; +$desktop_combo->set_popdown_strings(get_wm()); +$desktop_combo->entry->set_text($auto_mode{desktop}) if ($auto_mode{desktop}); +$x_combo_vbox->pack_start($user_combo, 0, 0, 0); +$x_combo_vbox->pack_start($desktop_combo, 0, 0, 0); $user_dedans->pack_start($x_yes_button, 0, 0, 0); -$user_dedans->pack_start($user_combo, 0, 0, 0); -#$user_dedans->pack_start($desktop_combo, 0, 0, 0); +$user_dedans->pack_start($x_combo_vbox, 0, 0, 0); $x_box->pack_start ($user_dedans, 0, 0, 0); - -$x_box->set_sensitive(!$x_mode); +$x_box->set_sensitive($x_mode); $x_dedans->pack_start ($x_box, 0, 0, 0); my $x_main_frame = new Gtk::Frame _("System mode"); $x_main_frame->add($x_dedans); @@ -186,40 +197,57 @@ $global_vbox->pack_start ($x_main_frame, 1, 1, 0); ### final buttons my $build_button = new Gtk::Button _("OK"); -my $cancel_button = new Gtk::Button _("Cancel"); +my $cancel_button = new Gtk::Button _("Quit"); my $fin_hbox = new Gtk::HBox( 0, 0 ); $cancel_button->signal_connect( clicked => sub {$::isEmbedded ? kill(USR1, $::CCPID) : Gtk->exit(0)}); -$build_button->signal_connect( clicked => sub { any::runlevel('', $x_mode ? 5 : 3); updateAutologin() }); +$build_button->signal_connect(clicked => sub {updateInit(); updateAutologin(); updateAurora();}); $fin_hbox->pack_end($cancel_button, 0, 0, 0); $fin_hbox->pack_end($build_button, 0, 0, 10); -$global_vbox->pack_start ($fin_hbox, 0, 0, 0); +$global_vbox->pack_start($fin_hbox, 0, 0, 0); ### back to window -$window->add( $global_vbox ); - +$window->add($global_vbox); $window->show_all(); -print "---->$a_mode<----\n"; - -$a_button->set_active(!$a_mode); -$a_box->set_sensitive(!$a_mode); -$pixmap->set($a_mode ? ($h_pixmap, $h_mask) : ($t_pixmap, $t_mask)); +$a_box->set_sensitive($a_mode); # box grisée == false == "0" +$a_button->set_active($a_mode); # up == false == "0" if ($a_mode) { - print "some where aurora exists ...\n"; -#we need to choose acording the aurora style -} else { - print "here aurora does not exist..\n"; + my $a = readlink "/etc/aurora/Monitor"; + $a =~ s#/lib/aurora/Monitors/##; + $a_h_button->set_active(1) && $pixmap->set($h_pixmap, $h_mask) if ($a eq "NewStyle-WsLib"); + $a_v_button->set_active(1) && $pixmap->set($v_pixmap, $v_mask) if ($a eq "Traditional-WsLib"); + $a_g_button->set_active(1) && $pixmap->set($g_pixmap, $g_mask) if ($a eq "Traditional-Gtk+"); +} else { + $pixmap->set($t_pixmap, $t_mask); } -Gtk->main_iteration while Gtk->events_pending; -$::isEmbedded and kill USR2, $::CCPID; -Gtk->main; +$a_h_button->hide() if !(-e "/lib/aurora/Monitors/NewStyle-WsLib"); +$a_v_button->hide() if !(-e "/lib/aurora/Monitors/Traditional-WsLib"); +$a_g_button->hide() if !(-e "/lib/aurora/Monitors/Traditional-Gtk+"); + +$inmain=1; +main Gtk; + #------------------------------------------------------------- # get user names to put in combo #------------------------------------------------------------- -sub parse_etc_passwd { - map { $_->[0] } grep { $_->[2] >= 500 } common::list_passwd(); +sub parse_etc_passwd +{ + my ($uname, $uid); + setpwent(); + do { + @user_info = getpwent(); + ($uname, $uid) = @user_info[0,2]; + if ($uid > 500) { + push (@usernames, $uname); + } + } while (@user_info); +} + +sub get_wm +{ + @winm = (split (' ', `/usr/sbin/chksession -l`)); } #------------------------------------------------------------- @@ -231,30 +259,109 @@ sub print_hello { } sub get_main_menu { - my ($window) = @_; + my ( $window ) = @_; my $accel_group = new Gtk::AccelGroup(); my $item_factory = new Gtk::ItemFactory( 'Gtk::MenuBar', '
', $accel_group ); - $item_factory->create_items(@menu_items); - $window->add_accel_group($accel_group); - return $item_factory->get_widget('
'); + $item_factory->create_items( @menu_items ); + $window->add_accel_group( $accel_group ); + return ( $item_factory->get_widget( '
' ) ); +} + +#------------------------------------------------------------- +# launch X functions +#------------------------------------------------------------- + +sub isXlaunched +{ + my $line; + + open INITTAB, "/etc/inittab" or die _("can not open /etc/inittab for reading : $!"); + while () { + if (/id:([1-6]):initdefault:/) { $line = $_; last; } + } + close INITTAB; + $line =~ s/id:([1-6]):initdefault:/$1/; + return ($line-3); } +sub updateInit +{ + my $runlevel = ($x_mode) ? 5 : 3; + substInFile { s/^id:\d:initdefault:\s*$/id:$runlevel:initdefault:\n/ } "/etc/inittab"; +} + +#------------------------------------------------------------- +# aurora functions +#------------------------------------------------------------- + +sub updateAurora +{ + if ($a_mode) { + symlinkf("/lib/aurora/Monitors/NewStyle-WsLib", "/etc/aurora/Monitor") if $a_h_button->get_active(); + symlinkf("/lib/aurora/Monitors/Traditional-WsLib", "/etc/aurora/Monitor") if $a_v_button->get_active(); + symlinkf("/lib/aurora/Monitors/Traditional-Gtk+", "/etc/aurora/Monitor") if $a_g_button->get_active(); + } else { + unlink "/etc/aurora/Monitor"; + } + +} + +#sub AuroraChoose +#{ +# opendir YREP, "/lib/aurora/Monitors" or die "bootlook: $!"; +# @files = grep !/^\.\.?$/, readdir YREP; +# print @files; +# closedir YREP; +#} #------------------------------------------------------------- # launch autologin functions #------------------------------------------------------------- -sub isAutologin { - ${{ common::getVarsFromSh("/etc/sysconfig/autologin") }}{AUTOLOGIN} eq 'yes'; +sub isAutologin +{ + my $line; + + open AUTOLOGIN, "/etc/sysconfig/autologin" or die _("can not open /etc/sysconfig/autologin for reading : $!"); + while () { + if (/AUTOLOGIN=(yes|no)/) { $line = $_; last; } + } + close AUTOLOGIN; + $line =~ s/AUTOLOGIN=(yes|no)/$1/; + chomp ($line); + $line = ($line eq "yes"); + return ($line); +} + +sub get_autologin { + my ($prefix) = @_; + my %o; + my %l = getVarsFromSh("$prefix/etc/sysconfig/autologin"); + + $o{autologin} = $l{USER}; + %l = getVarsFromSh("$prefix/etc/sysconfig/desktop"); + $o{desktop} = $l{DESKTOP}; + %o; } sub updateAutologin -{ - my ($autologin) = @_; - substInFile { - s/^AUTOLOGIN=.*//; - $_ .= 'AUTOLOGIN=' . bool2yesno($autologin) . "\n" if eof; - } '/etc/sysconfig/autologin'; +{ + my ($usern,$deskt)=($user_combo->entry->get_text(), $desktop_combo->entry->get_text()); + + if($x_yes_button->get_active() ) { + set_autologin('',$usern,$deskt); + } else { + set_autologin('',undef) if ($x_no_button->get_active()); + } } +sub set_autologin { + my ($prefix, $user, $desktop) = @_; + + output "$prefix/etc/sysconfig/desktop", uc($desktop), "\n" if $user; + + setVarsInSh("$prefix/etc/sysconfig/autologin", + { USER => $user, AUTOLOGIN => bool2yesno($user), EXEC => "/usr/X11R6/bin/startx" }); +# log::l("cat $prefix/etc/sysconfig/autologin: ", cat_("$prefix/etc/sysconfig/autologin")); +} -- cgit v1.2.1