summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xmdkapplet88
1 files changed, 60 insertions, 28 deletions
diff --git a/mdkapplet b/mdkapplet
index f1425dff..1a0c7234 100755
--- a/mdkapplet
+++ b/mdkapplet
@@ -68,6 +68,10 @@ my $localfile = "$localdir/mdkonline";
my $release = mdkonline::get_release();
+
+my %config = getVarsFromSh('/etc/sysconfig/mdkapplet');
+$config{UPDATE_FREQUENCY} ||= 3*60*60; # default to 3hours
+
sub my_sprintf_fixutf8 {
mdkonline::get_release() < 2006.0 ? common::sprintf_fixutf8(@_) : @_;
}
@@ -154,14 +158,11 @@ gtkadd(my $icon = Gtk2::TrayIcon->new("MdkApplet"),
);
#$icon->shape_combine_mask($img, 0, 0);
$eventbox->signal_connect(button_press_event => sub {
- if (!$raisedwindow) {
if ($_[1]->button == 1) {
- if (-e $conffile) { $raisedwindow = 1; showMainWindow() } else { $raisedwindow = 0; configure() }
- }
- } elsif ($_[1]->button == 1) {
- $applet_window->present;
+ installUpdates() if $state_global eq 'updates';
+ } elsif ($_[1]->button == 3) {
+ $menu and $menu->popup(undef, undef, undef, undef, $_[1]->button, $_[1]->time);
}
- $_[1]->button == 3 && $menu and $menu->popup(undef, undef, undef, undef, $_[1]->button, $_[1]->time);
});
my ($opt) = @ARGV;
if ($opt eq '--force' || $opt eq '-f') { setAutoStart('TRUE') }
@@ -171,7 +172,7 @@ shouldStart() or die "$localfile should be set to TRUE: please use --force or -f
checkConfig();
checkUpdates();
-cronUpdate();
+setup_cyclic_check();
$icon->show_all;
@@ -196,17 +197,12 @@ sub harvester {
return if $clean;
}
sub fork_exec {
- my $pid = fork();
- if (defined $pid) {
- !$pid and do { exec(@_) or POSIX::_exit() };
- return $pid;
- } else {
- refresh_gui(1);
- }
+ run_program::raw({ detach => 1 }, @_);
+ refresh_gui(1);
}
sub refresh_gui {
my ($sens) = @_;
- !$conf_launched and silentCheck(); $conf_launched = 0;
+ #!$conf_launched and silentCheck(); $conf_launched = 0;
my $w = $::main_window ? $::main_window->window : undef;
$insensitive_while_running_a_child = !$sens;
$sens ? gtkset_mousecursor_normal($w) : gtkset_mousecursor_wait($w);
@@ -288,7 +284,7 @@ sub installUpdates() {
my $oldmd5 = $release <= 10.2 ? mdkonline::md5file($binfile) : common::md5file($binfile);
logIt(N("Launching mdkupdate --applet\n"));
refresh_gui(0);
- fork_exec("/usr/sbin/mdkupdate --applet");
+ fork_exec('MandrivaUpdate', '--no-media-update', '--no-confirmation');
my $newmd5 = $release <= 10.2 ? mdkonline::md5file($binfile) : common::md5file($binfile);
restart_applet() if $newmd5 ne $oldmd5;
#my $w = $in->wait_message(N("Please wait"), N("Check updates"));
@@ -299,23 +295,60 @@ sub installUpdates() {
}
sub silentCheck() {
my %h = getVarsFromSh($conffile);
- my ($u, $ct);
+ my $u;
logIt(N("Computing new updates...\n"));
logIt(N("Connecting to") . " ...\n"); # i18n bug to fix in cooker
my $w = $::main_window ? $::main_window->window : undef;
gtkset_mousecursor_wait($w);
gtkflush(); go2State('busy'); gtkflush();
gtkset_mousecursor_normal($w) if !$insensitive_while_running_a_child;
- my $response = mdkonline::soap_get_updates_for_host($h{HOST_ID}, $h{HOST_KEY});
+ my $response = eval { mdkonline::soap_is_new_update_for_distro($h{HOST_ID}, $h{HOST_KEY}) };
+ $response = { code => 0, data => { isUpdateAvailable => 1 } };
my $status_err = mdkonline::check_server_response($response);
if ($status_err eq 'OK') {
- $ct = $response->{data}{updates};
# are there any updates ?
- if (@$ct) {
- logIt(N("Checking... Updates are available\n") . "\n");
- go2State('updates');
- } else { # no update
- okState();
+ if (my $data = $response->{data}) {
+ if ($data->{isUpdateAvailable}) {
+ if (!run_program::raw({}, 'urpmi.update', '--update')) { # shoud wait for it while gtkflus()ing: { detach => 1 }
+ logIt(N("Error updating media"));
+ go2State('critical');
+ return 0;
+ }
+
+ use urpm; # to force require
+ require urpm::select;
+ require urpm::media;
+ my $urpm = urpm->new;
+ urpm::media::configure($urpm);
+
+ logIt(N("Computing new updates...\n"));
+
+ if (my $db = urpm::db_open_or_die($urpm)) {
+ my $h = $urpm->request_packages_to_upgrade($db, {}, {});
+
+ if (my @pkgs = grep { !$_->flag_skip } map { $urpm->{depslist}[$_] } keys %$h) {
+ go2State('updates');
+ logIt(N("Checking... Updates are available\n") . "\n");
+
+ } else {
+ go2State('okay');
+ logIt(N("Packages are up to date") . "\n"); # mesg from urpmi
+ return;
+ }
+ } else {
+ go2State('critical');
+ logIt(N("Failed to open urpmi database") . "\n");
+ return;
+ }
+
+ go2State('updates');
+ logIt(N("Checking... Updates are available\n") . "\n");
+
+ } else { # no update
+ okState();
+ }
+ } else {
+ logIt(N("An error occurred"));
}
} else {
# 99 - log or host or action or pass empty, wrong action
@@ -334,7 +367,6 @@ sub silentCheck() {
eval { $retcode->{$response->{code}}->() }; if ($@) { logIt(N("Problem occured while connecting to the server, please contact the support team")); go2State('critical') }
}
if ($debug) {
- print "\nCONTENTS = $ct\n" if $debug;
require Data::Dumper;
logIt(N("Response from Mandriva Online server\n") . Data::Dumper->Dumper($response));
}
@@ -356,12 +388,12 @@ sub compareWithInstalled {
}
$isUpdate;
}
-sub cronUpdate() {
+sub setup_cyclic_check() {
Glib::Timeout->add(10*1000, sub {
checkConfig();
1;
});
- $timeout = Glib::Timeout->add(3*60*60*1000, sub {
+ $timeout = Glib::Timeout->add($config{UPDATE_FREQUENCY}*1000, sub {
checkUpdates();
1;
});
@@ -479,7 +511,7 @@ sub setState {
$w->signal_connect(response => sub { $_[0]->destroy });
$w->set_version($ver);
$w->set_icon(Gtk2::Gdk::Pixbuf->new_from_file('/usr/share/icons/mini/mdkonline.png'));
- $w->set_copyright(N("Copyright (C) %s by Mandriva", '2001-2006'));
+ $w->set_copyright(N("Copyright (C) %s by Mandriva", '2001-2007'));
$w->set_url_hook(sub {
my (undef, $url) = @_;
run_program::raw({ detach => 1 }, 'www-browser', $url);