diff options
author | Francesc Pinyol Margalef <francesc.pinyol.m@gmail.com> | 2013-12-21 14:34:43 +0100 |
---|---|---|
committer | Francesc Pinyol Margalef <francesc.pinyol.m@gmail.com> | 2013-12-21 14:34:43 +0100 |
commit | cb726fb709b77c4285153a1394798f9394eb3327 (patch) | |
tree | 16e6b233bdeda5aeaf540622e29de4c09ca576c2 /mgaapplet | |
parent | b316624bcffca8aa7da3811c5f2ab015f58cd369 (diff) | |
parent | bb3d7a0b3f5843a5f3d9455858f2e96975ca95f3 (diff) | |
download | mgaonline-cb726fb709b77c4285153a1394798f9394eb3327.tar mgaonline-cb726fb709b77c4285153a1394798f9394eb3327.tar.gz mgaonline-cb726fb709b77c4285153a1394798f9394eb3327.tar.bz2 mgaonline-cb726fb709b77c4285153a1394798f9394eb3327.tar.xz mgaonline-cb726fb709b77c4285153a1394798f9394eb3327.zip |
Merge branch 'master' of git://git.mageia.org/software/mgaonline
Diffstat (limited to 'mgaapplet')
-rwxr-xr-x | mgaapplet | 203 |
1 files changed, 40 insertions, 163 deletions
@@ -5,7 +5,7 @@ # Copyright (C) 2003-2010 Mandriva # # # # Daouda Lo # -# Thierry Vignaud <tvignaud at mandriva dot com> # +# Thierry Vignaud <thierry.vignaud at gmail dot com> # # # # This program is free software; you can redistribute it and/or modify # # it under the terms of the GNU General Public License Version 2 as # @@ -31,12 +31,13 @@ use feature 'state'; BEGIN { unshift @::textdomains, 'mgaonline' } -use mygtk2 qw(gtknew); #- do not import gtkadd which conflicts with ugtk2 version -use ugtk2 qw(:all); +use mygtk3 qw(gtknew); #- do not import gtkadd which conflicts with ugtk3 version +use ugtk3 qw(:all); use lib qw(/usr/lib/libDrakX/drakfirsttime); use mgaonline; +use mgaapplet; use mgaapplet_gui; -use Gtk2::Notify '-init', 'mgaapplet'; +use Gtk3::Notify '-init', 'mgaapplet'; use Net::DBus qw(:typing); use Rpmdrake::open_db; @@ -158,43 +159,6 @@ Then, restart \"%s\".", N("Enabled"), 'mgaapplet') ], }, ); -my %comm_codes = ( - locked => { - code => 2, - status => 'locked', - log => "urpmi database locked, skipping updating urpmi database", - }, - error_updating => { - code => 3, - status => 'critical', - log => N_("Error updating media"), - }, - no_update_medium => { - code => 4, - status => 'no_update_medium', - log => "no update media configured", - }, - no_enabled_medium => { - code => 5, - status => 'no_enabled_medium', - log => "all update media are disabled", - }, - updates => { - code => 6, - status => 'updates', - log => "Checking... Updates are available\n\n", - }, - uptodate => { - code => 7, - status => 'okay', - log => "Packages are up to date\n", - }, - db_not_open => { - code => 8, - status => 'critical', - log => "Failed to open urpmi database\n", - }, -); my %actions = ( 'update' => { name => N("Install updates"), launch => \&installUpdates }, @@ -203,7 +167,7 @@ my %actions = ( 'upgrade_distro' => { name => N("Upgrade the system"), launch => \&upgrade }, ); -my $icon = Gtk2::StatusIcon->new; +my $icon = Gtk3::StatusIcon->new; #$icon->shape_combine_mask($img, 0, 0); $icon->signal_connect(popup_menu => sub { my ($_icon, $button, $time) = @_; @@ -260,9 +224,9 @@ $SIG{HUP} = \&restart_applet; run_program::raw({ detach => 1 }, 'ionice', '-p', $$, '-n7'); -Gtk2->main; +Gtk3->main; -ugtk2::exit(0); +ugtk3::exit(0); sub gnome_shell_exit_overview() { eval { Net::DBus->session->get_service('org.gnome.Shell')->get_object('/org/gnome/Shell', 'org.freedesktop.DBus.Properties')->Set('org.gnome.Shell', 'OverviewActive', dbus_boolean(0)) }; @@ -384,14 +348,14 @@ sub configNetwork() { } sub confirm_upgrade() { - local $mygtk2::left_padding = 0; + local $mygtk3::left_padding = 0; my $warn_me = text2bool($local_config{DO_NOT_ASK_FOR_DISTRO_UPGRADE}); my $w = new_portable_dialog(N("New version of Mageia distribution")); my ($temp_dir, $box); my $browse; $browse = gtksignal_connect( - Gtk2::FileChooserButton->new(N("Browse"), 'select-folder'), + Gtk3::FileChooserButton->new(N("Browse"), 'select-folder'), 'current-folder-changed' => sub { $temp_dir = $_[0]->get_current_folder; my $ok = -d $temp_dir && ! -l $temp_dir && ((stat($temp_dir))[4] == 0); @@ -453,7 +417,7 @@ sub refresh_no_more_supported_msg() { } sub no_more_supported_choice() { - local $mygtk2::left_padding = 0; + local $mygtk3::left_padding = 0; my $warn_me = text2bool($local_config{DO_NOT_ASK_FOR_NO_MORE_SUPPORTED}); # FIXME: just tell radio buttons' children to wrap instead: local $mgaapplet_gui::width = 580; @@ -490,9 +454,9 @@ sub no_more_supported_choice() { # explicitely wrap too long message: foreach ($b1, $b2) { - next if !$_ || !$_->child; - $_->child->set_line_wrap(1); - $_->child->set_size_request($width-50, -1); + next if !$_ || !$_->get_child; + $_->get_child->set_line_wrap(1); + $_->get_child->set_size_request($width-50, -1); } my $res = fill_n_run_portable_dialog($w, \@widgets); @@ -522,8 +486,8 @@ sub no_more_supported() { } sub really_confirm_upgrade() { - local $mygtk2::left_padding = 0; - my $w = ugtk2->new(N("New version of Mageia distribution"), width => $width + 20); + local $mygtk3::left_padding = 0; + my $w = ugtk3->new(N("New version of Mageia distribution"), width => $width + 20); # estimated package size: my $c; @@ -588,22 +552,6 @@ sub installUpdates() { silentCheck(); gtkflush(); } -sub checker_exit { - my ($state) = @_; - POSIX::_exit($comm_codes{$state}{code}); -} - -sub update_backport_media { - my ($urpm) = @_; - # update inactive backport media: - my @inactive_backport_media = Rpmdrake::open_db::get_inactive_backport_media($urpm); - return if !@inactive_backport_media; - log::explanations("updating inactive backport media " . join(', ', @inactive_backport_media)); - foreach (@inactive_backport_media) { - run_program::run('urpmi.update', if_($root, "--urpmi-root=$root"), $_); - } -} - sub silentCheck() { state $check_time; my $new_time = time(); @@ -619,83 +567,8 @@ sub silentCheck() { # are there any updates ? - $checker_pid = fork(); - if (defined $checker_pid) { - return if $checker_pid; # parent - - # immediate exit, else forked gtk+ object destructors will badly catch up parent applet - my $_safe = before_leaving { - my $err = $@; - log::explanations("mgaapplet check crashed: $err "); - warn "Error: $err\n" . common::backtrace(); - POSIX::_exit(0); - }; - - # be nice with other processes: - setpriority(0, $$, 7); # 0 is PRIO_PROCESS - - my $will_not_update_media; - require urpm; - require urpm::lock; - # so that get_inactive_backport_media() doesn't vivify $urpm->{media}: - my $urpm = Rpmdrake::open_db::fast_open_urpmi_db(); - { - local $urpm->{fatal} = sub { - print "Fatal: @_\n"; - $will_not_update_media = 1; - }; - local $urpm->{error} = $urpm->{fatal}; - - urpm::lock::urpmi_db($urpm, 'exclusive', 1); - } - checker_exit('locked') if $will_not_update_media; - - my $is_it_a_devel_distro = is_it_a_devel_distro(); - - my $media = $is_it_a_devel_distro ? '-a' : '--update'; - if (!run_program::run('urpmi.update', $media, if_($root, "--urpmi-root=$root"))) { - checker_exit('error_updating') if $will_not_update_media; - } - - update_backport_media($urpm); - - require urpm::select; - require urpm::media; - # this eats 52Mb of RAM on 64bit: - # (hence we do it in the forked helper so that the applet doesn't eat too much RAM) - urpm::media::configure($urpm, if_(!$is_it_a_devel_distro, update => 1)); - - my @update_medias = get_update_medias($urpm); - - if (!@update_medias) { - checker_exit('no_update_medium'); - } elsif (!any { ! $_->{ignore} } @update_medias) { - checker_exit('no_enabled_medium'); - } - - if (my $_db = urpm::db_open_or_die($urpm)) { - my $requested = {}; - my $state = {}; - my $need_restart = urpm::select::resolve_dependencies( - $urpm, $state, $requested, - callback_choices => sub { 0 }, - priority_upgrade => $urpm->{options}{'priority-upgrade'}, - auto_select => 1, - ); - my @requested_strict = map { scalar $_->fullname } @{$urpm->{depslist}}[keys %{$state->{selected}}]; - - if ($need_restart || @requested_strict) { - # FIXME: log first found pkgs? - warn ">> need_restart=$need_restart, updates=" . join(', ', @requested_strict) . "\n"; - checker_exit('updates'); - } else { - checker_exit('uptodate'); - } - } else { - checker_exit('db_not_open'); - } - checker_exit('updates'); - } else { + $checker_pid = fork_exec('mgaapplet-update-checker', $root); + if (!$checker_pid) { log::explanations("cannot fork: %s", "update checker ($!)"); go2State('critical'); } @@ -762,8 +635,7 @@ sub about_dialog() { comments => N("Mageia Online gives access to Mageia web services."), website => $url, website_label => N("Online WebSite"), - authors => 'Thierry Vignaud <vignaud@mandriva.com>', - artists => 'Hélène Durosini', + authors => [ 'Thierry Vignaud <thierry.vignaud@gmail.com>' ], translator_credits => #-PO: put here name(s) and email(s) of translator(s) (eg: "John Smith <jsmith@nowhere.com>") N("_: Translator(s) name(s) & email(s)\n"), @@ -782,7 +654,7 @@ sub setState { my @arr = @{$state{$state}{menu}}; my $tmp = eval { gtkcreate_pixbuf($state{$state}{colour}[0]) }; $icon->set_from_pixbuf($tmp) if $tmp; - $icon->set_tooltip(formatAlaTeX(translate($state{$state}{tt}[0]))); + $icon->set_tooltip_text(formatAlaTeX(translate($state{$state}{tt}[0]))); my @invisible_states = qw(delayed okay disconnected locked); $icon->set_visible(!member($state, @invisible_states)); @@ -793,45 +665,50 @@ sub setState { gtkflush(); # so that bubbles are displayed on right icon - if ($state{$state}{tt}[0] && $icon->isa('Gtk2::StatusIcon') && !$state{$state}{do_not_use_bubble}) { - my $bubble = Gtk2::Notify->new(N("Warning"), formatAlaTeX(translate($state{$state}{tt}[0])) . "\n", + if ($state{$state}{tt}[0] && $icon->isa('Gtk3::StatusIcon') && !$state{$state}{do_not_use_bubble}) { + my $bubble = Gtk3::Notify::Notification->new(N("Warning"), formatAlaTeX(translate($state{$state}{tt}[0])) . "\n", '/usr/share/icons/mgaonline.png'); if ($state eq 'new_distribution') { - $bubble->add_action('clicked', N("More Information"), \&upgrade); + $bubble->add_action('upgrade', N("More Information"), sub { upgrade(); Gtk3->main_quit }); + $bubble->signal_connect('closed' => \&Gtk3::main_quit); if ($sub_state eq 'updates') { push @arr, 'update'; } } elsif ($state eq 'no_more_supported') { - $bubble->add_action('clicked', N("More Information"), \&no_more_supported); + $bubble->add_action('no_more', N("More Information"), sub { no_more_supported(); Gtk3->main_quit }); + $bubble->signal_connect('closed' => \&Gtk3::main_quit); if ($sub_state eq 'updates') { push @arr, 'update'; } } elsif ($state eq 'updates') { unshift @arr, 'upgrade_distro' if $new_distro; - $bubble->add_action('clicked', N("Install updates"), \&installUpdates); + $bubble->add_action('updates', N("Install updates"), sub { installUpdates(); Gtk3->main_quit }); + $bubble->signal_connect('closed' => \&Gtk3::main_quit); } elsif (member($state, qw(no_enabled_medium no_update_medium))) { - $bubble->add_action('clicked', N("Add media"), \&add_media); + $bubble->add_action('add_med', N("Add media"), sub { add_media(); Gtk3->main_quit }); + $bubble->signal_connect('closed' => \&Gtk3::main_quit); } $bubble->set_urgency($state{$state}{urgency}) if $state{$state}{urgency}; $bubble->set_timeout(5000); - eval { $bubble->show }; + eval { $bubble->show; Gtk3->main }; + warn ">> ERR:$@" if $@; } - my $menu = Gtk2::Menu->new; + my $menu = Gtk3::Menu->new; foreach (@arr) { my $action = $actions{$_}; next if !ref($action->{launch}); - $menu->append(gtksignal_connect(gtkshow(Gtk2::MenuItem->new_with_label($action->{name})), activate => $action->{launch})); + $menu->append(gtksignal_connect(gtkshow(Gtk3::MenuItem->new_with_label($action->{name})), activate => $action->{launch})); } - $menu->append(gtkshow(Gtk2::SeparatorMenuItem->new)); - $menu->append(gtksignal_connect(gtkshow(Gtk2::MenuItem->new_with_label(N("About..."))), + $menu->append(gtkshow(Gtk3::SeparatorMenuItem->new)); + $menu->append(gtksignal_connect(gtkshow(Gtk3::MenuItem->new_with_label(N("About..."))), activate => \&about_dialog)); - $menu->append(gtksignal_connect(gtkshow(Gtk2::MenuItem->new_with_label(N("Updates Configuration"))), + $menu->append(gtksignal_connect(gtkshow(Gtk3::MenuItem->new_with_label(N("Updates Configuration"))), activate => sub { run_program::raw({ detach => 1 }, 'mgaapplet-config') })); - $menu->append(gtksignal_connect(gtkset_active($checkme = Gtk2::CheckMenuItem->new_with_label(N("Always launch on startup")), shouldStart()), toggled => sub { setAutoStart(uc(bool2text($checkme->get_active))) })); + $menu->append(gtksignal_connect(gtkset_active($checkme = Gtk3::CheckMenuItem->new_with_label(N("Always launch on startup")), shouldStart()), toggled => sub { setAutoStart(uc(bool2text($checkme->get_active))) })); $checkme->show; - $menu->append(gtksignal_connect(gtkshow(Gtk2::MenuItem->new_with_label(N("Quit"))), activate => sub { mainQuit() })); + $menu->append(gtksignal_connect(gtkshow(Gtk3::MenuItem->new_with_label(N("Quit"))), activate => sub { mainQuit() })); $menu; } @@ -852,5 +729,5 @@ sub mainQuit() { # setAutoStart('FALSE'); Glib::Source->remove($timeout) if $timeout; Glib::Source->remove($network_timeout) if $network_timeout; - Gtk2->main_quit; + Gtk3->main_quit; } |