From b0ec9db99eabf9190b27ce945d3536d672251ac2 Mon Sep 17 00:00:00 2001 From: Thierry Vignaud Date: Mon, 9 Sep 2002 10:25:25 +0000 Subject: - consolidate some code in fork_() - use fork_: don't freeze in connecting to themes site, drakbug - consolidate some code in new_dialog() - drakconnect is too big too --- control-center | 94 ++++++++++++++++++++++++++-------------------------------- 1 file changed, 42 insertions(+), 52 deletions(-) diff --git a/control-center b/control-center index d71a5a79..f121236b 100755 --- a/control-center +++ b/control-center @@ -1,13 +1,13 @@ #!/usr/bin/perl # $Id$ -# Copyright (C) 1999-2001 MandrakeSoft -# Damien Krotkine (damien@mandrakesoft.com) +# Copyright (C) 1999-2002 MandrakeSoft +# Damien Krotkine +# Thierry Vignaud (tvignaud@mandrakesoft.com) # -# 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 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 @@ -275,7 +275,7 @@ my ($index, $left_locked, $pending_app) = (0, 0, 0); my $darea_left_sav; my $back; ($back->[0], undef) = gtkcreate_png('mcc-left-back'); -$back->[1] = $back->[0]; + $back->[1] = $back->[0]; ($back->[2], undef) = gtkcreate_png('mcc-left-back2'); # Create left icons foreach (@tree) { @@ -288,11 +288,11 @@ foreach (@tree) { my ($dbl_area_left, $pix, $width, $height); $darea_left->set_events(['exposure_mask', 'enter_notify_mask', 'leave_notify_mask', 'button_press_mask', 'button_release_mask' ]); - my @left_back_pixbuf; # 0 => unselected, 1 => highlited, 2 => selected - $left_back_pixbuf[0] = compose_with_back($_->[1], $left_back_pixbuf_unaltered); - $left_back_pixbuf[2] = compose_with_back($_->[1], $left_back_pixbuf_unaltered_h); - $left_back_pixbuf[1] = compose_with_back($_->[1], $left_back_pixbuf_unaltered, 170); + my @left_back_pixbuf = ( + compose_with_back($_->[1], $left_back_pixbuf_unaltered), + compose_with_back($_->[1], $left_back_pixbuf_unaltered, 170), + compose_with_back($_->[1], $left_back_pixbuf_unaltered_h)); my ($pixbuf_width, $pixbuf_height) = ($left_back_pixbuf[0]->get_width, $left_back_pixbuf[0]->get_height); my $draw = sub { my ($dx, $dy) = ($darea_left->allocation->[2], $darea_left->allocation->[3]); @@ -573,6 +573,16 @@ sub sig_usr2 { } } +sub fork_ { + my ($prog) = @_; + my $pid; + unless ($pid = fork) { + splash_warning(_("cannot fork: %s", $~)) unless defined $pid; + exec($prog); + } + push @pid_launched, $pid; +} + sub compute_exec_string { my ($icon, $log_exp, $exec, $gtkplug, $alternate) = ($_[0], @{$_[1]}); if ($embedded) { @@ -595,26 +605,17 @@ sub compute_exec_string { $timeout = Gtk->timeout_add(70, sub { $run_darea->draw(undef); 1 }); $left_locked = 1; $pending_app = 1; - my $pid; - unless ($pid = fork) { - splash_warning(_("cannot fork: %s", $~)) unless defined $pid; - exec($exec); - } - push @pid_launched, $pid; + fork_($exec); } elsif ($gtkplug == -1) { # explicitely not embedded - unless ($pid = fork) { - splash_warning(_("cannot fork: %s", $~)) unless defined $pid; - exec($exec); - } - #system($exec . " &"); + fork_($exec); } else { # gtkplug == 0 $emb_socket->show; $SIG{CHLD} = undef; $emb_socket->steal(launch_xapp($alternate)); - $SIG{CHLD} = sub { wait() }; + $SIG{CHLD} = wait; } } else { # not embedded - system(($gtkplug == 0 ? $alternate->[0] : $alternate || $exec) . " &"); + fork_($gtkplug == 0 ? $alternate->[0] : $alternate || $exec); } if ($embedded && $gtkplug != -1) { foreach (@darea_left_list) { @@ -631,26 +632,16 @@ sub compute_exec_string { $exp_socket->realize; my $exec_log = "logdrake --explain=$log_exp --embedded " . $exp_socket->window->XWINDOW . " " . $$; $show_log = 0; - if ($exec =~ /drakfont/) { $exp_frame->hide(); } - unless ($pid = fork) { - splash_warning(_("cannot fork: %s", $~)) unless defined $pid; - print "explain : $log_exp \n "; - exec($exec_log); - } - push @pid_exp, $pid; + if ($exec =~ /(drakfont|drakconnect)/) { $exp_frame->hide() } # $window_global->height < 600 + fork_($exec_log); } } sub launch_xapp { my $b = "xwininfo -root -tree -int | grep '" . $_[0]->[1] . "'"; my @before = split ('\n', `$b`); - my $pid; my $mcc_pid = $$; - unless ($pid = fork) { - splash_warning(_("cannot fork: %s", $~)) unless defined $pid; - exec($_[0]->[0] . "; kill -USR1 $mcc_pid"); - } - push @pid_launched, $pid; + fork_($_[0]->[0] . "; kill -USR1 $mcc_pid"); my $res = 0; while (!$res) { my @after = split ('\n', `$b`); @@ -721,13 +712,21 @@ sub splash_warning { $ret; } -sub more_themes { +sub new_dialog { + my ($title) = @_; my $window_about = new Gtk::Dialog(); $window_about->set_position(1); $window_about->set_border_width(10); - $window_about->set_title(_("More themes")); + $window_about->set_title($title); $window_about->action_area->pack_start(gtkadd(new Gtk::HButtonBox, gtksignal_connect(new Gtk::Button(_("Close")), "clicked" => sub { $window_about->destroy() })),0,0,0); + $window_about->set_policy(0, 0, 1); + $window_about->set_modal(1); + $window_about; +} + +sub more_themes { + my $window_about = new_dialog(_("More themes")); my $style1 = $window_about->style->copy(); $style1->font(Gtk::Gdk::Font->fontset_load(_("-*-helvetica-medium-r-normal-*-20-*-100-100-p-*-iso8859-1,*-r-*"))); gtkpack_($window_about->vbox, @@ -738,18 +737,11 @@ sub more_themes { ) ) ); - $window_about->set_policy(0, 0, 1); $window_about->show_all(); - $window_about->set_modal(1); } sub about_mdk_cc { - my $window_about = new Gtk::Dialog(); - $window_about->set_position(1); - $window_about->set_border_width(10); - $window_about->set_title(_("About - Mandrake Control Center")); - $window_about->action_area->pack_start(gtkadd(new Gtk::HButtonBox, - gtksignal_connect(new Gtk::Button(_("Close")), "clicked" => sub { $window_about->destroy() })),0,0,0); + my $window_about = new_dialog(_("About - Mandrake Control Center")); my $label = new Gtk::Label(); my $style1 = $label->style->copy(); @@ -779,9 +771,7 @@ sub about_mdk_cc { 1, $clist, ); $clist->columns_autosize(); - $window_about->set_policy(0, 0, 1); $window_about->show_all(); - $window_about->set_modal(1); } sub connect_to_site { @@ -792,10 +782,10 @@ sub connect_to_site { if (!$browser) { splash_warning(" ". _("Warning: No browser specified") ." "); return } if ($help) { - system("$browser $link &"); + fork_("$browser $link &"); } else { if ($initial_user ne "root" && $initial_user ne undef) { - system("su -m -l $initial_user -c \"$browser $link &\""); + fork_("su -m -l $initial_user -c \"$browser $link &\""); } else { splash_warning(" "._("Security Warning: I'm not allowed to connect to the internet as root user")." "); } @@ -844,7 +834,7 @@ sub get_main_menu { { path => _("/_Help"), type => '' }, { path => _("/Help")._("/_Report Bug"), - callback => sub { system("drakbug --report drakconf &") } }, + callback => sub { fork_("drakbug --report drakconf &") } }, { path => _("/Help")._("/_About..."), callback => \&about_mdk_cc } ) -- cgit v1.2.1