From 9228b5b393f964b988ec472d046b61cbde41ba62 Mon Sep 17 00:00:00 2001 From: Angelo Naselli Date: Tue, 2 Dec 2014 15:44:39 +0100 Subject: Converted _display_READMEs_if_needed Fixed treeview rpmnew in ncurses --- lib/AdminPanel/Rpmdragora/pkg.pm | 123 ++++++++++++++++++++++++++---------- lib/AdminPanel/Rpmdragora/rpmnew.pm | 49 ++++++-------- 2 files changed, 108 insertions(+), 64 deletions(-) (limited to 'lib/AdminPanel') diff --git a/lib/AdminPanel/Rpmdragora/pkg.pm b/lib/AdminPanel/Rpmdragora/pkg.pm index 9823fb6..8025399 100644 --- a/lib/AdminPanel/Rpmdragora/pkg.pm +++ b/lib/AdminPanel/Rpmdragora/pkg.pm @@ -31,9 +31,6 @@ use MDK::Common::System; use MDK::Common::File; use MDK::Common::Various; -# use lib qw(/usr/lib/libDrakX); -# use common; - use POSIX qw(_exit ceil); use URPM; use utf8; @@ -607,35 +604,93 @@ sub get_pkgs { }; } -sub display_READMEs_if_needed { - my ($urpm, $w) = @_; +sub _display_READMEs_if_needed { + my $urpm = shift; return if !$urpm->{readmes}; + my %Readmes = %{$urpm->{readmes}}; - if (keys %Readmes) { #- display the README*.urpmi files - interactive_packtable( - $loc->N("Upgrade information"), - $w, - $loc->N("These packages come with upgrade information"), - [ map { - my $fullname = $_; - [ gtkpack__( - gtknew('HBox'), - gtkset_selectable(gtknew('Label', text => $Readmes{$fullname}),1), - ), - gtksignal_connect( - gtknew('Button', text => $loc->N("Upgrade information about this package")), - clicked => sub { - interactive_msg( - $loc->N("Upgrade information about package %s", $Readmes{$fullname}), - (join '' => map { s/$/\n/smg; $_ } formatAlaTeX(scalar MDK::Common::File::cat_($fullname))), - scroll => 1, - ); - }, - ), - ] } keys %Readmes ], - [ gtknew('Button', text => $loc->N("Ok"), clicked => sub { Gtk2->main_quit }) ] - ); + return if ! scalar keys %Readmes; + + my $appTitle = yui::YUI::app()->applicationTitle(); + + ## set new title to get it in dialog + yui::YUI::app()->setApplicationTitle($loc->N("Upgrade information")); + my $factory = yui::YUI::widgetFactory; + + ## | [msg-label] | + ## | | + ## | pkg-list | + ## | | + ## | info on selected pkg |(1) + ## | | + ## | [ok] | + #### + # (1) info on pkg list: + # selected package readmi.urpmi + + my $dialog = $factory->createPopupDialog; + my $vbox = $factory->createVBox( $dialog ); + my $msgBox = $factory->createLabel($vbox, $loc->N("These packages come with upgrade information"), 1); + my $tree = $factory->createTree($vbox, $loc->N("Select a package")); + $factory->createVSpacing($vbox, 1); + my $infoBox = $factory->createRichText($vbox, "", 0); + $tree->setWeight($yui::YD_HORIZ, 2); + $infoBox->setWeight($yui::YD_HORIZ, 4); + $tree->setWeight($yui::YD_VERT, 10); + $infoBox->setWeight($yui::YD_VERT, 10); + $factory->createVSpacing($vbox, 1); + my $hbox = $factory->createHBox( $vbox ); + my $align = $factory->createHCenter($hbox); + my $okButton = $factory->createPushButton($align, $loc->N("Ok")); + $okButton->setDefaultButton(1); + + # adding packages to the list + my $itemColl = new yui::YItemCollection; + foreach my $f (sort keys %Readmes) { + my $item = new yui::YTreeItem ("$Readmes{$f}"); + my $child = new yui::YTreeItem ($item, "$f"); + $child->DISOWN(); + $itemColl->push($item); + $item->DISOWN(); + } + $tree->addItems($itemColl); + $tree->setImmediateMode(1); + + while(1) { + my $event = $dialog->waitForEvent(); + my $eventType = $event->eventType(); + + #event type checking + if ($eventType == $yui::YEvent::CancelEvent) { + last; + } + elsif ($eventType == $yui::YEvent::WidgetEvent) { + ### widget + my $widget = $event->widget(); + if ($widget == $tree) { + my $content = ""; + my $item = $tree->selectedItem(); + if ($item && !$item->hasChildren()) { + my $filename = $tree->currentItem()->label(); + $content = scalar MDK::Common::File::cat_($filename); + $content = $loc->N("(none)") if !$content; # should not happen + ensure_utf8($content); + $content =~ s/\n/
/g; + } + $infoBox->setValue($content); + } + elsif ($widget == $okButton) { + last; + } + } } + + destroy $dialog; + + # restore original title + yui::YUI::app()->setApplicationTitle($appTitle) if $appTitle; + + return; } sub perform_parallel_install { @@ -780,16 +835,16 @@ sub perform_installation { #- (partially) duplicated from /usr/sbin/urpmi :-( if ($subtype eq 'start') { if ($type eq 'trans') { print(1 ? $loc->N("Preparing package installation...") : $loc->N("Preparing package installation transaction...")); - # $gurpm->label(1 ? $loc->N("Preparing package installation...") : $loc->N("Preparing package installation transaction...")); + $gurpm->label($loc->N("Preparing package installation...")); } elsif (defined $pkg) { $something_installed = 1; print($loc->N("Installing package `%s' (%s/%s)...", $pkg->name, ++$transaction_progress_nb, scalar(@{$transaction->{upgrade}}))."\n" . $loc->N("Total: %s/%s", ++$progress_nb, $install_count)); - # $gurpm->label($loc->N("Installing package `%s' (%s/%s)...", $pkg->name, ++$transaction_progress_nb, scalar(@{$transaction->{upgrade}})) - # . "\n" . $loc->N("Total: %s/%s", ++$progress_nb, $install_count)); + $gurpm->label($loc->N("Installing package `%s' (%s/%s)...", $pkg->name, ++$transaction_progress_nb, scalar(@{$transaction->{upgrade}})) + . "\n" . $loc->N("Total: %s/%s", ++$progress_nb, $install_count)); } } elsif ($subtype eq 'progress') { $gurpm->progress($total ? ceil(($amount/$total)*100) : 100); - print("Progress: ".($total ? ($amount/$total)*100 : 100)."\n"); + # print("Progress: ".($total ? ($amount/$total)*100 : 100)."\n"); } }; @@ -909,7 +964,7 @@ you may now inspect some in order to take actions:"), %pkg2rpmnew) and statusbar_msg($loc->N("All requested packages were installed successfully."), 1); statusbar_msg($loc->N("Looking for \"README\" files..."), 1); - display_READMEs_if_needed($urpm, $w); + _display_READMEs_if_needed($urpm); }, already_installed_or_not_installable => sub { my ($msg1, $msg2) = @_; diff --git a/lib/AdminPanel/Rpmdragora/rpmnew.pm b/lib/AdminPanel/Rpmdragora/rpmnew.pm index 6ce912b..3ab242f 100644 --- a/lib/AdminPanel/Rpmdragora/rpmnew.pm +++ b/lib/AdminPanel/Rpmdragora/rpmnew.pm @@ -132,8 +132,8 @@ sub _performDiff ($$) { } my $diff = diff $file, $rpmnew, { STYLE => "Unified" }; - ensure_utf8($diff); $diff = $loc->N("(none)") if !$diff; + ensure_utf8($diff); $diff =~ s/\n/
/g; $diffBox->setValue($diff); @@ -171,8 +171,6 @@ sub rpmnew_dialog { my $sum_rpmnew = MDK::Common::Math::sum(map { int @{$p2r{$_}} } keys %p2r); $sum_rpmnew == 0 and return 1; - - ########################################################### my $appTitle = yui::YUI::app()->applicationTitle(); ## set new title to get it in dialog @@ -187,7 +185,7 @@ sub rpmnew_dialog { ## | info on selected pkg |(1) ## | Remove( ) Use ( ) Do nothing (*) | ## | | - ## | [cancel] [ok] | + ## | [ok] | #### # (1) info on pkg list: # selected configuration file diff between rpmnew/rpmsave and used one @@ -197,7 +195,7 @@ sub rpmnew_dialog { my $msgBox = $factory->createLabel($vbox, $msg, 1); $factory->createVSpacing($vbox, 1); # Tree for groups - my $tree = $factory->createTree($vbox, ""); + my $tree = $factory->createTree($vbox, $loc->N("Select a package")); $tree->setWeight($yui::YD_VERT,10); $factory->createVSpacing($vbox, 1); my $infoBox = $factory->createRichText($vbox, "", 0); @@ -211,51 +209,42 @@ sub rpmnew_dialog { use_rpmnew => $loc->N("Use new file"), do_onthing => $loc->N("Do nothing"), }; -# my %byActionRdnBtn = reverse %{$rdnBtn}; + my %radiobutton = (); my @rdnbtn_order = ('remove_rpmnew', 'use_rpmnew', 'do_onthing'); foreach my $btn_name (@rdnbtn_order) { $radiobutton{$btn_name} = $factory->createRadioButton($rbbox, $rdnBtn->{$btn_name}); + $radiobutton{$btn_name}->setValue(1) if $btn_name eq 'do_onthing'; $radiobutton{$btn_name}->setNotify(1); $radiobuttongroup->addRadioButton($radiobutton{$btn_name}); } $radiobuttongroup->setEnabled(0); my $hbox = $factory->createHBox( $vbox ); - my $align = $factory->createRight($hbox); - my $okButton = $factory->createPushButton($hbox, $loc->N("Ok")); + my $align = $factory->createHCenter($hbox); + my $okButton = $factory->createPushButton($align, $loc->N("Ok")); + $okButton->setDefaultButton(1); # adding packages to the list my $itemColl = new yui::YItemCollection; - my $num = 0; my %file_action = (); - foreach my $p (keys %p2r) { - my $item = new yui::YTreeItem ("$p", ($num==0)); - foreach my $f (@{$p2r{$p}}) { - my $child = new yui::YTreeItem ($item, "$f"); - $child->DISOWN(); - $file_action{$f} = 'do_onthing'; - if ($num == 0) { - $child->setSelected(1); - $num = 1; + foreach my $p (sort keys %p2r) { + if (scalar @{$p2r{$p}}) { + my $item = new yui::YTreeItem ("$p"); + foreach my $f (@{$p2r{$p}}) { + my $child = new yui::YTreeItem ($item, "$f"); + $child->DISOWN(); + $file_action{$f} = 'do_onthing'; } + $itemColl->push($item); + $item->DISOWN(); } - $itemColl->push($item); - $item->DISOWN(); } $tree->addItems($itemColl); $tree->setImmediateMode(1); $tree->rebuildTree(); - # show first diff occurence - my $filename = $tree->currentItem()->label(); - _performDiff($filename, $infoBox); - $radiobuttongroup->setEnabled(1); - yui::YUI::ui()->blockEvents(); - $radiobutton{$file_action{$filename}}->setValue(1); - yui::YUI::ui()->unblockEvents(); - while(1) { my $event = $dialog->waitForEvent(); my $eventType = $event->eventType(); @@ -271,7 +260,7 @@ sub rpmnew_dialog { #change info my $item = $tree->selectedItem(); if ($item && !$item->hasChildren()) { - $filename = $tree->currentItem()->label(); + my $filename = $tree->currentItem()->label(); _performDiff($filename, $infoBox); $radiobuttongroup->setEnabled(1); #$radiobuttongroup->uncheckOtherButtons ($radiobutton{$file_action{$filename}}); @@ -302,7 +291,7 @@ sub rpmnew_dialog { # radio buttons RDNBTN: foreach my $btn_name (@rdnbtn_order) { if ($widget == $radiobutton{$btn_name}) { - $filename = $tree->currentItem()->label(); + my $filename = $tree->currentItem()->label(); $file_action{$filename} = $btn_name; last RDNBTN; } -- cgit v1.2.1