summaryrefslogtreecommitdiffstats
path: root/clock.pl
diff options
context:
space:
mode:
authorThierry Vignaud <tvignaud@mandriva.org>2002-11-18 07:55:55 +0000
committerThierry Vignaud <tvignaud@mandriva.org>2002-11-18 07:55:55 +0000
commit6bdda06d2f204d64c9b5aa7da10d517b5db01f93 (patch)
tree189f5fc079be72ee2667c600d6511e10c2251ec1 /clock.pl
parentaf3ad14e2e0e37bb94f74dfc9691c70fee83393f (diff)
downloadcontrol-center-6bdda06d2f204d64c9b5aa7da10d517b5db01f93.tar
control-center-6bdda06d2f204d64c9b5aa7da10d517b5db01f93.tar.gz
control-center-6bdda06d2f204d64c9b5aa7da10d517b5db01f93.tar.bz2
control-center-6bdda06d2f204d64c9b5aa7da10d517b5db01f93.tar.xz
control-center-6bdda06d2f204d64c9b5aa7da10d517b5db01f93.zip
code cleaning/shrunking
clock.pl, menus_launchers.pl, print_launcher.pl - use my_gtk & common to : o automatically handle embedding o simplify code o ease gtk2 port o don't uselessly initialize gtk & locales o ... don't do what my_gtk already offer to do for us clock.pl: kill stupid code copied between two signal handlers whereas it has no purpose since my_gtk just exited in second handler mcc: - explain why we initialize interactive without using it - global workaround for broken locales - bump version
Diffstat (limited to 'clock.pl')
-rwxr-xr-xclock.pl70
1 files changed, 26 insertions, 44 deletions
diff --git a/clock.pl b/clock.pl
index ebf207f4..2eb0aa22 100755
--- a/clock.pl
+++ b/clock.pl
@@ -3,15 +3,11 @@
use strict;
use lib qw(/usr/lib/libDrakX);
use POSIX;
-use my_gtk;
+use common;
+use my_gtk qw(:helpers :wrappers :various);;
use interactive;
use standalone;
use timezone;
-init Gtk;
-Gtk->set_locale;
-#use strict;
-use MDK::Common;
-
#-------------------------------------------------------------
# i18n
@@ -37,11 +33,13 @@ my $is24;
my $h_old;
my ($old_year, $old_month, $old_day);
my $its_reset = 0;
-my $window = $::isEmbedded ? new Gtk::Plug ($::XID) : new Gtk::Window -toplevel;
+
+my $my_win = my_gtk->new('print_launcher');
+$my_win->{rwindow}->set_title(N("DrakClock")) unless $::isEmbedded;
+
my $vbox = new Gtk::VBox(0,0);
-$window->set_title(N("DrakClock"));
-$window->add($vbox);
-$window->signal_connect (delete_event => \&quit_global);
+$my_win->{window}->add($vbox);
+$my_win->{window}->signal_connect (delete_event => sub { my_gtk->exit(0) });
my $hbox = new Gtk::HBox(0,0);
$vbox->pack_start($hbox, 1, 1, 0);
my $vbox1 = new Gtk::VBox(0,0);
@@ -54,7 +52,7 @@ $calendar->signal_connect ($_ => \&cal_changed)
my $button_time = new Gtk::Button N("Time Zone");
$vbox1->pack_start($button_time, 0, 1, 10);
$button_time->signal_connect (clicked => sub {
- local $::isEmbedded = 0;
+ local $::isEmbedded = 0; # to prevent sub window embedding
$in->{timezone} = {};
add2hash($in->{timezone}, timezone::read(''));
my $timezone = $in->{timezone}{timezone};
@@ -106,36 +104,19 @@ $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 N("OK");
-$button_ok->signal_connect (clicked => sub {
+$bbox->add(gtksignal_connect(new Gtk::Button(N("OK")),
+ 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);
- $a = "date " .
- ($month<10 ? "0" : "") . $month .
- ($day<10 ? "0" : "") . $day .
- ($hour<10 ? "0" : "") . $hour .
- ($min<10 ? "0" : "") . $min .
- $year . "." .
- ($sec<10 ? "0" : "") . $sec;
- system($a);
+ system("date " .
+ join('', map { print_it0($_) } ($month, $day, $hour, $min, $year)) . '.' . print_it0($sec));
-e '/sbin/hwclock' and system('/sbin/hwclock --systohc');
- quit_global();
- });
-$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) });
- 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 {
+ my_gtk->exit(0);
+ } ));
+$bbox->add(gtksignal_connect(new Gtk::Button(N("Cancel")), clicked => sub { my_gtk->exit(0) }));
+my $button_reset;
+$button_reset = gtksignal_connect(new Gtk::Button(N("Reset")), 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);
@@ -144,9 +125,10 @@ $button_reset->signal_connect (clicked => sub {
$button_reset->set_sensitive(0);
$its_reset = 0;
});
+
$bbox->add($button_reset);
-$window->show_all;
+$my_win->{window}->show_all;
Gtk->main_iteration while Gtk->events_pending;
$calendar->realize;
@@ -157,7 +139,8 @@ $calendar->select_month($old_month, $old_year);
$calendar->select_day($old_day);
$button_reset->set_sensitive(0);
$timer = Gtk->timeout_add(120, sub { time_to_rad(localtime(time)); Repaint($drawing_area) });
-Gtk->main;
+
+$my_win->main;
my_gtk->exit(0);
sub cal_changed {
@@ -166,12 +149,10 @@ 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;
+ if ($h_old > $adj_h->get_value && $adj_h->get_value < ($is24 ? 18 : 6) && $h_old > ($is24 ? 18 : 6) && $h_old < ($is24 ? 24 : 12)) {
$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;
$is24 = !$is24;
}
$h_old = $adj_h->get_value;
@@ -216,8 +197,6 @@ sub determine_radian {
($r, $i);
}
-sub quit_global { my_gtk->exit() }
-
sub expose_event {
my ($widget) = @_;
$widget->window->draw_pixmap (
@@ -336,3 +315,6 @@ sub DrawPointAt {
$cx + 95/100 * $radius * sin ($dRadians),
$cy - 95/100 * $radius * cos ($dRadians))
}
+
+
+sub print_it0 { sprintf("%02d", @_[0]) }