diff options
author | Frédéric Buclin <LpSolit@gmail.com> | 2017-03-04 02:04:38 +0100 |
---|---|---|
committer | Frédéric Buclin <LpSolit@gmail.com> | 2017-03-04 02:04:38 +0100 |
commit | d15d7d0211b9e4e52a53aa4a349641c02b6a8474 (patch) | |
tree | 124a23d1e429ddc60edecaefa8413cdfff41bc8c | |
parent | 13db0f5dafc24b22ee5a1e6cf987180e2efd5cf4 (diff) | |
download | drakx-net-d15d7d0211b9e4e52a53aa4a349641c02b6a8474.tar drakx-net-d15d7d0211b9e4e52a53aa4a349641c02b6a8474.tar.gz drakx-net-d15d7d0211b9e4e52a53aa4a349641c02b6a8474.tar.bz2 drakx-net-d15d7d0211b9e4e52a53aa4a349641c02b6a8474.tar.xz drakx-net-d15d7d0211b9e4e52a53aa4a349641c02b6a8474.zip |
Fix the net_applet status icon (mga#17592)
This also restores the tooltip with IP information.
-rwxr-xr-x | bin/net_applet | 70 | ||||
-rw-r--r-- | lib/network/signal_strength.pm | 4 |
2 files changed, 43 insertions, 31 deletions
diff --git a/bin/net_applet b/bin/net_applet index 2f0e0ba..115c479 100755 --- a/bin/net_applet +++ b/bin/net_applet @@ -23,8 +23,13 @@ use network::signal_strength; use detect_devices; BEGIN { POSIX::sigprocmask(SIG_BLOCK, POSIX::SigSet->new(SIGCHLD)); } use Gtk3::Notify -init, 'NetApplet'; - use ugtk3 qw(:create :helpers :wrappers :dialogs); +use Glib::Object::Introspection; + +Glib::Object::Introspection->setup( + basename => 'StatusNotifier', + version => '0.1', + package => 'StatusNotifier'); my $onstartupfile = "$ENV{HOME}/.net_applet"; my $system_file = '/etc/sysconfig/drakx-net'; @@ -39,7 +44,7 @@ use mygtk3 qw(gtknew gtkset); use common; our ($current_state, $current_interface); -our $icon; +our ($icon, $icon_file_name); our $dbus; our ($interactive_cb, $ifw, $ifw_alert); @@ -58,18 +63,25 @@ sub get_current_network() { } sub get_state_pixbuf { - my ($o_big) = @_; + my $img; my $wnet = $current_state eq 'connected' && get_current_network(); - $wnet ? - network::signal_strength::get_strength_icon($wnet) : - $pixbufs{state}{$current_state . ($o_big ? '_big' : '')}; + if ($wnet) { + ($img, $icon_file_name) = network::signal_strength::get_strength_icon($wnet); + return $img; + } + else { + # By default, use the big image, and fall back to the small one if it does not exist. + $icon_file_name = $pixbufs{state}{"${current_state}_big"} ? "${current_state}_big" : $current_state; + return $pixbufs{state}{$icon_file_name}; + } } sub update_tray_icon() { - if (!$ifw_alert || $icon->get_storage_type ne 'pixbuf') { - $icon->set_from_pixbuf(get_state_pixbuf()); + if (!$ifw_alert) { + $icon->set_from_pixbuf('STATUS_NOTIFIER_ICON', get_state_pixbuf()); } else { - $icon->set_from_stock('gtk-dialog-warning'); + $icon_file_name = mygtk3::_find_imgfile('gtk-dialog-warning'); + $icon->set_from_icon_name('STATUS_NOTIFIER_ICON', $icon_file_name); } } @@ -222,7 +234,22 @@ my %actions = ( ); -$icon = Gtk3::StatusIcon->new; +$icon = StatusNotifier::Notifier->new_from_icon_name('net_applet', 'STATUS_NOTIFIER_CATEGORY_APPLICATION_STATUS', mygtk3::_find_imgfile('connected')); +$icon->set_title('netapplet'); +$icon->set_status('STATUS_NOTIFIER_STATUS_ACTIVE'); +$icon->register; +$icon->signal_connect(context_menu => sub { + $menu->popup(undef, undef, undef, undef, 0, Gtk3::get_current_event_time()) if $menu; + }); +$icon->signal_connect(activate => sub { + if ($ifw_alert) { + run_drakids(); + } elsif ($simple_menu) { + $simple_menu->popup(undef, undef, undef, undef, 0, Gtk3::get_current_event_time()); + } else { + run_netcenter(); + } + }); eval { $dbus = dbus_object::system_bus() } if !defined($global_settings{NET_APPLET_DBUS}) || text2bool($global_settings{NET_APPLET_DBUS}); if (my $err = $@) { @@ -251,21 +278,6 @@ if ($dbus) { dbus_object::set_gtk3_watch_helper($dbus); } -$icon->signal_connect(activate => sub { - my ($_icon, $button, $time) = @_; - if ($ifw_alert) { - run_drakids(); - } elsif ($simple_menu) { - $simple_menu->popup(undef, undef, undef, undef, $button, $time); - } else { - run_netcenter(); - } - }); -$icon->signal_connect(popup_menu => sub { - my ($_icon, $button, $time) = @_; - $menu->popup(undef, undef, undef, undef, $button, $time) if $menu; - }); - checkNetworkForce(); cronNetwork(); gtkflush(); #- for notifications to appear on the status icon position @@ -443,12 +455,10 @@ sub go2State { } if ($show) { my $msg; - my $ic = $icon; # fix stringification (WTF????) my $bubble = Gtk3::Notify::Notification->new( $old_description || $current_description || N("Network connection"), - get_state_message($old_interface || $current_interface), - $ic); - my $pixbuf = network::net_applet::get_state_pixbuf(1) || network::net_applet::get_state_pixbuf(); + get_state_message($old_interface || $current_interface)); + my $pixbuf = network::net_applet::get_state_pixbuf(); $bubble->set_icon_from_pixbuf($pixbuf) if $pixbuf; my $timeout = 5000; @@ -472,7 +482,7 @@ sub update_applet() { generate_menu(); network::net_applet::update_tray_icon(); - $icon->set_tooltip_text(get_state_message()); + $icon->set_tooltip($icon_file_name, 'net_applet', get_state_message()); } sub create_menu_choices { diff --git a/lib/network/signal_strength.pm b/lib/network/signal_strength.pm index 8a3a5be..4dd17aa 100644 --- a/lib/network/signal_strength.pm +++ b/lib/network/signal_strength.pm @@ -9,7 +9,9 @@ my %pixbufs; sub get_strength_icon { my ($network) = @_; my $approx = 20 + min(80, int($network->{signal_strength}/20)*20); - return $pixbufs{$approx} ||= ugtk3::gtkcreate_pixbuf('wifi-' . sprintf('%03d', $approx)); + my $file_name = 'wifi-' . sprintf('%03d', $approx); + $pixbufs{$approx} ||= ugtk3::gtkcreate_pixbuf($file_name); + return wantarray ? ($pixbufs{$approx}, $file_name) : $pixbufs{$approx}; } 1; |