diff options
author | Daouda Lo <daouda@mandriva.com> | 2003-10-29 14:45:19 +0000 |
---|---|---|
committer | Daouda Lo <daouda@mandriva.com> | 2003-10-29 14:45:19 +0000 |
commit | 6923a8de5686a64baee309aa2daa982a8237a8ce (patch) | |
tree | 533a7400d60ea1d41357a5809dab52902772adcb | |
parent | d78750ca2973cf26a26e113bd215625664485d88 (diff) | |
download | control-center-6923a8de5686a64baee309aa2daa982a8237a8ce.tar control-center-6923a8de5686a64baee309aa2daa982a8237a8ce.tar.gz control-center-6923a8de5686a64baee309aa2daa982a8237a8ce.tar.bz2 control-center-6923a8de5686a64baee309aa2daa982a8237a8ce.tar.xz control-center-6923a8de5686a64baee309aa2daa982a8237a8ce.zip |
- ntp feature for local users
-rwxr-xr-x | clock.pl | 105 |
1 files changed, 91 insertions, 14 deletions
@@ -6,7 +6,7 @@ use POSIX; use common; # i18n : IMPORTANT to get correct namespace (drakconf instead of libDrakX) BEGIN { unshift @::textdomains, 'drakconf' } -use ugtk2 qw(:helpers :wrappers); +use ugtk2 qw(:all); use interactive; use standalone; use timezone; @@ -21,6 +21,10 @@ my ($midx, $midy); my $first = 1; my $its_reset = 0; +my $conffile = '/etc/sysconfig/ntpclock'; +my $ntpfile = '/etc/ntp.conf'; +my $ntpdlock = '/var/lock/subsys/ntpd'; + my $my_win = ugtk2->new('print_launcher'); $my_win->{rwindow}->set_title(N("DrakClock")) unless $::isEmbedded; @@ -43,6 +47,8 @@ $button_time->signal_connect(clicked => sub { $in->{timezone}{timezone} = $timezone; } }); +#my $button_ntp = Gtk2::Button->new(N("Use NTP")); +#$button_time->signal_connect(clicked => sub { ask_ntp($in, $) }); my $drawing_area; @@ -50,7 +56,8 @@ my $adj_h = Gtk2::Adjustment->new(0.0, 0.0, 23.0, 1.0, 5.0, 0.0); my $adj_m = Gtk2::Adjustment->new(0.0, 0.0, 59.0, 1.0, 5.0, 0.0); my $adj_s = Gtk2::Adjustment->new(0.0, 0.0, 59.0, 1.0, 5.0, 0.0); -my $button_reset; +my ($button_reset, $check_ntp, $hb_ntp, $combo_ntpserver, $fullntp, $ntp); +my $mode = 0; my (undef, undef, $h_old, $old_day, $old_month, $old_year) = localtime(time()); @@ -59,9 +66,23 @@ my @image_size = (300, 300); $my_win->{window}->add(gtkpack_(Gtk2::VBox->new(0,0), 1, gtkpack_(Gtk2::HBox->new(0,0), 1, gtkpack_(Gtk2::VBox->new(0,0), - 1, $calendar, + 0, $calendar, 0, $button_time, - ), + 1, gtkadd(gtkset_shadow_type(Gtk2::Frame->new(N("Network Time Protocol")), 'etched_in'), + gtkpack_(Gtk2::VBox->new(0, 3), + 0, Gtk2::Label->new(N("Your computer can synchronize its clock\n with a remote time server using NTP")), + 0, gtksignal_connect(gtkset_active($check_ntp = Gtk2::CheckButton->new(N("Enable Network Time Protocol")), $mode), clicked => sub { + $mode = !$mode; + $hb_ntp->set_sensitive($mode); + if (!-e $ntpfile && $mode == 1) + { install_ntp() } + }), + 0, gtkpack_($hb_ntp = Gtk2::HBox->new(0, 2), + 0, Gtk2::Label->new(N("Server:")), + 1, $combo_ntpserver = Gtk2::Combo->new + ) + )) + ), 1, gtkpack_(Gtk2::VBox->new(0,0), 0, gtkpack_(Gtk2::HBox->new(0,0), 0, $drawing_area = gtkset_size_request(Gtk2::DrawingArea->new, @image_size), @@ -87,19 +108,44 @@ $my_win->{window}->add(gtkpack_(Gtk2::VBox->new(0,0), }), gtksignal_connect(Gtk2::Button->new_from_stock('gtk-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); - system("date " . - join('', map { print_it0($_) } ($month, $day, $hour, $min, $year)) . '.' . print_it0($sec)); - -e '/sbin/hwclock' and system('/sbin/hwclock --systohc'); - system("dcop kicker Panel restart") if $ENV{DESKTOP} eq 'kde'; - ugtk2->exit(0); + if ($check_ntp->get_active) { + my $choosed_serv = $combo_ntpserver->entry->get_text(); + $choosed_serv =~ s/(\S+)\s*(.*)$/$1/; + timezone::ntp_server('', $1); + system("/sbin/chkconfig --level 35 ntpd on"); + system("service ntpd restart"); + } else { + if (-e $ntpdlock) { + system("service ntpd stop"); + system("/sbin/chkconfig --level 35 ntpd off"); + } + } + my ($year, $month, $day) = $calendar->get_date; + $month++; + my ($hour, $min, $sec) = ($adj_h->get_value, $adj_m->get_value, $adj_s->get_value); + system(x"date " . + join('', map { print_it0($_) } ($month, $day, $hour, $min, $year)) . '.' . print_it0($sec)); + -e '/sbin/hwclock' and system('/sbin/hwclock --systohc'); + system("dcop kicker Panel restart") if $ENV{DESKTOP} eq 'kde'; + ugtk2->exit(0); }), ) ) ); - +my $servers = get_server(); +$combo_ntpserver->set_popdown_strings(@$servers); +if (-e $ntpfile && -e $ntpdlock) { + $ntp = timezone::ntp_server(''); + print "******$ntp*******\n"; + $ntp and ntp_widget_state(1); + foreach my $s (@$servers) { + $s =~ /\Q$ntp/ and $fullntp = $s; + $fullntp and last + } + $fullntp |= $ntp; + $combo_ntpserver->entry->set_text($fullntp); +} else { ntp_widget_state(0) } + my $pressed; $drawing_area->set_events([ 'button_press_mask', 'button_release_mask', "pointer_motion_mask" ]); $drawing_area->signal_connect(expose_event => \&expose_event); @@ -140,7 +186,38 @@ $drawing_area->show; $my_win->main; ugtk2->exit(0); - +sub ntp_widget_state { + my $state = shift; + $check_ntp->set_active($state); + $hb_ntp->set_sensitive($state); + $mode = $state; +} +sub install_ntp() { + my $w = ugtk2->new("Want to install ntp ?", grab => 1, center => 1, if_(!$::isEmbedded, transient => $my_win->{rwindow})); + gtkadd($w->{window}, + gtkpack__(Gtk2::VBox->new(0,5), + Gtk2::Label->new(N("We need to install ntp package\n to enable Network Time Protocol")), + Gtk2::HSeparator->new, + gtkpack(create_hbox(), + gtksignal_connect(Gtk2::Button->new(N("Yes")), clicked => sub { + Gtk2->main_quit; + $in->do_pkgs->install('ntp'); + }), + gtksignal_connect(Gtk2::Button->new(N("No")), clicked => sub { + Gtk2->main_quit; + ntp_widget_state(0); + })))); + $w->main; +} +sub get_server { + my ($servs, @sv); + $servs = timezone::ntp_servers(); + foreach my $l (keys %$servs) { + my $c = $l . " (" . $servs->{$l} . ")"; + push(@sv, $c); + } + \@sv +} sub update_time() { Repaint($drawing_area, 1); }; |