--- Emerge-Progress_0.1.7.perl 2005-04-25 12:56:14.000000000 +0200 +++ Emerge-Progress_0.1.8.perl 2005-05-12 00:07:13.997707808 +0200 @@ -15,6 +15,8 @@ my $lastline; my $status; my $tag; +my $updatetag; +my $noclickupdate = 0; my @cols = ( { title => 'Name', type => 'Glib::String', }, { title => 'Date', type => 'Glib::String', }, @@ -27,9 +29,11 @@ my $window = Gtk2::Window->new; my $vbox = Gtk2::VBox->new; my $buttonbox = Gtk2::HButtonBox->new; -my $exitbutton = Gtk2::Button->new("Lukk"); +my $exitbutton = Gtk2::Button->new('Lukk'); +my $updatebutton = Gtk2::Button->new('Update system'); my $treeview = Gtk2::TreeView->new_with_model($store); my $treeviewdone = Gtk2::TreeView->new_with_model($storedone); +my $statusbar = Gtk2::Statusbar->new; #sette parametre.. $window->set_default_size(600,400); @@ -39,9 +43,12 @@ $treeview->set_headers_visible(0); $treeviewdone->set_headers_visible(0); $exitbutton->signal_connect(clicked => sub { Gtk2->main_quit; }); +$updatebutton->signal_connect(clicked => sub { &updatesystem; }); $window->signal_connect(destroy => sub { Gtk2->main_quit; }); +$statusbar->set_has_resize_grip('0'); #vis ting.. +$buttonbox->pack_start($updatebutton,0,0,0); $buttonbox->pack_start($exitbutton,0,0,0); $window->add($vbox); $window->show_all(); @@ -59,7 +66,10 @@ $vbox->pack_start($treeview,1,1,0); $vbox->pack_start($label_done,0,0,0); $vbox->pack_start($treeviewdone,1,1,0); - $vbox->pack_end($buttonbox,0,0,0); + my $hbox = Gtk2::HBox->new; + $hbox->pack_start($statusbar,1,1,0); + $hbox->pack_start($buttonbox,0,0,0); + $vbox->pack_start($hbox,0,0,0); $window->show_all; &sett_opp_kolonner; &parselog("emerge"); @@ -100,6 +110,85 @@ return 1; } +sub updatesystem +{ + unless($noclickupdate eq 1) + { + my $updatewindow = Gtk2::Window->new; + my $vbox = Gtk2::VBox->new; + my $label = Gtk2::Label->new("Sync should only be done once a day.\nIf sync is selected, emerge world will automagically be run."); + my $buttonbox = Gtk2::HButtonBox->new; + my $syncbutton = Gtk2::Button->new('Sync'); + my $emergebutton = Gtk2::Button->new('emerge'); + $syncbutton->signal_connect(clicked => sub { + $statusbar->push('1','Running emerge --sync, this will take some time.'); + $noclickupdate = 1; + &sync; + $updatewindow->destroy; + }); + $emergebutton->signal_connect(clicked => sub { + $statusbar->push('1','Running emerge world, this will take some time.'); + $noclickupdate = 1; + &emergeworld; + $updatewindow->destroy; + }); + $updatewindow->add($vbox); + $vbox->pack_start($label,0,0,0); + $vbox->pack_start($buttonbox,0,0,0); + $buttonbox->add($syncbutton); + $buttonbox->add($emergebutton); + $updatewindow->show_all; + } + return 1; +} + +sub sync +{ + my $fh = FileHandle->new; + open($fh, q^emerge -q --sync|^); + $updatetag = Gtk2::Helper->add_watch ( $fh->fileno, 'in', sub { update_callback($fh,$updatetag); }); + return 1; +} + +sub update_callback +{ + my ( $fh, $updatetag) = @_; + + if ( eof($fh)) + { + Gtk2::Helper->remove_watch ($updatetag) or &error("Kunne ikke gi slipp på Gtk2::Helper."); + close($fh); + $statusbar->push('1','Done running emerge --sync, running emerge world..'); + &emergeworld; + return 1; + } + return 1; +} + +sub emergeworld +{ + $statusbar->push('1','Running emerge world, this WILL take some time..'); + my $fh = FileHandle->new; + open($fh, q^emerge -q world|^); + $updatetag = Gtk2::Helper->add_watch ( $fh->fileno, 'in', sub { emergeworld_callback($fh,$updatetag); }); + return 1; +} + +sub emergeworld_callback +{ + my ( $fh, $updatetag) = @_; + + if ( eof($fh)) + { + Gtk2::Helper->remove_watch ($updatetag) or &error("Kunne ikke gi slipp på Gtk2::Helper."); + close($fh); + $statusbar->push('1','Done running emerge world..'); + $noclickupdate = 0; + return 1; + } + return 1; +} + sub parselog { my $fh = FileHandle->new;