#!/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 Config; use POSIX; init Gtk; use Data::Dumper; my %pixmaps_global; my $xpm_path="pixmaps"; my $tree_depth_max = 1; my @treeitem_sub; my $window_global = new Gtk::Window -toplevel; $window_global->set_usize(800, 600); $window_global->signal_connect ( delete_event => sub { Gtk->exit(0); }); $window_global->set_position(1); $window_global->set_title("Mandrake Control Center"); $window_global->border_width(0); $vbox_global = new Gtk::VBox(0, 0); $window_global->add($vbox_global); ######### menus my @item_factory_entries = ( ["/_File", undef, 0, ""], ["/File/tearoff1", undef, 0, ""], #["/File/_Quit", "Q", 5], { '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 ] ); 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); $hseparator_global = new Gtk::HSeparator; $vbox_global->pack_start($hseparator_global, 0, 1, 0); ######### menus end 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"); #$scrolled_global->window->draw_rectangle(nil,1, 0, 0, 70, 70); #$scrolled_global->window->style->bg_gc('normal') $hpane_global->pack1($scrolled_global,0,1); #my $vseparator_global = new Gtk::VSeparator; #$hbox_global->pack_start($vseparator_global,0,1,0); 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 $hbox1= new Gtk::HBox(0,20); my ($pix_about_map, $pix_about_mask) = Gtk::Gdk::Pixmap->create_from_xpm(NULL, Gtk::Widget->get_default_style->bg('normal'), "$xpm_path/logo.xpm"); my $pix_about = new Gtk::Pixmap ($pix_about_map, $pix_about_mask); $pix_about->set_alignment(10,0); $hbox1->pack_start($pix_about, 0, 1, 0); my $style = new Gtk::Style; $style->font(Gtk::Gdk::Font->load('-adobe-times-bold-r-normal--25-180-100-100-p-132-iso8859-1')); my $label_about2 = new Gtk::Label ("Mandrake Control Center"); $label_about2->set_alignment(0,0); $label_about2->set_style($style); $hbox1->pack_start($label_about2, 0, 1, 0); my $vbox_about = new Gtk::VBox(0,10); $vbox_about->pack_start($hbox1, 0, 1, 0); my $label_about3 = new Gtk::Label ("The place where you can configure your Mandrake Box"); $vbox_about->pack_start($label_about3, 0, 0, 0); $table_info1 = new Gtk::Table(6,2,1); $table_info1->set_row_spacings(15); $table_info1->set_col_spacings(10); my @revtree; my @infotree; open VERS, "/etc/redhat-release" or die "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 $ld = new Gtk::Label("$username"); $table_info1->attach($ld, 1, 2, 0, 1, 0, 0, 0, 0); my $label_user = new Gtk::Label("User: "); $label_user->set_style($style1); $label_user->set_justify('right'); $table_info1->attach($label_user, 0, 1, 0, 1, 0, 0, 0, 0); my $ld1 = new Gtk::Label("$info_tree[0] $info_tree[1] $info_tree[3] $info_tree[4] "); $table_info1->attach($ld1, 1, 2, 1, 2, 0, 0, 0, 0); my $ld2 = new Gtk::Label("$nodename"); $table_info1->attach($ld2, 1, 2, 2, 3, 0, 0, 0, 0); my $ld3 = new Gtk::Label("$release $version"); $table_info1->attach($ld3, 1, 2, 3, 4, 0, 0, 0, 0); my $ld4 = new Gtk::Label("$machine"); $table_info1->attach($ld4, 1, 2, 4, 5, 0, 0, 0, 0); my $label_os = new Gtk::Label("System: "); $label_os->set_style($style1); $label_os->set_justify('right'); $table_info1->attach($label_os, 0, 1, 1, 2, 0, 0, 0, 0); my $label_host = new Gtk::Label("Hostname: "); $label_host->set_style($style1); $table_info1->attach_defaults($label_host, 0, 1, 2, 3); my $label_kernel = new Gtk::Label("Kernel Version : "); $label_kernel->set_style($style1); $table_info1->attach_defaults($label_kernel, 0, 1, 3, 4); my $label_box = new Gtk::Label("Machine: "); $label_box->set_style($style1); $table_info1->attach_defaults($label_box, 0, 1, 4, 5); $vbox_about->set_spacing(30); $vbox_about->pack_start($table_info1, 0, 0, 0); $vbox_about->reorder_child($table_info1,150); $notebook_global->append_page($vbox_about, ""); 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; $vbox_global_left->pack_start($tree,1,1,0); map { create_tree_item($tree,$_->[0], "$xpm_path/$_->[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); } (['Drakboot','item.xpm',5] , ['Drakfloppy', 'item.xpm',5] , ['Drakelogo', 'item.xpm',5], ['XFDrake','item.xpm',4] , ['Hardrake','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]); %tree_exec = ("Drakboot" => "drakeboot", "Drakfloppy" => "drakfloppy", "Drakelogo" => "DrakeLogo" , "xfdrake" => "XFDrake" , "Hardrake" => "harddrake-auth" , "Mousedrake" => "mousedrake" , "Printdrake" => "printerdrake" , "Kbddrake" => "keyboarddrake" , "Userdrake" => "userdrake" , "Draknet" => "draknet" , "Drakgw" => "drakgw" , "Menudrake" => "menudrake" , "Drakfont" => "drakfont" ); #exec_treeitem("harddrake-auth",4); my $rc = "control-center.rc"; Gtk::Rc->parse($rc); $window_global->show_all; print "num : " . $notebook_global->page_num($vbox_about) . "\n"; #$notebook_global->set_page(0); $SIG{USR1} = sub { $notebook_global->set_page(0); }; # embedded applications will send me that signal in order to "hide" them Gtk->main; 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->load('-adobe-times-bold-r-normal--14-100-100-100-p-76-iso8859-1')); $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 create_tree_item() { my ($parent_tree, $label, $pixmap, $tree_depth_max) =@_; my ( $treeitem, $treebox, $new_subtree, ); $treeitem = new Gtk::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($tree_exec{$label},1);}); } $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 ) = @_; my $box; my $style; my $pixmap; my $mask; my $pixmapwid; my $label; # Create box for xpm and label $box = new Gtk::HBox( $false, 0 ); # Get the style of the button to get the background color. $style = $parent->get_style()->bg( 'normal' ); # Now on to the xpm stuff ( $pixmap, $mask ) = Gtk::Gdk::Pixmap->create_from_xpm($parent->window, $style, $xpm_filename ); $pixmapwid = new Gtk::Pixmap( $pixmap, $mask ); # Create a label for the button $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 ($exec_string,$num) = @_; if ($exec_string) { my $socket = new Gtk::Socket; $socket->show; $notebook_global->append_page($socket, ""); $socket->realize; print ("The XID of the sockets window n° is [" . $socket->window->XWINDOW . "]\nMy PID is [" . $$ . "]\n"); my $a = $exec_string . " --embedded " . $socket->window->XWINDOW . " " . $$ . "&"; print "$a\n"; system ($a); $notebook_global->set_page($num); } } sub item_factory_cb { my ($widget, $action, @data) = @_; print "ItemFactory: activated ", $widget->item_factory_path(), " -> ", $action, "\n"; $action == 1 and Gtk->exit(0); $action == 4 and about_mdk_cc(); } 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; } if (!visible $item_factory_window) { show_all $item_factory_window; } else { destroy $item_factory_window; } }