#!/usr/bin/perl -w # Control-center # Copyright (C) 1999 MandrakeSoft # 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 Gtk; use Gtk::Gdk::ImlibImage; use Config; use POSIX; # for i18n use Locale::GetText; setlocale (LC_ALL, ""); Locale::GetText::textdomain ("DrakConf"); import Locale::GetText I_; *_ = *I_; init Gtk; Gtk::Gdk::ImlibImage->init; use Data::Dumper; my $false = 0; my $true = 1; my $_xbindir = "/usr/X11R6/bin"; my $_bindir = "/usr/bin"; my $_sbindir = "/usr/sbin"; my $_iconsdir = "/usr/share/icons"; my $_docdir = "/usr/share/doc"; my %pixmaps_global; my $xpm_path="$_iconsdir"; my $xpm_path_l="./pixmaps"; my $tree_depth_max = 1; my @treeitem_sub; my $nb_pages=0; my $window_global = new Gtk::Window -toplevel; $window_global->set_usize(745, 530); $window_global->signal_connect ( delete_event => sub { quit_global(); }); $window_global->set_position(1); $window_global->set_title(_("Mandrake Control Center")); $window_global->border_width(0); #$window_global->realize; my $vbox_global = new Gtk::VBox(0, 0); $window_global->add($vbox_global); ######### menus my @item_factory_entries = ( [_("/_File"), undef, 0, ""], #[_("/File/tearoff1"), undef, 0, ""], { 'path' => _("/File/_Quit"), 'accelerator' => _("Q"), 'action' => 1, 'type' => '' }, [_("/_Help"), undef, 0, ""], [_("/Help/_Mandrake Control Center"), undef, 2], [_("/Help/_Report Bug"), undef, 3 ], [_("/Help/_About..."), undef, 4 ], [_("/_Extras"), undef, 0, ""], [_("/_Extras/_Mandrake Security News"), undef, 5], [_("/_Extras/_Mandrake Campus"), undef, 6], [_("/_Extras/_Mandrake Expert"), undef, 7], ); my ($accel_group, $item_factory, $box1, $label, $box2); my ($separator, $button, $dummy); $accel_group = new Gtk::AccelGroup; $item_factory = new Gtk::ItemFactory('Gtk::MenuBar', "
", $accel_group); $accel_group->attach($window_global); foreach (@item_factory_entries) { $item_factory->create_item($_, \&item_factory_cb); } $vbox_global->pack_start($item_factory->get_widget('
'), 0, 0, 0); $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(190, 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); #-------------------------------- splash screeen -------------------------------------------------------- my ($pix_splash_map, $pix_splash_mask) = gtkcreate_png("$xpm_path_l/splash.png"); my $vbox_about = new Gtk::VBox(0,0); my $darea1= new Gtk::DrawingArea(); $darea1->size(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 $tree= new Gtk::Tree; $tree->set_selection_mode('browse'); $vbox_global_left->pack_start($tree,1,1,0); map { create_tree_item($tree, $_->[0] , "$xpm_path_l/$_->[1]",1); } ([_("Boot"), 'logo.xpm'] , [_("Hardware"), 'logo.xpm'] , [_("User and Groups"),'logo.xpm'], [_("Network & Internet"),'logo.xpm'] , [_("Menu Customization"),'logo.xpm'] , [_("Font Management"),'logo.xpm']); map { create_tree_item($treeitem_sub[int($_->[2])],$_->[0], "$xpm_path/$_->[1]",0); } ([_("Boot Loader"),'item.xpm',5] , [_("Boot Disk"), 'item.xpm',5] , [_("Boot Logo"), 'item.xpm',5], [_("XFDrake"),'item.xpm',4] , [_("HardDrake"),'item.xpm',4] , [_("Mousedrake"), 'item.xpm',4] , [_("Printerdrake"),'item.xpm',4] , [_("Keyboarddrake"), 'item.xpm',4], [_("Userdrake"),'item.xpm',3] , [_("Draknet") , 'item.xpm',2] , [_("Drakgw"),'item.xpm',2], [_("Menudrake") , 'item.xpm',1] , [_("Drakfont"), 'item.xpm', 0]); my %tree_exec = (_("Boot Loader") => " ../bootlookdrake/bootlookdrake", _("Boot Disk") => "$_xbindir/drakfloppy", _("Boot Logo") => "$_xbindir/DrakeLogo" , _("XFDrake") => "$_sbindir/XFdrake --expert" , _("HardDrake") => "$_bindir/harddrake-auth" , _("Mousedrake") => "$_sbindir/mousedrake" , _("Printerdrake") => "$_sbindir/printerdrake" , _("Keyboarddrake") => "$_sbindir/keyboarddrake" , _("Userdrake") => "$_bindir/userdrake" , _("Draknet") => "$_sbindir/draknet" , _("Drakgw") => "$_sbindir/drakgw" , _("Menudrake") => "$_bindir/menudrake" , _("Drakfont") => "$_xbindir/drakfont" ); my @pid_launched; my %tree_launched = (_("Boot Loader") => -1, _("Boot Disk") => -1, _("Boot Logo") => -1 , _("XFDrake") => -1 , _("HardDrake") => -1 , _("Mousedrake") => -1 , _("Printerdrake") => -1 , _("Keyboarddrake") => -1 , _("Userdrake") => -1 , _("Draknet") => -1 , _("Drakgw") => -1 , _("Menudrake") => -1 , _("Drakfont") => -1 ); #exec_treeitem("harddrake-auth",4); my $rc = "control-center.rc"; Gtk::Rc->parse($rc); $window_global->show_all; $SIG{USR1} = sub { $notebook_global->set_page(0); }; # embedded applications will send me that signal in order to "hide" them 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); }); Gtk->main; 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->load('-adobe-times-bold-r-normal--25-180-100-100-p-132-iso8859-1')); $pix->draw_string($style->font, $darea1->style->black_gc, 50, 130, _("The Mandrake Control Center") ); $pix->draw_string($style_dflt->font, $darea1->style->black_gc, 60, 160, ("The place where you can configure your Mandrake Box") ); my @revtree; my @info_tree; open VERS, "/etc/redhat-release" or die( sprintf _("cannot open this file for read: $!")); while () { push (@revtree,$_); } @info_tree = split / /, $revtree[0]; my ($sysname, $nodename, $release, $version, $machine ) = POSIX::uname(); my $username= POSIX::cuserid(); my $style1 = new Gtk::Style; $style1->font(Gtk::Gdk::Font->load('-adobe-times-bold-r-normal--14-100-100-100-p-76-iso8859-1')); my $i=0; foreach( [_("User:"), $username], [_("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, 50, 190+$i, $_->[0]); $pix->draw_string($style_dflt->font, $darea1->style->black_gc, 170, 190+$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 gtkpng { new Gtk::Pixmap(gtkcreate_png(@_)) } sub quit_global { print _("Cleaning...\n"); foreach (@pid_launched) { print "$_\n"; } kill TERM, @pid_launched; Gtk->exit(0); } sub about_mdk_cc { my $window_about = new Gtk::Dialog(); $window_about->set_position(1); my $button = new Gtk::Button(_("Close")); $button->signal_connect_object("clicked",$window_about => 'destroy'); $window_about->action_area->pack_start($button,$true,$true,0); my $label = new Gtk::Label( _("Mandrake Control Center 1.0 \n Copyright (C) 2001 Mandrakesoft SA\n") ); 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, $true, $true, 0 ); $window_about->vbox->pack_start( new Gtk::Label( _("Authors: ") . "\n\n Daouda Lo \n \n Damien Krotkine \n"), $true, $true, 0 ); $window_about->show_all(); $window_about->set_modal(1); } sub splash_warning { my ($label) = @_; my $win_about = new Gtk::Dialog(); $win_about->set_position(1); my $button = new Gtk::Button(_("Close")); $button->signal_connect_object("clicked",$window_about => 'destroy'); $win_about->action_area->pack_start($button,$true,$true,0); my $lab = new Gtk::Label($label); my $style1 = new Gtk::Style; $style1->font(Gtk::Gdk::Font->fontset_load(_("-adobe-times-bold-r-normal--14-*-100-100-p-*-iso8859-*,*-r-*"))); $lab->set_style($style1); $win_about->vbox->pack_start( $lab, $true, $true, 0 ); $win_about->show_all(); $win_about->set_modal(1); } sub connect_to_site { my ($link)=@_; my $browser="netscape"; if (system("$browser -geometry 600x800+10+10 -no-about-splash $link ")) { splash_warning(_("You seems to not have Netscape installed")); } } sub create_tree_item { my ($parent_tree, $label, $pixmap, $tree_depth_max) =@_; my ($treeitem, $treebox, $new_subtree); $treeitem = new Gtk::TreeItem(); $treeitem_selected=$treeitem; $treebox = xpm_label_box($window_global,$pixmap,$label); $treeitem->add($treebox); $treebox->show(); if ($tree_depth_max == 0) { $treeitem->signal_connect('select', sub { exec_treeitem($label, $tree_exec{$label});}); } else { $treeitem->signal_connect('select', sub { $treeitem->expand(); $treeitem->deselect(); }); } $parent_tree->append($treeitem); $treeitem->show(); 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 ) = @_; # Create box for xpm and label my $box = new Gtk::HBox( $false, 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) = Gtk::Gdk::Pixmap->create_from_xpm($parent->window, $style, $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, $false, $false, 3 ); $box->pack_start( $label, $false, $false, 3 ); $box->border_width( 2 ); $pixmapwid->show(); $label->show(); return ( $box ); } sub exec_treeitem { my ($label, $exec_string) = @_; if ($exec_string) { print _("SELECTED\n"); if ($tree_launched{$label}==-1) { print _("yes\n"); my $socket = new Gtk::Socket; $socket->show; $notebook_global->append_page($socket, ""); $socket->realize; printf (_("The XID of the sockets window nr. %s is [%s]\n"), "", $socket->window->XWINDOW ); printf (_("My PID is [%s]\n"), $$ ); my $a = $exec_string . " --embedded " . $socket->window->XWINDOW . " " . $$; print "$a\n"; my $pid; #($pid = fork) ? $pid_launched[$nb_pages] = $pid : system($a) == 0 or splash_warning(_("couldn't exec $a: $!")); unless ($pid = fork) { splash_warning("cannot fork: $~") unless defined $pid; exec("$a"); my $kid = waitpid(-1,&WNOHANG); } $pid_launched[$nb_pages] = $kid; $nb_pages++; $tree_launched{$label}=$nb_pages; $notebook_global->set_page($nb_pages); } else { print _("no\n"); $notebook_global->set_page($tree_launched{$label}); } } } sub item_factory_cb { my ($widget, $action, @data) = @_; print "ItemFactory: activated ", $widget->item_factory_path(), " -> ", $action, "\n"; $action == 1 and quit_global(); $action == 4 and about_mdk_cc(); $action == 2 and connect_to_site("/usr/share/doc/DrakConf.html"); $action == 3 and connect_to_site("https://qa.mandrakesoft.com"); $action == 5 and connect_to_site("http://www.mandrake.com"); $action == 6 and connect_to_site("http://www.mandrakecampus.com"); $action == 7 and connect_to_site("http://www.mandrakeexpert.com"); } sub create_item_factory { if (!defined $item_factory_window) { my ($accel_group, $item_factory, $box1, $label, $box2); my ($separator, $button, $dummy); $item_factory_window = new Gtk::Window('toplevel'); signal_connect $item_factory_window destroy => \&destroy_window, \$item_factory_window; signal_connect $item_factory_window "delete-event" => \&destroy_window, \$item_factory_window; $accel_group = new Gtk::AccelGroup; $item_factory = new Gtk::ItemFactory('Gtk::MenuBar', "
", $accel_group); #$item_factory_window->set_data('
', $item_factory); $accel_group->attach($item_factory_window); # $item_factory->create_items(); foreach (@item_factory_entries) { $item_factory->create_item($_, \&item_factory_cb); } $item_factory_window->set_title(_("Item Factory")); $item_factory_window->set_border_width(0); $box1 = new Gtk::VBox(0, 0); $item_factory_window->add($box1); $box1->pack_start($item_factory->get_widget('
'), 0, 0, 0); $label = new Gtk::Label( _("Type\n\nto start") ); $label->set_usize(200, 200); $label->set_alignment(0.5, 0.5); $box1->pack_start($label, 1, 1, 0); $separator = new Gtk::HSeparator; $box1->pack_start($separator, 0, 1, 0); $box2 = new Gtk::VBox(0, 10); $box2->set_border_width(10); $box1->pack_start($box2, 0, 1, 0); $button = new Gtk::Button(_("Close")); $button->signal_connect('clicked', sub {$item_factory_window->destroy;}); $box2->pack_start($button, 1, 1, 0); $button->can_default(1); $button->grab_default; } (!visible $item_factory_window) ? show_all $item_factory_window : destroy $item_factory_window; }