diff options
-rwxr-xr-x | mdkapplet | 133 |
1 files changed, 73 insertions, 60 deletions
@@ -22,6 +22,7 @@ use strict; use lib qw(/usr/lib/libDrakX); +use interactive; use common; use Gtk2::Pango; @@ -34,15 +35,16 @@ use lib qw(/usr/lib/libDrakX/drakfirsttime); use mdkonline; use Gtk2::TrayIcon; -my ($eventbox, $img); +my $in = interactive->vnew(''); + ugtk2::add_icon_path("/usr/share/mdkonline/pixmaps/"); -my ($menu, $timeout, $refreshtm, $networktm); -my $nowindow = 1; my $arch = arch(); my $online_site = "http://www.mandrakeonline.net/"; -my ($av_pkgs, $update_label, $lastch, $mLog, $buffer, $textview, $wlog, $textvw, $state_global); -my ($need_update, $raisedwindow, $isAvailable) = (0, 0, 0); +my ($menu, $timeout, $refreshtm, $networktm, $eventbox, $img, $av_pkgs, $update_label, $lastch, $mLog, $buffer, $textview, $wlog, $textvw, $state_global); +my ($need_update, $raisedwindow, $isAvailable, $debug) = (0, 0, 0, 0); + my @proctable; + my $conffile = '/etc/sysconfig/mdkonline'; my $localdir = "$ENV{HOME}/.MdkOnline"; my $localfile = "$localdir/mdkonline"; @@ -61,11 +63,11 @@ my %state = ( tt => [ N_("Your system is up-to-date") ] }, critical => { - colour => [ 'noconf' ], - changes => [ 'okay', 'busy', 'critical', 'disconnected' ], - menu => [ 'configureApplet', 'check', 'weblink' ], - tt => [ N_("Service configuration problem. Please check logs and send mail to support\@mandrakeonline.net") ] - }, + colour => [ 'noconf' ], + changes => [ 'okay', 'busy', 'critical', 'disconnected' ], + menu => [ 'configureApplet', 'check', 'weblink' ], + tt => [ N_("Service configuration problem. Please check logs and send mail to support\@mandrakeonline.net") ] + }, busy => { colour => [ 'busy' ], changes => [ 'okay', 'critical', 'error', 'disconnected' ], @@ -73,41 +75,43 @@ my %state = ( tt => [ N_("System is busy. Please wait ...") ] }, error => { - colour => [ 'error' ], - changes => [ 'okay' ], - menu => [ 'update', 'check', 'weblink' ], - tt => [ N_("New updates are available for your system") ] - }, + colour => [ 'error' ], + changes => [ 'okay' ], + menu => [ 'update', 'check', 'weblink' ], + tt => [ N_("New updates are available for your system") ] + }, noconfig => { - colour => [ 'noconf' ], - changes => [ 'okay' ], - menu => [ 'weblink', 'register' ], - tt => [ N_("Service is not configured. Please click on \"Configure the service\"") ] - }, + colour => [ 'noconf' ], + changes => [ 'okay' ], + menu => [ 'weblink', 'register' ], + tt => [ N_("Service is not configured. Please click on \"Configure the service\"") ] + }, disconnected => { - colour => [ 'disconnect' ], - changes => [ 'okay', 'busy', 'critical', 'error' ], - menu => [ 'confNetwork' ], - tt => [ N_("Network is down. Please configure your network") ] - }, + colour => [ 'disconnect' ], + changes => [ 'okay', 'busy', 'critical', 'error' ], + menu => [ 'confNetwork' ], + tt => [ N_("Network is down. Please configure your network") ] + }, disabled => { - colour => [ 'disabled' ], - changes => [ 'okay', 'busy', 'critical', 'error' ], - menu => [ 'configureApplet', 'weblink' ], - tt => [ N_("Service is not activated. Please click on \"Online Website\"") ] - }, + colour => [ 'disabled' ], + changes => [ 'okay', 'busy', 'critical', 'error' ], + menu => [ 'configureApplet', 'weblink' ], + tt => [ N_("Service is not activated. Please click on \"Online Website\"") ] + }, notsupported => { - colour => [ 'disabled' ], - changes => [ 'okay', 'busy', 'critical', 'error' ], - menu => [ 'weblink' ], - tt => [ N_("Release not supported (too old release, or development release)") ] - } + colour => [ 'disabled' ], + changes => [ 'okay', 'busy', 'critical', 'error' ], + menu => [ 'weblink' ], + tt => [ N_("Release not supported (too old release, or development release)") ] + } ); my %actions = ( 'update' => { name => N("Install updates"), launch => sub { installUpdates() } }, 'configureApplet' => { name => N("Configure the service"), launch => sub { configure() } }, - 'check' => { name => N("Check Updates"), launch => sub { checkUpdates() } }, + 'check' => { name => N("Check Updates"), launch => sub { + my $w = $in->wait_message(N("Please Wait"), N("Check updates") . '...'); + checkUpdates(); undef $w } }, 'weblink' => { name => N("Online WebSite"), launch => sub { mdkonline::get_site($online_site, 'info.php') } }, 'confNetwork' => { name => N("Configure Network"), launch => sub { configNetwork() } }, 'register' => { name => N("Configure Now!"), launch => sub { configure() } } @@ -130,6 +134,8 @@ $eventbox->signal_connect(button_press_event => sub { my ($opt) = @ARGV; if ($opt eq '--force' || $opt eq '-f') { setAutoStart('TRUE') }; +if ($opt eq '--debug') { $debug = 1} + shouldStart() or die "$localfile should be set to TRUE: please use --force or -f option to launch applet"; checkConfig(); @@ -157,19 +163,21 @@ sub showMainWindow() { gtkpack_(Gtk2::VBox->new(0, 3), 1, gtksignal_connect(Gtk2::Button->new(N("Install updates")), clicked => sub { installUpdates() }), 1, gtksignal_connect(Gtk2::Button->new(N("Configure")), clicked => sub { configure() }), - 1, gtksignal_connect(Gtk2::Button->new(N("Check updates")), clicked => sub { checkUpdates() }), + 1, gtksignal_connect(Gtk2::Button->new(N("Check updates")), clicked => sub { + my $w = $in->wait_message(N("Please Wait"), N("Check updates") . '...'); + checkUpdates(); undef $w }), 1, gtksignal_connect(Gtk2::Button->new(N("See logs")), clicked => sub { if (defined $wlog) { $wlog->{window}->show } else { $wlog = displayLogs(); $wlog->main } }), - ) - ), + ) + ), 1, gtkadd(gtkset_shadow_type(Gtk2::Frame->new(N("Status")), 'etched_in'), gtkpack_(Gtk2::VBox->new(0, 3), 1, create_scrolled_window(gtktext_insert($textvw, refresh_contents($state_global), wrap_mode => 'none')))), 0, gtkpack(Gtk2::HSeparator->new), 0, gtkpack(gtksignal_connect(Gtk2::Button->new(N("Close")), clicked => sub { - if (defined $wlog) { $wlog->destroy; undef $wlog }; $w->destroy; $raisedwindow = 0; - }) - ) - ) + if (defined $wlog) { $wlog->destroy; undef $wlog }; $w->destroy; $raisedwindow = 0; + }) + ) + ) ); $w->show_all } @@ -210,16 +218,18 @@ sub configNetwork() { logIt(N("Launching drakconnect\n")); system "/usr/sbin/dra sub installUpdates { my $binfile = '/usr/bin/mdkapplet'; my $oldmd5 = md5file($binfile); - logIt(N("Launching mdkupdate --applet\n")); - gtkroot()->set_cursor(Gtk2::Gdk::Cursor->new('watch')); - system "/usr/sbin/mdkupdate", "--applet"; + logIt(N("Launching mdkupdate --applet\n")); + system "/usr/sbin/mdkupdate", "--applet"; my $newmd5 = md5file($binfile); if ($newmd5 ne $oldmd5) { logIt(N("Mandrakeonline seems to be reinstalled, reloading applet ....")); exec('/usr/bin/mdkapplet') }; + my $w = $in->wait_message(N("Please Wait"), N("Check updates")); silentCheck(); gtkflush(); - gtkroot()->set_cursor(Gtk2::Gdk::Cursor->new('left-ptr')); + undef $w; + my $mdkupdate_status = cat_('/tmp/mdkupdate.log'); + if ($mdkupdate_status !~ /OK/) { logIt($mdkupdate_status); $in->ask_warn(N("Mandrakelinux Updates Applet"), $mdkupdate_status) } } sub silentCheck { - my $link = "http://www.mandrakeonline.net/online3_RemoteAction.php" . '?action=UpdateList'; + my $link = $online_site . "/online3_RemoteAction.php" . '?action=UpdateList'; my %h = getVarsFromSh($conffile); my $u; logIt(N("Computing new updates...\n")); @@ -229,13 +239,15 @@ sub silentCheck { # print "$link\n"; my $response = mdkonline::get_from_URL($link, 'MdkAppletAgent/0.1'); my $ct = $response->content; -# print "\nCONTENTS = $ct\n"; -# logIt(N("Response from Mandrakeonline server\n") . "$ct"); + if ($debug) { + print "\nCONTENTS = $ct\n" if $debug; + logIt(N("Response from Mandrakeonline server\n") . "$ct"); + } if ($ct =~ /rpm/) { $u = 11 } elsif ($ct =~ m/(\d+)/) { $u = sprintf("%d", $1) } else { $u = 10 }; # 99 - log or host or action or pass empty, wrong action # 98 - wrong pass # 97 - host not active -# print "Returned value = $u\n"; + logIt("Returned value after association (silentCheck)= $u\n") if $debug; my $retcode = { 10 => sub { okState() }, 11 => sub { @@ -247,13 +259,14 @@ sub silentCheck { $cand =~ /(.*)-(.*)-(.*)$/; my ($name, $ver, $rel) = ($1, $2, $3); $comp = compareWithInstalled($name, $ver, $rel, \@t); #print "COMP = $comp\n"; - if ($comp) { $isAvailable = 1; logIt(N("Checking... Updates are available\n") . "\n"); go2State('error') and last } else { $isAvailable = 0 } + if ($comp) { $isAvailable = 1; logIt(N("Checking... Updates are available\n") . "\n"); go2State('error') } else { $isAvailable = 0 } + $comp and last; } !$comp and okState(); }, 94 => sub { logIt(N("Development release not supported by service")); go2State('notsupported') }, 95 => sub { logIt(N("Too old release not supported by service")); go2State('notsupported') }, - 96 => sub { logIt(N("Unknown state")); go2State('okay') }, + 96 => sub { logIt(N("Unknown state")); go2State('critical') }, 97 => sub { logIt(N("Online services disabled. Contact Mandrakeonline site\n")); go2State('disabled') }, 98 => sub { logIt(N("Wrong Password.\n")); go2State('critical') }, 99 => sub { logIt(N("Wrong Action or host or login.\n")); go2State('critical') }, @@ -268,9 +281,10 @@ sub compareWithInstalled { foreach my $p (@$t) { $p =~ /(.*)-(.*)-(.*)$/; my ($n, $v, $r) = ($1, $2, $3); if ($name eq $n) { - #my $iu = mdkonline::rpmvercmp($ver, $v); my $ir = mdkonline::rpmvercmp($rel, $r); + my ($iu, $ir); + if ($debug) { $iu = mdkonline::rpmvercmp($ver, $v); $ir = mdkonline::rpmvercmp($rel, $r) }; if (mdkonline::rpm_ver_cmp($ver, $v) > 0 || mdkonline::rpm_ver_cmp($ver, $v) == 0 && mdkonline::rpm_ver_cmp($rel, $r) > 0) { - #print "$name-$ver-$rel $n-$v-$r *** CMPVER=$iu ** CMPREL = $ir \n"; + logIt("$name-$ver-$rel $n-$v-$r *** CMPVER=$iu ** CMPREL = $ir \n") if $debug; $isUpdate = 1 and last; } } @@ -323,7 +337,7 @@ sub checkConfig { } } sub checkUpdates { - silentCheck() unless member($state_global, qw(disconnected noconfig)); + member($state_global, qw(disconnected noconfig)) or silentCheck(); } sub go2State { my $state = shift; @@ -339,7 +353,7 @@ sub isNetwork { } sub configure { system("/usr/sbin/mdkonline &"); - $refreshtm = Glib::Timeout->add(1*10*1000, sub { + $refreshtm = Glib::Timeout->add(20*1000, sub { if (-e $conffile) { Glib::Source->remove($refreshtm); silentCheck(); @@ -348,8 +362,6 @@ sub configure { }); } sub displayLogs { - # system "/usr/sbin/logdrake --explain=drakxtools &" - #create_dialog(N("Logs"), $mLog, { use_markup => 1, height => 480, width => 580, scroll => 1 }) my $w = ugtk2->new(N("Logs"), center => 1); gtkset_size_request($w->{window}, 500, 400); $w->{window}->signal_connect(delete_event => sub { $w->destroy; undef $wlog }); @@ -401,7 +413,8 @@ sub setState { } sub logIt { my $log = shift; - $mLog .= $log; + my ($Second, $Minute, $Hour, $Day, $Month, $Year, $WeekDay, $DayOfYear, $IsDST) = localtime(); + $mLog .= $Hour . ':' . $Minute . ':' . $Second . ' ' . $log; if (defined $wlog) { $buffer->insert_at_cursor($log) } |