From 29d89e45ae0eff635ca2b547fd65371e7e38840d Mon Sep 17 00:00:00 2001 From: Olivier Blin Date: Fri, 14 Mar 2008 18:08:34 +0000 Subject: use OO notation for connection_manager objects --- lib/network/connection_manager.pm | 41 +++++++++++++++++++-------------------- lib/network/drakroam.pm | 23 +++++++++++----------- lib/network/netcenter.pm | 22 ++++++++++----------- 3 files changed, 42 insertions(+), 44 deletions(-) diff --git a/lib/network/connection_manager.pm b/lib/network/connection_manager.pm index cc0e74c..ca7bd17 100644 --- a/lib/network/connection_manager.pm +++ b/lib/network/connection_manager.pm @@ -80,7 +80,7 @@ sub setup_connection { return; } } - write_settings($cmanager); + $cmanager->write_settings; $cmanager->{connection}{passed_setup} = 1; } @@ -108,15 +108,14 @@ sub write_settings { sub configure_connection { my ($cmanager) = @_; - if (!check_setup($cmanager)) { - setup_connection($cmanager); - network::connection_manager::update_networks($cmanager) - if $cmanager->{connection}->can('get_networks'); - update_on_status_change($cmanager); + if (!$cmanager->check_setup) { + $cmanager->setup_connection; + $cmanager->update_networks if $cmanager->{connection}->can('get_networks'); + $cmanager->update_on_status_change; return; } - load_settings($cmanager); + $cmanager->load_settings; my $error; do { @@ -161,7 +160,7 @@ sub configure_connection { $cmanager->{connection}->install_packages($cmanager->{in}) if $cmanager->{connection}->can('install_packages'); $cmanager->{connection}->unload_connection if $cmanager->{connection}->can('unload_connection'); - write_settings($cmanager); + $cmanager->write_settings; 1; } @@ -173,14 +172,14 @@ sub start_connection { if ($cmanager->{connection}->can('get_networks')) { $cmanager->{connection}{network} && ($cmanager->{connection}->selected_network_is_configured || - configure_connection($cmanager)) + $cmanager->configure_connection) or return; } gtkset_mousecursor_wait($cmanager->{gui}{w}{window}->window); my $_wait = $cmanager->{in}->wait_message(N("Please wait"), N("Connecting...")); if ($cmanager->{connection}->can('apply_network_selection')) { - load_settings($cmanager); + $cmanager->load_settings; $cmanager->{connection}->apply_network_selection($cmanager); } $cmanager->{connection}->prepare_connection if $cmanager->{connection}->can('prepare_connection'); @@ -188,7 +187,7 @@ sub start_connection { $cmanager->{connection}->connect($cmanager->{in}, $cmanager->{net}); gtkset_mousecursor_normal($cmanager->{gui}{w}{window}->window); - update_on_status_change($cmanager); + $cmanager->update_on_status_change; } sub stop_connection { @@ -199,7 +198,7 @@ sub stop_connection { $cmanager->{connection}->disconnect; gtkset_mousecursor_normal($cmanager->{gui}{w}{window}->window); - update_on_status_change($cmanager); + $cmanager->update_on_status_change; } sub monitor_connection { @@ -219,10 +218,10 @@ sub toggle_would_disconnect { sub toggle_connection { my ($cmanager) = @_; - if (toggle_would_disconnect($cmanager)) { - stop_connection($cmanager); + if ($cmanager->toggle_would_disconnect) { + $cmanager->stop_connection; } else { - start_connection($cmanager); + $cmanager->start_connection; } } @@ -238,7 +237,7 @@ sub create_networks_list { N("Operating Mode") => "text", ); $cmanager->{gui}{networks_list}->get_selection->set_mode('single'); - $cmanager->{gui}{networks_list}->get_selection->signal_connect('changed' => sub { select_network($cmanager) }); + $cmanager->{gui}{networks_list}->get_selection->signal_connect('changed' => sub { $cmanager->select_network }); $cmanager->{gui}{networks_list}->signal_connect('query-tooltip' => sub { my ($widget, $x, $y, $kbd_tip, $tooltip) = @_; @@ -259,7 +258,7 @@ sub select_network { my ($selected) = $cmanager->{gui}{networks_list}->get_selected_indices; $cmanager->{connection}{network} = defined $selected && $cmanager->{gui}{networks_list}{data}[$selected][0]; } - update_on_status_change($cmanager); + $cmanager->update_on_status_change; } sub filter_networks { @@ -276,7 +275,7 @@ sub update_networks { @{$cmanager->{gui}{networks_list}{data}} = (); if ($cmanager->{connection}) { - check_setup($cmanager) || setup_connection($cmanager) or return; + $cmanager->check_setup || $cmanager->setup_connection or return; my $wait = $cmanager->{connection}->network_scan_is_slow && $cmanager->{in}->wait_message(N("Please wait"), N("Scanning for networks...")); $cmanager->{connection}{networks} = $cmanager->{connection}->get_networks; @@ -307,14 +306,14 @@ sub update_networks { undef $wait; } - update_on_status_change($cmanager); + $cmanager->update_on_status_change; } sub update_on_status_change { my ($cmanager) = @_; if ($cmanager->{gui}{buttons}{connect_toggle}) { - my $disconnect = toggle_would_disconnect($cmanager); + my $disconnect = $cmanager->toggle_would_disconnect; $cmanager->{gui}{buttons}{connect_toggle}->set_label($disconnect ? N("Disconnect") : N("Connect")); gtkset($cmanager->{gui}{buttons}{connect_toggle}, image => gtknew('Image', file => $disconnect ? 'stop-16' : 'activate-16')) if $cmanager->{gui}{buttons}{connect_toggle}->get_image; @@ -336,7 +335,7 @@ sub update_on_status_change { my $may_have_network = !$cmanager->{connection}->can('get_networks') || $cmanager->{connection}{network}; - $allow_configure = $may_have_network || !check_setup($cmanager); + $allow_configure = $may_have_network || !$cmanager->check_setup; } $cmanager->{gui}{buttons}{configure}->set_sensitive($allow_configure) diff --git a/lib/network/drakroam.pm b/lib/network/drakroam.pm index 71d7deb..d89a520 100755 --- a/lib/network/drakroam.pm +++ b/lib/network/drakroam.pm @@ -40,9 +40,8 @@ sub get_connection { sub select_connection { my ($droam) = @_; - network::connection_manager::set_connection($droam, get_connection($droam)); - network::connection_manager::check_setup($droam) || network::connection_manager::setup_connection($droam) - if $droam->{connection}; + $droam->set_connection(get_connection($droam)); + $droam->check_setup || $droam->setup_connection if $droam->{connection}; update_on_connection_change($droam); } @@ -50,7 +49,7 @@ sub update_on_connection_change { my ($droam) = @_; $droam->{gui}{buttons}{refresh}->set_sensitive(to_bool($droam->{connection})) if $droam->{gui}{buttons}{refresh}; - network::connection_manager::update_networks($droam); + $droam->update_networks; } sub get_network_event_message { @@ -96,7 +95,7 @@ sub create_drakroam_gui { my $member = $msg->get_member; my $message = get_network_event_message($droam, $member, $msg->get_args_list) or return; $droam->{on_network_event}($message) if $droam->{on_network_event}; - network::connection_manager::update_networks($droam) if $member eq 'status'; + $droam->update_networks if $member eq 'status'; }); $dbus->{connection}->add_match("type='signal',interface='com.mandriva.network'"); dbus_object::set_gtk2_watch_helper($dbus); @@ -111,10 +110,10 @@ sub create_drakroam_gui { gtksignal_connect($droam->{gui}{connections_combo}, changed => sub { select_connection($droam) }) ]), 1, gtknew('ScrolledWindow', width => 500, height => $scrolled_height, child => $droam->{gui}{networks_list}), 0, gtknew('HButtonBox', layout => 'edge', children_loose => [ - $droam->{gui}{buttons}{configure} = gtknew('Button', text => N("Configure"), clicked => sub { network::connection_manager::configure_connection($droam) }), - $droam->{gui}{buttons}{connect_start} = gtknew('Button', text => N("Connect"), relief => 'half', clicked => sub { network::connection_manager::start_connection($droam) }), - $droam->{gui}{buttons}{connect_stop} = gtknew('Button', text => N("Disconnect"), relief => 'half', clicked => sub { network::connection_manager::stop_connection($droam) }), - $droam->{gui}{buttons}{refresh} = gtknew('Button', text => N("Refresh"), clicked => sub { network::connection_manager::update_networks($droam) }), + $droam->{gui}{buttons}{configure} = gtknew('Button', text => N("Configure"), clicked => sub { $droam->configure_connection }), + $droam->{gui}{buttons}{connect_start} = gtknew('Button', text => N("Connect"), relief => 'half', clicked => sub { $droam->start_connection }), + $droam->{gui}{buttons}{connect_stop} = gtknew('Button', text => N("Disconnect"), relief => 'half', clicked => sub { $droam->stop_connection }), + $droam->{gui}{buttons}{refresh} = gtknew('Button', text => N("Refresh"), clicked => sub { $droam->update_networks }), gtknew('Button', text => N("Quit"), clicked => sub { Gtk2->main_quit }) ]), 0, $status_bar, @@ -135,7 +134,7 @@ sub main { my $pixbufs = network::connection_manager::create_pixbufs(); my $droam = network::connection_manager->new($in, $net, $w, $pixbufs); - network::connection_manager::create_networks_list($droam); + $droam->create_networks_list; create_drakroam_gui($droam, $dbus, $title, $icon); $droam->{gui}{w}->show; @@ -144,13 +143,13 @@ sub main { @{$droam->{all_connections}} = map { $_->get_connections(automatic_only => 1) } @connection_types; my $connection = $o_interface && find { $_->get_interface eq $o_interface } @{$droam->{all_connections}}; $connection ||= find { !$_->network_scan_is_slow } @{$droam->{all_connections}}; - network::connection_manager::set_connection($droam, $connection) if $connection; + $droam->set_connection($connection) if $connection; update_connections_list($droam); update_on_connection_change($droam); if ($o_ap && $droam->{connection}) { $droam->{connection}{network} = $o_ap; - network::connection_manager::start_connection($droam); + $droam->start_connection; } $droam->{gui}{w}->main; diff --git a/lib/network/netcenter.pm b/lib/network/netcenter.pm index 9f15856..49f82d8 100755 --- a/lib/network/netcenter.pm +++ b/lib/network/netcenter.pm @@ -16,13 +16,13 @@ sub build_cmanager { my ($in, $net, $w, $pixbufs, $connection) = @_; my $cmanager = network::connection_manager->new($in, $net, $w, $pixbufs); - network::connection_manager::set_connection($cmanager, $connection); + $cmanager->set_connection($connection); if ($connection->can('get_networks')) { - network::connection_manager::create_networks_list($cmanager); + $cmanager->create_networks_list; #- do not check if it is slow (either scan or device check) or unavailable - network::connection_manager::update_networks($cmanager) - if !$connection->network_scan_is_slow && network::connection_manager::check_setup($cmanager); + $cmanager->update_networks + if !$connection->network_scan_is_slow && $cmanager->check_setup; } $cmanager; } @@ -82,22 +82,22 @@ sub main { $cmanager->{gui}{buttons}{monitor} = gtknew('Button', text => N("_: This is a verb\nMonitor"), image => gtknew('Image', file => 'monitor-16'), - clicked => sub { network::connection_manager::monitor_connection($cmanager) }), + clicked => sub { $cmanager->monitor_connection }), $cmanager->{gui}{buttons}{configure} = gtknew('Button', text => N("Configure"), image => gtknew('Image', file => 'configure-16'), - clicked => sub { network::connection_manager::configure_connection($cmanager) }), + clicked => sub { $cmanager->configure_connection }), ($cmanager->{connection}->can('get_networks') ? ($cmanager->{gui}{buttons}{refresh} = gtknew('Button', text => N("Refresh"), image => gtknew('Image', file => 'refresh', size => 16), - clicked => sub { network::connection_manager::update_networks($cmanager) })) + clicked => sub { $cmanager->update_networks })) : ()), ]), 0, $cmanager->{gui}{buttons}{connect_toggle} = gtknew('Button', image => gtknew('Image', file => 'activate-16'), - clicked => sub { network::connection_manager::toggle_connection($cmanager) }), + clicked => sub { $cmanager->toggle_connection }), ]), ]), ]); @@ -119,7 +119,7 @@ sub main { ]); $content->hide; - network::connection_manager::update_on_status_change($cmanager); + $cmanager->update_on_status_change; ($::i > 0 ? Gtk2::HSeparator->new : ()), $box; } @connections, @@ -141,9 +141,9 @@ sub main { or return; #- FIXME: factorize in update_on_status_change() and check why update_networks() calls update_on_status_change() if ($cmanager->{connection}->can('get_networks') && !$cmanager->{connection}->network_scan_is_slow) { - network::connection_manager::update_networks($cmanager); + $cmanager->update_networks; } else { - network::connection_manager::update_on_status_change($cmanager); + $cmanager->network::connection_manager::update_on_status_change; } } }); -- cgit v1.2.1