/[libconf]/libconf/applications/netconfig/netconfig
ViewVC logotype

Diff of /libconf/applications/netconfig/netconfig

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by dams, Fri Jun 6 21:33:41 2003 UTC revision 1.4 by dams, Sat Jun 7 13:53:33 2003 UTC
# Line 26  use ugtk2 qw(:helpers :wrappers :create) Line 26  use ugtk2 qw(:helpers :wrappers :create)
26    
27  # we include the Network Systemconf module  # we include the Network Systemconf module
28  use Libconf::System::Network;  use Libconf::System::Network;
29    use Libconf::GUI::Gtk2 qw(generators);
30    
31  # for debugging purpose  # for debugging purpose
32  use Data::Dumper;  use Data::Dumper;
# Line 44  $window->signal_connect(delete_event => Line 45  $window->signal_connect(delete_event =>
45  $window->set_position('center');  $window->set_position('center');
46  $window->set_title(N('netconfig - Network configuration'));  $window->set_title(N('netconfig - Network configuration'));
47    
48  # in the window, we add the widget generated by libconf_generate_UI,  # in the window, we add the widget generated by Libconf::GUI::Gtk2::generateWidget(),
49  # an OK button that will save the modification in the network config files,  # an OK button that will save the modification in the network config files,
50  # an Cancel button that will leave without saving.  # a Cancel button that will leave without saving.
51  gtkadd($window,  gtkadd($window,
52         gtkpack_(Gtk2::VBox->new(0,10),         gtkpack_(Gtk2::VBox->new(0,10),
53                  1, gtkshow(libconf_generate_UI($sys_network)),                  1, gtkshow(generateWidget($sys_network)),
54                  0, gtkadd(gtkset_layout(Gtk2::HButtonBox->new, 'end'),                  0, gtkadd(gtkset_layout(Gtk2::HButtonBox->new, 'end'),
55                            gtksignal_connect(new Gtk2::Button(N("OK")),                            gtksignal_connect(new Gtk2::Button(N("OK")),
56                                              clicked => sub { save_exit(); }),                                              clicked => sub { save_exit(); }),
# Line 89  sub cancel_exit { Line 90  sub cancel_exit {
90      # we exit the gtk2 main loop      # we exit the gtk2 main loop
91      Gtk2->main_quit();      Gtk2->main_quit();
92  }  }
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
 #####  
 # The followings are here because it has not yet been incorporated into libconf.  
 # In the final version you won't need this, it'll be in libconf.  
 #  
 # So the program source code should terminate here.  
 #####  
   
 sub initialize_notebook {  
     gtkpack_(shift, 0, my $notebook = new Gtk2::Notebook);  
     #        $notebook->set_tab_pos('left');  
     $notebook;  
 }  
   
 sub initialize_table {  
     gtkpack_(shift,  
              0, gtkset_border_width(gtkset_shadow_type(gtkadd(Gtk2::Frame->new(N("test")),  
                                                               my $table = Gtk2::Table->new(0, 2, 0),  
                                                              ),  
                                                        'etched_out'),  
                                     5),  
             );  
     $table->set_col_spacings(5);  
     $table->set_row_spacings(5);  
     $table;  
 }  
   
 sub libconf_generate_UI {  
     my ($struct) = @_;  
     my $vbox = Gtk2::VBox->new(0,10);  
     my $notebook;  
     my $n_page;  
     my $table;  
     if (UNIVERSAL::isa($struct, 'HASH')) {  
         my $count = 0;  
         while (my ($key, $value) = each %$struct) {  
             if (UNIVERSAL::isa($value, 'HASH')) {  
                 if (!defined $notebook) {  
                     $notebook = initialize_notebook($vbox);  
                     $n_page = 0;  
                 }  
                 $notebook->append_page(  
                                        my $child = libconf_generate_UI($value),  
                                        gtkpack_(Gtk2::HBox->new(0,5),  
                                                 1, new Gtk2::Label($key),  
                                                 0, gtksignal_connect(# gtkadd(  
                                                                      Gtk2::Button->new('X'),  
                                                                      #gtkcreate_pixbuf('eth_card_mini2.png')  
                                                                      #),  
                                                                      clicked => sub {  
                                                                          my $n_page = $_[1];  
                                                                          if (create_dialog(N('Do you really want to remove this section?'))) {  
                                                                              print "  - $n_page\n";  
                                                                              $notebook->remove_page($n_page);  
                                                                              delete $struct->{$key};  
                                                                          }  
                                                                      }, $n_page  
                                                                     )  
                                                ),  
                                       );  
                 $n_page++;  
             } else {  
                 $table ||= initialize_table($vbox);  
                 $table->attach(gtkpack_(Gtk2::HBox->new(0,0),  
                                         1, Gtk2::HBox->new(0,0),  
                                         0, Gtk2::Label->new($key)  
                                        ),  
                                0, 1, $count, $count + 1,  
                                'fill',  
                                ['shrink', 'shrink'],  
                                0, 0);  
                 $table->attach(libconf_generate_UI($value), 1, 2, $count, $count + 1,  
                                ['fill', 'expand'],  
                                ['shrink', 'shrink'],  
                                0, 0);  
             }  
             $count++;  
         }  
         $vbox->show_all();  
         return $vbox;  
     }  
     if (UNIVERSAL::isa($struct, 'ARRAY')) {  
         my $tree_model = Gtk2::TreeStore->new(Gtk2::GType->STRING);  
         my $list = Gtk2::TreeView->new_with_model($tree_model);  
         $list->append_column(Gtk2::TreeViewColumn->new_with_attributes(N("list"), Gtk2::CellRendererText->new, 'text' => 0));  
         foreach my $element (@$struct) {  
             $tree_model->append_set(undef, [ 0 => $element ])->free;  
         }  
         $list->show_all();  
         return $list;  
     }  
     return gtkshow(gtkentry($struct));  
 }  
   
   
   
 sub create_dialog {  
     my ($label) = @_;  
     my $ret;  
     my $dialog = new Gtk2::Dialog();  
     $dialog->set_position('center');  
     $dialog->set_position('center-on-parent');  
     $dialog->vbox->set_border_width(10);  
     $dialog->signal_connect(delete_event => sub { Gtk2->main_quit() });  
     $dialog->vbox->pack_start(new Gtk2::Label($label),1,1,0);  
     my $bbox_dialog = new Gtk2::HButtonBox;  
     $dialog->action_area->add($bbox_dialog);  
     $bbox_dialog->set_layout('end');  
     $bbox_dialog->add(  
                       gtksignal_connect(new Gtk2::Button(N("OK")),  
                                         clicked => sub {  
                                             $ret = 1;  
                                             Gtk2->main_quit();  
                                         })  
                      );  
     $bbox_dialog->add(  
                       gtksignal_connect(new Gtk2::Button(N("Cancel")),  
                                         clicked => sub {  
                                             Gtk2->main_quit();  
                                         })  
                      );  
     $dialog->show_all;  
     $dialog->set_modal(1);  
     Gtk2->main();  
     $dialog->destroy;  
     $ret;  
 }  

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26