diff options
-rwxr-xr-x | clock.pm | 47 | ||||
-rwxr-xr-x | control-center3 | 232 |
2 files changed, 145 insertions, 134 deletions
@@ -1,6 +1,7 @@ #!/usr/bin/perl use Data::Dumper; +use POSIX; use Gtk; init Gtk; #use strict; @@ -16,6 +17,7 @@ my $Radian; my $timer; my $midx, $midy; my $first=1; +my $is24; my $window = $::isEmbedded ? new Gtk::Plug ($::XID) : new Gtk::Window -toplevel; my $vbox = new Gtk::VBox(0,0); $window->add($vbox); @@ -27,7 +29,7 @@ $hbox->pack_start($calendar, 1, 1, 0); my $vbox2 = new Gtk::VBox(0,0); $hbox->pack_start($vbox2, 1, 1, 0); my $drawing_area = new Gtk::DrawingArea; -$drawing_area->size(200,200); +$drawing_area->size(300,300); $vbox2->pack_start($drawing_area, 1, 1, 0); $drawing_area->set_events(['button_press_mask', 'button_release_mask', "pointer_motion_mask" ]); $drawing_area->signal_connect ( expose_event => \&expose_event ); @@ -57,15 +59,25 @@ my $bbox = new Gtk::HButtonBox; $bbox->set_layout(-end); $vbox->pack_start($bbox, 1, 1, 5); my $button_ok = new Gtk::Button "OK"; +$button_ok->signal_connect ( clicked => sub { + system("date -s " . $adj_h->set_value($hour) . ":" . $adj_m->set_value($min) . ":" . $adj_s->set_value($sec)); + quit_global(); + }); $bbox->add($button_ok ); my $button_cancel = new Gtk::Button "Cancel"; -$bbox->add($button_cancel ); my $button_reset = new Gtk::Button "Reset"; +$button_cancel->signal_connect ( clicked => sub { + $timer=Gtk->timeout_add(120, sub { time_to_rad(); Repaint($drawing_area) }); + time_to_rad(); Repaint($drawing_area); + $button_reset->set_sensitive(0); + quit_global(); + }); +$bbox->add($button_cancel ); $button_reset->signal_connect ( clicked => sub { $timer=Gtk->timeout_add(120, sub { time_to_rad(); Repaint($drawing_area) }); time_to_rad(); Repaint($drawing_area); $button_reset->set_sensitive(0); - }); + }); $bbox->add($button_reset); $button_reset->set_sensitive(0); @@ -80,14 +92,14 @@ sub motion_event { $pressed or return; if ($first) { Gtk->timeout_remove($timer); - $Radian = determine_radian($event->{'x'}, $event->{'y'}); + ($Radian, $type) = determine_radian($event->{'x'}, $event->{'y'}); $button_reset->set_sensitive(1); } $$Radian=-atan2(($event->{'x'}-$midx),($event->{'y'}-$midy)) + $pi; + Repaint($widget); -# print "AAAAAAAA" . $event->{'x'} . "\n"; -# print " -- # " . Data::Dumper->Dump([\$event], ['$event']) . "\n"; + rad_to_time(); $first=0; } @@ -96,12 +108,13 @@ sub determine_radian { my $res; my $r; + my $i=0; foreach (\$dRadians_hour, \$dRadians_min, \$dRadians_sec) { my $d=sqrt ( ($x - ($midx + 0.70 * $radius * sin ($$_)))**2 + ($y - ($midy - 0.70 * $radius * cos ($$_)))**2 ); $res or $res=$d, $r=$_; - $d<$res and $res=$d, $r=$_; + $d<$res and $res=$d, $r=$_, $i++; } - $r; + ($r, $i); } sub quit_global { @@ -125,17 +138,31 @@ sub configure_event { -1); } +sub rad_to_time { + my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);# now_tm = localtime (&now); + $adj_h->set_value($dRadians_hour * 6 / $pi); + $adj_m->set_value($dRadians_min*30/$pi); + $adj_s->set_value($dRadians_sec*30/$pi); +} + sub time_to_rad { my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);# now_tm = localtime (&now); - $dRadians_hour = ($hour % 12) * $pi / 6.0 + ($pi * $min / 360.0); - $dRadians_min = ($min * $pi / 30.0) + ($pi * $sec / 1800.0); + $dRadians_hour = $hour % 12 * $pi / 6.0; + $dRadians_min = $min * $pi / 30.0; $dRadians_sec = $sec * $pi / 30.0; + $adj_h->set_value($hour); + $adj_m->set_value($min); + $adj_s->set_value($sec); + $is24=$hour>12; } sub Repaint { my ($drawing_area) = @_; + $dRadians_hour = POSIX::floor($dRadians_hour / $pi * 6 + 0.5) * $pi / 6.0; + $dRadians_min = POSIX::floor($dRadians_min / $pi * 30 + 0.5) * $pi / 30.0; + $dRadians_sec = POSIX::floor($dRadians_sec / $pi * 30 + 0.5) * $pi / 30.0; $pixmap->draw_rectangle($drawing_area->style->white_gc, 1, 0, 0, $drawing_area->allocation->[2], $drawing_area->allocation->[3]); diff --git a/control-center3 b/control-center3 index 982e6f53..73758fa4 100755 --- a/control-center3 +++ b/control-center3 @@ -33,7 +33,14 @@ setlocale (LC_ALL, ""); Locale::GetText::textdomain ("DrakConf"); import Locale::GetText I_; -*_ = *I_; +#*_ = *I_; + +sub _ { + my $s = shift @_; my $t = I_($s); + $t && ref $t or return sprintf $t, @_; + my ($T, @p) = @$t; + sprintf $T, @_[@p]; +} init Gtk; Gtk::Gdk::ImlibImage->init; @@ -53,12 +60,10 @@ my @treeitem_sub; my $nb_pages=0; my $window_global = new Gtk::Window -toplevel; -#$window_global->set_usize(745, 499); $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); @@ -66,7 +71,6 @@ $window_global->add($vbox_global); ######### menus my @item_factory_entries = ( [_("/_File"), undef, 0, "<Branch>"], - #[_("/File/tearoff1"), undef, 0, "<Tearoff>"], { 'path' => _("/File/_Quit"), 'accelerator' => _("<control>Q"), @@ -83,16 +87,11 @@ my @item_factory_entries = ( # [_("/_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', "<main>", $accel_group); +my $accel_group = new Gtk::AccelGroup; +my $item_factory = new Gtk::ItemFactory('Gtk::MenuBar', "<main>", $accel_group); $accel_group->attach($window_global); -foreach (@item_factory_entries) { - $item_factory->create_item($_, \&item_factory_cb); -} +$item_factory->create_item($_, \&item_factory_cb) foreach (@item_factory_entries); $vbox_global->pack_start($item_factory->get_widget('<main>'), 0, 0, 0); $vbox_global->pack_start(new Gtk::HSeparator, 0, 1, 0); @@ -136,42 +135,32 @@ $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"), 'drakboot-mdk.xpm'] , [_("Hardware"), 'logo.xpm'] , [_("User and Groups"),'adduserdrake-mdk.xpm'], - [_("Network & Internet"),'draknet-mdk.xpm'] , [_("Menu Customization"),'menudrake-mdk.xpm'] , [_("Font Management"),'drakfont-mdk.xpm']); +} ([_("Boot"), 'drakboot-mdk.png'] , [_("Hardware"), 'logo.png'] , [_("User and Groups"),'adduserdrake-mdk.png'], + [_("Network & Internet"),'draknet-mdk.png'] , [_("Menu Customization"),'menudrake-mdk.png'] , [_("Font Management"),'drakfont-mdk.png']); map { create_tree_item($treeitem_sub[int($_->[2])],$_->[0], "$xpm_path_l/$_->[1]",0); -} ([_("Boot Loader"),'drakboot-mdk.xpm',5] , [_("Boot Disk"), 'drakboot-mdk.xpm',5] , [_("Boot Logo"), 'drakboot-mdk.xpm',5], - [_("XFDrake"),'item.xpm',4] , [_("HardDrake"),'item.xpm',4] , [_("Mousedrake"), 'item.xpm',4] , - [_("Printerdrake"),'printer-mdk.xpm',4] , [_("Keyboarddrake"), 'keyboard-mdk.xpm',4], - [_("Userdrake"),'item.xpm',3] , - [_("Draknet") , 'draknet-mdk.xpm',2] , [_("Drakgw"),'drakgw-mdk.xpm',2], - [_("Menudrake") , 'item.xpm',1] , - [_("Drakfont"), 'drakfont-mdk.xpm',0] +} ([_("Boot Config"),'drakboot-mdk.png',5] , [_("Boot Disk"), 'drakboot-mdk.png',5] , [_("Boot Logo"), 'drakboot-mdk.png',5], + [_("Display"),'item.png',4] , [_("Hardware"),'item.png',4] , [_("Mouse"), 'item.png',4] , + [_("Printer"),'printer-mdk.png',4] , [_("Keyboard"), 'keyboard-mdk.png',4], + [_("Users Config"),'item.png',3] , + [_("Internet & Network") , 'draknet-mdk.png',2] , [_("Gateway Config"),'drakgw-mdk.png',2], + [_("User Menus") , 'item.png',1] , [_("System Menus") , 'item.png',1] , + [_("Fonts"), 'drakfont-mdk.png',0] ); -my %tree_exec = (_("Boot Loader") => "$_sbindir/drakboot", _("Boot Disk") => "$_xbindir/drakfloppy", - _("Boot Logo") => "$_xbindir/DrakeLogo" , _("XFDrake") => "$_sbindir/XFdrake" , - _("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 %tree_exec = (_("Boot Config") => "$_sbindir/drakboot", _("Boot Disk") => "$_xbindir/drakfloppy", + _("Boot Logo") => "$_xbindir/DrakeLogo" , _("Display") => "$_sbindir/XFdrake" , + _("Hardware") => "$_bindir/harddrake-auth" , _("Mouse") => "$_sbindir/mousedrake" , + _("Printer") => "$_sbindir/printerdrake" , _("Keyboard") => "$_sbindir/keyboarddrake" , + _("Users Config") => "$_bindir/userdrake" , _("Internet & Network") => "$_sbindir/draknet" , + _("Gateway Config") => "$_sbindir/drakgw" , _("User Menus") => "$_bindir/menudrake" , + _("System Menus") => "$_bindir/menudrake", _("Fonts") => "$_xbindir/drakfont" ); my @pid_launched; my %tree_launched; -# = (_("Boot Loader") => [-1, 0], _("Boot Disk") => [-1, 0], -# _("Boot Logo") => [-1, 0] , _("XFDrake") => [-1, 0] , -# _("HardDrake") => [-1, 0] , _("Mousedrake") => [-1, 0] , -# _("Printerdrake") => [-1, 0] , _("Keyboarddrake") => [-1, 0] , -# _("Userdrake") => [-1, 0] , _("Draknet") => [-1, 0] , -# _("Drakgw") => [-1, 0] , _("Menudrake") => [-1, 0] , -# _("Drakfont") => [-1, 0] -# ); - -#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 @@ -179,7 +168,7 @@ $SIG{TERM} = sub { quit_global(); }; # embedded applications will send me that s my $global_vbox; my $global_time_tag; my $global_socket; -$SIG{USR2} = sub { $$global_vbox->hide; Gtk->timeout_remove($global_time_tag); $$global_socket->show; +$SIG{USR2} = sub { $$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); }; @@ -200,16 +189,12 @@ sub draw_exposed { 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, 100, 170, _("The Mandrake Control Center") ); $pix->draw_string($style->font, $darea1->style->black_gc, 73, 170, ("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 (<VERS>) { - push (@revtree,$_); - } - @info_tree = split / /, $revtree[0]; + while (<VERS>) { push (@revtree,$_) } + my @info_tree = split / /, $revtree[0]; my ($sysname, $nodename, $release, $version, $machine ) = POSIX::uname(); my $username= POSIX::cuserid(); @@ -236,8 +221,6 @@ sub gtkcreate_png { ($im->move_image(), $im->move_mask); } -sub gtkpng { new Gtk::Pixmap(gtkcreate_png(@_)) } - sub quit_global { print _("Cleaning...\n"); @@ -247,7 +230,7 @@ sub quit_global kill TERM, @pid_launched; Gtk->exit(0); } - + sub about_mdk_cc { my $window_about = new Gtk::Dialog(); @@ -259,15 +242,15 @@ sub about_mdk_cc 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 0.61 \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, 1, 1, 0 ); - + $window_about->vbox->pack_start( new Gtk::Label( _("Authors: ") . "\n\n Daouda Lo <daouda\@mandrakesoft.com> \n \n Damien Krotkine <dams\@mandrakesoft.com>\n"), 1, 1, 0 ); - + $window_about->show_all(); $window_about->set_modal(1); } @@ -287,10 +270,8 @@ sub splash_warning 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, 1, 1, 0 ); - + $win_about->show_all(); $win_about->set_modal(1); } @@ -352,13 +333,11 @@ sub create_tree_item $treebox->show(); if ($tree_depth_max == 0) { $tree_launched{$label}->[1]=\$treeitem; -# $treeitem->signal_connect('clicked', sub { exec_treeitem($label, $tree_exec{$label});}); - $treeitem->signal_connect('select', sub { exec_treeitem($label, $tree_exec{$label}); }); + $treeitem->signal_connect('select', sub { exec_treeitem($label, $tree_exec{$label}, -e $tree_exec{$label} ) }); } else { $treeitem->signal_connect('select', sub { $treeitem_old and $$treeitem_old->collapse(); $treeitem->expand(); $treeitem_old=\$treeitem; #$treeitem->deselect(); }); -# $treeitem->signal_connect('deselect', sub { $treeitem->collapse(); }); } $parent_tree->append($treeitem); $treeitem->show(); @@ -401,91 +380,96 @@ sub create_tree_item sub xpm_label_box { my ( $parent, $xpm_filename, $label_text ) = @_; - # Create box for xpm and label my $box = new Gtk::HBox( 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) = Gtk::Gdk::Pixmap->create_from_xpm($parent->window, $style, $xpm_filename ); + 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 ); $pixmapwid->show(); $label->show(); - return ( $box ); } sub exec_treeitem { - my ($label, $exec_string) = @_; - if ($exec_string) { - if (!$tree_launched{$label}->[0]) { - 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,0,0,0); - my $hbox = new Gtk::HBox(0, 0); - $hbox->show; - $vbox2->pack_start($hbox,0,0,0); - my $darea1= new Gtk::DrawingArea(); - $darea1->size(70,70); - $darea1->set_usize(70,70); - $hbox->pack_start($darea1,1,0,0); - $darea1->show; -# my $label = new Gtk::Label "Please be patient"; -# $vbox->pack_start( $label, 0, 0, 0); -# $label->show; - my $socket = new Gtk::Socket; - $global_socket = \$socket; - $vbox->pack_start($socket, 1, 1, 0); - $notebook_global->append_page($vbox, ""); - $pid_launched[$nb_pages] = undef; - $nb_pages++; - $tree_launched{$label}->[0]=$nb_pages; - $notebook_global->set_page($nb_pages); - print "##[ $label ]#######" . Data::Dumper->Dump([ $tree_launched{$label} ], ['$t']) . "\n"; - print "##[ $label ]#######" . Data::Dumper->Dump([ ${$tree_launched{$label}->[1]} ], ['$t2']) . "\n"; -# ${$tree_launched{$label}->[1]}->set_sensitive(0); -# print ("#########" . $tree_launched{$_}->[0] . "\n") foreach (keys %tree_launched); - $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(120, sub { - $darea1->window->draw_pixmap - ($darea1->style->white_gc, - $anim[$anim_nb]->[0], 0, 0, - ($darea1->allocation->[2]-70)/2, ($darea1->allocation->[3]-70)/2, - 70, 70); - $anim_nb++; - $anim_nb > 7 and $anim_nb=0; - 1; - }); - $socket->realize; -# $label->destroy; - 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"); - } - } else { - $notebook_global->set_page($tree_launched{$label}->[0]); + my ($label, $exec_string, $available) = @_; + if (!$available) { + my $vbox = new Gtk::VBox(0, 0); + $vbox->pack_start( new Gtk::Label (_(" +The application cannot be loaded, +the file '%s' has not be found. +Try to reinstall DrakConf.", $exec_string)), 1, 0, 0); + $vbox->show_all; + $notebook_global->append_page($vbox, ""); + $pid_launched[$nb_pages] = undef; + $nb_pages++; + $tree_launched{$label}->[0]=$nb_pages; + $notebook_global->set_page($nb_pages); + return; + } + if (!$tree_launched{$label}->[0]) { + 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,0,0,0); + my $label_ = new Gtk::Label (_("Please be patient")); + $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(70,70); + $darea1->set_usize(70,70); + $hbox->pack_start($darea1,1,0,0); + $darea1->show; + my $socket = new Gtk::Socket; + $global_socket = \$socket; + $vbox->pack_start($socket, 1, 1, 0); + $notebook_global->append_page($vbox, ""); + $pid_launched[$nb_pages] = undef; + $nb_pages++; + $tree_launched{$label}->[0]=$nb_pages; + $notebook_global->set_page($nb_pages); + print "##[ $label ]#######" . Data::Dumper->Dump([ $tree_launched{$label} ], ['$t']) . "\n"; + print "##[ $label ]#######" . Data::Dumper->Dump([ ${$tree_launched{$label}->[1]} ], ['$t2']) . "\n"; + # ${$tree_launched{$label}->[1]}->set_sensitive(0); + # print ("#########" . $tree_launched{$_}->[0] . "\n") foreach (keys %tree_launched); + $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(120, sub { + $darea1->window->draw_pixmap + ($darea1->style->white_gc, + $anim[$anim_nb]->[0], 0, 0, + ($darea1->allocation->[2]-70)/2, ($darea1->allocation->[3]-70)/2, + 70, 70); + $anim_nb++; + $anim_nb > 7 and $anim_nb=0; + 1; + }); + $socket->realize; + # $label->destroy; + 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"); } + } else { + $notebook_global->set_page($tree_launched{$label}->[0]); } } |