diff options
-rwxr-xr-x | clock.pl | 126 |
1 files changed, 59 insertions, 67 deletions
@@ -1,8 +1,9 @@ #!/usr/bin/perl -use POSIX; -use Gtk; +use strict; use lib qw(/usr/lib/libDrakX); +use POSIX; +use my_gtk; use interactive; use standalone; use timezone; @@ -11,24 +12,17 @@ Gtk->set_locale; #use strict; use MDK::Common; + #------------------------------------------------------------- -# 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) +# i18n +# IMPORTANT: next code is needed 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, @_; -} +push @::textdomains, 'drakconf'; -sub translate { - my ($s) = @_; - $s ? c::dgettext('drakconf', $s) : ''; -} - -my $in = vnew interactive('su'); +my $in = interactive->vnew('su'); my $pixmap; my $radius; my $dRadians_hour; @@ -38,35 +32,35 @@ my $Radian; my $type; my $timer; my ($midx, $midy); -my $first=1; +my $first = 1; my $is24; my $h_old; my ($old_year, $old_month, $old_day); -my $its_reset=0; +my $its_reset = 0; my $window = $::isEmbedded ? new Gtk::Plug ($::XID) : new Gtk::Window -toplevel; my $vbox = new Gtk::VBox(0,0); -$window->set_title(_("DrakClock")); +$window->set_title(N("DrakClock")); $window->add($vbox); -$window->signal_connect ( delete_event => \&quit_global ); +$window->signal_connect (delete_event => \&quit_global); my $hbox = new Gtk::HBox(0,0); $vbox->pack_start($hbox, 1, 1, 0); my $vbox1 = new Gtk::VBox(0,0); $hbox->pack_start($vbox1, 1, 1, 0); my $calendar = new Gtk::Calendar; $vbox1->pack_start($calendar, 1, 1, 0); -$calendar->signal_connect ( $_ => \&cal_changed ) +$calendar->signal_connect ($_ => \&cal_changed) foreach ('month-changed', 'day-selected', 'day-selected-double-click', 'prev-month', 'next-month', 'prev-year', 'next-year'); -my $button_time = new Gtk::Button _("Time Zone"); +my $button_time = new Gtk::Button N("Time Zone"); $vbox1->pack_start($button_time, 0, 1, 10); -$button_time->signal_connect ( clicked => sub { +$button_time->signal_connect (clicked => sub { local $::isEmbedded = 0; - $in->{timezone}={}; + $in->{timezone} = {}; add2hash($in->{timezone}, timezone::read('')); my $timezone = $in->{timezone}{timezone}; - $in->{timezone}{timezone} = $in->ask_from_treelist(_("Timezone - DrakClock"), _("Which is your timezone?"), '/', [ timezone::getTimeZones('') ], $timezone); - if( defined($in->{timezone}{timezone}) ){ - $in->{timezone}{UTC} = $in->ask_yesorno(_("GMT - DrakClock"), _("Is your hardware clock set to GMT?"), $in->{timezone}{UTC}); + $in->{timezone}{timezone} = $in->ask_from_treelist(N("Timezone - DrakClock"), N("Which is your timezone?"), '/', [ timezone::getTimeZones('') ], $timezone); + if (defined($in->{timezone}{timezone})) { + $in->{timezone}{UTC} = $in->ask_yesorno(N("GMT - DrakClock"), N("Is your hardware clock set to GMT?"), $in->{timezone}{UTC}); timezone::write('', $in->{timezone}); } else { $in->{timezone}{timezone} = $timezone; @@ -79,11 +73,11 @@ my $drawing_area = new Gtk::DrawingArea; $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 ); -$drawing_area->signal_connect ( configure_event => \&configure_event ); -$drawing_area->signal_connect ( button_press_event => sub { $pressed=1 }); -$drawing_area->signal_connect ( button_release_event => sub { $first=1; $pressed=0 }); -$drawing_area->signal_connect ( motion_notify_event => \&motion_event ); +$drawing_area->signal_connect (expose_event => \&expose_event); +$drawing_area->signal_connect (configure_event => \&configure_event); +$drawing_area->signal_connect (button_press_event => sub { $pressed = 1 }); +$drawing_area->signal_connect (button_release_event => sub { $first = 1; $pressed = 0 }); +$drawing_area->signal_connect (motion_notify_event => \&motion_event); my $hbox11 = new Gtk::HBox(1,0); $vbox2->pack_start($hbox11, 0, 0, 10); @@ -93,27 +87,27 @@ my $adj_h = new Gtk::Adjustment 0.0, 0.0, 23.0, 1.0, 5.0, 0.0; my $spinner_h = new Gtk::SpinButton $adj_h, 0, 0; $hbox2->pack_start($spinner_h, 0, 0, 0); $spinner_h->set_wrap(1); -$spinner_h->signal_connect ( activate => \&spinned); -$spinner_h->signal_connect ( button_release_event => \&spinned); -$spinner_h->signal_connect ( changed => \&changed ); +$spinner_h->signal_connect (activate => \&spinned); +$spinner_h->signal_connect (button_release_event => \&spinned); +$spinner_h->signal_connect (changed => \&changed); my $adj_m = new Gtk::Adjustment 0.0, 0.0, 59.0, 1.0, 5.0, 0.0; my $spinner_m = new Gtk::SpinButton $adj_m, 0, 0; $hbox2->pack_start($spinner_m, 0, 0, 0); $spinner_m->set_wrap(1); -$spinner_m->signal_connect ( activate => \&spinned ); -$spinner_m->signal_connect ( button_release_event => \&spinned ); +$spinner_m->signal_connect (activate => \&spinned); +$spinner_m->signal_connect (button_release_event => \&spinned); my $adj_s = new Gtk::Adjustment 0.0, 0.0, 59.0, 1.0, 5.0, 0.0; my $spinner_s = new Gtk::SpinButton $adj_s, 0, 0; $hbox2->pack_start($spinner_s, 0, 0, 0); $spinner_s->set_wrap(1); -$spinner_s->signal_connect ( activate => \&spinned ); -$spinner_s->signal_connect ( button_release_event => \&spinned ); +$spinner_s->signal_connect (activate => \&spinned); +$spinner_s->signal_connect (button_release_event => \&spinned); my $bbox = new Gtk::HButtonBox; $bbox->set_layout(-end); $vbox->pack_start($bbox, 0, 0, 5); -my $button_ok = new Gtk::Button _("OK"); -$button_ok->signal_connect ( clicked => sub { +my $button_ok = new Gtk::Button N("OK"); +$button_ok->signal_connect (clicked => sub { my ($year, $month, $day) = $calendar->get_date; $month++; my ($hour, $min, $sec) = ($adj_h->get_value, $adj_m->get_value, $adj_s->get_value); @@ -128,27 +122,27 @@ $button_ok->signal_connect ( clicked => sub { -e '/sbin/hwclock' and system('/sbin/hwclock --systohc'); quit_global(); }); -$bbox->add($button_ok ); -my $button_cancel = new Gtk::Button _("Cancel"); -my $button_reset = new Gtk::Button _("Reset"); -$button_cancel->signal_connect ( clicked => sub { +$bbox->add($button_ok); +my $button_cancel = new Gtk::Button N("Cancel"); +my $button_reset = new Gtk::Button N("Reset"); +$button_cancel->signal_connect (clicked => sub { quit_global(); Gtk->timeout_remove($timer); - $timer=Gtk->timeout_add(120, sub { time_to_rad(localtime(time)); Repaint($drawing_area) }); + $timer = Gtk->timeout_add(120, sub { time_to_rad(localtime(time)); Repaint($drawing_area) }); time_to_rad(localtime(time)); Repaint($drawing_area); $calendar->select_month($old_month, $old_year); $calendar->select_day($old_day); $button_reset->set_sensitive(0); }); -$bbox->add($button_cancel ); -$button_reset->signal_connect ( clicked => sub { - $its_reset=1; - $timer=Gtk->timeout_add(120, sub { time_to_rad(localtime(time)); Repaint($drawing_area) }); +$bbox->add($button_cancel); +$button_reset->signal_connect (clicked => sub { + $its_reset = 1; + $timer = Gtk->timeout_add(120, sub { time_to_rad(localtime(time)); Repaint($drawing_area) }); time_to_rad(localtime(time)); Repaint($drawing_area); $calendar->select_month($old_month, $old_year); $calendar->select_day($old_day); $button_reset->set_sensitive(0); - $its_reset=0; + $its_reset = 0; }); $bbox->add($button_reset); @@ -163,7 +157,7 @@ $calendar->select_month($old_month, $old_year); $calendar->select_day($old_day); $::isEmbedded and kill 'USR2', $::CCPID; $button_reset->set_sensitive(0); -$timer=Gtk->timeout_add(120, sub { time_to_rad(localtime(time)); Repaint($drawing_area) }); +$timer = Gtk->timeout_add(120, sub { time_to_rad(localtime(time)); Repaint($drawing_area) }); Gtk->main; sub cal_changed { @@ -173,14 +167,14 @@ sub cal_changed { sub changed { if ($h_old > $adj_h->get_value && $adj_h->get_value < ($is24 ? 18 : 6) && $h_old > ($is24 ? 18 : 6) && $h_old < ($is24 ? 24 : 12)) { - $h_old= $adj_h->get_value; + $h_old = $adj_h->get_value; $is24 = !$is24; } - elsif ($h_old < $adj_h->get_value && $adj_h->get_value > ($is24 ? 18 : 6) && $h_old < ($is24 ? 18 : 6) && ($adj_h->get_value-$h_old !=12 )) { - $h_old= $adj_h->get_value; + elsif ($h_old < $adj_h->get_value && $adj_h->get_value > ($is24 ? 18 : 6) && $h_old < ($is24 ? 18 : 6) && ($adj_h->get_value-$h_old != 12)) { + $h_old = $adj_h->get_value; $is24 = !$is24; } - $h_old= $adj_h->get_value; + $h_old = $adj_h->get_value; } sub spinned { @@ -201,11 +195,11 @@ sub motion_event { $button_reset->set_sensitive(1); } - $$Radian=-atan2(($event->{'x'}-$midx),($event->{'y'}-$midy)) + $PI; + $$Radian = -atan2(($event->{'x'}-$midx),($event->{'y'}-$midy)) + $PI; Repaint($widget); rad_to_time(); - $first=0; + $first = 0; } sub determine_radian { @@ -213,18 +207,16 @@ sub determine_radian { my $res; my $r; - my $i=0; + my $i = 0; foreach (\$dRadians_hour, \$dRadians_min, \$dRadians_sec) { - my $d=sqrt ( ($x - ($midx + 7/10 * $radius * sin ($$_)))**2 + ($y - ($midy - 7/10 * $radius * cos ($$_)))**2 ); - $res or $res=$d, $r=$_; - $d<$res and $res=$d, $r=$_, $i++; + my $d = sqrt ( ($x - ($midx + 7/10 * $radius * sin ($$_)))**2 + ($y - ($midy - 7/10 * $radius * cos ($$_)))**2); + $res or $res = $d, $r = $_; + $d<$res and $res = $d, $r = $_, $i++; } ($r, $i); } -sub quit_global { - $::isEmbedded ? kill('USR1', $::CCPID) : Gtk->exit(0); -} +sub quit_global { my_gtk->exit() } sub expose_event { my ($widget) = @_; @@ -264,8 +256,8 @@ sub time_to_rad { sub Repaint { my ($drawing_area) = @_; - my $dRadians_hour_real = POSIX::floor($dRadians_hour / $PI*6 ) * $PI/6.0 + $dRadians_min / 12; - my $dRadians_min_real = POSIX::floor($dRadians_min / $PI * 30 ) * $PI / 30; + my $dRadians_hour_real = POSIX::floor($dRadians_hour / $PI*6) * $PI/6.0 + $dRadians_min / 12; + my $dRadians_min_real = POSIX::floor($dRadians_min / $PI * 30) * $PI / 30; my $dRadians_sec_real = $dRadians_sec; $pixmap->draw_rectangle($drawing_area->style->white_gc, 1, 0, 0, $drawing_area->allocation->[2], |