diff options
author | Thierry Vignaud <tvignaud@mandriva.org> | 2003-12-09 09:18:19 +0000 |
---|---|---|
committer | Thierry Vignaud <tvignaud@mandriva.org> | 2003-12-09 09:18:19 +0000 |
commit | 0f7fa3230633117bfbc1a9dcca60b6616f3d48cc (patch) | |
tree | 6651f9a6cfcc6a1cabfe65f67690d8ee88ee0ace | |
parent | ca559c49c3813c198592ae0422e395e3f902079b (diff) | |
download | control-center-0f7fa3230633117bfbc1a9dcca60b6616f3d48cc.tar control-center-0f7fa3230633117bfbc1a9dcca60b6616f3d48cc.tar.gz control-center-0f7fa3230633117bfbc1a9dcca60b6616f3d48cc.tar.bz2 control-center-0f7fa3230633117bfbc1a9dcca60b6616f3d48cc.tar.xz control-center-0f7fa3230633117bfbc1a9dcca60b6616f3d48cc.zip |
add meta profiles managment
-rwxr-xr-x | control-center | 108 |
1 files changed, 107 insertions, 1 deletions
diff --git a/control-center b/control-center index 8d4f9bf2..f887d3fb 100755 --- a/control-center +++ b/control-center @@ -28,6 +28,7 @@ use standalone; use common; use detect_devices; use lang; +use network::netconnect; # for profiles # i18n: IMPORTANT: to get correct namespace (drakconf instead of libDrakX) BEGIN { unshift @::textdomains, 'drakconf' } @@ -300,7 +301,19 @@ my %options = ( 'wiz_expert' => [ N("/_Options"), N("/Expert mode in _wizards") ], ); +my %shared_translations = ( + "profiles" => N("/_Profiles"), + "delete" => N("/_Delete"), + "new" => N("/_New"), + ); + +# for profiles: +my ($netcnx, $netc, $intf) = ({}, {}, {}); +my @profiles; + my $mdk_rel = common::mandrake_release(); +my $done; + my @menu_items = ( [ N("/_File"), undef, undef, undef, '<Branch>' ], @@ -342,6 +355,51 @@ my @menu_items = ( } @themes), [ N("/_Themes").N("/_More themes"), undef, \&more_themes, undef, '<Item>' ] ), + [ $shared_translations{profiles}, undef, undef, undef, '<Branch>' ], + [ join('/', $shared_translations{profiles}, ""), undef, undef, undef, '<Separator>' ], + [ $shared_translations{profiles} . $shared_translations{new}, undef, sub { + my $dialog = _create_dialog(N("New profile..."), { small => 1, transient => $window_global }); + my $entry_dialog = Gtk2::Entry->new; + gtkpack($dialog->vbox, + Gtk2::WrappedLabel->new(N("Name of the profile to create (the new profile is created as a copy of the current one) :")), + $entry_dialog, + ); + gtkpack($dialog->action_area, + gtksignal_connect(Gtk2::Button->new(N("Cancel")), + clicked => sub { $dialog->destroy }), + gtksignal_connect(my $bok = Gtk2::Button->new(N("Ok")), clicked => sub { + my $prof = $entry_dialog->get_text; + # netprofile does not like spaces in profile names... + $prof =~ s/ /_/g; + # warn if already existing: + if (member($prof, @profiles)) { + err_dialog(N("Error"), N("The \"%s\" profile already exists !", $prof), + { transient => $dialog }); + return 1; + } + network::netconnect::add_profile($netcnx, $prof); + update_profiles(); + $dialog->destroy; + }), + ); + $bok->can_default(1); + $bok->grab_default; + $dialog->show_all; + $dialog->run; + update_profiles(); + }, undef, '<Item>' ], + + [ $shared_translations{profiles} . $shared_translations{delete}, undef, sub { + return unless $done || $netcnx->{PROFILE} eq "default"; + my $prof = $netcnx->{PROFILE}; + $netcnx->{PROFILE} = "default"; + network::netconnect::set_profile($netcnx); + # we must delete the old profile after the switch because set-profile "restore" the old one by saving current one... + network::netconnect::del_profile($prof); + update_profiles(1); + }, undef, '<Item>' ], + + [ join('/', $shared_translations{profiles}, ""), undef, undef, undef, '<Separator>' ], [ N("/_Help"), undef, undef, undef, '<Branch>' ], [ N("/_Help").N("/_Help"), undef, sub { fork_("drakhelp --id $help_on_context") }, undef, '<StockItem>', 'gtk-help' ], [ N("/_Help").N("/_Report Bug"), undef, sub { fork_("drakbug --report drakconf &") }, undef, '<Item>' ], @@ -350,9 +408,56 @@ my @menu_items = ( my ($menu, $factory) = create_factory_menu($window_global, @menu_items); +network::netconnect::read_net_conf('', $netcnx, $netc); + +# to retrieve a path, one must prevent "accelerators completion": +sub get_path { join('', map { my $i = $_; $i =~ s/_//; $i } @_) } + +# menus do not like "_" from profiles (whereas netprofile does not like spaces in profile names...) +sub profile2menu { + my ($profile) = @_; + $profile =~ s/_/ /; + "/$profile"; +} + +sub enable_profile_entry { + my ($profile, $value) = @_; + eval { + $factory->get_widget(get_path("<main>", $shared_translations{profiles} . profile2menu($profile)))->set_active($value); + }; + print "error: $@\n" if $@; +} + + +# update profiles list +sub update_profiles() { + my ($removing) = @_; + my $done; + $factory->delete_item(get_path("<main>", $shared_translations{profiles} . profile2menu($_))) foreach @profiles; + network::netconnect::load_conf($netcnx, $netc, $intf); #reread_net_conf(); + @profiles = network::netconnect::get_profiles(); + foreach my $prof (@profiles) { + $factory->create_item([ $shared_translations{profiles} . profile2menu($prof), undef, sub { + return unless $done; + # wait message is needed + $done = 0; + enable_profile_entry($netcnx->{PROFILE}, 0); + $netcnx->{PROFILE} = $prof; + network::netconnect::set_profile($netcnx); + enable_profile_entry($prof, 1) if !$removing; + $done = 1; + }, undef, '<CheckItem>' ]); # Radio + } + $factory->get_widget(get_path("<main>", $shared_translations{profiles}, $shared_translations{delete}))->set_sensitive(@profiles > 1); + eval { $factory->get_widget(get_path("<main>", $shared_translations{profiles} . profile2menu($netcnx->{PROFILE})))->set_active(1) }; + print "error is «$@»\n" if $@; + $done = 1; +} + +update_profiles(); %check_boxes = map { - $_ => $factory->get_widget("<main>" . join('', map { s/_//; $_ } @{$options{$_}})) + $_ => $factory->get_widget("<main>" . get_path(@{$options{$_}})) } ("embedded_mode", "show_log", if_($::isWiz, "wiz_expert")); @@ -657,6 +762,7 @@ $SIG{CHLD} = \&sig_child; $window_splash->destroy; undef $window_splash; +$done = 1; Gtk2->main; |