diff options
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/net_applet | 70 |
1 files changed, 40 insertions, 30 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 { |