diff options
author | Olivier Blin <blino@mageia.org> | 2013-05-07 02:12:29 +0000 |
---|---|---|
committer | Olivier Blin <blino@mageia.org> | 2013-05-07 02:12:29 +0000 |
commit | 946a66201d82a73c13398dc5dd811389a25d735c (patch) | |
tree | 151124a250b66a7122782794c4081e2810957afe | |
parent | 2f8bd5a7038ca023c4106862708ecd1e2ddb17ab (diff) | |
download | drakx-net-946a66201d82a73c13398dc5dd811389a25d735c.tar drakx-net-946a66201d82a73c13398dc5dd811389a25d735c.tar.gz drakx-net-946a66201d82a73c13398dc5dd811389a25d735c.tar.bz2 drakx-net-946a66201d82a73c13398dc5dd811389a25d735c.tar.xz drakx-net-946a66201d82a73c13398dc5dd811389a25d735c.zip |
connection manager gtk: use a global pixbufs hash to simplify API
-rw-r--r-- | lib/network/connection_manager.pm | 4 | ||||
-rw-r--r-- | lib/network/connection_manager/gtk.pm | 29 | ||||
-rwxr-xr-x | lib/network/drakroam.pm | 3 | ||||
-rwxr-xr-x | lib/network/netcenter.pm | 9 |
4 files changed, 24 insertions, 21 deletions
diff --git a/lib/network/connection_manager.pm b/lib/network/connection_manager.pm index fdfe5ca..fd5489c 100644 --- a/lib/network/connection_manager.pm +++ b/lib/network/connection_manager.pm @@ -13,9 +13,9 @@ use network::connection; use modules; sub new { - my ($class, $in, $net, $w, $pixbufs) = @_; + my ($class, $in, $net) = @_; bless { - in => $in, net => $net, gui => { w => $w, pixbufs => $pixbufs }, + in => $in, net => $net, }, $class; } diff --git a/lib/network/connection_manager/gtk.pm b/lib/network/connection_manager/gtk.pm index 5a3d8e0..3f8c21b 100644 --- a/lib/network/connection_manager/gtk.pm +++ b/lib/network/connection_manager/gtk.pm @@ -11,16 +11,21 @@ use Gtk2::SimpleList; use network::signal_strength; use locale; # for cmp -sub create_pixbufs() { - { - state => { map { $_ => gtkcreate_pixbuf($_) } qw(connected disconnected refresh) }, - link_level => { map { - $_ => gtkcreate_pixbuf('wifi-' . sprintf('%03d', $_))->scale_simple(24, 24, 'hyper'); - } qw(20 40 60 80 100) }, - encryption => { map { - $_ => gtkcreate_pixbuf("encryption-$_-24"); - } qw(open weak strong) }, - }; +our %pixbufs = ( + state => { map { $_ => gtkcreate_pixbuf($_) } qw(connected disconnected refresh) }, + link_level => { map { + $_ => gtkcreate_pixbuf('wifi-' . sprintf('%03d', $_))->scale_simple(24, 24, 'hyper'); + } qw(20 40 60 80 100) }, + encryption => { map { + $_ => gtkcreate_pixbuf("encryption-$_-24"); + } qw(open weak strong) }, +); + +sub new { + my ($class, $in, $net, $w) = @_; + bless { + in => $in, net => $net, gui => { w => $w }, + }, $class; } sub start_connection { @@ -177,7 +182,7 @@ sub update_networks_list { my @networks = filter_networks($cmanager->{connection}); foreach my $network (@networks) { my $ap = $network->{ap}; - my $connected_pixbuf = $network->{current} ? $connected ? $cmanager->{gui}{pixbufs}{state}{connected} : $cmanager->{gui}{pixbufs}{state}{refresh} : undef; + my $connected_pixbuf = $network->{current} ? $connected ? $pixbufs{state}{connected} : $pixbufs{state}{refresh} : undef; my $network_name = !$network->{essid} && exists $cmanager->{net}{wireless}{$ap} && $cmanager->{net}{wireless}{$ap}{WIRELESS_ESSID} || $network->{name}; my $strength_pixbuf = network::signal_strength::get_strength_icon($network); @@ -193,7 +198,7 @@ sub update_networks_list { $connected_pixbuf, $network_name, $strength_pixbuf, - $cmanager->{gui}{pixbufs}{encryption}{$network->{flags} =~ /WPA/i ? 'strong' : $network->{flags} =~ /WEP/i ? 'weak' : 'open'}, + $pixbufs{encryption}{$network->{flags} =~ /WPA/i ? 'strong' : $network->{flags} =~ /WEP/i ? 'weak' : 'open'}, $network->{mode}, ]; } diff --git a/lib/network/drakroam.pm b/lib/network/drakroam.pm index c29e41d..236a326 100755 --- a/lib/network/drakroam.pm +++ b/lib/network/drakroam.pm @@ -109,8 +109,7 @@ sub main { #- so that transient_for is defined, for wait messages and popups to be centered $::main_window = $w->{real_window}; - my $pixbufs = network::connection_manager::gtk::create_pixbufs(); - my $droam = network::connection_manager::gtk->new($in, $net, $w, $pixbufs); + my $droam = network::connection_manager::gtk->new($in, $net, $w); $droam->create_networks_list; create_drakroam_gui($droam, $dbus, $title, $icon); diff --git a/lib/network/netcenter.pm b/lib/network/netcenter.pm index 510aab7..603295d 100755 --- a/lib/network/netcenter.pm +++ b/lib/network/netcenter.pm @@ -16,9 +16,9 @@ use network::network; use run_program; sub build_cmanager { - my ($in, $net, $w, $pixbufs, $connection) = @_; + my ($in, $net, $w, $connection) = @_; - my $cmanager = network::connection_manager::gtk->new($in, $net, $w, $pixbufs); + my $cmanager = network::connection_manager::gtk->new($in, $net, $w); $cmanager->set_connection($connection); $cmanager->{gui}{show_unique_network} = $cmanager->{connection}->has_unique_network; @@ -160,8 +160,7 @@ sub main { my @connections = get_connections(); - my $pixbufs = network::connection_manager::gtk::create_pixbufs(); - my @cmanagers = map { build_cmanager($in, $net, $w, $pixbufs, $_) } @connections; + my @cmanagers = map { build_cmanager($in, $net, $w, $_) } @connections; (undef, my $rootwin_height) = gtkroot()->get_size; my $scrolled_height = $rootwin_height > 480 ? 400 : 295; @@ -192,7 +191,7 @@ sub main { detect_devices::probeall_update_cache(); my $connection = find { $_->get_interface eq $interface } get_connections() or return; - $cmanager = build_cmanager($in, $net, $w, $pixbufs, $connection); + $cmanager = build_cmanager($in, $net, $w, $connection); push @connections, $connection; push @cmanagers, $cmanager; my $box = build_cmanager_box($cmanager, @connections == 0); |