#!/usr/bin/perl -w # $Id$ # Copyright (C) 1999-2001 MandrakeSoft # Yves Duret # Damien Krotkine (damien@mandrakesoft.com) # Daouda Lo (daouda@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 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. use Config; use POSIX; my $_xbindir = "/usr/X11R6/bin"; my $_bindir = "/usr/bin"; my $_sbindir = "/usr/sbin"; my $_iconsdir = "/usr/share/icons"; my $_docdir = "/usr/share/doc"; my $_wizdir = "/usr/share/wizards"; my $_version = "0.70"; !$ENV{DISPLAY} and exec ("$_sbindir/drakxconf; reset"); use lib qw(/usr/lib/libDrakX); use common; use interactive; use standalone; my $in = 'interactive'->vnew('su', 'default'); require Gtk; require Gtk::Gdk::ImlibImage; init Gtk; Gtk->set_locale; Gtk::Gdk::ImlibImage->init; my %pixmaps_global; my $xpm_path="$_iconsdir"; my $xpm_path_l="$_iconsdir"; my $tree_depth_max = 1; my $treeitem_old; my @treeitem_sub; #------------------------------------------------------------- # tree def #------------------------------------------------------------- # proposal for the ultimate conf file.. ?? # leaf: label, icon, parent, file_to_seek, exec, gtk/x, grep, num_xwininfo # hum need to have a function to install a package when clicked. => rpmdrake $::isWiz = $in->do_pkgs->is_installed(q(wizard)); my @tree_parent = ([_("Boot"), 'boot-mdk.png'], [_("Hardware"), 'drakhard-mdk.png'], [_("Network & Internet"),'net-mdk.png'], [_("Security"),'security-mdk.png'], [_("System"),'system-mdk.png'], if_($::isWiz, [_("Servers"),'net-mdk.png']) ); my @tree_app = ([_("Boot Disk"), 'drakfloppy-mdk.png',1] , [_("Boot Config"),'drakboot-mdk.png',1], [_("Auto Install"), 'drakfloppy-mdk.png', 1], [_("Display"),'XFdrake-mdk.png',2] , [_("Hardware"),'harddrake-mdk.png',2] , [_("Mouse"), 'mousedrake-mdk.png',2], [_("Printer"),'printer-mdk.png',2] , [_("Keyboard"), 'keyboard-mdk.png',2], [_("Mount Points"),'partition-mdk.png',2], [_("Connection") , 'draknet-mdk.png',3] , [_("Connection Sharing"),'drakgw-mdk.png',3], #[_("Proxy"), 'drakgw-mdk.png', 3], [_("Security Level"), 'draksec-mdk.png',4], [_("Firewalling"), 'firewall-mdk.png',4], [_("Menus") , 'menudrake-mdk.png',5], [_("Services") , 'service-mdk.png' , 5], [_("Fonts"), 'drakfont-mdk.png',5], [_("Date & Time") , 'time-mdk.png',5], [_("Software Manager"), 'harddrake-mdk.png',5], [_("Logs"), 'logdrake-mdk.png',5], [_("Console"), 'drakboot-mdk.png', 5], if_($::isWiz,[_("Configuration Wizards"), 'service-mdk.png', 6]), # if_($::isWiz,[_("client"), 'drakboot-mdk.png', 6]), # if_($::isWiz,[_("Database"), 'drakboot-mdk.png', 6]), # if_($::isWiz,[_("Dhcp Server"), 'drakboot-mdk.png', 6]), # if_($::isWiz,[_("DNS"), 'drakboot-mdk.png', 6]), # if_($::isWiz,[_("Firewall"), 'drakboot-mdk.png', 6]), # if_($::isWiz,[_("Ftp Server"), 'drakboot-mdk.png', 6]), # if_($::isWiz,[_("global"), 'drakboot-mdk.png', 6]), # if_($::isWiz,[_("News Server"), 'drakboot-mdk.png', 6]), # if_($::isWiz,[_("Mail Server"), 'drakboot-mdk.png', 6]), # if_($::isWiz,[_("Samba Server"), 'drakboot-mdk.png', 6]), # if_($::isWiz,[_("server"), 'drakboot-mdk.png', 6]), # if_($::isWiz,[_("Time"), 'drakboot-mdk.png', 6]), # if_($::isWiz,[_("Web Server"), 'drakboot-mdk.png', 6]), ); my %tree_exec = (_("Boot Disk") => "$_xbindir/drakfloppy.real", _("Boot Config") => "$_sbindir/drakboot", _("Auto Install") => "$_sbindir/drakautoinst", _("Display") => "$_sbindir/XFdrake" , _("Hardware") => "$_sbindir/harddrake" , _("Mouse") => "$_sbindir/mousedrake" , _("Printer") => "$_sbindir/printerdrake" , _("Keyboard") => "$_sbindir/keyboarddrake" , _("Mount Points") => "$_sbindir/diskdrake", _("Connection") => "$_sbindir/draknet", _("Connection Sharing") => "$_sbindir/drakgw", _("Proxy") => "$_sbindir/drakproxy", _("Firewalling") => "$_sbindir/tinyfirewall", _("Security Level") => "$_sbindir/draksec", _("Date & Time") => "$_sbindir/clock.pm", _("Menus") => "$_sbindir/menus.pm", _("Services") => "$_sbindir/drakxservices", _("Fonts") => "$_xbindir/drakfont", _("Software Manager") => "$_bindir/rpmdrake", _("Logs") => "$_sbindir/logdrake", _("Console") => "$_xbindir/rxvt", # wizard java _("Configuration Wizards") => "$_sbindir/wizdrake", # _("client") => "$_wizdir/client_wizard/client.wiz", # _("Database") => "$_wizdir/db_wizard/db.wiz", # _("Dhcp Server") => "$_wizdir/dhcp_wizard/dhcp.wiz", # _("DNS") => "$_wizdir/dns_wizard/dns.wiz", # _("Firewall") => "$_wizdir/firewall_wizard/firewall.wiz", # _("Ftp Server") => "$_wizdir/ftp_wizard/ftp.wiz", # _("global") => "$_wizdir/global_wizard/global.wiz", # _("News Server") => "$_wizdir/news_wizard/news.wiz", # _("Mail Server") => "$_wizdir/postfix_wizard/postfix.wiz", # _("Samba Server") => "$_wizdir/samba_wizard/samba.wiz", # _("server") => "$_wizdir/server_wizard/server.wiz", # _("Time") => "$_wizdir/time_wizard/time.wiz", # _("Web Server") => "$_wizdir/web_wizard/web.wiz", ); my %xapp = (_("Console") => ["rxvt", "rxvt", 1], # _("client") => ["wiz $_wizdir/client_wizard/client.wiz", "wizdrake", 1], # _("Database") => ["wiz $_wizdir/db_wizard/db.wiz", "wizdrake", 1], # _("Dhcp Server") => ["wiz $_wizdir/dhcp_wizard/dhcp.wiz", "wizdrake", 1], # _("DNS") => ["wiz $_wizdir/dns_wizard/dns.wiz", "wizdrake", 1], # _("Firewall") => ["wiz $_wizdir/firewall_wizard/firewall.wiz", "wizdrake", 1], # _("Ftp Server") => ["wiz $_wizdir/ftp_wizard/ftp.wiz", "wizdrake", 1], # _("global") => ["wiz $_wizdir/global_wizard/global.wiz", "wizdrake", 1], # _("News Server") => ["wiz $_wizdir/news_wizard/news.wiz", "wizdrake", 1], # _("Mail Server") => ["wiz $_wizdir/postfix_wizard/postfix.wiz", "wizdrake", 1], # _("Samba Server") => ["wiz $_wizdir/samba_wizard/samba.wiz", "wizdrake", 1], # _("server") => ["wiz $_wizdir/server_wizard/server.wiz", "wizdrake", 1], # _("Time") => ["wiz $_wizdir/time_wizard/time.wiz", "wizdrake", 1], # _("Web Server") => ["wiz $_wizdir/web_wizard/web.wiz", "wizdrake", 1], ); #------------------------------------------------------------- my $nb_pages=0; my $window_global = new Gtk::Window -toplevel; $window_global->signal_connect ( delete_event => sub { quit_global(); }); $window_global->set_position(1); $window_global->set_title( _("Mandrake Control Center %s", $_version)); $window_global->border_width(0); my $vbox_global = new Gtk::VBox(0, 0); $window_global->add($vbox_global); ######### menus my @menu_items = ( { path => _("/_File"), type => '' }, { path => _("/File")._("/_Quit"), accelerator => _("Q"), callback => \&quit_global }, { path => _("/_Help"),type => '' }, # { path => _("/Help")._("/_Help on line"), callback => sub { Gtk->exit(0) } }, { path => _("/Help")._("/_Report Bug") , callback => sub {connect_to_site("https://qa.mandrakesoft.com/");}}, { path => _("/Help/-"), type => '' }, { path => _("/Help")._("/Mandrake_Campus"), callback => sub {connect_to_site("http://www.mandrakecampus.com/");} }, { path => _("/Help")._("/Mandrake_Expert"), callback => sub {connect_to_site("http://www.mandrakeexpert.com/");} }, { path => _("/Help/-"), type => '' }, { path => _("/Help")._("/_About..."), callback => \&about_mdk_cc } ); my $menubar = get_main_menu( $window_global ); $vbox_global->pack_start($menubar, 0, 0, 0); ######### menus end $vbox_global->pack_start(new Gtk::HSeparator, 0, 1, 0); my $hpane_global = new Gtk::HPaned; $vbox_global->pack_start($hpane_global, 1, 1, 0); $hpane_global->border_width(5); my $scrolled_global = new Gtk::ScrolledWindow; $scrolled_global->set_policy('automatic','automatic'); $scrolled_global->set_usize(210, 0); $scrolled_global->set_name("icons_back"); $hpane_global->pack1($scrolled_global,0,1); my $notebook_global = new Gtk::Notebook; $notebook_global->set_show_border(0); $notebook_global->set_show_tabs(0); $hpane_global->pack2($notebook_global,0,1); my $vbox_about = new Gtk::VBox(0,0); my $darea1 = new Gtk::DrawingArea(); $darea1->size(540,460); $darea1->set_usize(540,460); $vbox_about->pack_start($darea1,1,1,0); $notebook_global->append_page($vbox_about, undef); my $vbox_global_left = new Gtk::VBox(0,0); $scrolled_global->add_with_viewport($vbox_global_left); $window_global->realize; my @pid_launched; my %tree_launched; my $tree= new Gtk::Tree; $tree->set_selection_mode('browse'); $tree->set_view_lines(0); $tree->set_view_mode('item'); map { create_tree_item($tree, $_->[0] , "$xpm_path_l/$_->[1]",1); } @tree_parent; map { create_tree_item($treeitem_sub[st(int($_->[2]))],$_->[0], "$xpm_path_l/$_->[1]",0);} @tree_app; $vbox_global_left->pack_start($tree,1,1,0); $window_global->show_all; my ($pix_splash_map, $pix_splash_mask) = gtkcreate_png("$xpm_path_l/splash.png"); my @anim; ($anim[$_]->[0], $anim[$_]->[1]) = gtkcreate_png("$xpm_path_l/anim_" . ($_ + 1) . ".png") foreach (0..9); my $pix_dbl = new Gtk::Gdk::Pixmap($darea1->window, 540,460); draw_exposed($pix_dbl); $darea1->signal_connect( expose_event => sub { $darea1->window->draw_pixmap ($darea1->style->white_gc, $pix_dbl, 0, 0, ($darea1->allocation->[2]-540)/2, ($darea1->allocation->[3]-460)/2, 540, 460); return 0; }); $SIG{USR1} = sub { ${$tree_launched{$_}->[1]}->deselect() foreach (keys %tree_launched); $notebook_global->set_page(0); $scrolled_global->set_usize(210, 0); }; # embedded applications will send me that signal in order to "hide" them $SIG{TERM} = \&quit_global; # embedded applications will send me that signal in order to quit the cc. my $global_vbox; my $global_time_tag; my $lock_time_tag; my $global_socket; $SIG{USR2} = sub { Gtk->timeout_remove($lock_time_tag); $$global_vbox->hide; Gtk->timeout_remove($global_time_tag); $$global_socket->show; ${$tree_launched{$_}->[1]} and ${$tree_launched{$_}->[1]}->set_sensitive(1) foreach (keys %tree_launched); my $a = $notebook_global->get_current_page; $notebook_global->set_page(0); $notebook_global->set_page($a); }; Gtk->main_iteration while Gtk->events_pending; Gtk->main; #------------------------------------------------------------- # i18n routines # IMPORTANT: next two routines have to be redefined here to # get correct namespace (drakconf instead of libDrakX) # (This version is now UTF8 compliant - Sg 2001-08-18) #------------------------------------------------------------- sub _ { my $s = shift @_; my $t = translate($s); sprintf $t, @_; } sub translate { my ($s) = @_; $s ? c::dgettext('drakconf', $s) : ''; } #------------------------------------------------------------- # plug & tree sub #------------------------------------------------------------- sub st { return (@tree_parent - $_[0]); } sub exec_treeitem { my ($label, $exec_string, $available) = @_; # $scrolled_global->set_usize($label eq _("Software Manager") ? 1 : 210, 0); if (!$available) { my $vbox = new Gtk::VBox(0, 0); $vbox->pack_start( new Gtk::Label( _("The application cannot be loaded,\nthe file '%s' has not been found.\nTry to install it.", $exec_string)), 1, 0, 0); $vbox->show_all; $notebook_global->append_page($vbox, ""); $nb_pages++; $tree_launched{$label}->[0]=$nb_pages; $notebook_global->set_page($nb_pages); return; } if (!$tree_launched{$label}->[0]) { (member($label, keys(%xapp))) ? xplug($label) : gtkplug($label,$exec_string); } else { $notebook_global->set_page($tree_launched{$label}->[0]); } } sub gtkplug { my ($label, $exec_string) =@_; my $a; if($label eq _("Software Manager")) { $a = $exec_string; } else { my $vbox = new Gtk::VBox(0, 0); $vbox->show; my $vbox2 = new Gtk::VBox(0, 0); $vbox2->show; $global_vbox=\$vbox2; $vbox->pack_start($vbox2,1,0,0); my $label_ = new Gtk::Label (_("Please wait while loading ...")); $vbox2->pack_start( $label_, 0, 0, 0); $label_->show; my $hbox = new Gtk::HBox(0, 0); $hbox->show; $vbox2->pack_start($hbox,0,0,0); my $darea1= new Gtk::DrawingArea(); $darea1->size(350,12); $darea1->set_usize(340,12); $frame0 = new Gtk::Frame; $frame0->add($darea1); $frame0->show; $darea1->show; $frame0->set_shadow_type('etched_out'); $hbox->pack_start($frame0,1,0,0); my $socket = new Gtk::Socket; $global_socket = \$socket; $vbox->pack_start($socket, 1, 1, 0); $notebook_global->append_page($vbox, ""); $nb_pages++; $tree_launched{$label}->[0]=$nb_pages; $notebook_global->set_page($nb_pages); $tree_launched{$_}->[0] or ${$tree_launched{$_}->[1]} and ${$tree_launched{$_}->[1]}->set_sensitive(0) foreach (keys %tree_launched); my $anim_nb=0; $global_time_tag = Gtk->timeout_add(100, sub { $darea1->window->draw_pixmap ($darea1->style->white_gc, $anim[$anim_nb]->[0], 0, 0, ($darea1->allocation->[2]-340)/2, ($darea1->allocation->[3]-15)/2, 350, 13); $anim_nb++; $anim_nb > 9 and $anim_nb=0; 1; }); $lock_time_tag = Gtk->timeout_add(15000, sub { Gtk->timeout_remove($global_time_tag); ${$tree_launched{$_}->[1]} and ${$tree_launched{$_}->[1]}->set_sensitive(1) foreach (keys %tree_launched); $vbox->pack_start(new Gtk::Label (_("After 20 sec., Failed to launch \nSee if it's installed")), 1, 1, 0); $label_->set(_("After 15 sec., Failed to launch '%s'\nSee if it's installed", $exec_string)); $darea1->hide; }); $socket->realize; #$label->destroy; $a = $exec_string . " --embedded " . $socket->window->XWINDOW . " " . $$; } my $pid; unless ($pid = fork) { splash_warning(_("cannot fork: %s", $~)) unless defined $pid; exec("$a"); } $pid_launched[$nb_pages-1] = $pid unless $label eq _("Software Manager"); } sub xplug { # my ($label) =@_; my $socket = new Gtk::Socket; $notebook_global->append_page($socket, new Gtk::Label("")); $nb_pages++; $tree_launched{$_[0]}->[0]=$nb_pages; $notebook_global->set_page($nb_pages); $socket->realize; $socket->steal(launch_xapp($xapp{$_[0]})); $notebook_global->show_all(); $notebook_global->set_page($nb_pages); } sub launch_xapp { # my ($exec, $grep, $num) = @_; my $b = "xwininfo -root -tree -int | grep '" . $_[0]->[1] . "'"; my @before = split ('\n', `$b`); unless ($pid = fork) { print $pid ."\n"; splash_warning(_("cannot fork: %s", $~)) unless defined $pid; exec($_[0]->[0]); } $pid_launched[$nb_pages-1] = $pid; my $res = 0; while (!$res) { my @after = split ('\n', `$b`); while (@after ne ($_[0]->[2]+@before)) { @after = split ('\n', `$b`); } my $i = 0; my $c; foreach (@after) { $c = $after[$i] if !member($after[$i], @before); $i++; } $c =~ /\s*([0-9]*)\s*/; $res=$1; } $res; } #------------------------------------------------------------- # sub #------------------------------------------------------------- sub draw_exposed { my ( $pix )=@_; $pix->draw_pixmap($darea1->style->white_gc, $pix_splash_map, 0, 0, 0, 0, 540, 460); my $style = new Gtk::Style; my $style_dflt = new Gtk::Style; $style->font(Gtk::Gdk::Font->fontset_load(_("-adobe-times-bold-r-normal--17-*-100-100-p-*-iso8859-*,*-r-*"))); $pix->draw_string($style->font, $darea1->style->black_gc, 73, 170, _("The place where you can configure your Mandrake Box") ); my @revtree; open VERS, "/etc/mandrake-release" or die _("cannot open this file for read: %s", $!); while () { push (@revtree,$_) } my @info_tree = split / /, $revtree[0]; my ($sysname, $nodename, $release, $version, $machine) = POSIX::uname(); my $style1 = new Gtk::Style; $style1->font(Gtk::Gdk::Font->fontset_load(_("-adobe-times-bold-r-normal--14-*-100-100-p-*-iso8859-*,*-r-*"))); my $i=0; foreach( [_("System:"), "$info_tree[0] $info_tree[1] $info_tree[3] $info_tree[4]"], [_("Hostname:"), $nodename], [_("Kernel Version:"), "$release $version"], [_("Machine:"), $machine] ) { $pix->draw_string($style1->font, $darea1->style->black_gc, 80, 250+$i, $_->[0]); $pix->draw_string($style_dflt->font, $darea1->style->black_gc, 200, 250+$i, $_->[1]); $i+=20; } } sub gtkcreate_png { my ($f) = @_; my $im = Gtk::Gdk::ImlibImage->load_image($f) or die "gtkcreate_png: missing png file $f"; $im->render($im->rgb_width, $im->rgb_height); ($im->move_image(), $im->move_mask); } sub quit_global { foreach(@pid_launched) { kill TERM, $_ if (defined $_); } Gtk->exit(0); } sub splash_warning { my ($label) = @_; my $win_about = new Gtk::Dialog(); $win_about->set_position(1); my $bbox1 = new Gtk::HButtonBox; $win_about->action_area->pack_start($bbox1,0,0,0); my $button = new Gtk::Button(_("Close")); $button->signal_connect_object("clicked",$win_about => 'destroy'); $bbox1->add($button); my $lab = new Gtk::Label($label); my $style1 = new Gtk::Style; $win_about->vbox->pack_start($lab, 1, 1, 0); $win_about->show_all(); $win_about->set_modal(1); } sub create_tree_item { my ($parent_tree, $label, $pixmap, $tree_depth_max) =@_; my $expanded=0; my ($treeitem, $treebox, $new_subtree); $treeitem = new Gtk::TreeItem(); $treebox = xpm_label_box($window_global,$pixmap,$label, !$tree_depth_max); $treeitem->add($treebox); if ($tree_depth_max == 0) { $tree_launched{$label}->[1]=\$treeitem; $treeitem->signal_connect(select => sub { exec_treeitem($label, $tree_exec{$label}, -e $tree_exec{$label} ) }); } else { $treeitem->signal_connect(button_press_event => sub { $expanded ? $treeitem->collapse : $treeitem->expand; $expanded = !$expanded }); $treeitem->signal_connect(select => sub { $treeitem_old and $$treeitem_old->collapse(); $treeitem->expand(); $treeitem_old=\$treeitem; $expanded=1; }); } $parent_tree->append($treeitem); $treeitem->show_all(); if ($tree_depth_max) { $tree_depth_max--; $new_subtree= new Gtk::Tree(); $treeitem->set_subtree($new_subtree); $new_subtree->ref(); unshift(@treeitem_sub, $new_subtree); } } sub xpm_label_box { my ($parent, $xpm_filename, $label_text, $is_last) = @_; # Create box for xpm and label my $box = new Gtk::HBox( 0, 0 ); my $box2; if ($is_last) { $box2 = new Gtk::HBox( 0, 0 ); $box2->set_usize(20, 0); $box->pack_start($box2, 0, 0, 0); } # Get the style of the button to get the background color. my $style = $parent->get_style()->bg('normal'); # Now on to the xpm stuff my ($pixmap, $mask) = gtkcreate_png($xpm_filename); my $pixmapwid = new Gtk::Pixmap($pixmap, $mask); # Create a label for the button my $label = new Gtk::Label($label_text); # Pack the pixmap and label into the box $box->pack_start($pixmapwid, 0, 0, 3); $box->pack_start($label, 0, 0, 3); $box->border_width(2); return ($box); } #------------------------------------------------------------- # menu related functions #------------------------------------------------------------- sub connect_to_site { my ($link,$help)=@_; my $browser=$ENV{'BROWSER'}; my $initial_user=$ENV{'INITIAL_USER'}; my $user_current=$ENV{'USER'}; if (!$browser) {splash_warning( " ". _("Warning: No browser specified") ." "); return;} if ($help) { system("$browser $link &"); } else { if ($initial_user ne "root" && $initial_user ne undef) { system("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")." "); } } } sub about_mdk_cc { my $window_about = new Gtk::Dialog(); $window_about->set_position(1); $window_about->set_title( _("About - Mandrake Control Center")); my $bbox1 = new Gtk::HButtonBox; $window_about->action_area->pack_start($bbox1,0,0,0); my $button = new Gtk::Button(_("Close")); $button->signal_connect_object("clicked",$window_about => 'destroy'); $bbox1->add($button); my $label = new Gtk::Label( _("Mandrake Control Center %s \n \n Copyright (C) 2001 Mandrakesoft SA\n", $_version) ); my $style1 = new Gtk::Style; $style1->font(Gtk::Gdk::Font->fontset_load(_("-adobe-times-bold-r-normal--14-*-100-100-p-*-iso8859-*,*-r-*"))); $label->set_style($style1); $window_about->vbox->pack_start( $label, 1, 1, 0 ); $window_about->vbox->pack_start( new Gtk::Label( _("Authors: ") . "\n\n Yves Duret \n Damien Krotkine \n"), 1, 1, 0 ); $window_about->show_all(); $window_about->set_modal(1); } sub get_main_menu { 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( '
' ) ); }